Spaces:
Sleeping
Sleeping
mattritchey
commited on
Commit
•
77a46c3
1
Parent(s):
3d1bfb4
Update main.py
Browse files
main.py
CHANGED
@@ -56,17 +56,13 @@ def get_data(address, start_date, end_date, radius_miles, get_max):
|
|
56 |
years = [pd.Timestamp(start_date).year]
|
57 |
|
58 |
# Geocode Address
|
59 |
-
|
60 |
-
|
61 |
-
except:
|
62 |
-
lat, lon= None,None
|
63 |
|
64 |
-
|
65 |
# Convert Lat Lon to row & col on Array
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
row=col=None
|
70 |
|
71 |
|
72 |
files = [
|
@@ -80,33 +76,33 @@ def get_data(address, start_date, end_date, radius_miles, get_max):
|
|
80 |
files_choosen = [i for i in files if any(i for j in years if str(j) in i)]
|
81 |
|
82 |
|
83 |
-
#
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
|
98 |
-
|
99 |
-
|
100 |
|
101 |
-
|
102 |
-
|
103 |
|
104 |
-
#
|
105 |
-
|
106 |
|
107 |
-
#
|
108 |
-
|
109 |
-
|
110 |
|
111 |
# # Process to DataFrame
|
112 |
# # Find Max of Data
|
|
|
56 |
years = [pd.Timestamp(start_date).year]
|
57 |
|
58 |
# Geocode Address
|
59 |
+
lat, lon= geocode_address(address)
|
60 |
+
|
|
|
|
|
61 |
|
|
|
62 |
# Convert Lat Lon to row & col on Array
|
63 |
+
|
64 |
+
row, col = lat_lon_to_row_col(lat, lon)
|
65 |
+
|
|
|
66 |
|
67 |
|
68 |
files = [
|
|
|
76 |
files_choosen = [i for i in files if any(i for j in years if str(j) in i)]
|
77 |
|
78 |
|
79 |
+
# Query and Collect H5 Data
|
80 |
+
all_data = []
|
81 |
+
all_dates = []
|
82 |
+
for file in files_choosen:
|
83 |
+
with h5py.File(file, 'r') as f:
|
84 |
+
# Get Dates from H5
|
85 |
+
dates = f['date_time_hr'][:]
|
86 |
+
date_idx = np.where((dates >= int(start_date))
|
87 |
+
& (dates <= int(end_date)))[0]
|
88 |
|
89 |
+
# Select Data by Date and Radius
|
90 |
+
dates = dates[date_idx]
|
91 |
+
data = f['APCP'][date_idx, row-radius_miles:row +
|
92 |
+
radius_miles+1, col-radius_miles:col+radius_miles+1]
|
93 |
|
94 |
+
all_data.append(data)
|
95 |
+
all_dates.append(dates)
|
96 |
|
97 |
+
data_all = np.vstack(all_data)
|
98 |
+
dates_all = np.concatenate(all_dates)
|
99 |
|
100 |
+
# Convert to Inches
|
101 |
+
data_mat = np.where(data_all < 0, 0, data_all)*0.0393701
|
102 |
|
103 |
+
# Get Radius of Data
|
104 |
+
disk_mask = np.where(disk(radius_miles) == 1, True, False)
|
105 |
+
data_mat = np.where(disk_mask, data_mat, -1).round(3)
|
106 |
|
107 |
# # Process to DataFrame
|
108 |
# # Find Max of Data
|