@@ -30,7 +30,8 @@ def add_0d_stats(x, y):
3030 'abs_diff' : float (np .abs (x - y ))}
3131
3232
33- def calculate_result_statistics (gdir , data_logger , print_statistic = False ):
33+ def calculate_result_statistics (gdir , glacier_state , data_logger ,
34+ print_statistic = False ):
3435 """calculate some statistics of the result for analysis"""
3536
3637 # open the dataset of the run to add our calculated statistics
@@ -69,7 +70,8 @@ def calculate_result_statistics(gdir, data_logger, print_statistic=False):
6970 ds .unknown_parameters [- 1 ][control_indices [control_var ]].values
7071 controls_true = {}
7172 fls_true = gdir .read_pickle ('model_flowlines' ,
72- filesuffix = '_agile_true_init' )[0 ]
73+ filesuffix = '_agile_true_init_'
74+ f'{ glacier_state } ' )[0 ]
7375 for control_var in controls_mdl :
7476 if control_var in ['bed_h' , 'area_bed_h' ]:
7577 controls_true [control_var ] = \
@@ -81,7 +83,8 @@ def calculate_result_statistics(gdir, data_logger, print_statistic=False):
8183 controls_true [control_var ] = controls_mdl [control_var ]
8284 elif control_var in ['section' ]:
8385 fls_1980_true = gdir .read_pickle ('model_flowlines' ,
84- filesuffix = '_creation_spinup' )[0 ]
86+ filesuffix = '_creation_spinup_'
87+ f'{ glacier_state } ' )[0 ]
8588 controls_true [control_var ] = \
8689 fls_1980_true .section [:len (controls_mdl ['section' ])]
8790 else :
@@ -117,7 +120,8 @@ def calculate_result_statistics(gdir, data_logger, print_statistic=False):
117120 sfc_h_start = copy .deepcopy (data_logger .sfc_h_start [- 1 ])
118121 fls_start_mdl .surface_h = sfc_h_start
119122 fls_start_true = gdir .read_pickle ('model_flowlines' ,
120- filesuffix = '_creation_spinup' )[0 ]
123+ filesuffix = '_creation_spinup_'
124+ f'{ glacier_state } ' )[0 ]
121125
122126 past_state_stats = {}
123127 for var in ['thick' , 'area_m2' , 'volume_m3' ]:
@@ -150,7 +154,8 @@ def get_volume(fl):
150154 with xr .open_dataset (fp ) as ds_diag :
151155 past_evol_mdl = ds_diag .load ()
152156 fp = gdir .get_filepath ('model_diagnostics' ,
153- filesuffix = '_agile_true_total_run' )
157+ filesuffix = '_agile_true_total_run_'
158+ f'{ glacier_state } ' )
154159 with xr .open_dataset (fp ) as ds_diag :
155160 past_evol_true = ds_diag .load ()
156161
@@ -165,7 +170,8 @@ def get_volume(fl):
165170 # how well do we match today's glacier state ------------------------------
166171 fls_end_mdl = copy .deepcopy (data_logger .flowlines [- 1 ])
167172 fls_end_true = gdir .read_pickle ('model_flowlines' ,
168- filesuffix = '_agile_true_end' )[0 ]
173+ filesuffix = '_agile_true_end_'
174+ f'{ glacier_state } ' )[0 ]
169175
170176 today_state_stats = {}
171177 for var in ['thick' , 'area_m2' , 'volume_m3' ]:
@@ -196,7 +202,8 @@ def get_volume(fl):
196202 with xr .open_dataset (fp ) as ds_diag :
197203 future_evol_mdl = ds_diag .load ()
198204 fp = gdir .get_filepath ('model_diagnostics' ,
199- filesuffix = '_agile_true_future' )
205+ filesuffix = '_agile_true_future_'
206+ f'{ glacier_state } ' )
200207 with xr .open_dataset (fp ) as ds_diag :
201208 future_evol_true = ds_diag .load ()
202209
@@ -218,7 +225,8 @@ def get_volume(fl):
218225 # Here print the statistics in comparision to the default run
219226
220227 # open default statistics
221- fp_default = os .path .join (gdir .dir , 'default_oggm_statistics.pkl' )
228+ fp_default = os .path .join (gdir .dir , f'default_oggm_statistics_'
229+ f'{ glacier_state } .pkl' )
222230 with open (fp_default , 'rb' ) as handle :
223231 default_stats = pickle .load (handle )
224232
@@ -271,28 +279,32 @@ def get_volume(fl):
271279 raise NotImplementedError (f'{ stat_clean } ' )
272280
273281
274- def calculate_default_oggm_statistics (gdir ):
282+ def calculate_default_oggm_statistics (gdir , glacier_state ):
275283
276284 default_oggm_statistics = {}
277285
278286 for reali in ['dynamic' , 'static' ]:
279287 # open the run files
280288 with xr .open_dataset (
281289 gdir .get_filepath ('model_diagnostics' ,
282- filesuffix = f'_oggm_{ reali } _past' )) as ds :
290+ filesuffix = f'_oggm_{ reali } _past_'
291+ f'{ glacier_state } ' )) as ds :
283292 diag_past = ds .load ()
284293 f = gdir .get_filepath ('fl_diagnostics' ,
285- filesuffix = f'_oggm_{ reali } _past' )
294+ filesuffix = f'_oggm_{ reali } _past_'
295+ f'{ glacier_state } ' )
286296 with xr .open_dataset (f , group = f'fl_0' ) as ds :
287297 fl_diag_past = ds .load ()
288298 with xr .open_dataset (
289299 gdir .get_filepath ('model_diagnostics' ,
290- filesuffix = f'_oggm_{ reali } _future' )) as ds :
300+ filesuffix = f'_oggm_{ reali } _future_'
301+ f'{ glacier_state } ' )) as ds :
291302 diag_future = ds .load ()
292303
293304 # how well do we match the observations -------------------------------
294305 obs_given = gdir .read_pickle ('inversion_input' ,
295- filesuffix = '_agile_measurements' )
306+ filesuffix = '_agile_measurements_'
307+ f'{ glacier_state } ' )
296308 obs_stats = {}
297309 for obs_key in obs_given .keys ():
298310 obs_stats [obs_key ] = {}
@@ -374,9 +386,11 @@ def calculate_default_oggm_statistics(gdir):
374386 controls_mdl = {}
375387 controls_true = {}
376388 fls_mdl = gdir .read_pickle ('model_flowlines' ,
377- filesuffix = '_oggm_first_guess' )[0 ]
389+ filesuffix = '_oggm_first_guess_'
390+ f'{ glacier_state } ' )[0 ]
378391 fls_true = gdir .read_pickle ('model_flowlines' ,
379- filesuffix = '_agile_true_init' )[0 ]
392+ filesuffix = '_agile_true_init_'
393+ f'{ glacier_state } ' )[0 ]
380394
381395 for control_var in all_control_vars :
382396 if control_var in ['bed_h' , 'area_bed_h' ]:
@@ -405,7 +419,8 @@ def calculate_default_oggm_statistics(gdir):
405419 # how well do we match the past glacier state -----------------------------
406420 fls_start_mdl = fl_diag_past .sel (time = fl_diag_past .time [0 ])
407421 fls_start_true = gdir .read_pickle ('model_flowlines' ,
408- filesuffix = '_creation_spinup' )[0 ]
422+ filesuffix = '_creation_spinup_'
423+ f'{ glacier_state } ' )[0 ]
409424
410425 past_state_stats = {}
411426 for var in ['thick' , 'area_m2' , 'volume_m3' ]:
@@ -435,7 +450,8 @@ def get_volume(fl):
435450 # how well do we match the past glacier evolution ---------------------
436451 past_evol_mdl = diag_past
437452 fp = gdir .get_filepath ('model_diagnostics' ,
438- filesuffix = '_agile_true_total_run' )
453+ filesuffix = '_agile_true_total_run_'
454+ f'{ glacier_state } ' )
439455 with xr .open_dataset (fp ) as ds_diag :
440456 past_evol_true = ds_diag .load ()
441457
@@ -450,7 +466,8 @@ def get_volume(fl):
450466 # how well do we match today's glacier state --------------------------
451467 fls_end_mdl = fl_diag_past .sel (time = fl_diag_past .time [- 1 ])
452468 fls_end_true = gdir .read_pickle ('model_flowlines' ,
453- filesuffix = '_agile_true_end' )[0 ]
469+ filesuffix = '_agile_true_end_'
470+ f'{ glacier_state } ' )[0 ]
454471
455472 today_state_stats = {}
456473 for var in ['thick' , 'area_m2' , 'volume_m3' ]:
@@ -480,7 +497,8 @@ def get_volume(fl):
480497 # how well do we match the future glacier evolution -------------------
481498 future_evol_mdl = diag_future
482499 fp = gdir .get_filepath ('model_diagnostics' ,
483- filesuffix = '_agile_true_future' )
500+ filesuffix = '_agile_true_future_'
501+ f'{ glacier_state } ' )
484502 with xr .open_dataset (fp ) as ds_diag :
485503 future_evol_true = ds_diag .load ()
486504
@@ -494,7 +512,7 @@ def get_volume(fl):
494512
495513 # save final default statistics as pickle
496514 out = os .path .join (gdir .dir ,
497- 'default_oggm_statistics .pkl' )
515+ f'default_oggm_statistics_ { glacier_state } .pkl' )
498516 with open (out , 'wb' ) as handle :
499517 pickle .dump (default_oggm_statistics , handle ,
500518 protocol = pickle .HIGHEST_PROTOCOL )
0 commit comments