Add configurable feature-mask tasks for mesh and ocean components - #592
Open
xylar wants to merge 8 commits into
Open
Add configurable feature-mask tasks for mesh and ocean components#592xylar wants to merge 8 commits into
xylar wants to merge 8 commits into
Conversation
Collaborator
Author
|
The idea is that this shared step will be used in later workflows to generate masks for use in online Omega analysis members (e.g. the MOC and regional stats) as well as offline analysis here in Polaris. |
Collaborator
Author
TestingOn Chrysalis, I set up: Then, in the I edited the # options for creating region or transect masks on an MPAS mesh
[feature_masks]
# Path to an existing standard MPAS mesh file for configurable use
# source: /gpfs/fs1/home/ac.xylar/e3sm_work/polaris/add-region-mask-framework/polaris/tasks/mesh/spherical/feature_masks/feature_masks.cfg
mesh_filename = ocean.QU.240km.151209.omega.teos10eos.nc
# Mesh name used in output filenames and metadata
# source: /gpfs/fs1/home/ac.xylar/e3sm_work/polaris/add-region-mask-framework/polaris/tasks/mesh/spherical/feature_masks/feature_masks.cfg
mesh_name = oQU240When I ran the step, I got: So far, no attempt to translate these variable names into an Omega-friendly format but the hooks are in place to do that later. |
xylar
force-pushed
the
add-region-mask-framework
branch
2 times, most recently
from
May 28, 2026 20:36
0c64ad5 to
747dafc
Compare
xylar
commented
May 29, 2026
Comment on lines
+6
to
+7
| nRegions: NRegions | ||
| nTransects: NTransects |
Collaborator
Author
There was a problem hiding this comment.
I'm not sure we actually want these. We may instead want dimensions that are specific to different region groups.
This step computes feature masks for a given region or transect group for a given MPAS mesh. A related standalone task allows a user to point to a mesh, give it a name, and choose a feature group.
The ocean version can convert mesh variables from Omega format if an Omega horizontal mesh is provided as an input. It also has hooks for translating the mesh variables to Omega's preferred format (TBD).
The sourthern transects are added for each MOC region, and the file is writtent with a special prefix to indicate this.
xylar
force-pushed
the
add-region-mask-framework
branch
from
August 12, 2026 11:10
ec94852 to
ab51378
Compare
The MOC behavior lived only in `ComputeOceanFeatureMasksStep`, which bundles it with ocean-model I/O from `OceanIOStep`. A step in another component that wants the MOC filename convention and the southern- boundary transects was forced to inherit the Omega name translation too, and so to supply an `[ocean]` config section. Move the two model-agnostic pieces into `polaris/tasks/mesh/spherical/feature_masks/moc.py`: the `mocBasinsAndTransects` filename convention and appending the southern- boundary transects. Neither needs `self`, and neither touches an ocean model, so a leaf module holds them rather than a shared base class. `ComputeOceanFeatureMasksStep` now delegates to them, keeping its behavior and its API exactly as they are. Nothing about the produced file changes. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Cover the leaf module directly: the filename convention, appending the transects, and dropping the string variables that are incompatible with CDF5. These assertions move over from the ocean tests, which patched `add_moc_southern_boundary_transects` in a module that no longer imports it. What is left on the ocean side is the delegation boundary: that the MOC filename matches `moc_masks_filename()` so the two cannot silently drift, that `_post_process_masks` hands the masks, the mesh, and its logger to `add_moc_transects()`, and that other mask groups are still a no-op. Also check the property that makes the helpers reusable, in the two ways it can be checked. A `sys.modules` test is not one of them, since `polaris/tasks/__init__.py` imports every component: instead, assert that the module's own imports name neither `polaris.ocean` nor `polaris.tasks.ocean`, and that a step in another component can subclass the model-neutral step, use both helpers, and set up against a config with no `[ocean]` section. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Describe the leaf module where the mesh feature-mask page documents the rest of the model-neutral implementation, including why importing `mpas_tools.ocean.moc` does not drag in `polaris.tasks.ocean` and what that buys a step in another component. The ocean page keeps its MOC section but now describes the two hooks as delegating, and drops the claim that the mesh package must not import `add_moc_southern_boundary_transects`, which is what this refactor changes. The user's guide is unchanged: nothing about the produced file moved. Co-Authored-By: Claude Opus 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.
Summary
This PR adds a shared framework for computing geometric-feature region and transect masks on MPAS meshes, plus configurable mesh and ocean tasks that expose the workflow through Polaris.
Detailed Description
The PR adds a reusable
ComputeFeatureMasksStepthat builds mask feature collections fromgeometric_features, validates feature object and mask types, computes MPAS region or transect masks withmpas_tools, and writes both mask NetCDF output and the source GeoJSON. The workflow supports configurable mesh inputs, mesh metadata, mask groups, mask types, multiprocessing settings, subdivision options, and transect edge signs.The branch also registers configurable feature-mask tasks under both the mesh and ocean components. The ocean task subclasses the shared step so native MPAS-Ocean or Omega mesh files are opened through the ocean I/O layer before using the same mask-generation logic.
nRegionsandnTransectsare added to the MPAS-Ocean-to-Omega dimension map so mask output can be written in native Omega names.get_feature_mask_steps()is available for workflows that already have an upstream mesh-producing step; it takes the mesh step and filename explicitly rather than special-casing base or culled meshes.The "MOC Basins" regions get special treatment. A southern-boundary transect is added for each region, and the combined file is given the
mocBasinsAndTransectsprefix that E3SM and MPAS-Analysis expect.That MOC behavior lives in
polaris/tasks/mesh/spherical/feature_masks/moc.py, not in the ocean step. Both pieces of it — the filename convention and appending the transects — are model-agnostic: they operate on standard MPAS meshes and masks, and neither needs a step instance. Keeping them in a leaf module means a step in another component can subclass the model-neutralComputeFeatureMasksStepand reuse them without inheriting the Omega name translation, and so without having to supply an[ocean]config section.ComputeOceanFeatureMasksStepdelegates to the same two functions, so the MOC logic exists in exactly one place.polaris/tasks/e3sm/init/component_inputs/is the motivating caller: MPAS-Ocean reads the per-mesh MOC file at run time through itsregionalMasksInputandtransectMasksInputstreams, so it is a component input rather than an analysis product.Testing
Unit tests cover feature object-type detection, mask-type validation, shared-step configuration, configurable setup, output metadata and filenames, and a full step run against a small synthetic mesh.
The MOC helpers are tested directly, including that the module's own imports name neither
polaris.oceannorpolaris.tasks.ocean, and that a step in another component can subclass the model-neutral step, use both helpers, and set up against a config with no[ocean]section. On the ocean side the tests cover the Omega name-translation boundary and the delegation to the shared helpers.pytest tests/passes in full (365 tests), andpre-commit run --all-filesis clean.Checklist
api.md) has any new or modified class, method and/or functions listedTestingcomment in the PR documents testing used to verify the changes