Skip to content
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

Omit x, y coordinates, x & y bounds from conversion #330

Merged
merged 1 commit into from
Feb 24, 2025

Conversation

Huite
Copy link
Collaborator

@Huite Huite commented Feb 24, 2025

X and Y coords aren't relevant; they're stored in the Ugrid topology.

In particular, the original bounds might be somewhat messy (e.g. the triangle stuff...). If a user want the coordinates, they can use https://deltares.github.io/xugrid/api/xugrid.UgridDatasetAccessor.assign_face_coords.html

Which are nice and consistent (i.e. counterclockwise, and without repeated vertices).

@Huite Huite requested a review from veenstrajelmer February 24, 2025 15:21
Copy link
Collaborator

@veenstrajelmer veenstrajelmer left a comment

Choose a reason for hiding this comment

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

Tested with:

import xarray as xr
import xugrid as xu

file_nc = r'P:\archivedprojects\11206304-futuremares-rawdata-preps\data\CMIP6_BC\CMCC-ESM2\uo_Omon_CMCC-ESM2_historical_r1i1p1f1_gn_199001-200912.nc'
ds = xr.open_mfdataset(file_nc, chunks={'time':1})

topology = {"mesh2d":{"x":'i',
                      "y":'j',
                      "x_bounds":'vertices_longitude',
                      "y_bounds":'vertices_latitude',
                      }
            }

uds = xu.UgridDataset.from_structured2d(ds, topology=topology)
print(uds.coords)
print(uds.data_vars)

assert set(uds.coords) == set(['longitude', 'latitude', 'lev', 'mesh2d_nFaces', 'time'])
assert set(uds.data_vars) == set(['lev_bnds', 'time_bnds', 'uo'])

This now results in the expected coords/data_vars (and also dims)

@Huite Huite merged commit 18cc411 into main Feb 24, 2025
17 checks passed
@Huite Huite deleted the omit-xyvars-from_structured branch February 24, 2025 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants