File size: 12,143 Bytes
f8d0241
 
 
 
 
 
 
 
 
 
 
 
8741be4
f8d0241
 
8ca56f2
f8d0241
 
 
8ca56f2
 
bc5d4ee
f8d0241
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c650c6
f8d0241
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8741be4
f8d0241
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bc5d4ee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
import streamlit as st
import plotly.express as px
import openmeteo_requests
import requests_cache
import pandas as pd
from retry_requests import retry
from datetime import datetime, timedelta
from support_functions import *
import numpy as np
from scipy import interpolate

#Page Configuration
st.set_page_config(initial_sidebar_state="collapsed", page_title='10 Days Forecast', menu_items={
        'Get Help': None,
        'Report a bug': None,
        'About': "Designed by Meteorama"
    })


st.header("Meteorama")

st.header("10 Days Weather Forecast")

#Check for Lat Lon info and Get ECMWF Data
#Get Initial Configuration
url_params = st.query_params
url_params_keys = dict(url_params).keys()
if('lat' not in url_params_keys or 'lon' not in url_params_keys):
    latvals = 22.47
    lonvals = 70.05
    st.info("Latitude and Longitude values not defined. Defaulting to Jamnagar...")
else:
    latvals = float(url_params['lat'])
    lonvals = float(url_params['lon'])

wxdata = get_ecmwf_data(latvals, lonvals)

#Get Dates list
start_date = datetime(wxdata['Year'].values[0], wxdata['Month'].values[0], wxdata['Day'].values[0])
end_date = start_date + timedelta(days=10)
st.caption(f"Time Period: {parseday(start_date)} to {parseday(end_date)}")

#Draw Tabs
tab1, tab2 = st.tabs(['Overall', 'Daily'])

#Min and Max temperature
min_max_date_list = []
min_max_min_list = []
min_max_max_list = []
for i in range(11):
    cur_date = start_date + timedelta(days=i)
    minidf = wxdata[(wxdata['Day'] == cur_date.day)&(wxdata['Month'] == cur_date.month)&(wxdata['Year'] == cur_date.year)]
    min_max_date_list.append(cur_date)
    min_max_min_list.append(minidf['temperature_2m'].min())
    min_max_max_list.append(minidf['temperature_2m'].max())

min_max_df = pd.DataFrame()
min_max_df['Date'] = min_max_date_list
min_max_df['Minimum Temperature'] = min_max_min_list
min_max_df['Maximum Temperature'] = min_max_max_list

mintempfig = px.line(min_max_df, x = 'Date', y = 'Minimum Temperature')
maxtempfig = px.line(min_max_df, x = 'Date', y = 'Maximum Temperature')

with tab1.expander("Minimum and Maximum Temperature"):
    st.plotly_chart(mintempfig, use_container_width = True)
    st.plotly_chart(maxtempfig, use_container_width = True)

#temperature and inversion
#Temperature plot
tempfig = px.line(wxdata, x = 'Date_IST', y = 'temperature_2m', hover_data= 'temperature_925hPa',
                    labels = {'Date_IST': 'Date and Time', 'temperature_2m': 'Dry Bulb Temp', 'temperature_925hPa': 'Temp at F/L025'})

#Inversion
invlist = []
temp2mlist = wxdata['temperature_2m'].values
temp025list = wxdata['temperature_925hPa'].values

for t in range(len(temp2mlist)):
    if((temp025list[t] - temp2mlist[t])>0):
        invlist.append((temp025list[t] - temp2mlist[t]))
    else:
        invlist.append(0)

wxdata['Inversion'] = invlist
invfig = px.bar(wxdata, x='Date_IST', y='Inversion')


with tab1.expander("Temperature and Inversion"):
    st.plotly_chart(tempfig, use_container_width = True)
    st.plotly_chart(invfig, use_container_width = True)

#RH plot
rhfig = px.line(wxdata, x = 'Date_IST', y = 'relative_humidity_2m', labels = {'newdate': 'Date and Time', 'relative_humidity_2m': 'RH(%age)'})

with tab1.expander("Relative Humidity"):
    st.plotly_chart(rhfig, use_container_width = True)

#Cloud Plots
cloudsfig = px.line(wxdata, x = 'Date_IST', y = 'cloud_cover', hover_data = ['cloud_cover_low', 'cloud_cover_mid', 'cloud_cover_high'],
                labels = {'Date_IST': 'Date and Time', 'cloud_cover': 'Total Cloud Cover (%age)',
                                                        'cloud_cover_low': 'Low Clouds',
                                                        'cloud_cover_mid': 'Medium Clouds',
                                                        'cloud_cover_high': 'High Clouds'})
