Skip to content

Add Field tests and type guarding in Field init#1986

Merged
VeckoTheGecko merged 8 commits intov4-devfrom
field-testing
Apr 29, 2025
Merged

Add Field tests and type guarding in Field init#1986
VeckoTheGecko merged 8 commits intov4-devfrom
field-testing

Conversation

@VeckoTheGecko
Copy link
Copy Markdown
Contributor

This PR does some cleanup in the field.py file, adds type guarding in the Field initialiser, and adds some tests for, laying some of the prep work for structured grid compatability in the Field object.

  • Chose the correct base branch (v4-dev for v4 changes)
  • Added tests

Comment thread parcels/field.py Outdated
Comment on lines 685 to 697
def _validate_uxgrid(grid):
"""Verifies that all the required attributes are present in the uxarray.UxDataArray.UxGrid object."""
if "Conventions" not in grid.attrs.keys():
raise ValueError(
f"Field {name} is missing a 'Conventions' attribute in the field's metadata. "
"Field is missing a 'Conventions' attribute in the field's metadata. "
"This attribute is required for uxarray.UxDataArray objects."
)
if grid.attrs["Conventions"] != "UGRID-1.0":
raise ValueError(
f"Field {name} has a 'Conventions' attribute that is not 'UGRID-1.0'. "
"Field has a 'Conventions' attribute that is not 'UGRID-1.0'. "
"This attribute is required for uxarray.UxDataArray objects."
"See https://ugrid-conventions.github.io/ugrid-conventions/ for more information."
)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its nice removing name from here as it's only used in the error message itself. The context can be added via add_note (introduced in 3.11) as the message propagates up

@VeckoTheGecko VeckoTheGecko merged commit c916b2b into v4-dev Apr 29, 2025
3 of 9 checks passed
@VeckoTheGecko VeckoTheGecko deleted the field-testing branch April 29, 2025 12:22
@github-project-automation github-project-automation bot moved this from Backlog to Done in Parcels development Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants