@@ -132,10 +132,12 @@ def _error(x, y):
132132 reference_srad_path , parse_dates = True
133133 )
134134
135- srad_meta = {'optimization_title' : self .title ,
135+ srad_meta = {'stage' : 'swrad' ,
136+ 'hru_id' : station_nhru ,
137+ 'optimization_title' : self .title ,
136138 'optimization_description' : self .description ,
137- 'swrad_start_time ' : str (srad_start_time ),
138- 'swrad_end_time ' : str (srad_end_time ),
139+ 'start_time ' : str (srad_start_time ),
140+ 'end_time ' : str (srad_end_time ),
139141 'measured_swrad' : reference_srad_path ,
140142 'sim_dirs' : [],
141143 'original_params' : self .parameters .base_file
@@ -233,13 +235,59 @@ def _mod_params(parameters, intcp, slope):
233235 return ret
234236
235237
236- class OptimizationResult (Optimizer ):
238+ class OptimizationResult :
239+
240+ def __init__ (self , working_dir , stage = 'all' ):
241+ self .working_dir = working_dir
242+ self .metadata_json_paths = self .\
243+ get_optr_jsons (self .working_dir , stage )
244+ @staticmethod
245+ def get_optr_jsons (work_dir , stage = 'all' ):
246+ """
247+ Retrieve locations of optimization output jsons which contain
248+ important metadata needed to understand optimization results.
249+ Create dictionary of each optimization stage as keys, and lists
250+ of corresponding json file paths for each stage as values.
251+
252+ Arguments:
253+ work_dir (str): path to simulation directory where
254+ optimization simulations were conducted and where
255+ corresponding json files should exist.
256+ stage (str): the stage ('swrad', 'pet', 'flow', etc.) of
257+ the optimization in which to gather the jsons, if
258+ stage is 'all' then each stage will be gathered.
259+ Returns:
260+ ret (dict): dictionary of stage (keys) and lists of
261+ json file paths for that stage (values).
262+ """
263+
264+ ret = {}
265+ if stage != 'all' :
266+ ret [stage ] = [OPJ (work_dir , f ) for f in \
267+ os .listdir (work_dir ) if \
268+ f .endswith ('_{0}_opt.json' .format (stage )) ]
269+ else :
270+ stages = ['swrad' , 'pet' , 'flow' ]
271+ for s in stages :
272+ ret [s ] = OptimizationResult .get_optr_jsons (work_dir , s )
273+
274+ return ret
237275
238- pass
276+ class SradOptimizationResult ( OptimizationResult ):
239277
278+ def __init__ (self , working_dir , stage = 'swrad' ):
279+ self .working_dir = working_dir
280+ self .stage = stage
240281
241- class SradOptimizationResult ( OptimizationResult ):
282+ self . metadata_json_paths = OptimizationResult . get_optr_jsons ( self . working_dir , stage )
242283
243- pass
284+
285+
286+ class PetOptimizationResult (OptimizationResult ):
287+
288+ def __init__ (self , working_dir , stage = 'pet' ):
289+ self .working_dir = working_dir
290+ self .stage = stage
244291
292+ self .metadata_json_paths = OptimizationResult .get_optr_jsons (self .working_dir , stage )
245293
0 commit comments