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

Back and forth conversion xugrid - meshkernel does not work for spherical network #177

Closed
Tammo-Zijlker-Deltares opened this issue Nov 20, 2023 · 3 comments · Fixed by #186

Comments

@Tammo-Zijlker-Deltares
Copy link

Loading a ugriddataset, converting to a meshkernel object (to apply transformations such as deletion with meshkernel) and converting back to a ugrid dataset does not work for spherical networks.

This probably has to do that in conversion from ugrid to meshkernel, the sperical projection information is lost.

Sample code:

# Imports
import dfm_tools as dfmt
import meshkernel as mk

# Load a model grid as UgridDataset

network = dfmt.open_partitioned_dataset(r'p:\11208614-de-370a\01_models\Humber\DFLOWFM\Models\humber_basque_modelbuilder\humber_basque_net.nc') 

#Convert the network to a meshkernel object
mk_object = network.grid.meshkernel

# Delete non-contiguous parts of the grid
mk_object.mesh2d_remove_disconnected_regions()
crs = 'EPSG:4326'


#convert to xugrid, interpolate z-values and write to netcdf
xu_grid_uds = dfmt.meshkernel_to_UgridDataset(mk=mk_object, crs=crs)

The error is:

ValueError: is_geographic mismatch between provided grid (is_geographic=False) and provided crs (EPSG:4326, is_geographic=True)

@veenstrajelmer
Copy link
Collaborator

veenstrajelmer commented Nov 20, 2023

This has to do with the fact that all Ugrid2d.meshkernel instances are initialized as cartesian. We should support spherical networks in the xugrid to meshkernel conversion.

It is also related to Deltares/dfm_tools#661 and #42. If we set the uds crs automatically, we can derive is_geographic within uds.grid.meshkernel and apply cartesian/spherical projection correctly.

@Huite
Copy link
Collaborator

Huite commented Nov 21, 2023

Related to: #52

Any code that touches lengths or areas requires an alternative implementation.

It shouldn't be hard to support initializing things, but the next question is whether should put up some guard rails.
I.e. not allowing certain operations if the cartesian flag on the geometry is False. Maybe just raise some NotImplementedErrors.

@veenstrajelmer
Copy link
Collaborator

veenstrajelmer commented Dec 4, 2023

With #186 the meshkernel projection is now automatically derived from the uds. It is important to set the crs on the uds however. In the future we will automatically set it in #42 or Deltares/dfm_tools#684

This works:

import dfm_tools as dfmt
crs = 'EPSG:4326'
network = dfmt.open_partitioned_dataset(r'p:\11208614-de-370a\01_models\Humber\DFLOWFM\Models\humber_basque_modelbuilder\humber_basque_net.nc') 
network.ugrid.set_crs(crs)
mk_object = network.grid.meshkernel
xu_grid_uds = dfmt.meshkernel_to_UgridDataset(mk=mk_object, crs=crs)

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 a pull request may close this issue.

3 participants