From c134c2d0bc56e9749d26ed82e9c0da63ea269aa7 Mon Sep 17 00:00:00 2001 From: Patrick Date: Fri, 7 Apr 2023 09:04:11 +0200 Subject: [PATCH] added check for future developments --- oggm/params.cfg | 8 ++++---- oggm/tests/test_utils.py | 21 ++++++++++++++++----- oggm/utils/_workflow.py | 36 ++++++++++++++++++++++++++++++++---- 3 files changed, 52 insertions(+), 13 deletions(-) diff --git a/oggm/params.cfg b/oggm/params.cfg index bd4a5538f..d0a50c45b 100644 --- a/oggm/params.cfg +++ b/oggm/params.cfg @@ -401,8 +401,8 @@ store_model_geometry = False # What variables would you like to store in the diagnostics files # Currently available in standard files: -# volume, volume_bsl, volume_bwl, area, length, calving, calving_rate, -# terminus_thick_i (with i in 0..9). +# volume, volume_bsl, volume_bwl, area, area_min_h, length, calving, +# calving_rate, terminus_thick_i (with i in 0..9). # And with additional hydro output: # off_area, on_area, # melt_off_glacier, melt_on_glacier, @@ -410,7 +410,7 @@ store_model_geometry = False # Probably useful for debugging only # melt_residual_off_glacier, melt_residual_on_glacier # model_mb, residual_mb, snow_bucket, -# You need to kee all variables in one line unfortunately +# You need to keep all variables in one line unfortunately store_diagnostic_variables = volume, volume_bsl, volume_bwl, area, length, calving, calving_rate, off_area, on_area, melt_off_glacier, melt_on_glacier, liq_prcp_off_glacier, liq_prcp_on_glacier, snowfall_off_glacier, snowfall_on_glacier # Whether to store the model flowline diagnostic files during operational runs @@ -419,5 +419,5 @@ store_diagnostic_variables = volume, volume_bsl, volume_bwl, area, length, calv store_fl_diagnostics = False # What variables would you like to store in the flowline diagnostics files # Note: area and volume are mandatory -# You need to kee all variables in one line unfortunately +# You need to keep all variables in one line unfortunately store_fl_diagnostic_variables = area, thickness, volume, volume_bsl, volume_bwl, calving_bucket, ice_velocity diff --git a/oggm/tests/test_utils.py b/oggm/tests/test_utils.py index 232fcf50d..ec3a97b14 100644 --- a/oggm/tests/test_utils.py +++ b/oggm/tests/test_utils.py @@ -486,7 +486,20 @@ def test_compile_run_output(self, hef_gdir, hef_copy_gdir): filesuffix = '_compile_run_output_test' cfg.PARAMS['store_model_geometry'] = True - # we run the first gdir without the variables 'area_min_h' (2d) and + # all allowed data variables, for testing in compile_run_output + allowed_data_vars = ['volume', 'volume_bsl', 'volume_bwl', 'area', + 'area_min_h', 'length', 'calving', 'calving_rate', + 'off_area', 'on_area', + 'melt_off_glacier', 'melt_on_glacier', + 'liq_prcp_off_glacier', 'liq_prcp_on_glacier', + 'snowfall_off_glacier', 'snowfall_on_glacier', + 'melt_residual_off_glacier', + 'melt_residual_on_glacier', 'model_mb', + 'residual_mb', 'snow_bucket'] + for gi in range(10): + allowed_data_vars += [f'terminus_thick_{gi}'] + + # we run the first gdir excluding the variables 'area_min_h' (2d) and # 'melt_on_glacier' (3d, with store_monthly_hydro=True) def remove_diag_var(variable): try: @@ -504,10 +517,8 @@ def remove_diag_var(variable): y0=1980, halfsize=1, nyears=2, output_filesuffix=filesuffix) - # the second gdir run includes the variables 'area_min_h' (2d) and - # 'melt_on_glacier' (3d, with store_monthly_hydro=True) - cfg.PARAMS['store_diagnostic_variables'].append('area_min_h') - cfg.PARAMS['store_diagnostic_variables'].append('melt_on_glacier') + # the second gdir run includes all allowed data variables + cfg.PARAMS['store_diagnostic_variables'] = allowed_data_vars flowline.run_with_hydro(gdirs[1], run_task=flowline.run_constant_climate, store_monthly_hydro=True, diff --git a/oggm/utils/_workflow.py b/oggm/utils/_workflow.py index d6a95a982..b422b6836 100644 --- a/oggm/utils/_workflow.py +++ b/oggm/utils/_workflow.py @@ -1107,6 +1107,22 @@ def compile_run_output(gdirs, path=True, input_filesuffix='', # variables in case we have daily time_info = {} time_keys = ['hydro_year', 'hydro_month', 'calendar_year', 'calendar_month'] + allowed_data_vars = ['volume_m3', 'volume_bsl_m3', 'volume_bwl_m3', + 'area_m2', 'area_m2_min_h', 'length_m', 'calving_m3', + 'calving_rate_myr', 'off_area', + 'on_area', 'model_mb', 'is_fixed_geometry_spinup'] + for gi in range(10): + allowed_data_vars += [f'terminus_thick_{gi}'] + # this hydro variables can be _monthly or _daily + hydro_vars = ['melt_off_glacier', 'melt_on_glacier', + 'liq_prcp_off_glacier', 'liq_prcp_on_glacier', + 'snowfall_off_glacier', 'snowfall_on_glacier', + 'melt_residual_off_glacier', 'melt_residual_on_glacier', + 'snow_bucket', 'residual_mb'] + for v in hydro_vars: + allowed_data_vars += [v] + allowed_data_vars += [v + '_monthly'] + allowed_data_vars += [v + '_daily'] data_vars = {} name_2d_dim = 'month_2d' contains_3d_data = False @@ -1141,15 +1157,14 @@ def compile_run_output(gdirs, path=True, input_filesuffix='', # check if their are new data variables and add them for vn in ds.variables: # exclude time variables - if vn in ['month_2d', 'calender_month_2d', + if vn in ['month_2d', 'calendar_month_2d', 'hydro_month_2d']: name_2d_dim = 'month_2d' contains_3d_data = True - elif vn in ['day_2d', 'calender_day_2d', 'hydro_day_2d']: + elif vn in ['day_2d', 'calendar_day_2d', 'hydro_day_2d']: name_2d_dim = 'day_2d' contains_3d_data = True - elif vn not in ['time', 'hydro_year', 'hydro_month', - 'calendar_year', 'calendar_month']: + elif vn in allowed_data_vars: # check if data variable is new if vn not in data_vars.keys(): data_vars[vn] = dict() @@ -1160,6 +1175,19 @@ def compile_run_output(gdirs, path=True, input_filesuffix='', 'dtype']: data_vars[vn]['attrs'][attr] = getattr( ds.variables[vn], attr) + elif vn not in ['time'] + time_keys: + # This check has future developments in mind. + # If you end here it means the current data variable is + # not under the allowed_data_vars OR not under the + # defined time dimensions. If it is a new data variable + # add it to allowed_data_vars above (also add it to + # test_compile_run_output). If it is a new dimension + # handle it in the if/elif statements. + raise InvalidParamsError(f'The data variable "{vn}" ' + 'is not known. Is it new or ' + 'is it a new dimension? ' + 'Check comment above this ' + 'raise for more info!') # If this worked, keep it as template ppath = fp