-
Notifications
You must be signed in to change notification settings - Fork 58
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
cell center vs. cell corner confusion when using Local Coordinates #579
Comments
It seems like According to: @jsmariegaard do we have any documentation other than the FAQ where this convention is clearly stated? |
Thanks for the quick follow-up! |
Yes, I know. For me it is a known issue - but that should of course be communicated somehow and even better fixed 🙄 It was not easy to make an elegant solution to this inconsistency. |
...so in case I would like to use a workaround in the meantime - what would be a good way? |
We are doing something similar when we convert a Grid2D to a mesh - see mikeio/mikeio/spatial/_grid_geometry.py Line 921 in 66beb8d
|
This issue seems to be unresolved as of today - and I really would appreciate it a fix.
I have written a helper function to correct for it in case 3; however you may not apply it in case 1, so it easily gets confusing. |
@Snowthe Is this the behaviour you need? |
Yes, awesome, this looks like the solution. (As of the current version, this results in -0.25, -0.25 as corner coordinates instead of 0,0) I assume that this not only applies to da.plot(), but is properly passed on in case one e.g. uses xr_da = da.to_xarray() (and then work on with the resulting xarray, plot it etc) |
@Snowthe Would you be so kind to verify that this is the solution you need? You can install the branch like this: pip install https://github.com/DHI/mikeio/archive/non-utm.zip |
Thanks a lot. To me, it seems as if this gives the desired behaviour. I checked import mikeio
import numpy as np
import xarray as xr
import matplotlib.pyplot as plt
import rasterio
import rioxarray
da = mikeio.DataArray(data=np.array([[1,2],[3,4]]),
geometry=mikeio.Grid2D(dx=0.5, projection='NON-UTM', nx=2, ny=2))
da.geometry.x #now 0.25, 0.75
plt.figure(); da.plot() #now lower left corner as 0,0 (instead -0.25, -0.25)
xr_da = da.to_xarray()
xr_da.x #now 0.25, 0.75
plt.figure(); xr_da.plot() #now lower left corner as 0,0 (instead -0.25, -0.25)
xr_da.rio.to_raster('testtif2.tif') #now lower left corner as 0,0 (instead -0.25, -0.25) |
I fear I have to come back to this - I just realized that loading dfs2 files seems to work fine with the 2.0.dev0 version you provided me. Loading dfs3 files, however, still seems to show the same error in some cases: ds = mikeio.read(dfs3_fp) |
Thanks for re-opening. |
[This might be related to https://github.com//issues/540 or the fix of it]
Describe the bug
When using dfs2/3 files with local coordinates, one defines the corners coordinates of the origin cell in its properties - map projection coordinates - Easting and Northing. This is relfected correctly when viewing a dfs2/3 file in the MIKE Zero Result viewer, where one can see the correct corner coordinates.
When I load the same file with mikeio.read(), and inspect the mikeio.Dataset.geometry, it shows the same corner coordinates - as expected.
However, as soon as I try to plot the array (or write to tif via rioxarray), I can see that it is shifted by half a cell in both directions - i.e. the corner coordinates are wrongly interpreted as center coordinates.
To Reproduce
Is this related to some inconsistency between a mikeio Dataset/DataArray and the respective xarray data types?
System information:
The text was updated successfully, but these errors were encountered: