From de0fc7f081b776b1bd54747432f533d0768a86d6 Mon Sep 17 00:00:00 2001 From: btobers Date: Tue, 3 Jun 2025 13:13:40 -0400 Subject: [PATCH 1/9] use dictionary structure to aggregate regional and multi-gcm/realizaion results --- .../postproc/postproc_compile_simulations.py | 378 +++--------------- pygem/bin/postproc/postproc_monthly_mass.py | 4 +- 2 files changed, 47 insertions(+), 335 deletions(-) diff --git a/pygem/bin/postproc/postproc_compile_simulations.py b/pygem/bin/postproc/postproc_compile_simulations.py index 72a19247..04eb1606 100644 --- a/pygem/bin/postproc/postproc_compile_simulations.py +++ b/pygem/bin/postproc/postproc_compile_simulations.py @@ -175,20 +175,9 @@ def run(args): ] # instantiate variables that will hold all concatenated data for GCMs/realizations - # monthly vars - reg_glac_allgcms_runoff_monthly = None - reg_offglac_allgcms_runoff_monthly = None - reg_glac_allgcms_acc_monthly = None - reg_glac_allgcms_melt_monthly = None - reg_glac_allgcms_refreeze_monthly = None - reg_glac_allgcms_frontalablation_monthly = None - reg_glac_allgcms_massbaltotal_monthly = None - reg_glac_allgcms_prec_monthly = None - reg_glac_allgcms_mass_monthly = None - - # annual vars - reg_glac_allgcms_area_annual = None - reg_glac_allgcms_mass_annual = None + reg_all_gcms_data = {} + for var in vars: + reg_all_gcms_data[var] = [] ### LEVEL II ### # for each batch, loop through GCM(s) and realization(s) @@ -226,23 +215,9 @@ def run(args): ) # instantiate variables that will hold concatenated data for the current GCM - # monthly vars - reg_glac_gcm_runoff_monthly = None - reg_offglac_gcm_runoff_monthly = None - reg_glac_gcm_acc_monthly = None - reg_glac_gcm_melt_monthly = None - reg_glac_gcm_refreeze_monthly = None - reg_glac_gcm_frontalablation_monthly = None - reg_glac_gcm_snowline_monthly = None - reg_glac_gcm_massbaltotal_monthly = None - reg_glac_gcm_prec_monthly = None - reg_glac_gcm_mass_monthly = None - - # annual vars - reg_glac_gcm_area_annual = None - reg_glac_gcm_mass_annual = None - reg_glac_gcm_ELA_annual = None - reg_glac_gcm_mass_bsl_annual = None + reg_gcm_data = {} + for var in vars: + reg_gcm_data[var] = [] ### LEVEL IV ### # loop through each glacier in batch list @@ -255,297 +230,34 @@ def run(args): # try to load all glaciers in region try: # open netcdf file - ds_glac = xr.open_dataset(glacno_fp) - # get monthly vars - glac_runoff_monthly = ds_glac.glac_runoff_monthly.values - offglac_runoff_monthly = ds_glac.offglac_runoff_monthly.values - # try extra vars - try: - glac_acc_monthly = ds_glac.glac_acc_monthly.values - glac_melt_monthly = ds_glac.glac_melt_monthly.values - glac_refreeze_monthly = ds_glac.glac_refreeze_monthly.values - glac_frontalablation_monthly = ( - ds_glac.glac_frontalablation_monthly.values - ) - glac_snowline_monthly = ds_glac.glac_snowline_monthly.values - glac_massbaltotal_monthly = ( - ds_glac.glac_massbaltotal_monthly.values - ) - glac_prec_monthly = ds_glac.glac_prec_monthly.values - glac_mass_monthly = ds_glac.glac_mass_monthly.values - except: - glac_acc_monthly = np.full((1, len(time_values)), np.nan) - glac_melt_monthly = np.full((1, len(time_values)), np.nan) - glac_refreeze_monthly = np.full( - (1, len(time_values)), np.nan - ) - glac_frontalablation_monthly = np.full( - (1, len(time_values)), np.nan - ) - glac_snowline_monthly = np.full( - (1, len(time_values)), np.nan - ) - glac_massbaltotal_monthly = np.full( - (1, len(time_values)), np.nan - ) - glac_prec_monthly = np.full((1, len(time_values)), np.nan) - glac_mass_monthly = np.full((1, len(time_values)), np.nan) - # get annual vars - glac_area_annual = ds_glac.glac_area_annual.values - glac_mass_annual = ds_glac.glac_mass_annual.values - glac_ELA_annual = ds_glac.glac_ELA_annual.values - glac_mass_bsl_annual = ds_glac.glac_mass_bsl_annual.values + with xr.open_dataset(glacno_fp) as ds_glac: + for var in vars: + try: + arr = getattr(ds_glac, var).values + except AttributeError: + if 'monthly' in var: + arr = np.full((1, len(time_values)), np.nan) + elif 'annual' in var: + arr = np.full((1, year_values.shape[0]), np.nan) + reg_gcm_data[var].append(arr) # if glacier output DNE in sim output file, create empty nan arrays to keep record of missing glaciers except: - # monthly vars - glac_runoff_monthly = np.full((1, len(time_values)), np.nan) - offglac_runoff_monthly = np.full((1, len(time_values)), np.nan) - glac_acc_monthly = np.full((1, len(time_values)), np.nan) - glac_melt_monthly = np.full((1, len(time_values)), np.nan) - glac_refreeze_monthly = np.full((1, len(time_values)), np.nan) - glac_frontalablation_monthly = np.full( - (1, len(time_values)), np.nan - ) - glac_snowline_monthly = np.full((1, len(time_values)), np.nan) - glac_massbaltotal_monthly = np.full( - (1, len(time_values)), np.nan - ) - glac_prec_monthly = np.full((1, len(time_values)), np.nan) - glac_mass_monthly = np.full((1, len(time_values)), np.nan) - # annual vars - glac_area_annual = np.full((1, year_values.shape[0]), np.nan) - glac_mass_annual = np.full((1, year_values.shape[0]), np.nan) - glac_ELA_annual = np.full((1, year_values.shape[0]), np.nan) - glac_mass_bsl_annual = np.full( - (1, year_values.shape[0]), np.nan - ) - - # append each glacier output to master regional set of arrays - if reg_glac_gcm_mass_annual is None: - # monthly vars - reg_glac_gcm_runoff_monthly = glac_runoff_monthly - reg_offglac_gcm_runoff_monthly = offglac_runoff_monthly - reg_glac_gcm_acc_monthly = glac_acc_monthly - reg_glac_gcm_melt_monthly = glac_melt_monthly - reg_glac_gcm_refreeze_monthly = glac_refreeze_monthly - reg_glac_gcm_frontalablation_monthly = ( - glac_frontalablation_monthly - ) - reg_glac_gcm_snowline_monthly = glac_snowline_monthly - reg_glac_gcm_massbaltotal_monthly = glac_massbaltotal_monthly - reg_glac_gcm_prec_monthly = glac_prec_monthly - reg_glac_gcm_mass_monthly = glac_mass_monthly - # annual vars - reg_glac_gcm_area_annual = glac_area_annual - reg_glac_gcm_mass_annual = glac_mass_annual - reg_glac_gcm_ELA_annual = glac_ELA_annual - reg_glac_gcm_mass_bsl_annual = glac_mass_bsl_annual - # otherwise concatenate existing arrays - else: - # monthly vars - reg_glac_gcm_runoff_monthly = np.concatenate( - (reg_glac_gcm_runoff_monthly, glac_runoff_monthly), axis=0 - ) - reg_offglac_gcm_runoff_monthly = np.concatenate( - (reg_offglac_gcm_runoff_monthly, offglac_runoff_monthly), - axis=0, - ) - reg_glac_gcm_acc_monthly = np.concatenate( - (reg_glac_gcm_acc_monthly, glac_acc_monthly), axis=0 - ) - reg_glac_gcm_melt_monthly = np.concatenate( - (reg_glac_gcm_melt_monthly, glac_melt_monthly), axis=0 - ) - reg_glac_gcm_refreeze_monthly = np.concatenate( - (reg_glac_gcm_refreeze_monthly, glac_refreeze_monthly), - axis=0, - ) - reg_glac_gcm_frontalablation_monthly = np.concatenate( - ( - reg_glac_gcm_frontalablation_monthly, - glac_frontalablation_monthly, - ), - axis=0, - ) - reg_glac_gcm_snowline_monthly = np.concatenate( - (reg_glac_gcm_snowline_monthly, glac_snowline_monthly), - axis=0, - ) - reg_glac_gcm_massbaltotal_monthly = np.concatenate( - ( - reg_glac_gcm_massbaltotal_monthly, - glac_massbaltotal_monthly, - ), - axis=0, - ) - reg_glac_gcm_prec_monthly = np.concatenate( - (reg_glac_gcm_prec_monthly, glac_prec_monthly), axis=0 - ) - reg_glac_gcm_mass_monthly = np.concatenate( - (reg_glac_gcm_mass_monthly, glac_mass_monthly), axis=0 - ) - # annual vars - reg_glac_gcm_area_annual = np.concatenate( - (reg_glac_gcm_area_annual, glac_area_annual), axis=0 - ) - reg_glac_gcm_mass_annual = np.concatenate( - (reg_glac_gcm_mass_annual, glac_mass_annual), axis=0 - ) - reg_glac_gcm_ELA_annual = np.concatenate( - (reg_glac_gcm_ELA_annual, glac_ELA_annual), axis=0 - ) - reg_glac_gcm_mass_bsl_annual = np.concatenate( - (reg_glac_gcm_mass_bsl_annual, glac_mass_bsl_annual), axis=0 - ) - - # aggregate gcms - if reg_glac_allgcms_runoff_monthly is None: - # monthly vars - reg_glac_allgcms_runoff_monthly = reg_glac_gcm_runoff_monthly[ - np.newaxis, :, : - ] - reg_offglac_allgcms_runoff_monthly = reg_offglac_gcm_runoff_monthly[ - np.newaxis, :, : - ] - reg_glac_allgcms_acc_monthly = reg_glac_gcm_acc_monthly[ - np.newaxis, :, : - ] - reg_glac_allgcms_melt_monthly = reg_glac_gcm_melt_monthly[ - np.newaxis, :, : - ] - reg_glac_allgcms_refreeze_monthly = reg_glac_gcm_refreeze_monthly[ - np.newaxis, :, : - ] - reg_glac_allgcms_frontalablation_monthly = ( - reg_glac_gcm_frontalablation_monthly[np.newaxis, :, :] - ) - reg_glac_allgcms_snowline_monthly = reg_glac_gcm_snowline_monthly[ - np.newaxis, :, : - ] - reg_glac_allgcms_massbaltotal_monthly = ( - reg_glac_gcm_massbaltotal_monthly[np.newaxis, :, :] - ) - reg_glac_allgcms_prec_monthly = reg_glac_gcm_prec_monthly[ - np.newaxis, :, : - ] - reg_glac_allgcms_mass_monthly = reg_glac_gcm_mass_monthly[ - np.newaxis, :, : - ] - # annual vars - reg_glac_allgcms_area_annual = reg_glac_gcm_area_annual[ - np.newaxis, :, : - ] - reg_glac_allgcms_mass_annual = reg_glac_gcm_mass_annual[ - np.newaxis, :, : - ] - reg_glac_allgcms_ELA_annual = reg_glac_gcm_ELA_annual[ - np.newaxis, :, : - ] - reg_glac_allgcms_mass_bsl_annual = reg_glac_gcm_mass_bsl_annual[ - np.newaxis, :, : - ] - else: - # monthly vrs - reg_glac_allgcms_runoff_monthly = np.concatenate( - ( - reg_glac_allgcms_runoff_monthly, - reg_glac_gcm_runoff_monthly[np.newaxis, :, :], - ), - axis=0, - ) - reg_offglac_allgcms_runoff_monthly = np.concatenate( - ( - reg_offglac_allgcms_runoff_monthly, - reg_offglac_gcm_runoff_monthly[np.newaxis, :, :], - ), - axis=0, - ) - reg_glac_allgcms_acc_monthly = np.concatenate( - ( - reg_glac_allgcms_acc_monthly, - reg_glac_gcm_acc_monthly[np.newaxis, :, :], - ), - axis=0, - ) - reg_glac_allgcms_melt_monthly = np.concatenate( - ( - reg_glac_allgcms_melt_monthly, - reg_glac_gcm_melt_monthly[np.newaxis, :, :], - ), - axis=0, - ) - reg_glac_allgcms_refreeze_monthly = np.concatenate( - ( - reg_glac_allgcms_refreeze_monthly, - reg_glac_gcm_refreeze_monthly[np.newaxis, :, :], - ), - axis=0, - ) - reg_glac_allgcms_frontalablation_monthly = np.concatenate( - ( - reg_glac_allgcms_frontalablation_monthly, - reg_glac_gcm_frontalablation_monthly[np.newaxis, :, :], - ), - axis=0, - ) - reg_glac_allgcms_snowline_monthly = np.concatenate( - ( - reg_glac_allgcms_snowline_monthly, - reg_glac_gcm_snowline_monthly[np.newaxis, :, :], - ), - axis=0, - ) - reg_glac_allgcms_massbaltotal_monthly = np.concatenate( - ( - reg_glac_allgcms_massbaltotal_monthly, - reg_glac_gcm_massbaltotal_monthly[np.newaxis, :, :], - ), - axis=0, - ) - reg_glac_allgcms_prec_monthly = np.concatenate( - ( - reg_glac_allgcms_prec_monthly, - reg_glac_gcm_prec_monthly[np.newaxis, :, :], - ), - axis=0, - ) - reg_glac_allgcms_mass_monthly = np.concatenate( - ( - reg_glac_allgcms_mass_monthly, - reg_glac_gcm_mass_monthly[np.newaxis, :, :], - ), - axis=0, - ) - # annual vars - reg_glac_allgcms_area_annual = np.concatenate( - ( - reg_glac_allgcms_area_annual, - reg_glac_gcm_area_annual[np.newaxis, :, :], - ), - axis=0, - ) - reg_glac_allgcms_mass_annual = np.concatenate( - ( - reg_glac_allgcms_mass_annual, - reg_glac_gcm_mass_annual[np.newaxis, :, :], - ), - axis=0, - ) - reg_glac_allgcms_ELA_annual = np.concatenate( - ( - reg_glac_allgcms_ELA_annual, - reg_glac_gcm_ELA_annual[np.newaxis, :, :], - ), - axis=0, - ) - reg_glac_allgcms_mass_bsl_annual = np.concatenate( - ( - reg_glac_allgcms_mass_bsl_annual, - reg_glac_gcm_mass_bsl_annual[np.newaxis, :, :], - ), - axis=0, - ) + for var in vars: + if 'monthly' in var: + arr = np.full((1, len(time_values)), np.nan) + elif 'annual' in var: + arr = np.full((1, year_values.shape[0]), np.nan) + reg_gcm_data[var].append(arr) + + # stack all individual glacier data for each var, for the current GCM and append as 2D array to list of reg_all_gcms_data[var] + for var in vars: + reg_gcm_data[var] = np.vstack(reg_gcm_data[var]) + reg_all_gcms_data[var].append(reg_gcm_data[var]) + + # stack all gcms/realizations + for var in vars: + reg_all_gcms_data[var] = np.stack(reg_all_gcms_data[var],axis=0) # ===== CREATE NETCDF FILES===== @@ -595,7 +307,7 @@ def run(args): data_vars=dict( glac_runoff_monthly=( coord_order, - reg_glac_allgcms_runoff_monthly, + reg_all_gcms_data[var], ), crs=np.nan, ), @@ -616,7 +328,7 @@ def run(args): data_vars=dict( offglac_runoff_monthly=( coord_order, - reg_offglac_allgcms_runoff_monthly, + reg_all_gcms_data[var], ), crs=np.nan, ), @@ -635,7 +347,7 @@ def run(args): elif var == 'glac_acc_monthly': ds = xr.Dataset( data_vars=dict( - glac_acc_monthly=(coord_order, reg_glac_allgcms_acc_monthly), + glac_acc_monthly=(coord_order, reg_all_gcms_data[var]), crs=np.nan, ), coords=coords_dict, @@ -653,7 +365,7 @@ def run(args): elif var == 'glac_melt_monthly': ds = xr.Dataset( data_vars=dict( - glac_melt_monthly=(coord_order, reg_glac_allgcms_melt_monthly), + glac_melt_monthly=(coord_order, reg_all_gcms_data[var]), crs=np.nan, ), coords=coords_dict, @@ -672,7 +384,7 @@ def run(args): data_vars=dict( glac_refreeze_monthly=( coord_order, - reg_glac_allgcms_refreeze_monthly, + reg_all_gcms_data[var], ), crs=np.nan, ), @@ -692,7 +404,7 @@ def run(args): data_vars=dict( glac_frontalablation_monthly=( coord_order, - reg_glac_allgcms_frontalablation_monthly, + reg_all_gcms_data[var], ), crs=np.nan, ), @@ -723,7 +435,7 @@ def run(args): data_vars=dict( glac_snowline_monthly=( coord_order, - reg_glac_allgcms_snowline_monthly, + reg_all_gcms_data[var], ), crs=np.nan, ), @@ -746,7 +458,7 @@ def run(args): data_vars=dict( glac_massbaltotal_monthly=( coord_order, - reg_glac_allgcms_massbaltotal_monthly, + reg_all_gcms_data[var], ), crs=np.nan, ), @@ -767,7 +479,7 @@ def run(args): elif var == 'glac_prec_monthly': ds = xr.Dataset( data_vars=dict( - glac_prec_monthly=(coord_order, reg_glac_allgcms_prec_monthly), + glac_prec_monthly=(coord_order, reg_all_gcms_data[var]), crs=np.nan, ), coords=coords_dict, @@ -787,7 +499,7 @@ def run(args): elif var == 'glac_mass_monthly': ds = xr.Dataset( data_vars=dict( - glac_mass_monthly=(coord_order, reg_glac_allgcms_mass_monthly), + glac_mass_monthly=(coord_order, reg_all_gcms_data[var]), crs=np.nan, ), coords=coords_dict, @@ -805,7 +517,7 @@ def run(args): elif var == 'glac_area_annual': ds = xr.Dataset( data_vars=dict( - glac_area_annual=(coord_order, reg_glac_allgcms_area_annual), + glac_area_annual=(coord_order, reg_all_gcms_data[var]), crs=np.nan, ), coords=coords_dict, @@ -821,7 +533,7 @@ def run(args): elif var == 'glac_mass_annual': ds = xr.Dataset( data_vars=dict( - glac_mass_annual=(coord_order, reg_glac_allgcms_mass_annual), + glac_mass_annual=(coord_order, reg_all_gcms_data[var]), crs=np.nan, ), coords=coords_dict, @@ -839,7 +551,7 @@ def run(args): elif var == 'glac_ELA_annual': ds = xr.Dataset( data_vars=dict( - glac_ELA_annual=(coord_order, reg_glac_allgcms_ELA_annual), + glac_ELA_annual=(coord_order, reg_all_gcms_data[var]), crs=np.nan, ), coords=coords_dict, @@ -861,7 +573,7 @@ def run(args): data_vars=dict( glac_mass_bsl_annual=( coord_order, - reg_glac_allgcms_mass_bsl_annual, + reg_all_gcms_data[var], ), crs=np.nan, ), diff --git a/pygem/bin/postproc/postproc_monthly_mass.py b/pygem/bin/postproc/postproc_monthly_mass.py index b7367f32..d92e80fe 100644 --- a/pygem/bin/postproc/postproc_monthly_mass.py +++ b/pygem/bin/postproc/postproc_monthly_mass.py @@ -238,8 +238,8 @@ def main(): ncores = 1 # Parallel processing - print('Processing with ' + str(args.ncores) + ' cores...') - with multiprocessing.Pool(args.ncores) as p: + print('Processing with ' + str(ncores) + ' cores...') + with multiprocessing.Pool(ncores) as p: p.map(run, simpath) print('Total processing time:', time.time() - time_start, 's') From 4d821e98e09e3552a0e01d5aaaf5472e030c9576 Mon Sep 17 00:00:00 2001 From: btobers Date: Tue, 3 Jun 2025 13:14:35 -0400 Subject: [PATCH 2/9] ruff formatting --- pygem/bin/postproc/postproc_compile_simulations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygem/bin/postproc/postproc_compile_simulations.py b/pygem/bin/postproc/postproc_compile_simulations.py index 04eb1606..44b0497c 100644 --- a/pygem/bin/postproc/postproc_compile_simulations.py +++ b/pygem/bin/postproc/postproc_compile_simulations.py @@ -257,7 +257,7 @@ def run(args): # stack all gcms/realizations for var in vars: - reg_all_gcms_data[var] = np.stack(reg_all_gcms_data[var],axis=0) + reg_all_gcms_data[var] = np.stack(reg_all_gcms_data[var], axis=0) # ===== CREATE NETCDF FILES===== From ab8ad17c8a8839aa3a78f6e22fda1c95b8f5c6ea Mon Sep 17 00:00:00 2001 From: btobers Date: Fri, 6 Jun 2025 12:56:46 -0400 Subject: [PATCH 3/9] variable dictionary to cleanup if/elif statements --- .../postproc/postproc_compile_simulations.py | 391 +++++------------- 1 file changed, 106 insertions(+), 285 deletions(-) diff --git a/pygem/bin/postproc/postproc_compile_simulations.py b/pygem/bin/postproc/postproc_compile_simulations.py index 44b0497c..ca0f3703 100644 --- a/pygem/bin/postproc/postproc_compile_simulations.py +++ b/pygem/bin/postproc/postproc_compile_simulations.py @@ -55,6 +55,96 @@ 19: 'Antarctic & Subantarctic', } +# define metadata for each variable +var_metadata = { + 'glac_runoff_monthly': { + 'long_name': 'glacier-wide runoff', + 'units': 'm3', + 'temporal_resolution': 'monthly', + 'comment': 'runoff from the glacier terminus, which moves over time', + }, + 'offglac_runoff_monthly': { + 'long_name': 'off-glacier-wide runoff', + 'units': 'm3', + 'temporal_resolution': 'monthly', + 'comment': 'off-glacier runoff from area where glacier no longer exists', + }, + 'glac_acc_monthly': { + 'long_name': 'glacier-wide accumulation, in water equivalent', + 'units': 'm3', + 'temporal_resolution': 'monthly', + 'comment': 'only the solid precipitation', + }, + 'glac_melt_monthly': { + 'long_name': 'glacier-wide melt, in water equivalent', + 'units': 'm3', + 'temporal_resolution': 'monthly', + }, + 'glac_refreeze_monthly': { + 'long_name': 'glacier-wide refreeze, in water equivalent', + 'units': 'm3', + 'temporal_resolution': 'monthly', + }, + 'glac_frontalablation_monthly': { + 'long_name': 'glacier-wide frontal ablation, in water equivalent', + 'units': 'm3', + 'temporal_resolution': 'monthly', + 'comment': ( + 'mass losses from calving, subaerial frontal melting, sublimation above the waterline and ' + 'subaqueous frontal melting below the waterline; positive values indicate mass lost like melt' + ), + }, + 'glac_snowline_monthly': { + 'long_name': 'transient snowline altitude above mean sea level', + 'units': 'm', + 'temporal_resolution': 'monthly', + 'comment': 'transient snowline is altitude separating snow from ice/firn', + }, + 'glac_massbaltotal_monthly': { + 'long_name': 'glacier-wide total mass balance, in water equivalent', + 'units': 'm3', + 'temporal_resolution': 'monthly', + 'comment': 'total mass balance is the sum of the climatic mass balance and frontal ablation', + }, + 'glac_prec_monthly': { + 'long_name': 'glacier-wide precipitation (liquid)', + 'units': 'm3', + 'temporal_resolution': 'monthly', + 'comment': 'only the liquid precipitation, solid precipitation excluded', + }, + 'glac_mass_monthly': { + 'long_name': 'glacier mass', + 'units': 'kg', + 'temporal_resolution': 'monthly', + 'comment': ( + 'mass of ice based on area and ice thickness at start of the year and the monthly total mass balance' + ), + }, + 'glac_area_annual': { + 'long_name': 'glacier area', + 'units': 'm2', + 'temporal_resolution': 'annual', + 'comment': 'area at start of the year', + }, + 'glac_mass_annual': { + 'long_name': 'glacier mass', + 'units': 'kg', + 'temporal_resolution': 'annual', + 'comment': 'mass of ice based on area and ice thickness at start of the year', + }, + 'glac_ELA_annual': { + 'long_name': 'annual equilibrium line altitude above mean sea level', + 'units': 'm', + 'temporal_resolution': 'annual', + 'comment': 'equilibrium line altitude is the elevation where the climatic mass balance is zero', + }, + 'glac_mass_bsl_annual': { + 'long_name': 'glacier mass below sea leve', + 'units': 'kg', + 'temporal_resolution': 'annual', + 'comment': 'mass of ice below sea level based on area and ice thickness at start of the year', + }, +} def run(args): # unpack arguments @@ -277,11 +367,15 @@ def run(args): } # loop through variables for var in vars: - # get common coords + + # get time dimension if 'annual' in var: tvals = year_values else: tvals = time_values + + # build coordinate dictionary and coordinate order + # store realizations along Climate_Model dimension if realizations[0]: coords_dict = dict( RGIId=(['glacier'], rgiid_list), @@ -291,6 +385,7 @@ def run(args): time=tvals, ) coord_order = ['realization', 'glacier', 'time'] + # if no realizations, store gcms along Climate_Model dimension else: coords_dict = dict( RGIId=(['glacier'], rgiid_list), @@ -301,294 +396,20 @@ def run(args): ) coord_order = ['model', 'glacier', 'time'] - # glac_runoff_monthly - if var == 'glac_runoff_monthly': - ds = xr.Dataset( - data_vars=dict( - glac_runoff_monthly=( - coord_order, - reg_all_gcms_data[var], - ), - crs=np.nan, - ), - coords=coords_dict, - attrs=attrs_dict, - ) - ds.glac_runoff_monthly.attrs['long_name'] = 'glacier-wide runoff' - ds.glac_runoff_monthly.attrs['units'] = 'm3' - ds.glac_runoff_monthly.attrs['temporal_resolution'] = 'monthly' - ds.glac_runoff_monthly.attrs['comment'] = ( - 'runoff from the glacier terminus, which moves over time' - ) - ds.glac_runoff_monthly.attrs['grid_mapping'] = 'crs' - - # offglac_runoff_monthly - elif var == 'offglac_runoff_monthly': - ds = xr.Dataset( - data_vars=dict( - offglac_runoff_monthly=( - coord_order, - reg_all_gcms_data[var], - ), - crs=np.nan, - ), - coords=coords_dict, - attrs=attrs_dict, - ) - ds.offglac_runoff_monthly.attrs['long_name'] = 'off-glacier-wide runoff' - ds.offglac_runoff_monthly.attrs['units'] = 'm3' - ds.offglac_runoff_monthly.attrs['temporal_resolution'] = 'monthly' - ds.offglac_runoff_monthly.attrs['comment'] = ( - 'off-glacier runoff from area where glacier no longer exists' - ) - ds.offglac_runoff_monthly.attrs['grid_mapping'] = 'crs' - - # glac_acc_monthly - elif var == 'glac_acc_monthly': - ds = xr.Dataset( - data_vars=dict( - glac_acc_monthly=(coord_order, reg_all_gcms_data[var]), - crs=np.nan, - ), - coords=coords_dict, - attrs=attrs_dict, - ) - ds.glac_acc_monthly.attrs['long_name'] = ( - 'glacier-wide accumulation, in water equivalent' - ) - ds.glac_acc_monthly.attrs['units'] = 'm3' - ds.glac_acc_monthly.attrs['temporal_resolution'] = 'monthly' - ds.glac_acc_monthly.attrs['comment'] = 'only the solid precipitation' - ds.glac_acc_monthly.attrs['grid_mapping'] = 'crs' - - # glac_melt_monthly - elif var == 'glac_melt_monthly': - ds = xr.Dataset( - data_vars=dict( - glac_melt_monthly=(coord_order, reg_all_gcms_data[var]), - crs=np.nan, - ), - coords=coords_dict, - attrs=attrs_dict, - ) - ds.glac_melt_monthly.attrs['long_name'] = ( - 'glacier-wide melt, in water equivalent' - ) - ds.glac_melt_monthly.attrs['units'] = 'm3' - ds.glac_melt_monthly.attrs['temporal_resolution'] = 'monthly' - ds.glac_melt_monthly.attrs['grid_mapping'] = 'crs' - - # glac_refreeze_monthly - elif var == 'glac_refreeze_monthly': - ds = xr.Dataset( - data_vars=dict( - glac_refreeze_monthly=( - coord_order, - reg_all_gcms_data[var], - ), - crs=np.nan, - ), - coords=coords_dict, - attrs=attrs_dict, - ) - ds.glac_refreeze_monthly.attrs['long_name'] = ( - 'glacier-wide refreeze, in water equivalent' - ) - ds.glac_refreeze_monthly.attrs['units'] = 'm3' - ds.glac_refreeze_monthly.attrs['temporal_resolution'] = 'monthly' - ds.glac_refreeze_monthly.attrs['grid_mapping'] = 'crs' - - # glac_frontalablation_monthly - elif var == 'glac_frontalablation_monthly': - ds = xr.Dataset( - data_vars=dict( - glac_frontalablation_monthly=( - coord_order, - reg_all_gcms_data[var], - ), - crs=np.nan, - ), - coords=dict( - RGIId=(['glacier'], rgiid_list), - Climate_Model=(['model'], gcms), - lon=(['glacier'], cenlon_list), - lat=(['glacier'], cenlat_list), - time=time_values, - ), - attrs=attrs_dict, - ) - ds.glac_frontalablation_monthly.attrs['long_name'] = ( - 'glacier-wide frontal ablation, in water equivalent' - ) - ds.glac_frontalablation_monthly.attrs['units'] = 'm3' - ds.glac_frontalablation_monthly.attrs['temporal_resolution'] = 'monthly' - ds.glac_frontalablation_monthly.attrs['comment'] = ( - 'mass losses from calving, subaerial frontal melting, \ - sublimation above the waterline and subaqueous frontal melting below the waterline; \ - positive values indicate mass lost like melt' - ) - ds.glac_frontalablation_monthly.attrs['grid_mapping'] = 'crs' - - # glac_snowline_monthly - elif var == 'glac_snowline_monthly': - ds = xr.Dataset( - data_vars=dict( - glac_snowline_monthly=( - coord_order, - reg_all_gcms_data[var], - ), - crs=np.nan, - ), - coords=coords_dict, - attrs=attrs_dict, - ) - ds.glac_snowline_monthly.attrs['long_name'] = ( - 'transient snowline altitude above mean sea level' - ) - ds.glac_snowline_monthly.attrs['units'] = 'm' - ds.glac_snowline_monthly.attrs['temporal_resolution'] = 'monthly' - ds.glac_snowline_monthly.attrs['comment'] = ( - 'transient snowline is altitude separating snow from ice/firn' - ) - ds.glac_snowline_monthly.attrs['grid_mapping'] = 'crs' - - # glac_massbaltotal_monthly - elif var == 'glac_massbaltotal_monthly': - ds = xr.Dataset( - data_vars=dict( - glac_massbaltotal_monthly=( - coord_order, - reg_all_gcms_data[var], - ), - crs=np.nan, - ), - coords=coords_dict, - attrs=attrs_dict, - ) - ds.glac_massbaltotal_monthly.attrs['long_name'] = ( - 'glacier-wide total mass balance, in water equivalent' - ) - ds.glac_massbaltotal_monthly.attrs['units'] = 'm3' - ds.glac_massbaltotal_monthly.attrs['temporal_resolution'] = 'monthly' - ds.glac_massbaltotal_monthly.attrs['comment'] = ( - 'total mass balance is the sum of the climatic mass balance and frontal ablation' - ) - ds.glac_massbaltotal_monthly.attrs['grid_mapping'] = 'crs' - - # glac_prec_monthly - elif var == 'glac_prec_monthly': - ds = xr.Dataset( - data_vars=dict( - glac_prec_monthly=(coord_order, reg_all_gcms_data[var]), - crs=np.nan, - ), - coords=coords_dict, - attrs=attrs_dict, - ) - ds.glac_prec_monthly.attrs['long_name'] = ( - 'glacier-wide precipitation (liquid)' - ) - ds.glac_prec_monthly.attrs['units'] = 'm3' - ds.glac_prec_monthly.attrs['temporal_resolution'] = 'monthly' - ds.glac_prec_monthly.attrs['comment'] = ( - 'only the liquid precipitation, solid precipitation excluded' - ) - ds.glac_prec_monthly.attrs['grid_mapping'] = 'crs' - - # glac_mass_monthly - elif var == 'glac_mass_monthly': - ds = xr.Dataset( - data_vars=dict( - glac_mass_monthly=(coord_order, reg_all_gcms_data[var]), - crs=np.nan, - ), - coords=coords_dict, - attrs=attrs_dict, - ) - ds.glac_mass_monthly.attrs['long_name'] = 'glacier mass' - ds.glac_mass_monthly.attrs['units'] = 'kg' - ds.glac_mass_monthly.attrs['temporal_resolution'] = 'monthly' - ds.glac_mass_monthly.attrs['comment'] = ( - 'mass of ice based on area and ice thickness at start of the year and the monthly total mass balance' - ) - ds.glac_mass_monthly.attrs['grid_mapping'] = 'crs' - - # glac_area_annual - elif var == 'glac_area_annual': - ds = xr.Dataset( - data_vars=dict( - glac_area_annual=(coord_order, reg_all_gcms_data[var]), - crs=np.nan, - ), - coords=coords_dict, - attrs=attrs_dict, - ) - ds.glac_area_annual.attrs['long_name'] = 'glacier area' - ds.glac_area_annual.attrs['units'] = 'm2' - ds.glac_area_annual.attrs['temporal_resolution'] = 'annual' - ds.glac_area_annual.attrs['comment'] = 'area at start of the year' - ds.glac_area_annual.attrs['grid_mapping'] = 'crs' - - # glac_mass_annual - elif var == 'glac_mass_annual': + # pull variable metadata from var_metadata dictionary + if var in var_metadata: + meta = var_metadata[var] + # build xarray dataset ds = xr.Dataset( - data_vars=dict( - glac_mass_annual=(coord_order, reg_all_gcms_data[var]), - crs=np.nan, - ), + data_vars={var: (coord_order, reg_all_gcms_data[var]), 'crs': np.nan}, coords=coords_dict, attrs=attrs_dict, ) - ds.glac_mass_annual.attrs['long_name'] = 'glacier mass' - ds.glac_mass_annual.attrs['units'] = 'kg' - ds.glac_mass_annual.attrs['temporal_resolution'] = 'annual' - ds.glac_mass_annual.attrs['comment'] = ( - 'mass of ice based on area and ice thickness at start of the year' - ) - ds.glac_mass_annual.attrs['grid_mapping'] = 'crs' - - # glac_ELA_annual - elif var == 'glac_ELA_annual': - ds = xr.Dataset( - data_vars=dict( - glac_ELA_annual=(coord_order, reg_all_gcms_data[var]), - crs=np.nan, - ), - coords=coords_dict, - attrs=attrs_dict, - ) - ds.glac_ELA_annual.attrs['long_name'] = ( - 'annual equilibrium line altitude above mean sea level' - ) - ds.glac_ELA_annual.attrs['units'] = 'm' - ds.glac_ELA_annual.attrs['temporal_resolution'] = 'annual' - ds.glac_ELA_annual.attrs['comment'] = ( - 'equilibrium line altitude is the elevation where the climatic mass balance is zero' - ) - ds.glac_ELA_annual.attrs['grid_mapping'] = 'crs' - - # glac_mass_bsl_annual - elif var == 'glac_mass_bsl_annual': - ds = xr.Dataset( - data_vars=dict( - glac_mass_bsl_annual=( - coord_order, - reg_all_gcms_data[var], - ), - crs=np.nan, - ), - coords=coords_dict, - attrs=attrs_dict, - ) - ds.glac_mass_bsl_annual.attrs['long_name'] = ( - 'glacier mass below sea leve' - ) - ds.glac_mass_bsl_annual.attrs['units'] = 'kg' - ds.glac_mass_bsl_annual.attrs['temporal_resolution'] = 'annual' - ds.glac_mass_bsl_annual.attrs['comment'] = ( - 'mass of ice below sea level based on area and ice thickness at start of the year' - ) - ds.glac_mass_bsl_annual.attrs['grid_mapping'] = 'crs' + # add variable attributes + for attr_key in ['long_name', 'units', 'temporal_resolution', 'comment']: + if attr_key in meta: + ds[var].attrs[attr_key] = meta[attr_key] + ds[var].attrs['grid_mapping'] = 'crs' # crs attributes - same for all vars ds.crs.attrs['grid_mapping_name'] = 'latitude_longitude' From 3d92ad09e40671c4506cb3fbe5005e0007e328b9 Mon Sep 17 00:00:00 2001 From: btobers Date: Fri, 6 Jun 2025 12:59:47 -0400 Subject: [PATCH 4/9] forgot to run ruff formatting check --- .../bin/postproc/postproc_compile_simulations.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pygem/bin/postproc/postproc_compile_simulations.py b/pygem/bin/postproc/postproc_compile_simulations.py index ca0f3703..0de32b39 100644 --- a/pygem/bin/postproc/postproc_compile_simulations.py +++ b/pygem/bin/postproc/postproc_compile_simulations.py @@ -146,6 +146,7 @@ }, } + def run(args): # unpack arguments ( @@ -367,13 +368,12 @@ def run(args): } # loop through variables for var in vars: - # get time dimension if 'annual' in var: tvals = year_values else: tvals = time_values - + # build coordinate dictionary and coordinate order # store realizations along Climate_Model dimension if realizations[0]: @@ -401,12 +401,20 @@ def run(args): meta = var_metadata[var] # build xarray dataset ds = xr.Dataset( - data_vars={var: (coord_order, reg_all_gcms_data[var]), 'crs': np.nan}, + data_vars={ + var: (coord_order, reg_all_gcms_data[var]), + 'crs': np.nan, + }, coords=coords_dict, attrs=attrs_dict, ) # add variable attributes - for attr_key in ['long_name', 'units', 'temporal_resolution', 'comment']: + for attr_key in [ + 'long_name', + 'units', + 'temporal_resolution', + 'comment', + ]: if attr_key in meta: ds[var].attrs[attr_key] = meta[attr_key] ds[var].attrs['grid_mapping'] = 'crs' From f3fe40b68b71f823cd6347199033ce1ce5f0583c Mon Sep 17 00:00:00 2001 From: btobers Date: Fri, 6 Jun 2025 14:17:02 -0400 Subject: [PATCH 5/9] specify test order, initialize postproc test --- .github/workflows/test_suite.yml | 6 +++++- pygem/tests/{test_basics.py => test_01_basics.py} | 0 pygem/tests/{test_config.py => test_02_config.py} | 0 pygem/tests/{test_notebooks.py => test_03_notebooks.py} | 0 4 files changed, 5 insertions(+), 1 deletion(-) rename pygem/tests/{test_basics.py => test_01_basics.py} (100%) rename pygem/tests/{test_config.py => test_02_config.py} (100%) rename pygem/tests/{test_notebooks.py => test_03_notebooks.py} (100%) diff --git a/.github/workflows/test_suite.yml b/.github/workflows/test_suite.yml index 2a15a264..4bb4a542 100644 --- a/.github/workflows/test_suite.yml +++ b/.github/workflows/test_suite.yml @@ -69,4 +69,8 @@ jobs: - name: 'Run tests' run: | python3 -m coverage erase - python3 -m pytest --cov=pygem -v --durations=20 pygem/tests + # run each test file explicitly in the desired order + python3 -m pytest --cov=pygem -v --durations=20 pygem/tests/test_01_basics.py + python3 -m pytest --cov=pygem -v --durations=20 pygem/tests/test_02_config.py + python3 -m pytest --cov=pygem -v --durations=20 pygem/tests/test_03_notebooks.py + python3 -m pytest --cov=pygem -v --durations=20 pygem/tests/test_04_postproc.py diff --git a/pygem/tests/test_basics.py b/pygem/tests/test_01_basics.py similarity index 100% rename from pygem/tests/test_basics.py rename to pygem/tests/test_01_basics.py diff --git a/pygem/tests/test_config.py b/pygem/tests/test_02_config.py similarity index 100% rename from pygem/tests/test_config.py rename to pygem/tests/test_02_config.py diff --git a/pygem/tests/test_notebooks.py b/pygem/tests/test_03_notebooks.py similarity index 100% rename from pygem/tests/test_notebooks.py rename to pygem/tests/test_03_notebooks.py From 7967c056facc93732af9fe49f814e7512d77e45a Mon Sep 17 00:00:00 2001 From: btobers Date: Fri, 6 Jun 2025 16:10:10 -0400 Subject: [PATCH 6/9] test compile script --- pygem/bin/postproc/postproc_monthly_mass.py | 2 +- pygem/tests/test_03_notebooks.py | 8 ++ pygem/tests/test_04_postproc.py | 120 ++++++++++++++++++++ 3 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 pygem/tests/test_04_postproc.py diff --git a/pygem/bin/postproc/postproc_monthly_mass.py b/pygem/bin/postproc/postproc_monthly_mass.py index d92e80fe..267da544 100644 --- a/pygem/bin/postproc/postproc_monthly_mass.py +++ b/pygem/bin/postproc/postproc_monthly_mass.py @@ -225,7 +225,7 @@ def main(): simpath = None if args.simdir: # get list of sims - simpath = glob.glob(args.simdir + '*.nc') + simpath = glob.glob(args.simdir + '/*.nc') else: if args.simpath: simpath = args.simpath diff --git a/pygem/tests/test_03_notebooks.py b/pygem/tests/test_03_notebooks.py index d57d5b19..6c4defd1 100644 --- a/pygem/tests/test_03_notebooks.py +++ b/pygem/tests/test_03_notebooks.py @@ -3,6 +3,14 @@ import pytest +from pygem.setup.config import ConfigManager + +# instantiate ConfigManager +config_manager = ConfigManager() +# update export_extra_vars to True before running tests +config_manager.update_config({'sim.out.export_extra_vars': True}) + + # Get all notebooks in the PyGEM-notebooks repository nb_dir = os.environ.get('PYGEM_NOTEBOOKS_DIRPATH') or os.path.join( os.path.expanduser('~'), 'PyGEM-notebooks' diff --git a/pygem/tests/test_04_postproc.py b/pygem/tests/test_04_postproc.py new file mode 100644 index 00000000..9d7f42f4 --- /dev/null +++ b/pygem/tests/test_04_postproc.py @@ -0,0 +1,120 @@ +import glob +import os +import subprocess + +import numpy as np +import pytest +import xarray as xr + +from pygem.setup.config import ConfigManager + + +@pytest.fixture(scope='module') +def rootdir(): + config_manager = ConfigManager() + pygem_prms = config_manager.read_config() + return pygem_prms['root'] + + +def test_postproc_monthly_mass(rootdir): + """ + Test the postproc_monthly_mass CLI script. + """ + simdir = os.path.join( + rootdir, 'Output', 'simulations', '15', 'CESM2', 'ssp245', 'stats' + ) + + # Run postproc_monthyl_mass CLI script + subprocess.run(['postproc_monthly_mass', '-simdir', simdir], check=True) + + +def test_postproc_compile_simulations(rootdir): + """ + Test the postproc_compile_simulations CLI script. + """ + + # Run postproc_compile_simulations CLI script + subprocess.run( + [ + 'postproc_compile_simulations', + '-rgi_region01', + '15', + '-option_calibration', + 'HH2015', + '-sim_climate_name', + 'CESM2', + '-sim_climate_scenario', + 'ssp245', + '-sim_startyear', + '2000', + '-sim_endyear', + '2100', + ], + check=True, + ) + + # Check if output files were created + compdir = os.path.join(rootdir, 'Output', 'simulations', 'compile', 'glacier_stats') + output_files = glob.glob(os.path.join(compdir, '**', '*.nc'), recursive=True) + assert output_files, f'No output files found in {compdir}' + + +def test_check_compiled_product(rootdir): + """ + Verify the contents of the files created by postproc_compile_simulations. + There should be a single glacier with non-nan values in each dataset (1.03622) + """ + # skip variables that are not in the compiled products + vars_to_skip = [ + 'glac_temp_monthly', + 'glac_mass_change_ignored_annual', + 'offglac_prec_monthly', + 'offglac_refreeze_monthly', + 'offglac_melt_monthly', + 'offglac_snowpack_monthly', + ] + + simpath = os.path.join( + rootdir, + 'Output', + 'simulations', + '15', + 'CESM2', + 'ssp245', + 'stats', + '15.03733_CESM2_ssp245_HH2015_ba1_1sets_2000_2100_all.nc', + ) + compdir = os.path.join(rootdir, 'Output', 'simulations', 'compile', 'glacier_stats') + + with xr.open_dataset(simpath) as simds: + # loop through vars + vars_to_check = [ + name for name, var in simds.variables.items() if len(var.dims) > 1 + ] + vars_to_check = [item for item in vars_to_check if item not in vars_to_skip] + + for var in vars_to_check: + simvar = simds[var] + comppath = os.path.join(compdir, var, '15') + comppath = glob.glob(f'{comppath}/R15_{var}*.nc')[0] + assert os.path.isfile(comppath), ( + f'Compiled product not found for {var} at {comppath}' + ) + with xr.open_dataset(comppath) as compds: + compvar = compds[var] + + # verify coords (compiled product has one more dimension for the `model`) + assert compvar.ndim == simvar.ndim + 1 + + # pull data values + simvals = simvar.values + compvals = compvar.values[0, :, :] # first index is the glacier index + + # check that compiled product has same shape as original data + assert simvals.shape == compvals.shape, ( + f'Compiled product shape {compvals.shape} does not match original data shape {simvals.shape}' + ) + # check that compiled product matches original data + assert np.all(np.array_equal(simvals, compvals)), ( + f'Compiled product for {var} does not match original data' + ) From 03783e5d7e4405b553648c9fd2caa0f8c78e82cb Mon Sep 17 00:00:00 2001 From: btobers Date: Fri, 6 Jun 2025 16:15:59 -0400 Subject: [PATCH 7/9] commenting --- pygem/tests/test_04_postproc.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pygem/tests/test_04_postproc.py b/pygem/tests/test_04_postproc.py index 9d7f42f4..c6a2ee7f 100644 --- a/pygem/tests/test_04_postproc.py +++ b/pygem/tests/test_04_postproc.py @@ -62,7 +62,6 @@ def test_postproc_compile_simulations(rootdir): def test_check_compiled_product(rootdir): """ Verify the contents of the files created by postproc_compile_simulations. - There should be a single glacier with non-nan values in each dataset (1.03622) """ # skip variables that are not in the compiled products vars_to_skip = [ From 84b1c18e5e88096ab3029828ea341a1ee2e044e6 Mon Sep 17 00:00:00 2001 From: btobers Date: Fri, 6 Jun 2025 16:29:24 -0400 Subject: [PATCH 8/9] set rootdir as `sample_data` --- pygem/tests/test_04_postproc.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pygem/tests/test_04_postproc.py b/pygem/tests/test_04_postproc.py index c6a2ee7f..5850a9a7 100644 --- a/pygem/tests/test_04_postproc.py +++ b/pygem/tests/test_04_postproc.py @@ -13,6 +13,8 @@ def rootdir(): config_manager = ConfigManager() pygem_prms = config_manager.read_config() + # need to remove '_tw' suffix from root since we'll use results from sample_data produced in simple_test.ipynb + pygem_prms['root'] = pygem_prms['root'].replace('sample_data_tw', 'sample_data') return pygem_prms['root'] From 2ec7e469399d30e1ce05317e25d582a7afab3647 Mon Sep 17 00:00:00 2001 From: btobers Date: Fri, 6 Jun 2025 16:47:11 -0400 Subject: [PATCH 9/9] use leconte output since that will be last glacier run in test_advanced_tw.ipynb --- pygem/tests/test_04_postproc.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pygem/tests/test_04_postproc.py b/pygem/tests/test_04_postproc.py index 5850a9a7..6fbd6bd3 100644 --- a/pygem/tests/test_04_postproc.py +++ b/pygem/tests/test_04_postproc.py @@ -13,8 +13,6 @@ def rootdir(): config_manager = ConfigManager() pygem_prms = config_manager.read_config() - # need to remove '_tw' suffix from root since we'll use results from sample_data produced in simple_test.ipynb - pygem_prms['root'] = pygem_prms['root'].replace('sample_data_tw', 'sample_data') return pygem_prms['root'] @@ -23,7 +21,7 @@ def test_postproc_monthly_mass(rootdir): Test the postproc_monthly_mass CLI script. """ simdir = os.path.join( - rootdir, 'Output', 'simulations', '15', 'CESM2', 'ssp245', 'stats' + rootdir, 'Output', 'simulations', '01', 'CESM2', 'ssp245', 'stats' ) # Run postproc_monthyl_mass CLI script @@ -40,9 +38,9 @@ def test_postproc_compile_simulations(rootdir): [ 'postproc_compile_simulations', '-rgi_region01', - '15', + '01', '-option_calibration', - 'HH2015', + 'MCMC', '-sim_climate_name', 'CESM2', '-sim_climate_scenario', @@ -79,11 +77,11 @@ def test_check_compiled_product(rootdir): rootdir, 'Output', 'simulations', - '15', + '01', 'CESM2', 'ssp245', 'stats', - '15.03733_CESM2_ssp245_HH2015_ba1_1sets_2000_2100_all.nc', + '1.03622_CESM2_ssp245_MCMC_ba1_50sets_2000_2100_all.nc', ) compdir = os.path.join(rootdir, 'Output', 'simulations', 'compile', 'glacier_stats') @@ -95,9 +93,12 @@ def test_check_compiled_product(rootdir): vars_to_check = [item for item in vars_to_check if item not in vars_to_skip] for var in vars_to_check: + # skip mad + if 'mad' in var: + continue simvar = simds[var] - comppath = os.path.join(compdir, var, '15') - comppath = glob.glob(f'{comppath}/R15_{var}*.nc')[0] + comppath = os.path.join(compdir, var, '01') + comppath = glob.glob(f'{comppath}/R01_{var}*.nc')[0] assert os.path.isfile(comppath), ( f'Compiled product not found for {var} at {comppath}' )