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

Reading spectra from Dfs2s: x0 and y0 defaults to zero #574

Open
stkistner opened this issue Jun 2, 2023 · 6 comments
Open

Reading spectra from Dfs2s: x0 and y0 defaults to zero #574

stkistner opened this issue Jun 2, 2023 · 6 comments

Comments

@stkistner
Copy link

Description

x0 and y0 defaults to zero when reading Dfs2 files.

To Reproduce

Steps to reproduce the behavior:

filein = r'mikeio\tests\testdata\single_row.dfs2'
x0_current =  mikeio.Dfs2(filein).read().geometry._x0
x0_actual =  mikeio.Dfs2(filein,type='spectral').read().geometry._x0
print(x0_current)
print(x0_actual)
>>> 0.0
>>> -139.0500030517578

Expected behavior

In 9 out of 10 cases the x0 and y0 origins aren't necessary in Dfs2 files, but it is used in some cases e.g. vertical boundaries:

https://faq.dhigroup.com/default.asp?module=MIKE+3&ID=532

I see this traces back to the read_x0y0=False parameter in mikeio.dfs._dfs2._read_dfs2_header, which is only set to True when reading spectral datasets. Is there any logical way around this?

System information

  • MIKE IO version: 1.5.1
@ecomodeller
Copy link
Member

AFAIK a Dfs2 file has no metadata which tells you that this file should be interpreted as a vertical slice. So I guess the pragmatic solution is to use the same approach as the spectral data, and supply that information when you open the file, e.g. Dfs2(...,type='vertical')

@jsmariegaard
Copy link
Member

We did some work on this a little while ago. See #544 and the related issues #538 and #540

@stkistner
Copy link
Author

Thanks. I'll try and implemented something pragmatic.

@jsmariegaard
Copy link
Member

@stkistner I am curious - could you describe the need a bit more? Is there an engine that needs this information? In that case I think we should consider to re-open :-)

@stkistner
Copy link
Author

@stkistner I am curious - could you describe the need a bit more? Is there an engine that needs this information? In that case I think we should consider to re-open :-)

I think it's best described in the FAQ for MIKE.

When using dfs2 files for boundary conditions, the x-axis defines the spatial extension in the horizontal plane and the y-axis is interpreted as the extension in the vertical given relative to a level defined by the y-axis origin. The z-level for the rows in a dfs2 file is found by

z(j) = origin(y) – dy*(NY – j)

where dy is the grid-spacing in y-axis direction, NY is the grid size -1 and Origin(y) is the level for the upper row (j=NY).

It's a niche case, but I have used this type of functionality to create vertical boundaries from HYCOM or CMEMS.

Another example was when trying to convert a Dfs2 that was incorrectly read in as a non-spectral Dfs2 to a spectral Dfs2. But without the x0 or y0 data available anywhere it's not possible. The solution was to throw an Exception telling the user to use the type='spectral'

@stkistner stkistner reopened this Jun 29, 2023
@stkistner
Copy link
Author

@jsmariegaard on another related note:
I have a Dfs2 from a model with a UTM projection. The Geographical info of the spectrum includes the northing of the projection, e.g. see below:
image

When read with mikeio, this is added to the direction-axis of the spectral data:
image

@ecomodeller ecomodeller changed the title Reading Dfs2s: x0 and y0 defaults to zero Reading spectra from Dfs2s: x0 and y0 defaults to zero Feb 16, 2024
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

No branches or pull requests

3 participants