Repository navigation
Make vertical direction analysis more robust (direction of W and ErrorThroughSurface) - #3078
Conversation
…d ThroughSurface errors
Adding a `_assert_has_positive_attribute` method on model.py to check if the vertical axis has a `positive` attribute. This is in line with CF conventions
wyatt-fluidnumerics
left a comment
There was a problem hiding this comment.
Looks good, just the one question below!
…m/erikvansebille/Parcels into use_positive_depth_in_outofbounds
…th_in_outofbounds
When positive z is up, we can assume that positive W is also up. it would be very strange if that then points down The issue between mismatched Z and W direction is only when positive Z is down
wyatt-fluidnumerics
left a comment
There was a problem hiding this comment.
Great changes overall, just a few things I am wondering about.
Additionally, should we add documentation for this attribute in docs/user_guide/convert_writing_functions.md?
| if "positive" not in depth.attrs: | ||
| raise ValueError( | ||
| f"Vertical coordinate {depth.name!r} must have a 'positive' attribute specifying 'up' or 'down'." | ||
| ) |
There was a problem hiding this comment.
Should we verify here that the attribute itself is either "up" or "down"? Something like
if depth.attrs["positive"] not in ("up", "down"):
raise ValueError(
f"Vertical coordinate "positive" attribute must be "up" or "down", got depth.attrs["positive"]"
)| interface_dim, center_dim = _detect_vertical_coordinates(ds, _FESOM2_VERTICAL_DIMS) | ||
| return _rename_vertical_dims(ds, interface_dim, center_dim) | ||
| ds = _rename_vertical_dims(ds, interface_dim, center_dim) | ||
| ds = _maybe_flip_w_to_positive_depth_direction(ds) |
There was a problem hiding this comment.
_maybe_flip_w_to_positive_depth_direction only looks at ds.depth.attrs, for UxDatasets we need to look at either zf or zc.
| particles.state, | ||
| ) | ||
| if "Z" in grid_positions: | ||
| positive = field.grid.depth_positive_direction |
There was a problem hiding this comment.
Should we call .lower() on positive here or is it okay for this to be case sensitive?
Yes, very good idea. Added in 9815ea6 |
Description
Until now, the code that distinguished between an
ErrorThroughSurfaceand anErrorOutOfBoundsin the vertical dimension quietly assumed that depth was pointing downward. This PR uses thepositiveattribute of the depth axis to determine whether aLEFTor aRIGHTout of bounds is a ThroughSurface errorThis PR also adds a requirement for the vertical coordinate to have a positive attribute (either up or down). This is in line with the CF-convention: https://cfconventions.org/cf-conventions/cf-conventions.html#vertical-coordinate
Not only will this make the ThroughSurfaceError more robust (because we can now definitely tell what is the surface and what is the ocean floor or top of atmosphere), but it also allows for more stringent checks whether the direction of positive depth and positive W are aligned.
This PR therefore also makes the flipping of the sign of W in convert functions more robust - these are now only flipped when the direction of positive depth is different from the direction of positive W
Checklist
mainfor normal development,v3-supportfor v3 support)AI Disclosure
Asked CoPilot to assist me in making these changes and writing unit tests