Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

googleMaps Issue #38

Open
Tanvi-Jain01 opened this issue Jun 17, 2023 · 0 comments
Open

googleMaps Issue #38

Tanvi-Jain01 opened this issue Jun 17, 2023 · 0 comments

Comments

@Tanvi-Jain01
Copy link

Tanvi-Jain01 commented Jun 17, 2023

@nipunbatra , @patel-zeel

Bug:

Expecting Parameter Name column for pollutant name in the code.(It expects a column filled with pollutant name.)

Code:

import numpy as np
import pandas as pd
np.random.seed(42)  

start_date = pd.to_datetime('2022-01-01')
end_date = pd.to_datetime('2022-12-31')

dates = pd.date_range(start_date, end_date)

pm25_values = np.random.rand(365)  # Generate 365 random values
lat_values = np.random.rand(365)
lon_values = np.random.rand(365)


df = pd.DataFrame({
    'date': dates,
    'pm25': pm25_values,
    'latitude': lat_values,
    'longitude': lon_values
})

df['date'] = df['date'].dt.strftime('%Y-%m-%d')  # Convert date format to 'YYYY-MM-DD'

print(df)
from vayu.googleMaps  import googleMaps
googleMaps(df, 'latitude', 'longitude', 'pm25', '2022-02-23')

Error:

KeyError                                  Traceback (most recent call last)
File ~\anaconda3\lib\site-packages\pandas\core\indexes\base.py:3802, in Index.get_loc(self, key, method, tolerance)
   3801 try:
-> 3802     return self._engine.get_loc(casted_key)
   3803 except KeyError as err:

File ~\anaconda3\lib\site-packages\pandas\_libs\index.pyx:138, in pandas._libs.index.IndexEngine.get_loc()

File ~\anaconda3\lib\site-packages\pandas\_libs\index.pyx:165, in pandas._libs.index.IndexEngine.get_loc()

File pandas\_libs\hashtable_class_helper.pxi:5745, in pandas._libs.hashtable.PyObjectHashTable.get_item()

File pandas\_libs\hashtable_class_helper.pxi:5753, in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'Parameter Name'

The above exception was the direct cause of the following exception:

KeyError                                  Traceback (most recent call last)
Cell In[5], line 4
      1 from vayu.googleMaps  import googleMaps
      2 #print(df)
----> 4 googleMaps(df, 'latitude', 'longitude', 'pm25', '2022-02-23')

File ~\anaconda3\lib\site-packages\vayu\googleMaps.py:39, in googleMaps(df, lat, long, pollutant, dataLoc)
     34 # =============================================================================
     35 # df = pd.read_csv('interpolData.csv')
     36 # =============================================================================
     38 some_value = pollutant
---> 39 df = df.loc[df["Parameter Name"] == some_value]
     41 some_value = "2018-05-07"
     42 df = df.loc[df["Date Local"] == some_value]

File ~\anaconda3\lib\site-packages\pandas\core\frame.py:3807, in DataFrame.__getitem__(self, key)
   3805 if self.columns.nlevels > 1:
   3806     return self._getitem_multilevel(key)
-> 3807 indexer = self.columns.get_loc(key)
   3808 if is_integer(indexer):
   3809     indexer = [indexer]

File ~\anaconda3\lib\site-packages\pandas\core\indexes\base.py:3804, in Index.get_loc(self, key, method, tolerance)
   3802     return self._engine.get_loc(casted_key)
   3803 except KeyError as err:
-> 3804     raise KeyError(key) from err
   3805 except TypeError:
   3806     # If we have a listlike key, _check_indexing_error will raise
   3807     #  InvalidIndexError. Otherwise we fall through and re-raise
   3808     #  the TypeError.
   3809     self._check_indexing_error(key)

KeyError: 'Parameter Name'

Issue-1:

Source Code:

vayu/vayu/googleMaps.py

Lines 38 to 39 in ef99aef

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

It expects a whole column filled with pm25 or any pollutant name like:

      Parameter Name
        pm25
        pm25
        pm25
        ....

The above isn't possible and feasible in any quality dataset.

The ideal pollutant column in any dataset looks like below:

        pm25
        16.24
        12.345
        134.21
        ....

Hence dataloc parameter should be removed from the signature.

vayu/vayu/googleMaps.py

Lines 17 to 21 in ef99aef

pollutant: str
Name of pollutant
dataLoc: str
Name of df column where pollutanat values are stored

Reason:

As pollutant attribute will also contain the value for it, hence we do not require to take another parameter for it which is dataloc the alone pollutant will contain Name of pollutant and Name of df column where pollutant values are stored

Solution:

Considering the above reasons in mind, dataloc as a parameter should be removed from the method signature.
The new method signature should look like:

       def googleMaps(df, lat, long, pollutant):

Issue-2: Allowing user-provided date in the code instead of a predefined date

Source Code:

vayu/vayu/googleMaps.py

Lines 41 to 42 in ef99aef

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

Here, date is hardcoded as 2018-05-07 which should be taken from user.
Further more, in other plots(timePlot, calendarPlot etc.) the column name is date in source code and here is Date Local which can create confusion to the user, hence it should be date

Solution:

def googleMaps(df, lat, long, pollutant, date)
          .....
        .........
 some_value = date
 df = df.loc[df['date'] == some_value] 
            .........

For which the new method signature should look like:
def googleMaps(df, lat, long, pollutant, date)
Considering above reasons, removing dataloc with date as parameter of function should be more feasible.

Example:

def googleMaps(df, lat, long, pollutant, date):
    df1=df
    print(date)
    df1=df[df['date']==date]
    print(df1)
    
    #colordict = {45: "lightblue", 100: "lightgreen", 150: "orange", 200: "red"}
    
    lat= 28.815329  
    long=77.153010
    my_map4 = folium.Map(location = [lat, long], zoom_start = 10)
   #df['station']  should be the name of the place/air station
    for lat,long,pol,st in zip(df['latitude'],df['longitude'],df[pollutant],df['station']):
        

        folium.CircleMarker([lat, long],radius=0.01 * pol, popup=(str(st).capitalize()+"<br>"+ str(pol)), fill=True, fill_opacity=0.7, color = 'red').add_to(my_map4)
      
    
    my_map4.save("googleMaps.html")
    print('your map has been saved')
    
googleMaps(df, 'latitude', 'longitude', 'pm25', '2022-02-23')

Output:

googlemap
Tanvi-Jain01 added a commit to Tanvi-Jain01/vayu that referenced this issue Jun 30, 2023
This was referenced Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant