Meteorama commited on
Commit
f8d0241
·
verified ·
1 Parent(s): 15a1fa1

Upload 5 files

Browse files
Files changed (5) hide show
  1. README.md +4 -4
  2. app.py +257 -0
  3. gitattributes +35 -0
  4. requirements.txt +7 -0
  5. support_functions.py +263 -0
README.md CHANGED
@@ -1,10 +1,10 @@
1
  ---
2
  title: Tendaysforecast
3
- emoji: 👁
4
- colorFrom: red
5
- colorTo: gray
6
  sdk: streamlit
7
- sdk_version: 1.41.1
8
  app_file: app.py
9
  pinned: false
10
  ---
 
1
  ---
2
  title: Tendaysforecast
3
+ emoji: 👀
4
+ colorFrom: pink
5
+ colorTo: green
6
  sdk: streamlit
7
+ sdk_version: 1.31.1
8
  app_file: app.py
9
  pinned: false
10
  ---
app.py ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import plotly.express as px
3
+ import openmeteo_requests
4
+ import requests_cache
5
+ import pandas as pd
6
+ from retry_requests import retry
7
+ from datetime import datetime, timedelta
8
+ from support_functions import *
9
+ import numpy as np
10
+ from scipy import interpolate
11
+
12
+ #Page Configuration
13
+ st.set_page_config(initial_sidebar_state="collapsed", page_title='10 Days Forecast', menu_items={
14
+ 'Get Help': None,
15
+ 'Report a bug': None,
16
+ 'About': "Designed by Manaruchi Mohapatra"
17
+ })
18
+
19
+
20
+ st.header("Weather Forecast")
21
+
22
+ #Check for Lat Lon info and Get ECMWF Data
23
+ #Get Initial Configuration
24
+ url_params = st.query_params
25
+ url_params_keys = dict(url_params).keys()
26
+ if('lat' not in url_params_keys or 'lon' not in url_params_keys):
27
+ latvals = 22.47
28
+ lonvals = 70.05
29
+ st.info("Latitude and Longitude values not defined. Defaulting to Jamnagar...")
30
+ else:
31
+ latvals = float(url_params['lat'])
32
+ lonvals = float(url_params['lon'])
33
+
34
+ wxdata = get_ecmwf_data(latvals, lonvals)
35
+
36
+ #Get Dates list
37
+ start_date = datetime(wxdata['Year'].values[0], wxdata['Month'].values[0], wxdata['Day'].values[0])
38
+ end_date = start_date + timedelta(days=10)
39
+ st.caption(f"Time Period: {parseday(start_date)} to {parseday(end_date)}")
40
+
41
+ #Draw Tabs
42
+ tab1, tab2 = st.tabs(['Overall', 'Daily'])
43
+
44
+ #Min and Max temperature
45
+ min_max_date_list = []
46
+ min_max_min_list = []
47
+ min_max_max_list = []
48
+ for i in range(11):
49
+ cur_date = start_date + timedelta(days=i)
50
+ minidf = wxdata[(wxdata['Day'] == cur_date.day)&(wxdata['Month'] == cur_date.month)&(wxdata['Year'] == cur_date.year)]
51
+ min_max_date_list.append(cur_date)
52
+ min_max_min_list.append(minidf['temperature_2m'].min())
53
+ min_max_max_list.append(minidf['temperature_2m'].max())
54
+
55
+ min_max_df = pd.DataFrame()
56
+ min_max_df['Date'] = min_max_date_list
57
+ min_max_df['Minimum Temperature'] = min_max_min_list
58
+ min_max_df['Maximum Temperature'] = min_max_max_list
59
+
60
+ mintempfig = px.line(min_max_df, x = 'Date', y = 'Minimum Temperature')
61
+ maxtempfig = px.line(min_max_df, x = 'Date', y = 'Maximum Temperature')
62
+
63
+ with tab1.expander("Minimum and Maximum Temperature"):
64
+ st.plotly_chart(mintempfig, use_container_width = True)
65
+ st.plotly_chart(maxtempfig, use_container_width = True)
66
+
67
+ #temperature and inversion
68
+ #Temperature plot
69
+ tempfig = px.line(wxdata, x = 'Date_IST', y = 'temperature_2m', hover_data= 'temperature_925hPa',
70
+ labels = {'Date_IST': 'Date and Time', 'temperature_2m': 'Dry Bulb Temp', 'temperature_925hPa': 'Temp at F/L025'})
71
+
72
+ #Inversion
73
+ invlist = []
74
+ temp2mlist = wxdata['temperature_2m'].values
75
+ temp025list = wxdata['temperature_925hPa'].values
76
+
77
+ for t in range(len(temp2mlist)):
78
+ if((temp025list[t] - temp2mlist[t])>0):
79
+ invlist.append((temp025list[t] - temp2mlist[t]))
80
+ else:
81
+ invlist.append(0)
82
+
83
+ wxdata['Inversion'] = invlist
84
+ invfig = px.bar(wxdata, x='Date_IST', y='Inversion')
85
+
86
+
87
+ with tab1.expander("Temperature and Inversion"):
88
+ st.plotly_chart(tempfig, use_container_width = True)
89
+ st.plotly_chart(invfig, use_container_width = True)
90
+
91
+ #RH plot
92
+ rhfig = px.line(wxdata, x = 'Date_IST', y = 'relative_humidity_2m', labels = {'newdate': 'Date and Time', 'relative_humidity_2m': 'RH(%age)'})
93
+
94
+ with tab1.expander("Relative Humidity"):
95
+ st.plotly_chart(rhfig, use_container_width = True)
96
+
97
+ #Cloud Plots
98
+ cloudsfig = px.line(wxdata, x = 'Date_IST', y = 'cloud_cover', hover_data = ['cloud_cover_low', 'cloud_cover_mid', 'cloud_cover_high'],
99
+ labels = {'Date_IST': 'Date and Time', 'cloud_cover': 'Total Cloud Cover (%age)',
100
+ 'cloud_cover_low': 'Low Clouds',
101
+ 'cloud_cover_mid': 'Medium Clouds',
102
+ 'cloud_cover_high': 'High Clouds'})
103
+ cloudsfig.update_layout(yaxis_range=[0,100])
104
+ lowcloudsfig = px.line(wxdata, x = 'Date_IST', y = 'cloud_cover_low', hover_data = ['cloud_cover', 'cloud_cover_mid', 'cloud_cover_high'],
105
+ labels = {'Date_IST': 'Date and Time', 'cloud_cover': 'Total Cloud Cover (%age)',
106
+ 'cloud_cover_low': 'Low Clouds',
107
+ 'cloud_cover_mid': 'Medium Clouds',
108
+ 'cloud_cover_high': 'High Clouds'})
109
+ midcloudsfig = px.line(wxdata, x = 'Date_IST', y = 'cloud_cover_mid', hover_data = ['cloud_cover', 'cloud_cover_low', 'cloud_cover_high'],
110
+ labels = {'Date_IST': 'Date and Time', 'cloud_cover': 'Total Cloud Cover (%age)',
111
+ 'cloud_cover_low': 'Low Clouds',
112
+ 'cloud_cover_mid': 'Medium Clouds',
113
+ 'cloud_cover_high': 'High Clouds'})
114
+ highcloudsfig = px.line(wxdata, x = 'Date_IST', y = 'cloud_cover_high', hover_data = ['cloud_cover', 'cloud_cover_low', 'cloud_cover_mid'],
115
+ labels = {'Date_IST': 'Date and Time', 'cloud_cover': 'Total Cloud Cover (%age)',
116
+ 'cloud_cover_low': 'Low Clouds',
117
+ 'cloud_cover_mid': 'Medium Clouds',
118
+ 'cloud_cover_high': 'High Clouds'})
119
+ lowcloudsfig.update_layout(yaxis_range=[0,100])
120
+ midcloudsfig.update_layout(yaxis_range=[0,100])
121
+ highcloudsfig.update_layout(yaxis_range=[0,100])
122
+
123
+ with tab1.expander("Cloudiness"):
124
+ st.plotly_chart(cloudsfig, use_container_width = True)
125
+ st.plotly_chart(lowcloudsfig, use_container_width = True)
126
+ st.plotly_chart(midcloudsfig, use_container_width = True)
127
+ st.plotly_chart(highcloudsfig, use_container_width = True)
128
+
129
+ #precipitaion plot
130
+ pptfig = px.bar(wxdata, x = 'Date_IST', y = 'precipitation', labels = {'Date_IST': 'Date and Time', 'precipitation': 'Precipitation'})
131
+
132
+ with tab1.expander("Precipitation"):
133
+ st.plotly_chart(pptfig, use_container_width = True)
134
+
135
+ #pressure plot
136
+ qnhfig = px.line(wxdata, x = 'Date_IST', y = 'surface_pressure', labels = {'Date_IST': 'Date and Time', 'surface_pressure': 'QNH(hPa)'})
137
+ qnhfig.update_layout(yaxis_range=[995,1018])
138
+
139
+
140
+ with tab1.expander("Surface Pressure"):
141
+ st.plotly_chart(qnhfig, use_container_width = True)
142
+
143
+
144
+ #Daily Data
145
+ ds = tab2.slider(
146
+ "Forecast for ", start_date, end_date,
147
+ value=start_date,
148
+ format="DD MMM YY")
149
+
150
+ wxdata2 = wxdata[(wxdata['Day'] == ds.day)&(wxdata['Month'] == ds.month)&(wxdata['Year'] == ds.year)]
151
+
152
+ with tab2.expander("Current Weather Register"):
153
+ st.table(makecwr(wxdata2))
154
+
155
+
156
+ #temperature and inversion
157
+ #Temperature plot
158
+ tempfig = px.line(wxdata2, x = 'Date_IST', y = 'temperature_2m', hover_data= 'temperature_925hPa',
159
+ labels = {'Date_IST': 'Date and Time', 'temperature_2m': 'Dry Bulb Temp', 'temperature_925hPa': 'Temp at F/L025'})
160
+
161
+ #Inversion
162
+ invlist = []
163
+ temp2mlist = wxdata2['temperature_2m'].values
164
+ temp025list = wxdata2['temperature_925hPa'].values
165
+
166
+ for t in range(len(temp2mlist)):
167
+ if((temp025list[t] - temp2mlist[t])>0):
168
+ invlist.append((temp025list[t] - temp2mlist[t]))
169
+ else:
170
+ invlist.append(0)
171
+
172
+ wxdata2['Inversion'] = invlist
173
+ invfig = px.bar(wxdata2, x='Date_IST', y='Inversion')
174
+ invfig.update_layout(yaxis_range=[0,5])
175
+
176
+ with tab2.expander("Temperature and Inversion"):
177
+ st.plotly_chart(tempfig, use_container_width = True)
178
+ st.plotly_chart(invfig, use_container_width = True)
179
+
180
+ #RH plot
181
+ rhfig = px.line(wxdata2, x = 'Date_IST', y = 'relative_humidity_2m', labels = {'newdate': 'Date and Time', 'relative_humidity_2m': 'RH(%age)'})
182
+
183
+ with tab2.expander("Relative Humidity"):
184
+ st.plotly_chart(rhfig, use_container_width = True)
185
+
186
+ #Cloud Plots
187
+ cloudsfig = px.line(wxdata2, x = 'Date_IST', y = 'cloud_cover', hover_data = ['cloud_cover_low', 'cloud_cover_mid', 'cloud_cover_high'],
188
+ labels = {'Date_IST': 'Date and Time', 'cloud_cover': 'Total Cloud Cover (%age)',
189
+ 'cloud_cover_low': 'Low Clouds',
190
+ 'cloud_cover_mid': 'Medium Clouds',
191
+ 'cloud_cover_high': 'High Clouds'})
192
+ cloudsfig.update_layout(yaxis_range=[0,100])
193
+ lowcloudsfig = px.line(wxdata2, x = 'Date_IST', y = 'cloud_cover_low', hover_data = ['cloud_cover', 'cloud_cover_mid', 'cloud_cover_high'],
194
+ labels = {'Date_IST': 'Date and Time', 'cloud_cover': 'Total Cloud Cover (%age)',
195
+ 'cloud_cover_low': 'Low Clouds',
196
+ 'cloud_cover_mid': 'Medium Clouds',
197
+ 'cloud_cover_high': 'High Clouds'})
198
+ midcloudsfig = px.line(wxdata2, x = 'Date_IST', y = 'cloud_cover_mid', hover_data = ['cloud_cover', 'cloud_cover_low', 'cloud_cover_high'],
199
+ labels = {'Date_IST': 'Date and Time', 'cloud_cover': 'Total Cloud Cover (%age)',
200
+ 'cloud_cover_low': 'Low Clouds',
201
+ 'cloud_cover_mid': 'Medium Clouds',
202
+ 'cloud_cover_high': 'High Clouds'})
203
+ highcloudsfig = px.line(wxdata2, x = 'Date_IST', y = 'cloud_cover_high', hover_data = ['cloud_cover', 'cloud_cover_low', 'cloud_cover_mid'],
204
+ labels = {'Date_IST': 'Date and Time', 'cloud_cover': 'Total Cloud Cover (%age)',
205
+ 'cloud_cover_low': 'Low Clouds',
206
+ 'cloud_cover_mid': 'Medium Clouds',
207
+ 'cloud_cover_high': 'High Clouds'})
208
+ lowcloudsfig.update_layout(yaxis_range=[0,100])
209
+ midcloudsfig.update_layout(yaxis_range=[0,100])
210
+ highcloudsfig.update_layout(yaxis_range=[0,100])
211
+
212
+ with tab2.expander("Cloudiness"):
213
+ st.plotly_chart(cloudsfig, use_container_width = True)
214
+ st.plotly_chart(lowcloudsfig, use_container_width = True)
215
+ st.plotly_chart(midcloudsfig, use_container_width = True)
216
+ st.plotly_chart(highcloudsfig, use_container_width = True)
217
+
218
+ #pressure plot
219
+ qnhfig = px.line(wxdata2, x = 'Date_IST', y = 'surface_pressure', labels = {'Date_IST': 'Date and Time', 'surface_pressure': 'QNH(hPa)'})
220
+ qnhfig.update_layout(yaxis_range=[995,1018])
221
+
222
+
223
+ with tab2.expander("Surface Pressure"):
224
+ st.plotly_chart(qnhfig, use_container_width = True)
225
+
226
+ old_ht = [500,2500,5000,10000,18000,30000,35000,40000]
227
+ new_ht = [1000, 2000, 3000, 5000, 7000, 9000, 15000, 18000, 25000, 30000]
228
+ upper_air_df = pd.DataFrame()
229
+ upper_air_df['Height(KM)'] = [0.3,0.6,0.9,1.5,2.1,3.0,4.5,6.0,7.5,9.0][::-1]
230
+ #Upper Air Data
231
+ sel_times = tab2.multiselect("Select Time for Upper Air Data (IST)", wxdata2['Hour'].values, [5,11,17,23])
232
+ for sel_time in sel_times:
233
+ filter_df = wxdata2[wxdata2['Hour'] == sel_time]
234
+ wind_dir_list = []
235
+ wind_speed_list = []
236
+ temp_list = []
237
+ for level in ['200hPa', '250hPa', '300hPa', '500hPa', '700hPa', '850hPa', '925hPa', '1000hPa'][::-1]:
238
+ wind_dir_list.append(filter_df[f'winddirection_{level}'].values[0])
239
+ wind_speed_list.append(filter_df[f'windspeed_{level}'].values[0])
240
+ temp_list.append(int(filter_df[f'temperature_{level}'].values[0]))
241
+
242
+ new_wind_dir = interp_for_levels(old_ht, wind_dir_list, new_ht, is_wind_dir = True)[::-1]
243
+ new_wind_speed = interp_for_levels(old_ht, wind_speed_list, new_ht)[::-1]
244
+ new_temp = interp_for_levels(old_ht, temp_list, new_ht, round_to = 1)[::-1]
245
+
246
+ text_to_be_shown = []
247
+ for y in range(len(new_wind_dir)):
248
+ while(new_wind_dir[y]>360):
249
+ new_wind_dir[y] = new_wind_dir[y]-360
250
+ wwww = f"{new_wind_dir[y]:03d}/{new_wind_speed[y]:02d}({new_temp[y]:02d})"
251
+ text_to_be_shown.append(wwww)
252
+
253
+ upper_air_df[f"{sel_time:02d}:30Hr"] = text_to_be_shown
254
+
255
+ tab2.dataframe(upper_air_df, use_container_width=True)
256
+
257
+ st.success("Made by Manaruchi Mohapatra")
gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ openmeteo-requests
2
+ requests-cache
3
+ retry-requests
4
+ numpy
5
+ pandas
6
+ plotly
7
+ scipy
support_functions.py ADDED
@@ -0,0 +1,263 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openmeteo_requests
2
+ import requests_cache
3
+ import pandas as pd
4
+ from retry_requests import retry
5
+ from datetime import datetime, timedelta
6
+ import numpy as np
7
+ from scipy import interpolate
8
+
9
+ def get_ecmwf_data(lat, lon):
10
+
11
+ # Setup the Open-Meteo API client with cache and retry on error
12
+ cache_session = requests_cache.CachedSession('.cache', expire_after = 3600)
13
+ retry_session = retry(cache_session, retries = 5, backoff_factor = 0.2)
14
+ openmeteo = openmeteo_requests.Client(session = retry_session)
15
+
16
+ # Make sure all required weather variables are listed here
17
+ # The order of variables in hourly or daily is important to assign them correctly below
18
+ url = "https://api.open-meteo.com/v1/ecmwf"
19
+ params = {
20
+ "latitude": lat,
21
+ "longitude": lon,
22
+ "hourly": ["temperature_2m", "relative_humidity_2m", "dew_point_2m", "precipitation", "weather_code", "surface_pressure", "cloud_cover", "cloud_cover_low", "cloud_cover_mid", "cloud_cover_high", "wind_speed_10m", "wind_direction_10m", "wind_gusts_10m", "surface_temperature", "temperature_1000hPa", "temperature_925hPa", "temperature_850hPa", "temperature_700hPa", "temperature_500hPa", "temperature_300hPa", "temperature_250hPa", "temperature_200hPa", "temperature_50hPa", "relative_humidity_1000hPa", "relative_humidity_925hPa", "relative_humidity_850hPa", "relative_humidity_700hPa", "relative_humidity_500hPa", "relative_humidity_300hPa", "relative_humidity_250hPa", "relative_humidity_200hPa", "relative_humidity_50hPa", "windspeed_1000hPa", "windspeed_925hPa", "windspeed_850hPa", "windspeed_700hPa", "windspeed_500hPa", "windspeed_300hPa", "windspeed_250hPa", "windspeed_200hPa", "windspeed_50hPa", "winddirection_1000hPa", "winddirection_925hPa", "winddirection_850hPa", "winddirection_700hPa", "winddirection_500hPa", "winddirection_300hPa", "winddirection_250hPa", "winddirection_200hPa", "winddirection_50hPa"],
23
+ "wind_speed_unit": "kn"
24
+ }
25
+ responses = openmeteo.weather_api(url, params=params)
26
+
27
+ # Process first location. Add a for-loop for multiple locations or weather models
28
+ response = responses[0]
29
+
30
+ # Process hourly data. The order of variables needs to be the same as requested.
31
+ hourly = response.Hourly()
32
+ hourly_temperature_2m = hourly.Variables(0).ValuesAsNumpy()
33
+ hourly_relative_humidity_2m = hourly.Variables(1).ValuesAsNumpy()
34
+ hourly_dew_point_2m = hourly.Variables(2).ValuesAsNumpy()
35
+ hourly_precipitation = hourly.Variables(3).ValuesAsNumpy()
36
+ hourly_weather_code = hourly.Variables(4).ValuesAsNumpy()
37
+ hourly_surface_pressure = hourly.Variables(5).ValuesAsNumpy()
38
+ hourly_cloud_cover = hourly.Variables(6).ValuesAsNumpy()
39
+ hourly_cloud_cover_low = hourly.Variables(7).ValuesAsNumpy()
40
+ hourly_cloud_cover_mid = hourly.Variables(8).ValuesAsNumpy()
41
+ hourly_cloud_cover_high = hourly.Variables(9).ValuesAsNumpy()
42
+ hourly_wind_speed_10m = hourly.Variables(10).ValuesAsNumpy()
43
+ hourly_wind_direction_10m = hourly.Variables(11).ValuesAsNumpy()
44
+ hourly_wind_gusts_10m = hourly.Variables(12).ValuesAsNumpy()
45
+ hourly_surface_temperature = hourly.Variables(13).ValuesAsNumpy()
46
+ hourly_temperature_1000hPa = hourly.Variables(14).ValuesAsNumpy()
47
+ hourly_temperature_925hPa = hourly.Variables(15).ValuesAsNumpy()
48
+ hourly_temperature_850hPa = hourly.Variables(16).ValuesAsNumpy()
49
+ hourly_temperature_700hPa = hourly.Variables(17).ValuesAsNumpy()
50
+ hourly_temperature_500hPa = hourly.Variables(18).ValuesAsNumpy()
51
+ hourly_temperature_300hPa = hourly.Variables(19).ValuesAsNumpy()
52
+ hourly_temperature_250hPa = hourly.Variables(20).ValuesAsNumpy()
53
+ hourly_temperature_200hPa = hourly.Variables(21).ValuesAsNumpy()
54
+ #hourly_temperature_50hPa = hourly.Variables(22).ValuesAsNumpy()
55
+ hourly_relative_humidity_1000hPa = hourly.Variables(23).ValuesAsNumpy()
56
+ hourly_relative_humidity_925hPa = hourly.Variables(24).ValuesAsNumpy()
57
+ hourly_relative_humidity_850hPa = hourly.Variables(25).ValuesAsNumpy()
58
+ hourly_relative_humidity_700hPa = hourly.Variables(26).ValuesAsNumpy()
59
+ hourly_relative_humidity_500hPa = hourly.Variables(27).ValuesAsNumpy()
60
+ hourly_relative_humidity_300hPa = hourly.Variables(28).ValuesAsNumpy()
61
+ hourly_relative_humidity_250hPa = hourly.Variables(29).ValuesAsNumpy()
62
+ hourly_relative_humidity_200hPa = hourly.Variables(30).ValuesAsNumpy()
63
+ #hourly_relative_humidity_50hPa = hourly.Variables(31).ValuesAsNumpy()
64
+ hourly_windspeed_1000hPa = hourly.Variables(32).ValuesAsNumpy()
65
+ hourly_windspeed_925hPa = hourly.Variables(33).ValuesAsNumpy()
66
+ hourly_windspeed_850hPa = hourly.Variables(34).ValuesAsNumpy()
67
+ hourly_windspeed_700hPa = hourly.Variables(35).ValuesAsNumpy()
68
+ hourly_windspeed_500hPa = hourly.Variables(36).ValuesAsNumpy()
69
+ hourly_windspeed_300hPa = hourly.Variables(37).ValuesAsNumpy()
70
+ hourly_windspeed_250hPa = hourly.Variables(38).ValuesAsNumpy()
71
+ hourly_windspeed_200hPa = hourly.Variables(39).ValuesAsNumpy()
72
+ #hourly_windspeed_50hPa = hourly.Variables(40).ValuesAsNumpy()
73
+ hourly_winddirection_1000hPa = hourly.Variables(41).ValuesAsNumpy()
74
+ hourly_winddirection_925hPa = hourly.Variables(42).ValuesAsNumpy()
75
+ hourly_winddirection_850hPa = hourly.Variables(43).ValuesAsNumpy()
76
+ hourly_winddirection_700hPa = hourly.Variables(44).ValuesAsNumpy()
77
+ hourly_winddirection_500hPa = hourly.Variables(45).ValuesAsNumpy()
78
+ hourly_winddirection_300hPa = hourly.Variables(46).ValuesAsNumpy()
79
+ hourly_winddirection_250hPa = hourly.Variables(47).ValuesAsNumpy()
80
+ hourly_winddirection_200hPa = hourly.Variables(48).ValuesAsNumpy()
81
+ #hourly_winddirection_50hPa = hourly.Variables(49).ValuesAsNumpy()
82
+
83
+ hourly_data = {"date": pd.date_range(
84
+ start = pd.to_datetime(hourly.Time(), unit = "s", utc = True),
85
+ end = pd.to_datetime(hourly.TimeEnd(), unit = "s", utc = True),
86
+ freq = pd.Timedelta(seconds = hourly.Interval()),
87
+ inclusive = "left"
88
+ )}
89
+
90
+ d_vals, m_vals, y_vals, h_vals, date_vals = [],[],[],[], []
91
+ for d in hourly_data['date'].values:
92
+ cur_date = pd.Timestamp(d)
93
+ cur_date_ist = cur_date + timedelta(hours=5, minutes=30)
94
+ date_vals.append(cur_date_ist)
95
+ d_vals.append(cur_date_ist.day)
96
+ m_vals.append(cur_date_ist.month)
97
+ y_vals.append(cur_date_ist.year)
98
+ h_vals.append(cur_date_ist.hour)
99
+
100
+ hourly_data['Date_IST'] = date_vals
101
+ hourly_data['Day'] = d_vals
102
+ hourly_data['Month'] = m_vals
103
+ hourly_data['Year'] = y_vals
104
+ hourly_data['Hour'] = h_vals
105
+ hourly_data["temperature_2m"] = hourly_temperature_2m
106
+ hourly_data["relative_humidity_2m"] = hourly_relative_humidity_2m
107
+ hourly_data["dew_point_2m"] = hourly_dew_point_2m
108
+ hourly_data["precipitation"] = hourly_precipitation
109
+ hourly_data["weather_code"] = hourly_weather_code
110
+ hourly_data["surface_pressure"] = hourly_surface_pressure
111
+ hourly_data["cloud_cover"] = hourly_cloud_cover
112
+ hourly_data["cloud_cover_low"] = hourly_cloud_cover_low
113
+ hourly_data["cloud_cover_mid"] = hourly_cloud_cover_mid
114
+ hourly_data["cloud_cover_high"] = hourly_cloud_cover_high
115
+ hourly_data["wind_speed_10m"] = hourly_wind_speed_10m
116
+ hourly_data["wind_direction_10m"] = hourly_wind_direction_10m
117
+ hourly_data["wind_gusts_10m"] = hourly_wind_gusts_10m
118
+ hourly_data["surface_temperature"] = hourly_surface_temperature
119
+ hourly_data["temperature_1000hPa"] = hourly_temperature_1000hPa
120
+ hourly_data["temperature_925hPa"] = hourly_temperature_925hPa
121
+ hourly_data["temperature_850hPa"] = hourly_temperature_850hPa
122
+ hourly_data["temperature_700hPa"] = hourly_temperature_700hPa
123
+ hourly_data["temperature_500hPa"] = hourly_temperature_500hPa
124
+ hourly_data["temperature_300hPa"] = hourly_temperature_300hPa
125
+ hourly_data["temperature_250hPa"] = hourly_temperature_250hPa
126
+ hourly_data["temperature_200hPa"] = hourly_temperature_200hPa
127
+ #hourly_data["temperature_50hPa"] = hourly_temperature_50hPa
128
+ hourly_data["relative_humidity_1000hPa"] = hourly_relative_humidity_1000hPa
129
+ hourly_data["relative_humidity_925hPa"] = hourly_relative_humidity_925hPa
130
+ hourly_data["relative_humidity_850hPa"] = hourly_relative_humidity_850hPa
131
+ hourly_data["relative_humidity_700hPa"] = hourly_relative_humidity_700hPa
132
+ hourly_data["relative_humidity_500hPa"] = hourly_relative_humidity_500hPa
133
+ hourly_data["relative_humidity_300hPa"] = hourly_relative_humidity_300hPa
134
+ hourly_data["relative_humidity_250hPa"] = hourly_relative_humidity_250hPa
135
+ hourly_data["relative_humidity_200hPa"] = hourly_relative_humidity_200hPa
136
+ #hourly_data["relative_humidity_50hPa"] = hourly_relative_humidity_50hPa
137
+ hourly_data["windspeed_1000hPa"] = hourly_windspeed_1000hPa
138
+ hourly_data["windspeed_925hPa"] = hourly_windspeed_925hPa
139
+ hourly_data["windspeed_850hPa"] = hourly_windspeed_850hPa
140
+ hourly_data["windspeed_700hPa"] = hourly_windspeed_700hPa
141
+ hourly_data["windspeed_500hPa"] = hourly_windspeed_500hPa
142
+ hourly_data["windspeed_300hPa"] = hourly_windspeed_300hPa
143
+ hourly_data["windspeed_250hPa"] = hourly_windspeed_250hPa
144
+ hourly_data["windspeed_200hPa"] = hourly_windspeed_200hPa
145
+ #hourly_data["windspeed_50hPa"] = hourly_windspeed_50hPa
146
+ hourly_data["winddirection_1000hPa"] = hourly_winddirection_1000hPa
147
+ hourly_data["winddirection_925hPa"] = hourly_winddirection_925hPa
148
+ hourly_data["winddirection_850hPa"] = hourly_winddirection_850hPa
149
+ hourly_data["winddirection_700hPa"] = hourly_winddirection_700hPa
150
+ hourly_data["winddirection_500hPa"] = hourly_winddirection_500hPa
151
+ hourly_data["winddirection_300hPa"] = hourly_winddirection_300hPa
152
+ hourly_data["winddirection_250hPa"] = hourly_winddirection_250hPa
153
+ hourly_data["winddirection_200hPa"] = hourly_winddirection_200hPa
154
+ #hourly_data["winddirection_50hPa"] = hourly_winddirection_50hPa
155
+
156
+ hourly_dataframe = pd.DataFrame(data = hourly_data, index = None)
157
+ hourly_dataframe = hourly_dataframe.drop('date', axis = 1)
158
+ return hourly_dataframe
159
+
160
+ def wxcode_to_text(w):
161
+ if(w==0): return "SKC"
162
+ elif(w==1): return "Mainly Clear"
163
+ elif(w==2): return "Partly Cloudy"
164
+ elif(w==3): return "Overcast"
165
+ elif(w==45): return "Fog"
166
+ elif(w==48): return "Depositing Rime Fog"
167
+ elif(w==51): return "Light Drizzle"
168
+ elif(w==53): return "Moderate Drizzle"
169
+ elif(w==55): return "Dense Drizzle"
170
+ elif(w==56): return "Light Freezing Drizzle"
171
+ elif(w==57): return "Dense Freezing Drizzle"
172
+ elif(w==61): return "Slight Rain"
173
+ elif(w==63): return "Moderate Rain"
174
+ elif(w==65): return "Heavy Rain"
175
+ elif(w==66): return "Light Freezing Rain"
176
+ elif(w==67): return "Heavy Freezing Rain"
177
+ elif(w==71): return "Slight Snowfall"
178
+
179
+ def extractdateforcwr(d):
180
+ d = pd.Timestamp(d)
181
+ day, month, year, hour = d.day, d.month, d.year, d.hour
182
+ mtext = "Jan"
183
+ if(month == 1): mtext = "Jan"
184
+ elif(month == 2): mtext = "Feb"
185
+ elif(month == 3): mtext = "Mar"
186
+ elif(month == 4): mtext = "Apr"
187
+ elif(month == 5): mtext = "May"
188
+ elif(month == 6): mtext = "Jun"
189
+ elif(month == 7): mtext = "Jul"
190
+ elif(month == 8): mtext = "Aug"
191
+ elif(month == 9): mtext = "Sep"
192
+ elif(month == 10): mtext = "Oct"
193
+ elif(month == 11): mtext = "Nov"
194
+ elif(month == 12): mtext = "Dec"
195
+ else: mtext = "NA"
196
+
197
+ #GMT + 5:30
198
+ new_time_local = datetime(year, month, day, hour)
199
+ return f"{day:02d} {mtext} {str(year)[2:]} {new_time_local.hour:02d}{new_time_local.minute:02d}"
200
+
201
+ def parseday(d):
202
+ d = pd.Timestamp(d)
203
+ day, month, year, hour = d.day, d.month, d.year, d.hour
204
+ mtext = "Jan"
205
+ if(month == 1): mtext = "Jan"
206
+ elif(month == 2): mtext = "Feb"
207
+ elif(month == 3): mtext = "Mar"
208
+ elif(month == 4): mtext = "Apr"
209
+ elif(month == 5): mtext = "May"
210
+ elif(month == 6): mtext = "Jun"
211
+ elif(month == 7): mtext = "Jul"
212
+ elif(month == 8): mtext = "Aug"
213
+ elif(month == 9): mtext = "Sep"
214
+ elif(month == 10): mtext = "Oct"
215
+ elif(month == 11): mtext = "Nov"
216
+ elif(month == 12): mtext = "Dec"
217
+ else: mtext = "NA"
218
+
219
+ #GMT + 5:30
220
+ new_time_local = datetime(year, month, day, hour) + timedelta(hours = 5, minutes = 30)
221
+ return f"{day:02d} {mtext} {str(year)[2:]}"
222
+
223
+ def makecwr(df):
224
+ finaldf = pd.DataFrame()
225
+ finaldf['Time'] = [extractdateforcwr(x) for x in df['Date_IST'].values]
226
+ finaldf['DDD'] = [f"{int((x//10)*10):03d}" for x in df['wind_direction_10m'].values]
227
+ finaldf['ff'] = [f"{int(x):02d}" for x in df['wind_speed_10m'].values]
228
+ finaldf['Wx'] = [wxcode_to_text(x) for x in df['weather_code'].values]
229
+ finaldf['DB'] = [round(float(x),2) for x in df['temperature_2m'].values]
230
+ finaldf['DP'] = [round(x,2) for x in df['dew_point_2m'].values]
231
+ finaldf['RH'] = [int(x) for x in df['relative_humidity_2m'].values]
232
+ finaldf['Cloud Total'] = [int(x/12.5) for x in df['cloud_cover'].values]
233
+ finaldf['QNH'] = [int(p) for p in df['surface_pressure'].values]
234
+ return finaldf
235
+
236
+ def myround(x, base=5):
237
+ x = int(x)
238
+ return base * round(x/base)
239
+
240
+ def interp_for_levels(ht, vals, new_ht, is_wind_dir = False, round_to=5):
241
+ if(is_wind_dir):
242
+ wrapped_winds = np.unwrap(vals, period=360)
243
+ f = interpolate.interp1d(ht, wrapped_winds ,kind="slinear")
244
+ interpolated_vals = f(new_ht)
245
+ actual_vals = []
246
+ rounded_vals = []
247
+ for w in interpolated_vals:
248
+ if(w<0):
249
+ actual_vals.append(w+360)
250
+ else:
251
+ actual_vals.append(w)
252
+ for v in actual_vals:
253
+ x = int(v)
254
+ rounded_vals.append(10 * round(x/10))
255
+ return rounded_vals
256
+ else:
257
+ f = interpolate.interp1d(ht, vals ,kind="slinear")
258
+ interpolated_vals = f(new_ht)
259
+ rounded_vals = []
260
+ for v in interpolated_vals:
261
+ x = int(v)
262
+ rounded_vals.append(round_to * round(x/round_to))
263
+ return rounded_vals