@@ -88,18 +88,28 @@ def read_layer(layer_name):
8888 flowpaths_df = table_dict .get ('flowpaths' , pd .DataFrame ())
8989 flowpath_attributes_df = table_dict .get ('flowpath_attributes' , pd .DataFrame ())
9090
91- # Check if 'link' column exists and rename it to 'id'
91+ # Check if 'link' column exists; drop existing 'id' col; rename 'link' to 'id'
9292 if 'link' in flowpath_attributes_df .columns :
93+ # In HF 2.2, a 'link' field was introduced. The field is identical to
94+ # previous version's 'id' field, but it preferred moving forwards.
95+ flowpath_attributes_df .drop (columns = ['id' ], errors = 'ignore' , inplace = True )
9396 flowpath_attributes_df .rename (columns = {'link' : 'id' }, inplace = True )
94-
97+
98+ # NOTE: aaraney: `flowpaths_df` and `flowpath_attributes_df` can share
99+ # column names but this is not accounted for elsewhere. im not sure if it
100+ # is okay to assume that if the left and right df have the same `id` field
101+ # that the other shared columns will match and thus it is safe to set, for
102+ # example, the left suffix to "".
95103 # Merge flowpaths and flowpath_attributes
96104 flowpaths = pd .merge (
97105 flowpaths_df ,
98106 flowpath_attributes_df ,
99107 on = 'id' ,
100- how = 'inner'
108+ how = 'inner' ,
109+ # NOTE: aaraney: not sure if this is safe
110+ suffixes = ("" , "_flowpath_attributes" ),
101111 )
102-
112+
103113 lakes = table_dict .get ('lakes' , pd .DataFrame ())
104114 network = table_dict .get ('network' , pd .DataFrame ())
105115 nexus = table_dict .get ('nexus' , pd .DataFrame ())
@@ -601,7 +611,7 @@ def preprocess_waterbodies(self, lakes, nexus):
601611 self ._duplicate_ids_df = pd .DataFrame ()
602612 self ._gl_climatology_df = pd .DataFrame ()
603613
604- self ._dataframe = self .dataframe .drop ('waterbody' , axis = 1 ).drop_duplicates ()
614+ self ._dataframe = self .dataframe .drop ('waterbody' , axis = 1 , errors = 'ignore' ).drop_duplicates ()
605615
606616 def preprocess_data_assimilation (self , network ):
607617 if not network .empty :
@@ -726,7 +736,16 @@ def build_qlateral_array(self, run,):
726736 # This capability should be here, but we need to think through how to handle all of this
727737 # data in memory for large domains and many timesteps... - shorvath, Feb 28, 2024
728738 qlat_file_pattern_filter = self .forcing_parameters .get ("qlat_file_pattern_filter" , None )
729- if qlat_file_pattern_filter == "nex-*" :
739+
740+ if qlat_file_pattern_filter == "*.CATOUT.csv" :
741+ for f in qlat_files :
742+ df = pd .read_csv (f )
743+ df = df .set_index ('feature_id' )
744+ dfs .append (df )
745+
746+ qlats_df = pd .concat (dfs , axis = 1 )
747+ qlats_df = qlats_df [qlats_df .index .isin (self .segment_index )]
748+ elif qlat_file_pattern_filter == "nex-*" :
730749 for f in qlat_files :
731750 df = pd .read_csv (f , names = ['timestamp' , 'qlat' ], index_col = [0 ])
732751 df ['timestamp' ] = pd .to_datetime (df ['timestamp' ]).dt .strftime ('%Y%m%d%H%M' )
@@ -752,10 +771,11 @@ def build_qlateral_array(self, run,):
752771 # lateral flows [m^3/s] are stored at NEXUS points with NEXUS ids
753772 nexuses_lateralflows_df = pd .concat (dfs , axis = 1 )
754773
755- # Take flowpath ids entering NEXUS and replace NEXUS ids by the upstream flowpath ids
756- qlats_df = nexuses_lateralflows_df .rename (index = self .downstream_flowpath_dict )
757- qlats_df = qlats_df [qlats_df .index .isin (self .segment_index )]
758-
774+ if qlat_file_pattern_filter != "*.CATOUT.csv" :
775+ # Take flowpath ids entering NEXUS and replace NEXUS ids by the upstream flowpath ids
776+ qlats_df = nexuses_lateralflows_df .rename (index = self .downstream_flowpath_dict )
777+ qlats_df = qlats_df [qlats_df .index .isin (self .segment_index )]
778+
759779 '''
760780 #For a terminal nexus, we want to include the lateral flow from the catchment contributing to that nexus
761781 #one way to do that is to cheat and put that lateral flow at the upstream...this is probably the simplest way
0 commit comments