Repository navigation
Conversation
Converts gate geometry (e.g. Mankoff/GEUS) to fluxGateMasks.nc for use with MALI's flux-gates analysis member. Reads GeoPackage via sqlite3 (no fiona dependency), calls compute_mpas_transect_masks, culls ambiguous edges, and renames transect variables to MALI convention. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
trhille
marked this pull request as draft
September 30, 2026 21:36
Prints warning for gates with <2 points and continues processing valid gates. Only errors if ALL requested gates are invalid. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Automatically queries distinct gate IDs from the gpkg table and processes all of them. Mutually exclusive with --gates. Usage: ./make_flux_gate_masks.py -g gates.gpkg -m mesh.nc -o output.nc --all-gates Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Changes make_flux_gate_masks.py to generate fluxGateEdgeID(nEdges) and fluxGateEdgeSign(nEdges) instead of the sparse 2D one-hot arrays. Reduces output from ~5 GB to ~20 MB for 266 gates (250x reduction). Detects and warns on edges belonging to multiple gates. Matches MALI Registry changes in E3SM commit 9bacdeb83e. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Previously fluxGateNames held generated names like 'gate27'. Now the Mouginot_2019 attribute from the gpkg is used for fluxGateNames, and a new fluxGateIds variable holds the gate number. Also drops the unused empty 'constituents' property that mpas_tools was writing out as a spurious character variable.
Plots MALI iceFluxThroughGates (from fluxGatesOutput) aggregated by Mouginot & Rignot (2019) region against GEUS (Mankoff et al., 2020) gate_D.csv discharge, restricted to gates present in the mask file's fluxGateIds. Per-gate MALI fluxes are shown as thin gray lines, the MALI regional total in black, and the GEUS regional total in tab:blue with linewidth=2 and +/- linearly-summed-error shading.
Gate ID numbers in gates.gpkg and GEUS gate_meta.csv/gate_D.csv can refer to different physical gates (e.g. gpkg gate 184 is Jakobshavn, but gate_meta.csv gate 184 is Styrte in a different region). Match each mask gate to the nearest gate_meta.csv gate by (mean_x, mean_y) instead, warning on unmatched or inconsistently-named gates. Also plot per-gate GEUS observation curves alongside the per-gate MALI curves already shown in each panel.
Each space-separated item passed to -f is now one run (quote glob patterns like "run1/fluxGates_*.nc" for runs split across multiple files), rather than requiring -f to be repeated per run. --labels names each run; defaults to 'MALI total' for a single run or 'Run 1', 'Run 2', ... for multiple. Each run gets its own total/per-gate color (tab10 minus tab:blue, which stays reserved for GEUS observations); a single run keeps the original black/gray styling.
Moves xtime_to_decimal_year, load_mali_flux, load_mask_gate_ids, load_mask_gate_locations, match_gates_by_location, and load_observations out of plot_flux_gates.py into a shared module, so other scripts (e.g. a planned muFriction correction tool) can reuse the same gate-matching logic instead of reimplementing it. plot_flux_gates.py now imports from it; verified output is unchanged.
Adds an unweighted-mean creep-fill mode to extrapolate_into_mask(), alongside the existing 'min' and 'idw' methods, for use by the new flux-gate muFriction correction script. Also wraps the module's CLI driver in main()/if __name__ == '__main__' since it previously ran unconditionally at import time, which made extrapolate_into_mask impossible to import and reuse from another script without executing unrelated CLI argument parsing and crashing.
Derives a per-gate multiplicative correction muScale = (Fm/Fo)**exponent from the mismatch between mean modeled (MALI fluxGatesOutput) and mean observed (GEUS/Mankoff et al., 2020) discharge over a user-selected time window, matching gates by location via flux_gate_utils. The correction is computed independently per gate, seeded onto cells adjacent to that gate's edges (geometric mean in log space where gates share a cell via cellsOnEdge), creep-filled across the full connected mesh in log space using extrapolate_variable.extrapolate_into_mask's new 'mean' method, and applied as muFriction_new = muFriction_old * muScale. Cells not connected to any gate get muScale = 1, with a warning. Writes a copy of the input mu-file with muFriction, muFrictionScale, logMuFrictionScale, and a seed-only diagnostic updated/added, plus an optional per-gate diagnostic CSV.
--start-index/--end-index now accept Python-style negative indices (e.g. --end-index -1 for the last time step), resolved against nTime before validation.
make_flux_gate_masks.py now writes the compact per-edge fluxGateEdgeID format (fluxGateEdgeID(nEdges), 1-based gate index) instead of the sparse 2D fluxGateEdgeMasks(nEdges, nFluxGates). Update this script's mask-file reader and gate_seed_cells accordingly. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
trhille
force-pushed
the
landice/add_flux_gates_processing
branch
from
October 20, 2026 16:25
284da4a to
e3f0535
Compare
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved numerical correctness and workflow errors can distort discharge comparisons and prevent successful mask generation or repeated friction corrections.
6 open issues
Correct no-leap date conversion and round boundary timestamps · New Reuse existing diagnostic variables in iterative correction output · New Mask non-finite neighbors before weighted mean calculation · New Remove broken no-edge-sign option or preserve required edge signs · New Restrict modeled totals to gates matched with observations · New Normalize leap-year day-of-year values by actual year length · New
What changed in this PR
Adds a GeoPackage-to-MALI flux-gate workflow, with tools to compare modeled discharge against GEUS observations and use discharge mismatches to adjust basal friction.
Changes:
- Generate compact flux-gate masks from GeoPackage coordinates using SQLite and MPAS transect masking.
- Match gates to observations and plot regional discharge comparisons across runs.
- Apply gate-based friction corrections using reusable mean extrapolation.
| File | Description |
|---|---|
landice/output_processing_li/plot_flux_gates.py |
Plots regional and Greenland discharge comparisons. |
landice/mesh_tools_li/make_flux_gate_masks.py |
Generates compact MALI masks from GeoPackage gates. |
landice/mesh_tools_li/flux_gate_utils.py |
Shares flux loading, date conversion, and observation matching. |
landice/mesh_tools_li/extrapolate_variable.py |
Adds mean extrapolation and makes the helper importable. |
landice/mesh_tools_li/adjust_mu_friction_from_flux_gates.py |
Computes and spreads gate-based friction corrections. |
Review effort: Balanced
Comment on lines
+67
to
+69
| year = int(np.floor(decimal_year)) | ||
| day_of_year = (decimal_year - year) * 365.0 | ||
| return pd.Timestamp(year=year, month=1, day=1) + pd.Timedelta(days=day_of_year) |
Comment on lines
+345
to
+356
| scale_var = f.createVariable('muFrictionScale', 'f8', ('nCells',)) | ||
| scale_var[:] = mu_scale_final | ||
| scale_var.long_name = 'Multiplicative correction applied to muFriction, from flux-gate discharge mismatch' | ||
| scale_var.units = '1' | ||
|
|
||
| log_scale_var = f.createVariable('logMuFrictionScale', 'f8', ('nCells',)) | ||
| log_scale_var[:] = log_mu_scale_final | ||
| log_scale_var.long_name = 'log(muFrictionScale)' | ||
| log_scale_var.units = '1' | ||
|
|
||
| seed_var = f.createVariable('fluxGateLogMuFrictionScaleSeed', 'f8', ('nCells',), | ||
| fill_value=SEED_FILL_VALUE) |
| varValue[cand] = np.sum(w * neighVals, axis=1) / np.sum(w, axis=1) | ||
| elif method == 'mean': | ||
| w = nbFilled.astype(float) | ||
| varValue[cand] = np.sum(w * neighVals, axis=1) / np.sum(w, axis=1) |
Comment on lines
+341
to
+344
| parser.add_argument("--add-edge-sign", dest="add_edge_sign", action="store_true", | ||
| default=True, help="Compute edge signs (default: True)") | ||
| parser.add_argument("--no-edge-sign", dest="add_edge_sign", action="store_false", | ||
| help="Skip edge sign computation (not recommended for flux gates)") |
| r: flux[:, idx].sum(axis=1) if idx else None | ||
| for r, idx in region_gate_indices.items() | ||
| } | ||
| gis_total = flux.sum(axis=1) |
| print(f"Reading GEUS observations from: {args.obs_dir}") | ||
| region_of_gate, gate_D, gate_err = load_observations( | ||
| args.obs_dir, args.gpkg, gate_ids, tolerance=args.match_tolerance) | ||
| obs_years = gate_D.index.year + (gate_D.index.dayofyear - 1) / 365.0 |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Converts gate geometry (e.g. Mankoff/GEUS from https://dataverse.geus.dk/api/access/datafile/:persistentId?persistentId=doi:10.22008/promice/data/ice_discharge/gates/) to fluxGateMasks.nc for use with MALI's flux-gates analysis member. Reads GeoPackage via sqlite3 (no fiona dependency), calls compute_mpas_transect_masks, culls ambiguous edges, and renames transect variables to MALI convention.