cloudsfig.update_layout(yaxis_range=[0,100])
lowcloudsfig = px.line(wxdata, x = 'Date_IST', y = 'cloud_cover_low', hover_data = ['cloud_cover', 'cloud_cover_mid', 'cloud_cover_high'],
                labels = {'Date_IST': 'Date and Time', 'cloud_cover': 'Total Cloud Cover (%age)',
                                                        'cloud_cover_low': 'Low Clouds',
                                                        'cloud_cover_mid': 'Medium Clouds',
                                                        'cloud_cover_high': 'High Clouds'})
midcloudsfig = px.line(wxdata, x = 'Date_IST', y = 'cloud_cover_mid', hover_data = ['cloud_cover', 'cloud_cover_low', 'cloud_cover_high'],
                labels = {'Date_IST': 'Date and Time', 'cloud_cover': 'Total Cloud Cover (%age)',
                                                        'cloud_cover_low': 'Low Clouds',
                                                        'cloud_cover_mid': 'Medium Clouds',
                                                        'cloud_cover_high': 'High Clouds'})
highcloudsfig = px.line(wxdata, x = 'Date_IST', y = 'cloud_cover_high', hover_data = ['cloud_cover', 'cloud_cover_low', 'cloud_cover_mid'],
                labels = {'Date_IST': 'Date and Time', 'cloud_cover': 'Total Cloud Cover (%age)',
                                                        'cloud_cover_low': 'Low Clouds',
                                                        'cloud_cover_mid': 'Medium Clouds',
                                                        'cloud_cover_high': 'High Clouds'})
lowcloudsfig.update_layout(yaxis_range=[0,100])
midcloudsfig.update_layout(yaxis_range=[0,100])
highcloudsfig.update_layout(yaxis_range=[0,100])

with tab1.expander("Cloudiness"):
    st.plotly_chart(cloudsfig, use_container_width = True)
    st.plotly_chart(lowcloudsfig, use_container_width = True)
    st.plotly_chart(midcloudsfig, use_container_width = True)
    st.plotly_chart(highcloudsfig, use_container_width = True)

#precipitaion plot
pptfig = px.bar(wxdata, x = 'Date_IST', y = 'precipitation', labels = {'Date_IST': 'Date and Time', 'precipitation': 'Precipitation'})

with tab1.expander("Precipitation"):
    st.plotly_chart(pptfig, use_container_width = True)

#pressure plot
qnhfig = px.line(wxdata, x = 'Date_IST', y = 'surface_pressure', labels = {'Date_IST': 'Date and Time', 'surface_pressure': 'QNH(hPa)'})
qnhfig.update_layout(yaxis_range=[995,1018])


with tab1.expander("Surface Pressure"):
    st.plotly_chart(qnhfig, use_container_width = True)


#Daily Data
ds = tab2.slider(
    "Forecast for ", start_date, end_date,
    value=start_date,
    format="DD MMM YY")

wxdata2 = wxdata[(wxdata['Day'] == ds.day)&(wxdata['Month'] == ds.month)&(wxdata['Year'] == ds.year)]

with tab2.expander("Current Weather Register"):
    st.table(makecwr(wxdata2))


#temperature and inversion
#Temperature plot
tempfig = px.line(wxdata2, x = 'Date_IST', y = 'temperature_2m', hover_data= 'temperature_925hPa',
                    labels = {'Date_IST': 'Date and Time', 'temperature_2m': 'Dry Bulb Temp', 'temperature_925hPa': 'Temp at F/L025'})

#Inversion
invlist = []
temp2mlist = wxdata2['temperature_2m'].values
temp025list = wxdata2['temperature_925hPa'].values

for t in range(len(temp2mlist)):
    if((temp025list[t] - temp2mlist[t])>0):
        invlist.append((temp025list[t] - temp2mlist[t]))
    else:
        invlist.append(0)

wxdata2['Inversion'] = invlist
invfig = px.bar(wxdata2, x='Date_IST', y='Inversion')
invfig.update_layout(yaxis_range=[0,5])

with tab2.expander("Temperature and Inversion"):
    st.plotly_chart(tempfig, use_container_width = True)
    st.plotly_chart(invfig, use_container_width = True)

#RH plot
rhfig = px.line(wxdata2, x = 'Date_IST', y = 'relative_humidity_2m', labels = {'newdate': 'Date and Time', 'relative_humidity_2m': 'RH(%age)'})

with tab2.expander("Relative Humidity"):
    st.plotly_chart(rhfig, use_container_width = True)

