Skip to content
Suwi_Project
  • AI Chat
  • Code
  • Report
  • Spinner

    references: https://servicos.cetesb.sp.gov.br/qa/ DOWNLOAD DATAS https://matplotlib.org/stable/plot_types/basic/plot.html#sphx-glr-plot-types-basic-plot-py FOR GRAPHS https://www.alura.com.br/artigos/lidando-com-datas-e-horarios-no-python?gclid=Cj0KCQiAxbefBhDfARIsAL4XLRrcE88UQUe0M4dAkLOcnf6TfVN1Srl53BhKP7KZSxIO2RdBxRaO88kaAmc7EALw_wcB DATETIME https://vlsantos5938.medium.com/criando-mapas-meteorol%C3%B3gicos-interativos-usando-a-biblioteca-folium-5a95b4655924 FOLIUM

    Script that opens MP10 data by measurement stations in the city of são paulo: -calculates a monthly average and presents results in a graph -calculates the annual average that will be used to create the map

    import pandas as pd #Import the Pandas library
    from matplotlib import pyplot as plt #Import the matplotlib library
    import numpy as np #Import the numby library
    santoamaro = pd.read_csv('santoamaro.csv') #Open the csv of the Santo Amaro measuring station with the parameter MP10(Inhalable Paritciculas)
    
    AnualAve_santoamaro = santoamaro['Media Horaria'].mean() #Calculates the average of parameter MP10 for the entire time interval
    print(AnualAve_santoamaro) #Print average result
    
    santoamaro["Data"] = pd.to_datetime(santoamaro["Data"], dayfirst=True) # Convert date column to datetime
    
    MonthAve_santoamaro = santoamaro.groupby(santoamaro['Data'].dt.month)['Media Horaria'].mean() #Calculate the monthly average
    
    y = MonthAve_santoamaro #call 'x' from the monthly average
    x = np.array([1,2,3,4,5,6,7,8,9,10,11,12]) #call 'y' the months
    
    plt.bar(x,y) #creates the graph with the variables x and y
    plt.ylabel('Media de MP10/µg/m3') #legend the variable y
    plt.xlabel('Meses') #legend the variable x
    plt.title('Concentração Média do Poluente MP10 na estação de Santo Amaro, 2022') #creates a title
    
    plt.show() #show the graph
    pqdompedroii = pd.read_csv('pqdompedroii.csv') #Open the csv of the Parque dom Pedro II easuring station with the parameter MP10(Inhalable Paritciculas)
    
    AnualAve_pqdompedro = pqdompedroii['Media Horaria'].mean #Calculates the average of parameter MP10 for the entire time interval
    print(AnualAve_pqdompedro) #Print average result
    
    pqdompedroii["Data"] = pd.to_datetime(pqdompedroii["Data"], dayfirst=True) # Convert date column to datetime
    
    MonthAve_pqdompedro = pqdompedroii.groupby(pqdompedroii['Data'].dt.month)['Media Horaria'].mean() #Calculate the monthly average
    
    
    y = MonthAve_pqdompedro #call 'x' from the monthly average
    x = np.array([1,2,3,4,5,6,7,8,9,10,11,12])  #call 'y' the months
    
    plt.bar(x,y,)  #creates the graph with the variables x and y
    plt.ylabel('Media de MP10/µg/m3')#legend the variable y
    plt.xlabel('Meses') #legend the variable x
    plt.title('Concentração Média do Poluente MP10 na estação de Parque Dom Pedro II, 2022') #creates a title
    
    plt.show() #show the graph
    nsenhoradoo = pd.read_csv('nsenhoradoo.csv') #Abre o csv da estação de medição de Nossa Senhora do Ó com o parâmetro MP10(Paritciculas Inalaveis) #Open the csv of the Santo Amaro measuring station with the parameter MP10(Inhalable Paritciculas)
    
    AnualAve_nsenhoradoo = nsenhoradoo['Media Horaria'].mean()#Calculates the average of parameter MP10 for the entire time interval
    print(AnualAve_nsenhoradoo) #Print average result
    
    nsenhoradoo["Data"] = pd.to_datetime(nsenhoradoo["Data"], dayfirst=True) # Convert date column to datetime
    
    MonthAve_nsenhorado = nsenhoradoo.groupby(santoamaro['Data'].dt.month)['Media Horaria'].mean() #Calculate the monthly average
    
    
    y = MonthAve_nsenhorado #call 'x' from the monthly average
    x = np.array([1,2,3,4,5,6,7,8,9,10,11,12]) #call 'y' the months
    
    plt.bar(x,y,) #creates the graph with the variables x and y
    plt.ylabel('Media de MP10/µg/m3') #legend the variable y
    plt.xlabel('Meses') #legend the variable x
    plt.title('Concentração Média do Poluente MP10 na estação Nossa Senhora do O, 2022') #creates a title
    
    plt.show()#show the graph
    margtiete = pd.read_csv('marg_tiete_ptedosremedios.csv') #Open the csv of the MArginal Tiete easuring station with the parameter MP10(Inhalable Paritciculas)
    
    AnualAve_margtiete = margtiete['Media Horaria'].mean()  #Calculates the average of parameter MP10 for the entire time interval
    print(AnualAve_santoamaro) #Print average result
    
    
    margtiete["Data"] = pd.to_datetime(margtiete["Data"], dayfirst=True) # Convert date column to datetime
    
    
    MonthAve_margtiete = margtiete.groupby(margtiete['Data'].dt.month)['Media Horaria'].mean() #Calculate the monthly average
    
    y = MonthAve_margtiete #call 'x' from the monthly average
    x = np.array([1,2,3,4,5,6,7,8,9,10,11,12])  #call 'y' the months
    
    plt.bar(x,y,)  #creates the graph with the variables x and y
    plt.ylabel('Media de MP10/µg/m3') #legend the variable y
    plt.xlabel('Meses') #legend the variable x
    plt.title('Concentração Média do Poluente MP10 na estação de Marginal Tiete, 2022') #creates a title
    
    plt.show()#show the graph
    itaimpaulista = pd.read_csv('itaimpaulista.csv') #Open the csv of the Itaim PAulista easuring station with the parameter MP10(Inhalable Paritciculas)
    
    AnualAve_itaimpaulista = itaimpaulista['Media Horaria'].mean()#Calculates the average of parameter MP10 for the entire time interval
    print(AnualAve_itaimpaulista)  #Print average result
    
    itaimpaulista["Data"] = pd.to_datetime(margtiete["Data"], dayfirst=True)  # Convert date column to datetime
    
    MonthAve_itaimpaulista = itaimpaulista.groupby(santoamaro['Data'].dt.month)['Media Horaria'].mean()#Calculate the monthly average
    
    
    
    y = MonthAve_itaimpaulista #call 'y' from the monthly average
    x = np.array([1,2,3,4,5,6,7,8,9,10,11,12]) #call 'x' the months
    
    
    plt.bar(x,y,)   #creates the graph with the variables x and y
    plt.ylabel('Media de MP10/µg/m3') #legend the variable y
    plt.xlabel('Meses') #legend the variable x
    plt.title('Concentração Média do Poluente MP10 na estação de Itaim Paulista, 2022') #creates a title
    
    plt.show() #show the graph
    interlagos = pd.read_csv('interlagos.csv') #Open the csv of the Interlagos measuring station with the parameter MP10(Inhalable Paritciculas)
    
    AnualAve_interlagos = interlagos['Media Horaria'].mean() #Calculates the average of parameter MP10 for the entire time interval
    print(AnualAve_interlagos) #Print average result
    
    
    interlagos["Data"] = pd.to_datetime(margtiete["Data"], dayfirst=True) # Convert date column to datetime
    
    
    MonthAve_interlagos = interlagos.groupby(interlagos['Data'].dt.month)['Media Horaria'].mean() #Calculate the monthly average
    
    
    y = MonthAve_interlagos  #call 'y' from the monthly average
    x = np.array([1,2,3,4,5,6,7,8,9,10,11,12]) #call 'x' the months
    
    plt.bar(x,y,)  #creates the graph with the variables x and y
    plt.ylabel('Media de MP10/µg/m3') #legend the variable y
    plt.xlabel('Meses') #legend the variable x
    plt.title('Concentração Média do Poluente MP10 na estação de Interlagos, 2022')  #creates a title
    
    plt.show() #show the graph
    congonhas = pd.read_csv('congonhas.csv') #Open the csv of the Congonhaso measuring station with the parameter MP10(Inhalable Paritciculas)
    AnualAve_congonhas = congonhas['Media Horaria'].mean()#Calculates the average of parameter MP10 for the entire time interval
    print(AnualAve_congonhas) #Print average result
    
    congonhas["Data"] = pd.to_datetime(margtiete["Data"], dayfirst=True)# Convert date column to datetime
    
    
    MonthAve_congonhas = congonhas.groupby(congonhas['Data'].dt.month)['Media Horaria'].mean() #Calculate the monthly average
    
    
    
    
    y = MonthAve_congonhas #call 'y' from the monthly average
    x = np.array([1,2,3,4,5,6,7,8,9,10,11,12])  #call 'x' the months
    
    plt.bar(x,y,)  #creates the graph with the variables x and y
    plt.ylabel('Media de MP10/µg/m3') #legend the variable y
    plt.xlabel('Meses') #legend the variable x
    plt.title('Concentração Média do Poluente MP10 na estação de Congonhas, 2022') #creates a title
    
    
    plt.show()#show the graph
    capaoredondo = pd.read_csv('capaoredondo.csv') #Open the csv of the Capao Redondo measuring station with the parameter MP10(Inhalable Paritciculas)
    
    AnualAve_capaoredondo = capaoredondo['Media Horaria'].mean() #Calculates the average of parameter MP10 for the entire time interval
    print(AnualAve_capaoredondo) #Print average result
    
    
    capaoredondo["Data"] = pd.to_datetime(margtiete["Data"], dayfirst=True) # Convert date column to datetime
    
    MonthAve_capaoredondo = capaoredondo.groupby(capaoredondo['Data'].dt.month)['Media Horaria'].mean() #Calculate the monthly average
    
    
    y = MonthAve_capaoredondo #call 'y' from the monthly average
    x = np.array([1,2,3,4,5,6,7,8,9,10,11,12]) #call 'x' the months
    
    plt.bar(x,y)  #creates the graph with the variables x and y
    plt.ylabel('Media de MP10/µg/m3') #legend the variable y
    plt.xlabel('Meses') #legend the variable x
    plt.title('Concentração Média do Poluente MP10 na estação de Capão Redondo, 2022') #creates a title
    
    
    plt.show()#show the graph
    perus = pd.read_csv('perus.csv') #Open the csv of the Perus measuring station with the parameter MP10(Inhalable Paritciculas)
    
    AnualAve_perus = perus['Media Horaria'].mean() #Calculates the average of parameter MP10 for the entire time interval
    print(AnualAve_perus) #Print average result
    
    perus["Data"] = pd.to_datetime(perus["Data"], dayfirst=True) # Convert date column to datetime 
    
    MonthAve_perus = perus.groupby(perus['Data'].dt.month)['Media Horaria'].mean() #Calculate the monthly average
    
    
    y = MonthAve_perus #call 'y' from the monthly average
    x = np.array([1,2,3,4,5,6,7,8,9,10,11,12])  #call 'x' the months
    
    plt.bar(x,y,) #creates the graph with the variables x and y
    plt.ylabel('Media de MP10/µg/m3') #legend the variable y
    plt.xlabel('Meses') #legend the variable x
    plt.title('Concentração Média do Poluente MP10 na estação de Perus, 2022') #creates a title
    
    plt.show() #show the graph

    TRY TO CREATE A MAP OF THE ANUAL AVERAGE DISTRIBUTION OF MP10 IN THE CITY BY THE STATIONS DATAS.

    -csv has been created with the Anual Average and the Latitude and Longitude of the stations.

    -not concluded, error of show the points of the map...

    -not work in data camp(erro notebook file), but work kn the colab OPEN IN COLAB

    https://colab.research.google.com/drive/1UuLA1rl-rap7HsLfNhSya-eHff7PIJ0M#scrollTo=iKv1smaZiWgX&line=1&uniqifier=1

    import pandas as pd
    import matplotlib.pyplot as plt
    import numpy as np
    from matplotlib.colors import BoundaryNorm
    from scipy.interpolate import griddata  
    import numpy.ma as ma
    import folium
    from folium.plugins import HeatMap
    import branca.colormap as cm
    
    Filename= "cordenadasestacoes.csv" #create a variable to the file
    colnames = ['Estacao', 'Media Anual', 'Lat' ,'Lon'] #add title to columns
    dado=pd.read_csv(Filename, sep=';', names=colnames) #create a dataframe 
    
    nd = pd.DataFrame(dado, columns=['Lat', 'Lon', 'Media Anual']).groupby(['Lat','Lon'])['Media Anual'].sum().reset_index() #grophy the variables we want to show
    p = nd.loc[0:70]
    nnd = pd.DataFrame(dado,columns=['Lat', 'Lon'])
    nnw = nnd.loc[1:70].values.astype(float)
    
    Lat = p.Lat.tolist() #creates a list with the latitudes
    lon = p.Lon.tolist() #creates a list with the longotudelongitude 
    
    m = folium.Map(
        location=[-23, -46],
        tiles='Stamen Terrain',
        zoom_start=5.49
    ) #create a map with folium library, with locations, the mapa base, and the zoom to startes 
    #insert points in the map
    
    HeatMap(list(zip(Lat, lon))).add_to(m)
    
    # Add things in the map
    
    folium.TileLayer('Stamen Terrain').add_to(m) #add themala base
    folium.TileLayer('openstreetmap').add_to(m) #add mapa base
    folium.map.LayerControl('bottomright', collapsed=False, autoZIndex=True).add_to(m) #add control to the map
    # Criated legend 
    colormap = cm.LinearColormap(colors=['lightblue','green','yellow','red'],vmin=0,vmax=110) #add the color off tbe pointes with a buffer
    colormap.caption= ('Contracao Anual de MP10') #give a legend to the point
    colormap.add_to(m) #add the colormap defined to the map
    
    m #print the map
    

    -the idea is to download the data of other pollutants by station and create an input that would show the pollutant data by station and the distribution map in the city

    -for a better visualization of the map it would be necessary to interpolate the annual values ​​obtained by station, it is necessary to study more about

    so, continue.....:)