-
Notifications
You must be signed in to change notification settings - Fork 168
Feature/uxarray xarray fields #1946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Ultimately, yes, these will replace Field and Fieldset. For the time being, because this is a massive overhaul, keeping xfield and xfieldset in their own files is a small step towards leveraging xarray and uxarray natively under the hood.
…stommel gyre example
…via particle as key
Non-working draft of structured grid index search has been brought in as well. This needs a bit of work.
This is done since the Field object holds either an xr.DataArray or ux.UxDataArray which contain the grid, dimensions, and coordinates. With this, the time argument is now set to be a datetime object.
The fieldset.dimrange function is meant to be a replacement for fieldset.grid.dimrange. Functionally, it operates in the same way but relies on the fields underneath the (u)xarray.(Ux)dataset. Currently, this is incompatible with a fieldset constructed using the `fieldset.add_field` function, since add_field does not update the `ds`. Need to think on how we want to track this. The `fieldset.gridset_size` property is set to be equivalent to the number of fields (dataarrays) stored under the fieldset. This property is meant to replace the `fieldset.gridset.size` property.
This commit allows us to define a fieldset using a list of UXarray.UxDatasets and Xarray.Datasets. Currently, because `fieldset.add_field` is used to add pointers to each field, the field names between the variables in each list item must be unique
This limits the changes required in advection.py. Still need to check that the VectorField.igrid value is set appropriately.
VeckoTheGecko
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we have the tests folder as tests/v4 rather than v4-tests . At the moment the tests aren't being collected (hence aren't run in CI)
pytest --collect-only | grep v4-tests
|
(also, would you be able to run |
for more information, see https://pre-commit.ci
…ls/Parcels into feature/uxarray_xarray_fields
|
@VeckoTheGecko - This is ready for review and for fixing the test data ingestion for the |
Done Can do a full review tomorrow |
Also move the data to a pytest fixture :)
d3a26ae to
4bf5096
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just dropping a partial review now since a lot of thoughts have come up. Some small review comments for the timebeing.
I think we need to answer an important question moving forward:
How are lat,lon,depth handled? Previously these were numpy arrays anywhere from dimension 1-4 depending on the geometry of the grid itself. This became a maintenance burden since every part of the code that needed these values also needed to include logic to deal with it for each different type of grid. With the addition of unstructured grids if we go the same route it will just further complicate things. IMO we need to find a good abstraction that we can use to bridge the gap between datasets and interpolation, so that we can tuck this complexity into a module and provide a clean API to the rest of the codebase (I can start investigating what sort of stuff is used internally in xarray and scipy for interpolation - perhaps there is inspiration we can take from those packages). For reference, @fluidnumerics-joe what is the structure of lon,lat,depth in the case of unstructured grids?
I don't know if this PR is the right place to answer this, or whether these questions should block this PR. Another option would be to create new issues to highlight these concerns. Next week I'm also hardly in the office (conference for 2 days, and then shortened week due to easter). @fluidnumerics-joe I assume this might be a blocker on your end? Not sure what other development you're working on.
parcels/field.py
Outdated
| interp_method: InterpMethod = "linear", | ||
| name: str, | ||
| data: xr.DataArray | ux.UxDataArray, | ||
| grid: ux.Grid | None = None, # To do : Once parcels.Grid class is added, allow for it to be passed here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've been using # TODO:, # TODO v4:, # TODO Nick:... across the codebase for todo comments. I'd be keen to stick to that for searchability (i.e., all caps TODO), wouldn't want this to slip through :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. I'll make these changes
In an unstructured grid, we think about a mesh as a collection of vertices (often called nodes). Elements are formed by creating convex shapes by joining sets of nodes; for FESOM and ICON, elements are just extruded triangular cells. In FESOM and ICON, the mesh is unstructured in 2-D (lat,lon) but extruded in the depth direction. Because of this the unstructured mesh description is 2-D; the third depth dimension is handled similarly to structured grid models. In this context, the top and bottom faces of each element is related to three vertices (where the vertices are defined by lat and lon only). Edges are just lines that connect two vertices; you can also relate an element to the edges that make up its boundary. Depending on the discretization, a field can be located on a For a
The
There's no hope of having a single memory layout that would efficiently be used for rectinlinear structured, curvilinear structured, and unstructured lat, lon, and depth. In the end, the primary workhorse of the Keeping these bits underneath the call stack of the
Not really a blocker right now. I have built-in interpolators for face registered and node registered data, which is sufficient for a FESOM and ICON mesh. The |
|
Thank you for the in depth response here @fluidnumerics-joe and for the overview of how unstructured grids are handled here!
Yes. I have seen quite some stalled discussions in the xarray repo about custom interpolation. Ok, going to give everything a once over now before approving just to clarify some things and get familiar. |
VeckoTheGecko
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Managed to look through in full now
…ls/Parcels into feature/uxarray_xarray_fields
VeckoTheGecko
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to merge when you're ready @fluidnumerics-joe :)
mainfor v3 changes,v4-devfor v4 changes)