DHI/mikeio

Defining landvalue when writing dfs2-file

Achton-Boel opened this issue · 6 comments

There does not seem to be an option to define a landvalue when wrtiting a dfs2-file from python with Dfs2().write. The landvalue is greyed out when opening the file in MIKE Zero.
We neeed the functionallity when importing a bathymetry into a simulation-setup such as .m21fm. When the dfs2 is used as a domain/mesh we are prompted with the error: "no landvalue set". How can we specify a custom landvalue?

That seems useful, I just have to figure out how the landvalue is actually stored in the dfs2 file.
I imagine it is stored here somehow
image
@JesperGr can you explain what is necessary to store a landvalue correctly in a dfs2 file?

Land value is stored in the custom block named "M21_Misc", the 4th value, as is also seen from the attached image. To store that correctly in a dfs2 file, check out e.g. (C# code):
https://github.com/DHI/MIKECore-Examples/blob/47b5c74130d57091df2853254fb0718462c1c3b5/Examples/CSharp/ExamplesDfs2.cs#L220

builder.AddCustomBlock(factory.CreateCustomBlock("M21_Misc", new float[] { 327f, 0.2f, -900f, 10f, 0f, 0f, 0f }));

There is a similar example for Python in the mikecore-python repository:

https://github.com/DHI/mikecore-python/blob/04c36b1ee3dc6c81905d75ff8c39d7b8a8411bd7/tests/examples_dfs2.py#L165

builder.AddCustomBlock(factory.CreateCustomBlock("M21_Misc", np.array([ 327, 0.2, -900, 10, 0, 0, 0 ], np.float32)));

Well, there is actually a full example of making a bathymetry dfs2 file, look for CreateM21Bathymetry:

https://github.com/DHI/mikecore-python/blob/04c36b1ee3dc6c81905d75ff8c39d7b8a8411bd7/tests/examples_dfs2.py#L359

This issue has been raised earlier #202 so we will consider how to best support this in mikeio, and in the meantime, you should be able to get by just fine with the example that @JesperGr posted above, using mikecore directly.

Hello Henrik and Jesper

Thanks for your quick respons. It helped a great deal.

We will look forward to see it implemented in MIKEIO 👍