"""Sensitivity of OGGM elev-band runs to flowline_dx and the elevation binsize. One call = one configuration (flowline_dx, elevation_band_flowline_binsize): re-runs L2 -> L3 from the 2025.6 elev_bands L1 directories (border 80), then two 300-yr commitment runs (constant and random 2000-2019 climate). Usage (from repo root, through the sandbox wrapper): .cluster_env/run.sh python claude/flowline_dx/run_config.py DX BINSIZE [GLEN_A_FACTOR] Without GLEN_A_FACTOR, Glen A is calibrated on the four glaciers together against the consensus volume (that's what we do for the reference config). """ import sys import json import shutil from pathlib import Path import pandas as pd from oggm import cfg, utils, workflow, tasks HERE = Path(__file__).resolve().parent RGI_IDS = ['RGI60-11.00897', # Hintereisferner, 8.0 km2 'RGI60-11.00787', # Kesselwandferner, 4.0 km2 'RGI60-11.00289', # Goldbergkees, 0.64 km2 'RGI60-11.00892', # Plattalva, 0.42 km2 ] L12_URL = ('https://cluster.klima.uni-bremen.de/~oggm/gdirs/oggm_v1.6/' 'L1-L2_files/2025.6/elev_bands/') TB_URL = ('https://cluster.klima.uni-bremen.de/~oggm/ref_mb_params/oggm_v1.6/' 'w5e5_rgi6_perglacier_temp_bias_v2025.6.2.csv') Y0, HALFSIZE, NYEARS, SEED = 2009, 10, 300, 1 def main(dx, binsize, glen_a_factor=None): cfg.initialize(logging_level='WARNING') cfg.PARAMS['use_multiprocessing'] = False cfg.PARAMS['border'] = 80 cfg.PARAMS['continue_on_error'] = False cfg.PARAMS['store_model_geometry'] = True cfg.PARAMS['flowline_dx'] = dx cfg.PARAMS['elevation_band_flowline_binsize'] = binsize name = f'dx{dx}_b{binsize}' wd = HERE / 'work' / name if wd.exists(): shutil.rmtree(wd) cfg.PATHS['working_dir'] = utils.mkdir(str(wd)) gdirs = workflow.init_glacier_directories(RGI_IDS, from_prepro_level=1, prepro_border=80, prepro_rgi_version='62', prepro_base_url=L12_URL) # L2 (elev bands) for task in [tasks.simple_glacier_masks, tasks.elevation_band_flowline, tasks.fixed_dx_elevation_band_flowline, tasks.compute_downstream_line, tasks.compute_downstream_bedshape]: workflow.execute_entity_task(task, gdirs) # L3 workflow.execute_entity_task(tasks.process_climate_data, gdirs) workflow.execute_entity_task(tasks.mb_calibration_from_geodetic_mb, gdirs, informed_threestep=True, temp_bias_file_path=TB_URL) workflow.execute_entity_task(tasks.apparent_mb_from_any_mb, gdirs) inv_df = workflow.calibrate_inversion_from_ref_table( gdirs, ref_table='consensus', glen_a_factor=glen_a_factor, apply_fs_on_mismatch=True, error_on_mismatch=False, filter_inversion_output=True) workflow.execute_entity_task(tasks.init_present_time_glacier, gdirs) # Runs workflow.execute_entity_task(tasks.run_constant_climate, gdirs, nyears=NYEARS, y0=Y0, halfsize=HALFSIZE, output_filesuffix='_const') workflow.execute_entity_task(tasks.run_random_climate, gdirs, nyears=NYEARS, y0=Y0, halfsize=HALFSIZE, seed=SEED, output_filesuffix='_random') workflow.execute_entity_task(tasks.run_random_climate, gdirs, nyears=NYEARS, y0=Y0, halfsize=HALFSIZE, seed=SEED, temperature_bias=-1, output_filesuffix='_random_m1') out = HERE / 'output' out.mkdir(exist_ok=True) for suf in ['_const', '_random', '_random_m1']: utils.compile_run_output(gdirs, input_filesuffix=suf, path=str(out / f'run{suf}_{name}.nc')) stats = utils.compile_glacier_statistics(gdirs) # Some extra info per glacier rows = {} for gdir in gdirs: fl = gdir.read_store('model_flowlines')[-1] rows[gdir.rgi_id] = dict( map_dx=gdir.grid.dx, dx_meter=float(fl.dx_meter), nx_glacier=int((fl.thick > 0).sum()), n_bands=int(len(pd.read_csv( gdir.get_filepath('elevation_band_flowline')))), melt_f=gdir.settings['melt_f'], prcp_fac=gdir.settings['prcp_fac'], temp_bias=gdir.settings['temp_bias'], ) stats = stats.join(pd.DataFrame(rows).T, rsuffix='_x') stats.to_csv(out / f'stats_{name}.csv') with open(out / f'inv_{name}.json', 'w') as f: json.dump({k: float(v) for k, v in inv_df.attrs.items() if k in ['glen_a', 'glen_a_factor', 'fs']}, f) if __name__ == '__main__': dx = int(sys.argv[1]) binsize = int(sys.argv[2]) gaf = float(sys.argv[3]) if len(sys.argv) > 3 else None main(dx, binsize, gaf)