""" GLAMBIE fixed-geometry monthly specific MB run — ERA5_SnowModel_Glambie source. Same as run_fixed_geometry_glambie.py, but for the new source built with `--mb-model-class SfcTypeTIModel` (surface-type snow/firn/ice tracking, melt_f/prcp_fac/temp_bias calibrated for that class specifically - NOT interchangeable with the plain-TIModel ERA5_Glambie source) and `--dynamic-spinup-start-year 1970` (a 5-year earlier spinup target than the TIModel source's 1975, to reduce cold-start-relaxation shock at the 1975 analysis start). Verified against gdir.settings['reference_mb'] on 5 glaciers each in RGI16 and RGI11: SfcTypeTIModel matches to ~0.1-0.6 mm w.e./yr, MonthlyTIModel (this pipeline's other source's model class) is 2-4x too negative if used here by mistake - the two sources are NOT interchangeable inputs to fixed_geometry_specific_mb_ts. Source only has L4 (no separate L3 export) - it starts from a shared L3 (prepro_base_url points at .../ERA5_SnowModel/, without _Glambie) and adds the GLAMBIE-specific dynamic-spinup + hydro output on top, published under .../ERA5_SnowModel_Glambie/. from_prepro_level=4 accordingly (still has model_flowlines et al., L4 is a superset of L3). Environment variables (all required): OGGM_WORKDIR – scratch working directory for OGGM OGGM_OUTDIR – root output directory; a sub-directory RGI{reg} is created OGGM_RGI_REG – two-digit GTN-G / RGI region (01–19) """ import logging import os import geopandas as gpd from oggm import cfg, utils, workflow from oggm.core.massbalance import SfcTypeTIModel from glambie_helper import ( compile_fixed_geometry_specific_mb_region, fixed_geometry_specific_mb_ts, ) # --------------------------------------------------------------------------- # Environment # --------------------------------------------------------------------------- WORKING_DIR = os.environ.get("OGGM_WORKDIR", "") if not WORKING_DIR: raise RuntimeError("Set OGGM_WORKDIR") WORKING_DIR = utils.mkdir(WORKING_DIR) OUTPUT_DIR = os.environ.get("OGGM_OUTDIR", "") if not OUTPUT_DIR: raise RuntimeError("Set OGGM_OUTDIR") rgi_reg = os.environ.get("OGGM_RGI_REG", "") if rgi_reg not in [f"{r:02d}" for r in range(1, 20)]: raise RuntimeError("Set OGGM_RGI_REG to a two-digit region code (01–19)") OUTPUT_DIR = utils.mkdir(OUTPUT_DIR) GLACIER_DIR = utils.mkdir(os.path.join(OUTPUT_DIR, "per_glacier", f"RGI{rgi_reg}")) # --------------------------------------------------------------------------- # OGGM configuration # --------------------------------------------------------------------------- cfg.initialize(logging_level="INFO") cfg.PARAMS["use_multiprocessing"] = True cfg.PARAMS["continue_on_error"] = True cfg.PATHS["working_dir"] = WORKING_DIR log = logging.getLogger(__name__) log.workflow(f"Starting GLAMBIE fixed-geometry (SnowModel) run for RGI region {rgi_reg}") utils.show_versions(logger=log) # --------------------------------------------------------------------------- # Glacier list # --------------------------------------------------------------------------- rgi_ids = gpd.read_file(utils.get_rgi_region_file(rgi_reg, version="62")) # Greenland: skip peripheral glaciers connected at level 2 if rgi_reg == "05": rgi_ids = rgi_ids.loc[rgi_ids["Connect"] != 2] log.workflow(f"Number of glaciers: {len(rgi_ids)}") # --------------------------------------------------------------------------- # Glacier directories from the oggm_v1.7a ERA5_SnowModel_Glambie source # --------------------------------------------------------------------------- base_url = ( "https://cluster.klima.uni-bremen.de/~oggm/gdirs/oggm_v1.7a/tests/" "L3-L5_files/elev_bands/consensus/ERA5_SnowModel_Glambie/" ) gdirs = workflow.init_glacier_directories( rgi_ids, prepro_base_url=base_url, from_prepro_level=4, prepro_border=160, ) # --------------------------------------------------------------------------- # Per-glacier fixed-geometry monthly specific MB (1975-01 to 2025-12) # Files land in GLACIER_DIR/batch_XXXX/RGI60-XX.XXXXX.nc # --------------------------------------------------------------------------- workflow.execute_entity_task( fixed_geometry_specific_mb_ts, gdirs, y0=1975, y1=2025, glacier_dir=GLACIER_DIR, mb_model_class=SfcTypeTIModel, ) # --------------------------------------------------------------------------- # Regional aggregation → OUTPUT_DIR/region_specific_mb_RGI{reg}_v17a_SnowModel.nc # --------------------------------------------------------------------------- compile_fixed_geometry_specific_mb_region( y0=1975, y1=2025, outdir=OUTPUT_DIR, glacier_dir=GLACIER_DIR, filesuffix="_v17a_SnowModel", ) log.workflow("GLAMBIE fixed-geometry (SnowModel) run complete.")