Skip to content

UgridDataset is converted to Dataset with assign_attrs #412

Description

@veenstrajelmer

Interesting bug that when constructing a uds from a ugrid2d instead of a ugrid2d.to_dataset(). With the latter, .assign_attrs() converts the UgridDataset to a Dataset:

import xugrid as xu
from meshkernel import MakeGridParameters, MeshKernel

# user input
crs = 'EPSG:4326' # coordinate reference system, only EPSG 4326 (WGS84) is currently supported by the ERA5 and CMEMS download scripts.

# domain and resolution
lon_min, lon_max, lat_min, lat_max = 105.8, 106.85, 17.75, 18.5
dxy = 0.1

# create base grid
make_grid_parameters = MakeGridParameters(
    angle=0,
    origin_x=lon_min,
    origin_y=lat_min,
    upper_right_x=lon_max,
    upper_right_y=lat_max,
    block_size_x=dxy,
    block_size_y=dxy,
    )

mk = MeshKernel()#projection=projection)
mk.curvilinear_compute_rectangular_grid_on_extension(make_grid_parameters)
mk.curvilinear_convert_to_mesh2d() #convert to ugrid/mesh2d

mesh2d_grid = mk.mesh2d_get()

crs = 'EPSG:28992'
xu_ugrid2d = xu.Ugrid2d.from_meshkernel(mesh2d_grid, crs=crs)

uds1 = xu.UgridDataset(xu_ugrid2d.to_dataset()) # this results in a UgridDataset after assign_attrs
uds2 = xu.UgridDataset(grids=[xu_ugrid2d]) # this results in a Dataset after assign_attrs

print(type(uds1))
print(type(uds2))

uds1 = uds1.assign_attrs({
    'institution': 'Deltares',
    'references': 'https://www.deltares.nl',
    })
uds2 = uds2.assign_attrs({
    'institution': 'Deltares',
    'references': 'https://www.deltares.nl',
    })

print(type(uds1))
print(type(uds2))

Gives:

<class 'xugrid.core.wrap.UgridDataset'>
<class 'xugrid.core.wrap.UgridDataset'>
<class 'xugrid.core.wrap.UgridDataset'>
<class 'xarray.core.dataset.Dataset'>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions