Skip to content

Update FieldSet.gridset to use a list#2057

Merged
VeckoTheGecko merged 3 commits into
v4-devfrom
gridset-overhaul
Jun 30, 2025
Merged

Update FieldSet.gridset to use a list#2057
VeckoTheGecko merged 3 commits into
v4-devfrom
gridset-overhaul

Conversation

@VeckoTheGecko

@VeckoTheGecko VeckoTheGecko commented Jun 30, 2025

Copy link
Copy Markdown
Contributor

This PR updates FieldSet.gridset to be a list of BaseGrid instances (i.e., XGrid of UxGrid objects). It also removes FieldSet.get_fields() since we now have the fields dictionary.

Note that to see if grids are the same, this code looks at whether the grid objects point to the same location in memory (this is the default with the ... in ... when working with custom objects) . This results in something like:

grid1 = XGrid(xgcm.Grid(ds))
fieldset.add_field(Field("field1", data, grid1, mesh_type="flat"))
# ^ gridset size increased by 1

grid2 = XGrid(xgcm.Grid(ds))
fieldset.add_field(Field("field2", data, grid2, mesh_type="flat"))
# ^ gridset size increased by 1

This is because calling XGrid twice results in two different XGrid objects in memory despite them having the same arguments. I think that this is fine (I don't really see an usecase where this would limit us) - keen to discuss if someone has a different opinion on this.

Not needed anymore now that in v4 fields are explicitly stored in FieldSet.fields
Also remove `FieldSet.gridset_size` which was used as a patch
Comment thread parcels/fieldset.py
@VeckoTheGecko VeckoTheGecko merged commit 0d5d374 into v4-dev Jun 30, 2025
1 of 2 checks passed
@VeckoTheGecko VeckoTheGecko deleted the gridset-overhaul branch June 30, 2025 16:29
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Parcels development Jun 30, 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