File size: 3,380 Bytes
0585eae
d7b9aaa
0585eae
 
 
 
 
 
 
 
 
 
b066138
0585eae
 
 
 
 
 
f959bb1
9291f9c
0585eae
 
 
 
 
 
 
 
9291f9c
0585eae
 
 
 
 
 
 
 
 
 
 
 
d7b9aaa
8ff9764
 
 
 
 
906b1b6
8ff9764
0585eae
8ff9764
0585eae
 
 
 
 
 
8ff9764
0585eae
 
 
 
 
 
 
 
8ff9764
0585eae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8ff9764
0585eae
 
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
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='local forecast', menu_items={
        'Get Help': None,
        'Report a bug': None,
        'About': "Designed by Meteorama"
    })


st.header("FOR LOCAL FORECAST")
st.caption("winds & temp")

#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(['PPTN', 'LOCAL FCST'])

#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)

#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))


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..!!")