mattritchey commited on
Commit
df00985
1 Parent(s): c2c0e17

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -38
app.py CHANGED
@@ -43,9 +43,9 @@ def geocode(address):
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 = []
@@ -207,6 +207,24 @@ transform = crs_dic['affine']
207
 
208
  row, col = rasterio.transform.rowcol(transform, lon, lat)
209
  st.write(row,col)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
  # center=row,col
211
  radius = int(np.ceil(circle_radius*1.6))
212
  # crop_coords = col-radius, row-radius, col+radius+1, row+radius+1
@@ -218,50 +236,50 @@ files_dates_selected = [i for i in files if any(
218
 
219
 
220
 
221
- # Get Data
222
- df_data, max_values = get_data(row, col, radius)
223
 
224
- df_data = df_data.query(f"'{start_date}'<=Date<='{end_date}'")
225
- df_data['Max'] = df_data['Max'].round(3)
226
- df_data['Actual'] = df_data['Actual'].round(3)
227
 
228
 
229
- # Create the bar chart
230
- fig = alt.Chart(df_data).mark_bar(size=3, color='red').encode(
231
- x='Date:T', # Temporal data type
232
- y='Actual:Q', # Quantitative data type
233
- color='Actual:Q', # Color based on Actual values
234
- tooltip=[ # Adding tooltips
235
- alt.Tooltip('Date:T', title='Date'),
236
- alt.Tooltip('Actual:Q', title='Actual Value'),
237
- alt.Tooltip('Max:Q', title=f'Max Value with {circle_radius} Miles')
238
- ]
239
- ).configure(
240
- view=alt.ViewConfig(
241
- strokeOpacity=0 # No border around the chart
242
- )
243
- ).configure_axis(
244
- grid=False # Disable grid lines
245
- ).configure_legend(
246
- fillColor='transparent', # Ensure no legend is shown
247
- strokeColor='transparent'
248
- )
249
 
250
 
251
 
252
 
253
  with col1:
254
  st.title(f'Hail')
255
- try:
256
- st.altair_chart(fig, use_container_width=True)
257
- csv = convert_df(df_data)
258
- st.download_button(
259
- label="Download data as CSV",
260
- data=csv,
261
- file_name='data.csv',
262
- mime='text/csv')
263
- except:
264
- pass
265
 
266
 
267
  with col2:
 
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 = []
 
207
 
208
  row, col = rasterio.transform.rowcol(transform, lon, lat)
209
  st.write(row,col)
210
+
211
+ files = [
212
+ "data/2023_hail.h5",
213
+ "data/2022_hail.h5",
214
+ "data/2021_hail.h5",
215
+ "data/2020_hail.h5"
216
+ ]
217
+ all_data = []
218
+ all_dates = []
219
+ for i in files:
220
+ with h5py.File(i, 'r') as f:
221
+ data = f['hail'][:, 100 - radius:100 + radius+ 1,
222
+ 100-radius: 100+radius+1]
223
+ st.write(data)
224
+ dates = f['dates'][:]
225
+ all_data.append(data)
226
+ all_dates.append(dates)
227
+
228
  # center=row,col
229
  radius = int(np.ceil(circle_radius*1.6))
230
  # crop_coords = col-radius, row-radius, col+radius+1, row+radius+1
 
236
 
237
 
238
 
239
+ # # Get Data
240
+ # df_data, max_values = get_data(row, col, radius)
241
 
242
+ # df_data = df_data.query(f"'{start_date}'<=Date<='{end_date}'")
243
+ # df_data['Max'] = df_data['Max'].round(3)
244
+ # df_data['Actual'] = df_data['Actual'].round(3)
245
 
246
 
247
+ # # Create the bar chart
248
+ # fig = alt.Chart(df_data).mark_bar(size=3, color='red').encode(
249
+ # x='Date:T', # Temporal data type
250
+ # y='Actual:Q', # Quantitative data type
251
+ # color='Actual:Q', # Color based on Actual values
252
+ # tooltip=[ # Adding tooltips
253
+ # alt.Tooltip('Date:T', title='Date'),
254
+ # alt.Tooltip('Actual:Q', title='Actual Value'),
255
+ # alt.Tooltip('Max:Q', title=f'Max Value with {circle_radius} Miles')
256
+ # ]
257
+ # ).configure(
258
+ # view=alt.ViewConfig(
259
+ # strokeOpacity=0 # No border around the chart
260
+ # )
261
+ # ).configure_axis(
262
+ # grid=False # Disable grid lines
263
+ # ).configure_legend(
264
+ # fillColor='transparent', # Ensure no legend is shown
265
+ # strokeColor='transparent'
266
+ # )
267
 
268
 
269
 
270
 
271
  with col1:
272
  st.title(f'Hail')
273
+ # try:
274
+ # st.altair_chart(fig, use_container_width=True)
275
+ # csv = convert_df(df_data)
276
+ # st.download_button(
277
+ # label="Download data as CSV",
278
+ # data=csv,
279
+ # file_name='data.csv',
280
+ # mime='text/csv')
281
+ # except:
282
+ # pass
283
 
284
 
285
  with col2: