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

calendarPlot: Jan and Dec plots are not proper #41

Open
Tanvi-Jain01 opened this issue Jun 21, 2023 · 2 comments
Open

calendarPlot: Jan and Dec plots are not proper #41

Tanvi-Jain01 opened this issue Jun 21, 2023 · 2 comments
Assignees
Labels
priority1 Priority Level 1

Comments

@Tanvi-Jain01
Copy link

Tanvi-Jain01 commented Jun 21, 2023

Jan and Dec plots aspect ratio is incorrect

While exploring this package I tried calendarPlot, and the plot for January and December was not correct. (The beginning days of Jan and Dec is wrong) Also, the plot for Jan and Dec is same, which isn't possible.

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
ws_values = np.random.rand(365)
wd_values = np.random.rand(365)


df = pd.DataFrame({
    'date': dates,
    'pm25': pm25_values,
    'ws': ws_values,
    'wd': wd_values
})

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

from vayu.calendarPlot  import calendarPlot
calendarPlot(df, 'pm25', '2022','India')`

Output:

calendar

Source Code:

vayu/vayu/calendarPlot.py

Lines 114 to 133 in ef99aef

while t <= 12:
avg_ws = []
avg_wd = []
avg_pm25 = []
df_year_1 = df_year[df_year.month == t]
avg_wd = df_year_1["wd"]
avg_ws = df_year_1["ws"]
avg_pm25 = df_year_1[pollutant]
i = 1
a = 0
b = len(avg_pm25)
while i <= 1:
data = avg_pm25[a:b]
num = len(data)
if t == 12:
start = dt.datetime(int(year), 1, 1)
else:
start = dt.datetime(int(year), t, 1)

Explaination:

while t <= 12:
           ...
     while i <= 1:
         ...
      if t == 12:
       start = dt.datetime(int(year), 1, 1)

Here, first 1 represents the month value, second 1 represents the day value.
In this case, month value is hardcoded as 1, indicating January for December plot,

Solution:

Hence, month value 1 should be replaced with t

Additionally, we don't require while i <= 1: this while loop, as we already have a parent while loop which is while t <= 12:

@patel-zeel
Copy link
Member

@Tanvi-Jain01 Please refer to this link: https://sustainability-lab.github.io/vayu/examples/nbs/calendarPlot.html

If there was an issue with the code, we should have seen the same issue in the above link. So, something else might also be the root cause.

@patel-zeel patel-zeel added the priority1 Priority Level 1 label Jul 9, 2023
@patel-zeel
Copy link
Member

@nipunbatra Here is another library with a nice calendar plot: july. @Tanvi-Jain01 We may adapt some features from there.

Two months plot Year Plot
image image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority1 Priority Level 1
Projects
None yet
Development

No branches or pull requests

2 participants