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