Repository navigation
Conversation
When constructing fields from SGRID conventions in StructuredModelData, default tracer fields defined at cell centers (face dimensions) on staggered C-grids to CGrid_Tracer rather than hardcoding all scalar fields to XLinear.
|
Thanks for this PR< but you have not filled out the AI statement in our PR template. As per our AI-usage policy, that is very important for us |
Thanks, I have updated the PR description with the AI disclosure. |
|
Updated with root-cause fix and synced with latest main:
|
There was a problem hiding this comment.
Hello, thanks for this PR! See comments.
Broadly I think some of the testing introduced in this PR is out of scope since it focuses more on the correctness of the CGrid_Tracer interpolator rather than the interpolator selection.
It also broke CI but that seemed to be resolved as I finalized this review.
| model.grid.sgrid_metadata, | ||
| model.vector_field_components, | ||
| ) | ||
| if interp_cls is not None: |
There was a problem hiding this comment.
_select_xinterpolator never returns None
There was a problem hiding this comment.
Fixed, directly instantiated without the redundant None check.
| return XLinear | ||
|
|
||
| # Velocity components (U, V, W or components of vector fields) are not tracers | ||
| velocity_names = {"U", "V", "W"} |
There was a problem hiding this comment.
I don't think this is needed. CGrid horizontal velocities will be caught in the second check above since they are not on the face, and the vertical velocity gets caught below.
There was a problem hiding this comment.
Agreed, removed the velocity names check.
| @pytest.mark.parametrize( | ||
| "dataset_name", | ||
| [ | ||
| "ds_2d_left", |
There was a problem hiding this comment.
These datasets all store their velocities/tracers on CGrids, so they all check the exact same logic, only one should be used.
There was a problem hiding this comment.
Updated to test only \ds_2d_left.
| assert isinstance(fieldset.UV.interp_method, CGrid_Velocity) | ||
|
|
||
|
|
||
| def test_cgrid_tracer_piecewise_constant_evaluation(): |
There was a problem hiding this comment.
I think this is out of scope for this PR.
| ) | ||
|
|
||
| # Unstaggered grid metadata (face == node) -> XLinear | ||
| from parcels._sgrid.core import FaceNodePadding, Padding, SGrid2DMetadata |
There was a problem hiding this comment.
This import should be moved to the top of the file.
| assert _select_xinterpolator(da_unstaggered, unstaggered_metadata) is XLinear | ||
|
|
||
|
|
||
| def test_cgrid_tracer_particle_sampling(): |
| over the grid cell using CGrid_Tracer. Non-tracer fields, velocity components, | ||
| node-located variables, or fields on unstaggered grids default to XLinear. | ||
| """ | ||
| fnp_x, fnp_y = sgrid_metadata.face_dimensions |
There was a problem hiding this comment.
I am confused on what this is checking for, my understanding is that if a single dimension is assigned to both the faces and nodes it would break assertions during Fieldset creation, so I believe this is unneeded.
|
Thanks for the review and guidance @wyatt-fluidnumerics! I have addressed all the feedback in commit
|
Description
Fixes #3049
Problem
In
StructuredModelData.from_sgrid_conventions, all scalar fields defaulted toXLinear, even for tracer fields located at cell centers on staggered C-grids. Following Delandmeter and Van Sebille (2019), C-grid tracers should default toCGrid_Tracerto be interpolated constant over the grid cell.Solution
_select_xinterpolatorinsrc/parcels/_core/model.pyto identify tracer fields defined at cell centers (face dimensions) on staggered C-grids and default them toCGrid_Tracer.XLinear.XLinear.peninsula_dataset, aligned streamfunctionPdimensions to["YG", "XG"]to match its underlying node coordinateslat(YG) andlon(XG) (consistent withstommel_gyre_dataset).Testing
tests/test_fieldset.pycovering default interpolators on C-grids (test_cgrid_tracer_default_interpolator), dimensional edge cases (test_select_xinterpolator_edge_cases), and A-grid behavior (test_agrid_all_fields_default_to_xlinear).tests/test_fieldset.py,tests/test_advection.py,tests/test_interpolation.py,tests/test_field.py,tests/test_xgrid.py).pixi run lintandpixi run typing.Checklist
mainfor normal development,v3-supportfor v3 support)AI Disclosure
_select_xinterpolator, align dataset coordinates, and author regression tests. The code was developed at my direction, and I have read, tested, and validated all changes locally.