Repository navigation
Add UM mesh generation script and support differing input/output meshes in generate_rof_weights.py - #154
Add UM mesh generation script and support differing input/output meshes in generate_rof_weights.py#154anton-seaice wants to merge 7 commits into
Conversation
Part 4 of issue #142: move create_um_mesh() out of land-fraction-ancillary-suite's create_landfrac.py into om3-scripts as a standalone script, so it can be reused without the rest of that repo's land-fraction-specific regridding. The core element/node/connectivity logic is unchanged; wrapped with this repo's usual CLI/provenance conventions. Includes pytest coverage of resolution parsing, mesh geometry (dims, element types, total sphere area) and esmpy loadability.
Add an optional input_mesh_filename (CLI: --input_mesh_filename), so the source (runoff-providing, e.g. a UM atmosphere mesh) and destination (masked ocean) meshes can differ. Defaults to mesh_filename, preserving existing default behaviour exactly. Several places previously assumed source and destination were the same mesh (only true by coincidence, since both were the same file): the source cell mask/coordinates, the nospread_i/spread_i and col index arrays, and - most importantly - the per-cell area used to scale weights for volume conservation, which now correctly distinguishes source area from destination area. Verified with a standalone numerical check (esmpy-loaded meshes, exact volume conservation to machine precision) for same-mesh and differing -mesh cases, with and without spreading, since the existing pytest file currently segfaults on this login node due to an unrelated regionmask/cupy import conflict (reproduced on the pre-change file too).
Covers UM-style source meshes alongside the existing same-resolution case, including different runoff placements on the source mesh. Also fixes a bug where source_area was left as the input_mesh_filename string instead of mesh_area(self.input_mesh_filename).
a0e5fe4 to
b89834d
Compare
|
Should be ready to go @kieranricardo |
Line wraps in generate_rof_weights.py bring it under black's 88-char width (comments/docstrings/argparse strings aren't auto-wrapped by black). mesh_in_um was too coarse (nlat=10, nlon=16) for any cell to fall within SRC_DIST of a real SPREAD_POINTS location, so spread=True never actually triggered spreading for that mesh in CI. Bumped to nlat=24, nlon=32 (n16), verified to reliably intersect a spread point (Lena) and exercise the spreading code path.
…read points n16 (nlat=24, nlon=32) only had a single cell matching a SPREAD_POINTS location, and it happened to be classified as land in the synthetic mask - so "Ocean" and "Ocean_Touching_Land" test data never deposited anything there, and the "proof spreading occurred" assertion failed for those cases in CI. n42 (nlat=63, nlon=84) has multiple matching cells including both land- and ocean-classified ones, verified against all 6 data placements with spread=True.
kieranricardo
left a comment
There was a problem hiding this comment.
Looks good! Can SRC_DIST, SPREAD_N, FOLD, and SPREAD_POINTS be configurable? We'll definitely want to change at least SPREAD_POINTS for the UM
|
My naive hope is we can just settle on a list of points that works for both models. With spread points, it's too long to make a command line input, so then there needs to be an input file of points. And then there needs to be a way to keep track of the input file, so they may as well just be written in the script. |
|
sounds good re spread points, especially if |
Co-authored-by: Kieran Ricardo <kieran.ricardo@anu.edu.au>
|
What about making an overall option (e.g. Just thinking the list of input arguments is already long, is continueing to make it longer better ? |
|
|
Summary
mesh_generation/generate_um_mesh.pyto generate an ESMF mesh file for a UM atmosphere grid (n96/n96e style resolutions), adapted fromcreate_landfrac.pyin land-fraction-ancillary-suite. Related to Update drof weights to include spreading #142.generate_rof_weights.pyto support a source (runoff-providing) mesh that differs from the destination mesh, via a new optionalinput_mesh_filenameparameter. Default behaviour (input mesh == output mesh) is unchanged.test/test_mesh/test_um_mesh.pyfor the new UM mesh script, and extendstest/test_mesh/test_rof_weights.pyto cover both same-mesh and differing-mesh (UM) cases, including different runoff placements on the source mesh (all on land, all on ocean, touching/not touching land, etc).Test plan
blackformatting passespytest test/test_mesh/test_um_mesh.pyandpytest test/test_mesh/test_rof_weights.pycollect and run (previously blocked by an environment-levelesmpy/regionmaskimport-order segfault in this session's shell, fixed by reordering imports)🤖 Generated with Claude Code