mattritchey commited on
Commit
77a46c3
1 Parent(s): 3d1bfb4

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +27 -31
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
- try:
60
- lat, lon= geocode_address(address)
61
- except:
62
- lat, lon= None,None
63
 
64
-
65
  # Convert Lat Lon to row & col on Array
66
- try:
67
- row, col = lat_lon_to_row_col(lat, lon)
68
- except:
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
- # # Query and Collect H5 Data
84
- # all_data = []
85
- # all_dates = []
86
- # for file in files_choosen:
87
- # with h5py.File(file, 'r') as f:
88
- # # Get Dates from H5
89
- # dates = f['date_time_hr'][:]
90
- # date_idx = np.where((dates >= int(start_date))
91
- # & (dates <= int(end_date)))[0]
92
 
93
- # # Select Data by Date and Radius
94
- # dates = dates[date_idx]
95
- # data = f['APCP'][date_idx, row-radius_miles:row +
96
- # radius_miles+1, col-radius_miles:col+radius_miles+1]
97
 
98
- # all_data.append(data)
99
- # all_dates.append(dates)
100
 
101
- # data_all = np.vstack(all_data)
102
- # dates_all = np.concatenate(all_dates)
103
 
104
- # # Convert to Inches
105
- # data_mat = np.where(data_all < 0, 0, data_all)*0.0393701
106
 
107
- # # Get Radius of Data
108
- # disk_mask = np.where(disk(radius_miles) == 1, True, False)
109
- # data_mat = np.where(disk_mask, data_mat, -1).round(3)
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