@@ -157,11 +157,18 @@ def struct_open_props(struct, th_data, out_freq="15min", datetime_idx=None):
157157 For instance, a simple gate might just be (width * height)/(max(width) * max(height))
158158 """
159159
160- if struct ["type" ] == "weir" :
160+ if isinstance (struct , dict ):
161+ structtype = struct ["type" ]
162+ structname = struct ["name" ]
163+ else :
164+ structtype = struct .type
165+ structname = struct .name
166+
167+ if structtype == "weir" :
161168 # width, elevation, op_down, op_up
162169 up_cols_to_multiply = ["install" , "ndup" , "op_up" , "elev" , "width" ]
163170 down_cols_to_multiply = ["install" , "ndup" , "op_down" , "elev" , "width" ]
164- elif struct [ "type" ] == "radial" :
171+ elif structtype == "radial" :
165172 # width, height, elevation, op_down, op_up
166173 up_cols_to_multiply = ["install" , "ndup" , "op_up" , "elev" , "width" , "height" ]
167174 down_cols_to_multiply = [
@@ -172,11 +179,11 @@ def struct_open_props(struct, th_data, out_freq="15min", datetime_idx=None):
172179 "width" ,
173180 "height" ,
174181 ]
175- elif struct [ "type" ] == "culvert" :
182+ elif structtype == "culvert" :
176183 # rad, elevation, op_down, op_up
177184 up_cols_to_multiply = ["install" , "ndup" , "op_up" , "elev" , "rad" ]
178185 down_cols_to_multiply = ["install" , "ndup" , "op_down" , "elev" , "rad" ]
179- elif struct [ "type" ] == "radial_relheight" :
186+ elif structtype == "radial_relheight" :
180187 # width, height, elevation, op_down, op_up
181188 up_cols_to_multiply = ["install" , "ndup" , "op_up" , "elev" , "width" , "height" ]
182189 down_cols_to_multiply = [
@@ -187,7 +194,7 @@ def struct_open_props(struct, th_data, out_freq="15min", datetime_idx=None):
187194 "width" ,
188195 "height" ,
189196 ]
190- elif struct [ "type" ] == "weir_culvert" :
197+ elif structtype == "weir_culvert" :
191198 # elevation, width, op_down, op_up - weirs
192199 # elevation, width, op_up, op_down - culvert
193200 up_cols_to_multiply = [
@@ -213,7 +220,7 @@ def struct_open_props(struct, th_data, out_freq="15min", datetime_idx=None):
213220 "down_op_pipe" ,
214221 ]
215222 else :
216- raise ValueError (f"structure type { struct [ 'type' ] } is not yet supported!" )
223+ raise ValueError (f"structure type { structtype } is not yet supported!" )
217224
218225 # Take the dataframe and normalize to max/min of each column
219226 norm_df = normalize_df (th_data )
@@ -225,8 +232,8 @@ def struct_open_props(struct, th_data, out_freq="15min", datetime_idx=None):
225232 norm_df = norm_df .ffill ()
226233
227234 up_df = norm_df [["open_up" ]].copy ()
228- up_df .columns = [f"{ struct [ 'name' ] } _up" ]
235+ up_df .columns = [f"{ structname } _up" ]
229236 down_df = norm_df [["open_down" ]].copy ()
230- down_df .columns = [f"{ struct [ 'name' ] } _down" ]
237+ down_df .columns = [f"{ structname } _down" ]
231238
232239 return up_df , down_df
0 commit comments