Skip to content

Commit

Permalink
modifying the code of googleMaps
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanvi-Jain01 committed Jun 30, 2023
1 parent d7d2e6b commit fd7c45c
Showing 1 changed file with 21 additions and 45 deletions.
66 changes: 21 additions & 45 deletions vayu/googleMaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ def googleMaps(df, lat, long, pollutant, dataLoc):
long: str
Name of column in df of where longitude points are
pollutant: str
Name of pollutant
dataLoc: str
Name of df column where pollutanat values are stored
Name of pollutant where values of that pollutant is stored.
date: str
visualizing the pollutant of a specific date.
markersize: int
The int by which the value of pollutant will be multiplied.
"""
import folium
Expand All @@ -26,56 +28,30 @@ def googleMaps(df, lat, long, pollutant, dataLoc):
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

latitude = 37.0902
longitude = -95.7129
Arithmetic_Mean_map = folium.Map(location=[latitude, longitude], zoom_start=4)

def googleMaps(df, lat, long, pollutant, date, markersize):
df1=df
print(date)
df1=df[df['date']==date]
print(df1)


# =============================================================================
# df = pd.read_csv('interpolData.csv')
# =============================================================================

some_value = pollutant
df = df.loc[df["Parameter Name"] == some_value]

some_value = "2018-05-07"
df = df.loc[df["Date Local"] == some_value]

df = df.sample(frac=1)
lat= df1[lat].values[0]
long=df1[long].values[0]
my_map4 = folium.Map(location = [lat, long], zoom_start = 10)

# df_train, df_test = train_test_split(df, test_size=0.2)
df["Arithmetic Mean Q"] = pd.qcut(df[dataLoc], 4, labels=False)
colordict = {0: "lightblue", 1: "lightgreen", 2: "orange", 3: "red"}
for lat,long,pol,st in zip(df['latitude'],df['longitude'],df[pollutant],df['station']):
folium.CircleMarker([lat, long],radius=markersize * pol, popup=(str(st).capitalize()+"<br>"+ str(round(pol, 3))), fill=True, fill_opacity=0.7, color = 'red').add_to(my_map4)

for lat, lon, Arithmetic_Mean_Q, Arithmetic_Mean, city, AQI in zip(
df[lat],
df[long],
df["Arithmetic Mean Q"],
df[dataLoc],
df["City Name"],
df["AQI"],
):
folium.CircleMarker(
[lat, lon],
radius=0.15 * AQI,
popup=(
"City: "
+ str(city).capitalize()
+ "<br>"
#'Bike score: ' + str(bike) + '<br>'
"Arithmetic_Mean level: "
+ str(Arithmetic_Mean)
+ "%"
),
color="b",
key_on=Arithmetic_Mean_Q,
threshold_scale=[0, 1, 2, 3],
fill_color=colordict[Arithmetic_Mean_Q],
fill=True,
fill_opacity=0.7,
).add_to(Arithmetic_Mean_map)
Arithmetic_Mean_map.save("mymap.html")
my_map4.save("googleMaps.html")
print('your map has been saved')


#Example
# df = pd.read_csv('interpolData.csv')
# googleMaps(df,'Latitude','Longitude','Ozone','Arithmetic Mean')

0 comments on commit fd7c45c

Please sign in to comment.