Spaces:
Sleeping
Sleeping
mattritchey
commited on
Commit
•
e3aa2de
1
Parent(s):
8fbedd2
Update app.py
Browse files
app.py
CHANGED
@@ -40,38 +40,38 @@ def geocode(address):
|
|
40 |
return pd.DataFrame({'Lat': lat, 'Lon': lon}, index=[0])
|
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 |
def map_folium(lat, lon,files_dates_selected, within_days ):
|
@@ -206,6 +206,7 @@ crs_dic = pickle.load(open('data/mrms_hail_crs.pkl', 'rb'))
|
|
206 |
transform = crs_dic['affine']
|
207 |
|
208 |
row, col = rasterio.transform.rowcol(transform, lon, lat)
|
|
|
209 |
st.write(row,col)
|
210 |
|
211 |
# center=row,col
|
@@ -221,12 +222,11 @@ files = [
|
|
221 |
all_data = []
|
222 |
all_dates = []
|
223 |
for i in files:
|
224 |
-
with h5py.File(
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
all_dates.append(dates)
|
230 |
|
231 |
|
232 |
|
@@ -237,8 +237,8 @@ files_dates_selected = [i for i in files if any(
|
|
237 |
|
238 |
|
239 |
|
240 |
-
#
|
241 |
-
|
242 |
|
243 |
# df_data = df_data.query(f"'{start_date}'<=Date<='{end_date}'")
|
244 |
# df_data['Max'] = df_data['Max'].round(3)
|
|
|
40 |
return pd.DataFrame({'Lat': lat, 'Lon': lon}, index=[0])
|
41 |
|
42 |
|
43 |
+
def get_data(row, col, radius=8):
|
44 |
+
files = [
|
45 |
+
"data/2023_hail.h5",
|
46 |
+
"data/2022_hail.h5",
|
47 |
+
"data/2021_hail.h5",
|
48 |
+
"data/2020_hail.h5"
|
49 |
+
]
|
50 |
+
all_data = []
|
51 |
+
all_dates = []
|
52 |
+
for f in files:
|
53 |
+
with h5py.File(f, 'r') as f:
|
54 |
+
data = f['hail'][:, row - radius: row + radius+ 1, col-radius: col+radius+1]
|
55 |
+
dates = f['dates'][:]
|
56 |
+
all_data.append(data)
|
57 |
+
all_dates.append(dates)
|
58 |
+
|
59 |
+
data_mat = np.concatenate(all_data)
|
60 |
+
data_mat = np.where(data_mat < 0, 0, data_mat)*0.0393701
|
61 |
+
dates_mat = np.concatenate(all_dates)
|
62 |
+
|
63 |
+
data_actual = [i[radius, radius] for i in data_mat]
|
64 |
+
data_max = np.max(data_mat, axis=(1, 2))
|
65 |
+
data_max_2 = np.max(data_mat, axis=0)
|
66 |
+
|
67 |
+
df = pd.DataFrame({'Date': dates_mat,
|
68 |
+
'Actual': data_actual,
|
69 |
+
'Max': data_max})
|
70 |
+
|
71 |
+
df['Date'] = pd.to_datetime(df['Date'], format='%Y%m%d')
|
72 |
+
df['Date']=df['Date']+pd.Timedelta(days=1)
|
73 |
+
|
74 |
+
return df, data_max_2
|
75 |
|
76 |
|
77 |
def map_folium(lat, lon,files_dates_selected, within_days ):
|
|
|
206 |
transform = crs_dic['affine']
|
207 |
|
208 |
row, col = rasterio.transform.rowcol(transform, lon, lat)
|
209 |
+
row, col =int(row), int(col)
|
210 |
st.write(row,col)
|
211 |
|
212 |
# center=row,col
|
|
|
222 |
all_data = []
|
223 |
all_dates = []
|
224 |
for i in files:
|
225 |
+
with h5py.File(f, 'r') as f:
|
226 |
+
data = f['hail'][:, row - radius: row + radius+ 1, col-radius: col+radius+1]
|
227 |
+
dates = f['dates'][:]
|
228 |
+
all_data.append(data)
|
229 |
+
all_dates.append(dates)
|
|
|
230 |
|
231 |
|
232 |
|
|
|
237 |
|
238 |
|
239 |
|
240 |
+
# Get Data
|
241 |
+
df_data, max_values = get_data(row, col, radius)
|
242 |
|
243 |
# df_data = df_data.query(f"'{start_date}'<=Date<='{end_date}'")
|
244 |
# df_data['Max'] = df_data['Max'].round(3)
|