Spaces:
Build error
Build error
Update pages/Hail.py
Browse files- pages/Hail.py +1 -92
pages/Hail.py
CHANGED
|
@@ -1,92 +1,4 @@
|
|
| 1 |
|
| 2 |
-
|
| 3 |
-
# -*- coding: utf-8 -*-
|
| 4 |
-
"""
|
| 5 |
-
Created on Tue Dec 6 09:56:29 2022
|
| 6 |
-
|
| 7 |
-
@author: mritchey
|
| 8 |
-
"""
|
| 9 |
-
#streamlit run "C:\Users\mritchey\.spyder-py3\Python Scripts\streamlit projects\mrms\mrms_hail2 buffer.py"
|
| 10 |
-
|
| 11 |
-
import plotly.express as px
|
| 12 |
-
import os
|
| 13 |
-
from PIL import Image
|
| 14 |
-
from joblib import Parallel, delayed
|
| 15 |
-
import pandas as pd
|
| 16 |
-
import streamlit as st
|
| 17 |
-
from geopy.extra.rate_limiter import RateLimiter
|
| 18 |
-
from geopy.geocoders import Nominatim
|
| 19 |
-
import folium
|
| 20 |
-
from streamlit_folium import st_folium
|
| 21 |
-
import math
|
| 22 |
-
import geopandas as gpd
|
| 23 |
-
from skimage.io import imread
|
| 24 |
-
from streamlit_plotly_events import plotly_events
|
| 25 |
-
import requests
|
| 26 |
-
from requests.packages.urllib3.exceptions import InsecureRequestWarning
|
| 27 |
-
import rasterio
|
| 28 |
-
import rioxarray
|
| 29 |
-
import numpy as np
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
@st.cache(allow_output_mutation=True)
|
| 33 |
-
def geocode(address, buffer_size):
|
| 34 |
-
try:
|
| 35 |
-
address2 = address.replace(' ', '+').replace(',', '%2C')
|
| 36 |
-
df = pd.read_json(
|
| 37 |
-
f'https://geocoding.geo.census.gov/geocoder/locations/onelineaddress?address={address2}&benchmark=2020&format=json')
|
| 38 |
-
results = df.iloc[:1, 0][0][0]['coordinates']
|
| 39 |
-
lat, lon = results['y'], results['x']
|
| 40 |
-
except:
|
| 41 |
-
geolocator = Nominatim(user_agent="GTA Lookup")
|
| 42 |
-
geocode = RateLimiter(geolocator.geocode, min_delay_seconds=1)
|
| 43 |
-
location = geolocator.geocode(address)
|
| 44 |
-
lat, lon = location.latitude, location.longitude
|
| 45 |
-
|
| 46 |
-
df = pd.DataFrame({'Lat': [lat], 'Lon': [lon]})
|
| 47 |
-
gdf = gpd.GeoDataFrame(
|
| 48 |
-
df, geometry=gpd.points_from_xy(df.Lon, df.Lat, crs=4326))
|
| 49 |
-
gdf['buffer'] = gdf['geometry'].to_crs(
|
| 50 |
-
3857).buffer(buffer_size/2*2580).to_crs(4326)
|
| 51 |
-
return gdf
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
@st.cache(allow_output_mutation=True)
|
| 55 |
-
def get_pngs(date):
|
| 56 |
-
year, month, day = date[:4], date[4:6], date[6:]
|
| 57 |
-
url = f'https://mrms.nssl.noaa.gov/qvs/product_viewer/local/render_multi_domain_product_layer.php?mode=run&cpp_exec_dir=/home/metop/web/specific/opv/&web_resources_dir=/var/www/html/qvs/product_viewer/resources/&prod_root={prod_root}&qperate_pal_option=0&qpe_pal_option=0&year={year}&month={month}&day={day}&hour={hour}&minute={minute}&clon={lon}&clat={lat}&zoom={zoom}&width=920&height=630'
|
| 58 |
-
data = imread(url)[:, :, :3]
|
| 59 |
-
data2 = data.reshape(630*920, 3)
|
| 60 |
-
data2_df = pd.DataFrame(data2, columns=['R', 'G', 'B'])
|
| 61 |
-
data2_df2 = pd.merge(data2_df, lut[['R', 'G', 'B', 'Hail Scale', 'Hail Scale In']], on=['R', 'G', 'B'],
|
| 62 |
-
how='left')[['Hail Scale', 'Hail Scale In']]
|
| 63 |
-
data2_df2['Date'] = date
|
| 64 |
-
return data2_df2.reset_index()
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
@st.cache(allow_output_mutation=True)
|
| 68 |
-
def get_pngs_parallel(dates):
|
| 69 |
-
results1 = Parallel(n_jobs=32, prefer="threads")(
|
| 70 |
-
delayed(get_pngs)(i) for i in dates)
|
| 71 |
-
return results1
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
@st.cache(allow_output_mutation=True)
|
| 75 |
-
def png_data(date):
|
| 76 |
-
year, month, day = date[:4], date[4:6], date[6:]
|
| 77 |
-
url = f'https://mrms.nssl.noaa.gov/qvs/product_viewer/local/render_multi_domain_product_layer.php?mode=run&cpp_exec_dir=/home/metop/web/specific/opv/&web_resources_dir=/var/www/html/qvs/product_viewer/resources/&prod_root={prod_root}&qperate_pal_option=0&qpe_pal_option=0&year={year}&month={month}&day={day}&hour={hour}&minute={minute}&clon={lon}&clat={lat}&zoom={zoom}&width=920&height=630'
|
| 78 |
-
data = imread(url)
|
| 79 |
-
return data
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
@st.cache(allow_output_mutation=True)
|
| 83 |
-
def map_folium(data, gdf):
|
| 84 |
-
m = folium.Map(location=[lat, lon], zoom_start=zoom, height=300)
|
| 85 |
-
folium.Marker(
|
| 86 |
-
location=[lat, lon],
|
| 87 |
-
popup=address).add_to(m)
|
| 88 |
-
|
| 89 |
-
folium.GeoJson(gdf['buffer']).add_to(m)
|
| 90 |
folium.raster_layers.ImageOverlay(
|
| 91 |
data, opacity=0.8, bounds=bounds).add_to(m)
|
| 92 |
return m
|
|
@@ -300,7 +212,4 @@ except:
|
|
| 300 |
st.markdown(""" <style>
|
| 301 |
#MainMenu {visibility: hidden;}
|
| 302 |
footer {visibility: hidden;}
|
| 303 |
-
</style> """, unsafe_allow_html=True)
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
|
|
|
| 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
folium.raster_layers.ImageOverlay(
|
| 3 |
data, opacity=0.8, bounds=bounds).add_to(m)
|
| 4 |
return m
|
|
|
|
| 212 |
st.markdown(""" <style>
|
| 213 |
#MainMenu {visibility: hidden;}
|
| 214 |
footer {visibility: hidden;}
|
| 215 |
+
</style> """, unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|