Add tool to adjust bed topography to achieve target height above flotation - #756
Draft
trhille wants to merge 12 commits into
Draft
Add tool to adjust bed topography to achieve target height above flotation#756trhille wants to merge 12 commits into
trhille wants to merge 12 commits into
Conversation
…ation This adds a new command-line tool `adjust_bed_to_haf` that modifies bed topography within grounding line regions to achieve a user-specified height above flotation (HAF). The tool loads grounding line delineations from GeoJSON files, identifies mesh cells within those regions, and calculates the required bed elevation using hydrostatic flotation physics. Key features: - Accepts GeoJSON grounding line polygons and MALI mesh files - Adjusts bed topography while preserving ice thickness - Configurable physics parameters (ice/ocean density, sea level) - Verifies results and updates file metadata - Includes comprehensive documentation and examples This tool is useful for initializing grounding line regions in MALI simulations and conducting sensitivity experiments with varying HAF values. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
trhille
marked this pull request as draft
September 11, 2026 18:03
Adds adjust_bed_to_haf.py to landice/mesh_tools_li as a standalone script that adjusts bed topography within grounding line regions to achieve a user-specified height above flotation. This complements the conda package version with a directly runnable script for users who prefer standalone tools. The script uses xarray for NetCDF I/O and shapely for spatial operations, identifying mesh cells within GeoJSON grounding line polygons and calculating required bed elevations from hydrostatic flotation physics. Usage: python landice/mesh_tools_li/adjust_bed_to_haf.py --mesh input.nc --geojson gl.geojson --output output.nc --target-haf 10.0 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Adds map_regional_to_global_mesh.py to copy modified variables from a regional mesh back to the corresponding cells in a global mesh. This is designed for workflows where a regional mesh (e.g., Amundsen Sea Embayment) is extracted from a larger mesh (e.g., all Antarctica), modified, and then needs to be integrated back into the global mesh. The tool uses exact coordinate matching (not interpolation) since the regional mesh cells are a subset of the global mesh cells with identical (x,y) or (lon,lat) coordinates. It builds a cell-to-cell mapping and copies specified variables, leaving all other global mesh cells unchanged. Key features: - Exact coordinate matching with configurable tolerance - Supports both spherical (lon/lat) and planar (x/y) coordinates - Handles 1D, 2D, and 3D variables with multiple dimensions - Safety checks to prevent accidental overwrites - Reports unmatched cells and verification statistics Usage: python landice/mesh_tools_li/map_regional_to_global_mesh.py --regional ASE_mesh.nc --global AIS_mesh.nc --output AIS_updated.nc --vars bedTopography thickness Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Fixed incorrect usage of RawDescriptionHelpFormatter in both scripts. The formatter class should be imported from argparse, not accessed as an attribute of ArgumentParser. This was causing an AttributeError when running the scripts with -h or --help. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Modified adjust_bed_to_haf.py to properly handle coordinate projections: - Added --projection argument (required) to specify MALI mesh projection - Supports: ais-bedmap2, ais-bedmap2-sphere, gis-bamber, gis-gimp, latlon - Auto-detects GeoJSON CRS from file metadata - Transforms mesh coordinates (xCell, yCell) to GeoJSON CRS for matching - Uses pyproj for accurate coordinate transformations - Reads mesh coordinates from xCell/yCell instead of lonCell/latCell This fixes the previous assumption that GeoJSON and MALI files would be in the same projection, allowing proper spatial matching between files with different coordinate systems (e.g., BEDMAP2 projection for mesh and WGS84 lat/lon for GeoJSON). Updated README with projection documentation and examples. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Fixed issue where grounding line GeoJSON files with LineString or MultiLineString geometries (e.g., Thwaites grounding lines) were not being matched to mesh cells. LineStrings don't contain points like polygons do, so the script now automatically buffers line geometries to create polygons. Changes: - Added --buffer-distance argument (default: 0.01 degrees, ~1km) - Automatically buffers LineString/MultiLineString geometries - Reports geometry types in output - Polygon geometries are preserved as-is - Updated documentation with buffer distance info This fixes the Found 0 cells within polygons error when using grounding line data represented as lines rather than polygons. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Modified both scripts to capture and store the complete command line (sys.argv) in the NetCDF history attribute instead of just the script name. This ensures full reproducibility by recording all input files, parameters, and options used. Before: '2026-09-11 12:00:00: adjust_bed_to_haf.py' After: '2026-09-11 12:00:00: python adjust_bed_to_haf.py --mesh input.nc --geojson gl.geojson --projection ais-bedmap2 --target-haf 15.0' Updated scripts: - adjust_bed_to_haf.py - map_regional_to_global_mesh.py Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Modified both scripts to use mpas_tools.io.write_netcdf() instead of xarray's to_netcdf() for proper MPAS NetCDF format. This ensures: - Proper fill values for different NetCDF types - Conversion of int64 to int32 for MPAS compatibility - Correct handling of Time dimension (unlimited) - Proper string variable encoding - Automatic history attribute updates with command line The scripts gracefully fall back to xarray's to_netcdf() if mpas_tools is not available, with a warning that the output may not be in proper MPAS format. Benefits: - Output files are guaranteed to be MPAS-compatible - Consistent with other MPAS-Tools utilities - Better handling of NetCDF format quirks Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Use NETCDF3_64BIT_DATA instead of default NETCDF3_64BIT, which significantly speeds up writing larger files.
Added --thickness-threshold argument (default: 1.0 m) to prevent adjusting bed topography in cells without ice. This fixes the issue where cells with thickness = 0 were having their bed elevation changed to match the target HAF, which is physically meaningless. The script now: - Only modifies cells that are both: 1. Within the grounding line polygons 2. Have ice thickness >= threshold - Reports counts at each filtering step - Updates the comment attribute to record the thickness threshold used This ensures bed topography adjustments only occur where ice is actually present, preventing unrealistic changes in ice-free areas. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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.
This adds a new command-line tool
adjust_bed_to_hafand scriptadjust_bed_to_haf.pythat modifies bed topography within grounding line regions to achieve a user-specified height above flotation (HAF). The tool loads grounding line delineations from GeoJSON files, identifies mesh cells within those regions, and calculates the required bed elevation using hydrostatic flotation physics.Key features:
This also adds a script
landice/mesh_tools_li/map_regional_to_global_mesh.pythat can map a subdomain created with the COMPASS subdomain extractor back onto its parent mesh.I'm packaging these seemingly unrelated tools together in one PR because they will be used together in ISMIP7 mesh modifications.