#Cloud Plots
cloudsfig = px.line(wxdata2, x = 'Date_IST', y = 'cloud_cover', hover_data = ['cloud_cover_low', 'cloud_cover_mid', 'cloud_cover_high'],
                labels = {'Date_IST': 'Date and Time', 'cloud_cover': 'Total Cloud Cover (%age)',
                                                        'cloud_cover_low': 'Low Clouds',
                                                        'cloud_cover_mid': 'Medium Clouds',
                                                        'cloud_cover_high': 'High Clouds'})
cloudsfig.update_layout(yaxis_range=[0,100])
lowcloudsfig = px.line(wxdata2, x = 'Date_IST', y = 'cloud_cover_low', hover_data = ['cloud_cover', 'cloud_cover_mid', 'cloud_cover_high'],
                labels = {'Date_IST': 'Date and Time', 'cloud_cover': 'Total Cloud Cover (%age)',
                                                        'cloud_cover_low': 'Low Clouds',
                                                        'cloud_cover_mid': 'Medium Clouds',
                                                        'cloud_cover_high': 'High Clouds'})
midcloudsfig = px.line(wxdata2, x = 'Date_IST', y = 'cloud_cover_mid', hover_data = ['cloud_cover', 'cloud_cover_low', 'cloud_cover_high'],
                labels = {'Date_IST': 'Date and Time', 'cloud_cover': 'Total Cloud Cover (%age)',
                                                        'cloud_cover_low': 'Low Clouds',
                                                        'cloud_cover_mid': 'Medium Clouds',
                                                        'cloud_cover_high': 'High Clouds'})
highcloudsfig = px.line(wxdata2, x = 'Date_IST', y = 'cloud_cover_high', hover_data = ['cloud_cover', 'cloud_cover_low', 'cloud_cover_mid'],
                labels = {'Date_IST': 'Date and Time', 'cloud_cover': 'Total Cloud Cover (%age)',
                                                        'cloud_cover_low': 'Low Clouds',
                                                        'cloud_cover_mid': 'Medium Clouds',
                                                        'cloud_cover_high': 'High Clouds'})
lowcloudsfig.update_layout(yaxis_range=[0,100])
midcloudsfig.update_layout(yaxis_range=[0,100])
highcloudsfig.update_layout(yaxis_range=[0,100])

with tab2.expander("Cloudiness"):
    st.plotly_chart(cloudsfig, use_container_width = True)
    st.plotly_chart(lowcloudsfig, use_container_width = True)
    st.plotly_chart(midcloudsfig, use_container_width = True)
    st.plotly_chart(highcloudsfig, use_container_width = True)

#pressure plot
qnhfig = px.line(wxdata2, x = 'Date_IST', y = 'surface_pressure', labels = {'Date_IST': 'Date and Time', 'surface_pressure': 'QNH(hPa)'})
qnhfig.update_layout(yaxis_range=[995,1018])


with tab2.expander("Surface Pressure"):
    st.plotly_chart(qnhfig, use_container_width = True)

old_ht = [500,2500,5000,10000,18000,30000,35000,40000]
new_ht = [1000, 2000, 3000, 5000, 7000, 9000, 15000, 18000, 25000, 30000]
upper_air_df = pd.DataFrame()
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]
#Upper Air Data
sel_times = tab2.multiselect("Select Time for Upper Air Data (IST)", wxdata2['Hour'].values, [5,11,17,23])
for sel_time in sel_times:
    filter_df = wxdata2[wxdata2['Hour'] == sel_time]
    wind_dir_list = []
    wind_speed_list = []
    temp_list = []
    for level in ['200hPa', '250hPa', '300hPa', '500hPa', '700hPa', '850hPa', '925hPa', '1000hPa'][::-1]:
        wind_dir_list.append(filter_df[f'winddirection_{level}'].values[0])
        wind_speed_list.append(filter_df[f'windspeed_{level}'].values[0])
        temp_list.append(int(filter_df[f'temperature_{level}'].values[0]))

    new_wind_dir = interp_for_levels(old_ht, wind_dir_list, new_ht, is_wind_dir = True)[::-1]
    new_wind_speed = interp_for_levels(old_ht, wind_speed_list, new_ht)[::-1]
    new_temp = interp_for_levels(old_ht, temp_list, new_ht, round_to = 1)[::-1]

    text_to_be_shown = []
    for y in range(len(new_wind_dir)):
        while(new_wind_dir[y]>360):
            new_wind_dir[y] = new_wind_dir[y]-360
        wwww = f"{new_wind_dir[y]:03d}/{new_wind_speed[y]:02d}({new_temp[y]:02d})"
        text_to_be_shown.append(wwww)

    upper_air_df[f"{sel_time:02d}:30Hr"] = text_to_be_shown

tab2.dataframe(upper_air_df, use_container_width=True)

st.success("Made by Meteo Rama..!!")