@@ -16,7 +16,7 @@ def __init__(self, path_results, dtw_inc=0.01, hrs_per=50, z_thresh=3.75):
16
16
# highest values (closest to 0) = most hours with lowest DTW
17
17
self .mat_dtw_sum = (self .mat_dtw * - 1 ).sum (axis = 1 )
18
18
self .summer = pd .date_range ('2012-06-01-00' , '2012-09-01-00' , freq = 'h' )
19
-
19
+
20
20
def _ccap_wetlands (self ):
21
21
""" Get CCAP wetlands df and full matrix grid """
22
22
df_subs = pd .read_csv (op .join (self .path_data , 'SWMM_subs.csv' ))
@@ -151,7 +151,7 @@ def apply_indicator(self, seasonal=False):
151
151
### best for summer is ~ 61% wetlands and 34.4% of drylands
152
152
BB .print_all (df_new )
153
153
154
- def find_cells (self , dtw_thresh = 0.01 , hrs_thresh = 4442 ):
154
+ def find_cells (self , dtw_thresh = 0.05 , hrs_thresh = 4442 ):
155
155
""" Find locations that meet the threshold conditions """
156
156
df_dtw = pd .DataFrame (self .mat_dtw , columns = self .ts_yr_hr )
157
157
@@ -167,12 +167,53 @@ def find_cells(self, dtw_thresh=0.01, hrs_thresh=4442):
167
167
left_index = True , right_index = True , how = 'outer' )
168
168
df_passed = df_merged [df_merged ['wet_test' ]]
169
169
170
- df_low = df_passed [df_passed .Esurf <= z_thresh ]
171
- df_passed_wets = df_low [df_low .index .isin (self .df_wets .Zone )]
172
- df_passed_drys = df_low [~ df_low .index .isin (self .df_wets .Zone )]
170
+ df_low = df_passed [df_passed .Esurf <= self .z_thresh ]
171
+ # df_passed_wets = df_low[df_low.index.isin(self.df_wets.Zone)]
172
+ # df_passed_drys = df_low[~df_low.index.isin(self.df_wets.Zone)]
173
+ df_low ['dry' ] = df_low .index .map (lambda x : - 1 if x in self .df_wets .loc [:, 'Zone' ].values else 0 )
174
+
175
+ print ('Wets: {}' .format (df_low [df_low ['dry' ]< 0 ].shape [0 ]))
176
+ print ('Drys: {}' .format (df_low [df_low ['dry' ]== 0 ].shape [0 ]))
177
+ # return df_passed_wets, df_passed_drys
178
+ return df_low
179
+
180
+
181
+ def plot_wets_drys (self ):
182
+ df_lows = self .find_cells (dtw_thresh = 0.05 , hrs_thresh = 4442 )
183
+
184
+ ## change value for cells not considered (visualization purposes)
185
+ df_subs = pd .DataFrame (index = self .df_swmm .index )
186
+ df_subs ['dry' ] = df_subs .index .map (lambda x : df_lows .loc [x , 'dry' ]
187
+ if x in df_lows .index .values else 1 )
173
188
174
- print ('Wets: {}' .format (df_passed_wets .shape [0 ]))
175
- print ('Drys: {}' .format (df_passed_drys .shape [0 ]))
189
+ ## converts dfs to matrixes
190
+ mat_lows = res_base .fill_grid (df_subs .dry , fill_value = - 2 )
191
+
192
+ fig , axes = plt .subplots (ncols = 3 , sharey = True )
193
+ axe = axes .ravel ()
194
+ # cm = plt.get_cmap('coolwarm')
195
+ cm = mpl .colors .ListedColormap (['black' , 'blue' , 'green' , 'gray' ])
196
+ # axe = axes.ravel()
197
+ for i , ax in enumerate (axes .ravel ()):
198
+ im = axe [i ].imshow (mat_lows .reshape (self .nrows , self .ncols ), cmap = cm )
199
+
200
+ axe [i ].set (title = 'SLR: {}' .format (0.0 ),
201
+ xlabel = '# Wetlands: {}' .format (
202
+ df_lows [((df_lows ['dry' ]== 0 ) | (df_lows ['dry' ]== 1 ))].shape [0 ]),
203
+ )
204
+
205
+ cbar_ax = fig .add_axes ([0.945 , 0.18 , 0.025 , 0.62 ])
206
+
207
+ cbar = fig .colorbar (im , cbar_ax , spacing = 'proportional' )
208
+ cbar .ax .get_yaxis ().set_ticks ([])
209
+ cbar .ax .set_xlabel ('Legend' , fontsize = 12 , labelpad = 10 )
210
+ cbar .ax .xaxis .set_label_position ('top' )
211
+ for j , lab in enumerate (['inactive' ,'wetland (CCAP)' ,'wetland(nonCCAP)' ,'upland' ]):
212
+ cbar .ax .text (.5 , (2 * j + 1 ) / 8.0 , lab , ha = 'center' , va = 'center' ,
213
+ bbox = dict (facecolor = 'white' , alpha = 0.75 ), rotation = 90 )
214
+
215
+ fig .subplots_adjust (left = 0.05 , right = 0.915 , wspace = 0.25 , hspace = 0.25 )
216
+ plt .show ()
176
217
177
218
def optimize (self , increment = 1 ):
178
219
""" Maximize the percent correctly identiified """
@@ -248,6 +289,7 @@ def indicator_all(self, cutoff=-2500, show=False):
248
289
performance = (count_correct - count_incorrect ) / float (np .count_nonzero (~ mask_wet )) * 100
249
290
# print ('Percent corretly identified: {} %\n'.format(round(performance, 3)))
250
291
return (performance , count_correct , count_incorrect )
292
+
251
293
### probably useless
252
294
def dtw_wet_all (self , transpose = False ):
253
295
""" Separate ALL dtw / cells / times by wetlands/nonwetland """
@@ -314,10 +356,11 @@ def dtw_wet_avg_ann(self):
314
356
'WNC' , 'Wetlands_Paper' , 'Results_Default' )
315
357
res = Wetlands (PATH_res , dtw_inc = 0.01 , hrs_per = 50 , z_thresh = 3.75 )
316
358
# res.optimize(increment=10)
317
- res .make_indicator (masked = True , seasonal = False )
359
+ # res.make_indicator(masked=True, seasonal=False)
318
360
# res.apply_indicator(seasonal=False)
319
361
320
362
## nonseasonal indicators: dtw < 0.05; hrs_thresh>4443 --------- best
321
363
## seasonal indicators : dtw < 0.17; hrs_thresh > 1211
322
364
323
365
# res.find_cells()
366
+ res .plot_wets_drys ()
0 commit comments