Spaces:
Sleeping
Sleeping
mattritchey
commited on
Commit
•
d091265
1
Parent(s):
e801fec
Update main.py
Browse files
main.py
CHANGED
@@ -56,66 +56,66 @@ def get_data(address, start_date, end_date, radius_miles, get_max):
|
|
56 |
row, col = rasterio.transform.rowcol(transform['affine'], lon, lat)
|
57 |
|
58 |
|
59 |
-
files = [
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
]
|
66 |
-
|
67 |
-
files_choosen = [i for i in files if any(i for j in years if str(j) in i)]
|
68 |
-
|
69 |
-
|
70 |
-
# Query and Collect H5 Data
|
71 |
-
all_data = []
|
72 |
-
all_dates = []
|
73 |
-
for file in files_choosen:
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
data_all = np.vstack(all_data)
|
89 |
-
dates_all = np.concatenate(all_dates)
|
90 |
-
|
91 |
-
# Convert to Inches
|
92 |
-
data_mat = np.where(data_all < 0, 0, data_all)*0.0393701
|
93 |
-
|
94 |
-
# Get Radius of Data
|
95 |
-
disk_mask = np.where(disk(radius_miles) == 1, True, False)
|
96 |
-
data_mat = np.where(disk_mask, data_mat, -1).round(3)
|
97 |
-
|
98 |
-
# Process to DataFrame
|
99 |
-
# Find Max of Data
|
100 |
-
if get_max == True:
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
# Get all Data
|
105 |
-
else:
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
df_data['Date'] = pd.to_datetime(df_data['Date'], format='%Y%m%d%H')
|
111 |
-
df_data = df_data.set_index('Date')
|
112 |
-
|
113 |
-
df_data = df_data.reindex(date_range_days, fill_value=0).reset_index().rename(
|
114 |
-
|
115 |
-
df_data['Date'] = df_data['Date'].dt.strftime('%Y-%m-%d:%H')
|
116 |
-
|
117 |
-
return df_data
|
118 |
-
|
119 |
|
120 |
@app.get('/APCP_Docker_Data')
|
121 |
async def predict(address: str, start_date: str, end_date: str, radius_miles: int, get_max: bool):
|
|
|
56 |
row, col = rasterio.transform.rowcol(transform['affine'], lon, lat)
|
57 |
|
58 |
|
59 |
+
# files = [
|
60 |
+
# # 'Data/APCP_2024_hrrr_v2.h5',
|
61 |
+
# 'Data/APCP_2020_hrrr_v3.h5',
|
62 |
+
# 'Data/APCP_2021_hrrr_3.h5',
|
63 |
+
# 'Data/APCP_2022_hrrr_v2.h5',
|
64 |
+
# # 'Data/APCP_2023_hrrr_v2c.h5'
|
65 |
+
# ]
|
66 |
+
|
67 |
+
# files_choosen = [i for i in files if any(i for j in years if str(j) in i)]
|
68 |
+
|
69 |
+
|
70 |
+
# # Query and Collect H5 Data
|
71 |
+
# all_data = []
|
72 |
+
# all_dates = []
|
73 |
+
# for file in files_choosen:
|
74 |
+
# with h5py.File(file, 'r') as f:
|
75 |
+
# # Get Dates from H5
|
76 |
+
# dates = f['date_time_hr'][:]
|
77 |
+
# date_idx = np.where((dates >= int(start_date))
|
78 |
+
# & (dates <= int(end_date)))[0]
|
79 |
+
|
80 |
+
# # Select Data by Date and Radius
|
81 |
+
# dates = dates[date_idx]
|
82 |
+
# data = f['APCP'][date_idx, row-radius_miles:row +
|
83 |
+
# radius_miles+1, col-radius_miles:col+radius_miles+1]
|
84 |
+
|
85 |
+
# all_data.append(data)
|
86 |
+
# all_dates.append(dates)
|
87 |
+
|
88 |
+
# data_all = np.vstack(all_data)
|
89 |
+
# dates_all = np.concatenate(all_dates)
|
90 |
+
|
91 |
+
# # Convert to Inches
|
92 |
+
# data_mat = np.where(data_all < 0, 0, data_all)*0.0393701
|
93 |
+
|
94 |
+
# # Get Radius of Data
|
95 |
+
# disk_mask = np.where(disk(radius_miles) == 1, True, False)
|
96 |
+
# data_mat = np.where(disk_mask, data_mat, -1).round(3)
|
97 |
+
|
98 |
+
# # Process to DataFrame
|
99 |
+
# # Find Max of Data
|
100 |
+
# if get_max == True:
|
101 |
+
# data_max = np.max(data_mat, axis=(1, 2))
|
102 |
+
# df_data = pd.DataFrame({'Date': dates_all,
|
103 |
+
# 'APCP_max': data_max})
|
104 |
+
# # Get all Data
|
105 |
+
# else:
|
106 |
+
# data_all = list(data_mat)
|
107 |
+
# df_data = pd.DataFrame({'Date': dates_all,
|
108 |
+
# 'APCP_all': data_all})
|
109 |
+
|
110 |
+
# df_data['Date'] = pd.to_datetime(df_data['Date'], format='%Y%m%d%H')
|
111 |
+
# df_data = df_data.set_index('Date')
|
112 |
+
|
113 |
+
# df_data = df_data.reindex(date_range_days, fill_value=0).reset_index().rename(
|
114 |
+
# columns={'index': 'Date'})
|
115 |
+
# df_data['Date'] = df_data['Date'].dt.strftime('%Y-%m-%d:%H')
|
116 |
+
|
117 |
+
# return df_data
|
118 |
+
return lat, lon, transform, row, col
|
119 |
|
120 |
@app.get('/APCP_Docker_Data')
|
121 |
async def predict(address: str, start_date: str, end_date: str, radius_miles: int, get_max: bool):
|