4
4
import pickle
5
5
6
6
class Wetlands (res_base ):
7
- def __init__ (self , path_results , dtw_inc = 0.01 , hrs_per = 50 , z_thresh = 3.75 ):
7
+ def __init__ (self , path_results , z_thresh = 3.75 ):
8
8
super (Wetlands , self ).__init__ (path_results )
9
9
self .path_res = path_results
10
- self .dtw_inc = dtw_inc
11
- self .hrs_per = 50
12
10
self .z_thresh = 3.75
13
11
self .mat_dtw , self .mat_dtw_masked = self ._make_dtw ()
14
12
self .df_wets , self .mat_wets = self ._ccap_wetlands ()
@@ -50,7 +48,7 @@ def _make_dtw(self, slr=0.0):
50
48
51
49
return mat_dtw_trunc , mask_z
52
50
53
- def make_indicator (self , masked = True , seasonal = False ):
51
+ def make_indicator (self , dtw_inc = 0.01 , hrs_per = 50 , masked = True , seasonal = False ):
54
52
"""
55
53
Make an indicator by iterating over depth to water and hours at that dtw
56
54
dtw_inc = dtw increment, use 0.01 for increased precision (expensive)
@@ -73,11 +71,6 @@ def make_indicator(self, masked=True, seasonal=False):
73
71
mat_nonwet_dtw = mat_dtw [mask_wet ]
74
72
mat_dry_dtw = mat_nonwet_dtw [~ np .isnan (mat_nonwet_dtw )].reshape (
75
73
- 1 , mat_nonwet_dtw .shape [1 ])
76
-
77
- ## to view the amount of wetlands and drylands working with
78
- # print (mat_wet_dtw.shape)
79
- # print (mat_dry_dtw.shape)
80
-
81
74
## truncate for just summer
82
75
if seasonal :
83
76
df_wet_dtw1 = pd .DataFrame (mat_wet_dtw .T , index = self .ts_yr_hr )
@@ -86,11 +79,13 @@ def make_indicator(self, masked=True, seasonal=False):
86
79
df_dry_dtw = pd .DataFrame (mat_dry_dtw .T , index = self .ts_yr_hr ).loc [self .summer , :]
87
80
mat_wet_dtw = df_wet_dtw .values .T
88
81
mat_dry_dtw = df_dry_dtw .values .T
89
- names = ['dtw_hrs_wet_dry_summer.npy' , 'dtw_hrs_wet_dry_summer.df' ]
82
+ ## fix this to add to previously made name
83
+ names = ['{}_summer' .format (n ) for n in names ]
90
84
85
+ ## to view the amount of wetlands and drylands working with
91
86
print ('Finding optimum criteria; will take a bit' )
92
- dtw_tests = np .arange (0 , 1 , self . dtw_inc )
93
- hrs_tests = range (int (np . floor ( 1. / self . hrs_per ) * self .mat_dtw .shape [1 ]), self .mat_dtw .shape [1 ])
87
+ dtw_tests = np .arange (0 , 1 , dtw_inc )
88
+ hrs_tests = range (int (hrs_per / 100. * self .mat_dtw .shape [1 ]), self .mat_dtw .shape [1 ])
94
89
mat_all = np .zeros ([len (dtw_tests ) * len (hrs_tests ), 7 ])
95
90
96
91
for i , dtw_test in enumerate (dtw_tests ):
@@ -126,18 +121,25 @@ def make_indicator(self, masked=True, seasonal=False):
126
121
127
122
print ('Elapsed time: ~{} min' .format (round ((end - start )/ 60. ), 4 ))
128
123
129
- def apply_indicator (self , seasonal = False ):
124
+ def apply_indicator (self , z = True , seasonal = False ):
130
125
""" Analyze the indicator developed using make_indicator """
131
- if seasonal :
126
+ if seasonal and not z :
132
127
names = ['dtw_hrs_wet_dry_summer.npy' , 'dtw_hrs_wet_dry_summer.df' ]
133
128
perWet_thresh = 0.61
134
129
perDry_thresh = 0.35
135
- else :
130
+ elif not z :
136
131
names = ['dtw_hrs_wet_dry.npy' , 'dtw_hrs_wet_dry.df' ]
137
132
perWet_thresh = 0.645
138
133
perDry_thresh = 0.35
134
+ elif z and not seasonal :
135
+ names = ['dtw_hrs_wet_dry_masked.npy' , 'dtw_hrs_wet_dry_masked.df' ]
136
+ perWet_thresh = 0.7
137
+ perDry_thresh = 0.4
138
+
139
139
mat_all = np .load (op .join (self .path_data , names [0 ]))
140
140
df_all = pd .read_pickle (op .join (self .path_data , names [1 ]))
141
+ print (df_all .shape )
142
+ return
141
143
# print (df_all.head(25))
142
144
## do some cropping
143
145
df_new = (df_all [((df_all .hrs_thresh > df_all .hrs_thresh .max ()/ 2. ) &
@@ -197,8 +199,7 @@ def plot_wets_drys(self, test=False):
197
199
xlabel = '# Wetlands: {}' .format (
198
200
df [((df ['dry' ]== 0 ) | (df ['dry' ]== 1 ))].shape [0 ]),
199
201
)
200
- if test :
201
- break
202
+ if test : break
202
203
203
204
cbar_ax = fig .add_axes ([0.945 , 0.12 , 0.025 , 0.75 ])
204
205
@@ -352,13 +353,12 @@ def dtw_wet_avg_ann(self):
352
353
353
354
PATH_res = op .join (op .expanduser ('~' ), 'Google_Drive' ,
354
355
'WNC' , 'Wetlands_Paper' , 'Results_Default' )
355
- res = Wetlands (PATH_res , dtw_inc = 0.01 , hrs_per = 50 , z_thresh = 3.75 )
356
+ res = Wetlands (PATH_res , z_thresh = 3.75 )
356
357
# res.optimize(increment=10)
357
- # res.make_indicator(masked=True, seasonal=False)
358
- # res.apply_indicator(seasonal=False)
358
+ res .make_indicator (dtw_inc = 0.01 , hrs_per = 50 , masked = True , seasonal = False )
359
359
360
360
## nonseasonal indicators: dtw < 0.05; hrs_thresh>4443 --------- best
361
361
## seasonal indicators : dtw < 0.17; hrs_thresh > 1211
362
362
363
- res .find_cells (0.05 , hrs_thresh = 4442 )
364
- res .plot_wets_drys ()
363
+ # res.find_cells(0.05, hrs_thresh=4442)
364
+ # res.plot_wets_drys()
0 commit comments