Skip to content

Commit

Permalink
added check for future developments
Browse files Browse the repository at this point in the history
  • Loading branch information
pat-schmitt committed Apr 7, 2023
1 parent b45b78b commit c134c2d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 13 deletions.
8 changes: 4 additions & 4 deletions oggm/params.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -401,16 +401,16 @@ 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,
# liq_prcp_off_glacier, liq_prcp_on_glacier, snowfall_off_glacier, snowfall_on_glacier,
# 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
Expand All @@ -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
21 changes: 16 additions & 5 deletions oggm/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
Expand Down
36 changes: 32 additions & 4 deletions oggm/utils/_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down

0 comments on commit c134c2d

Please sign in to comment.