DHI / mikecore-python

MIKE Core in Python
5 stars 0 forks source link

dfsu file created by old version of MIKE MeshGenerator cannot be opened #24

Open Hendrik1987 opened 1 year ago

Hendrik1987 commented 1 year ago

Describe the bug I have a dfsu file of a friction map, which I would like to open in mikeio. I get the following error messages: image

The file is accepted by a MIKE 21 HD run and in the data utility it looks like this: image

What I tried I did create, save and reload a mikeio.dataset with EUMType.Mannings_M, EUMUnit.meter_pow__1_per_3__per_sec without any problems. I did then also open this 2nd dfsu file in the data utility and could not find a difference.

System information:

jsmariegaard commented 1 year ago

Could you send the file to me? Then I can try.

jsmariegaard commented 1 year ago

This seems to be due to an empty item name. Will try to confirm with another file. If this is indeed the problem it can be transferred to https://github.com/DHI/mikecore-python

Hendrik1987 commented 1 year ago

I have created a .dfsu file in Mesh Generator with empty item. I have also imported the problematic dfsu file in Mesh Generator and exported again as .dfsu with an item name. Will send you both files.

I can read both files in mikeio. I am still puzzled what the problem or combination of problems in the original file is... But my problem at hand is solved now.

jsmariegaard commented 1 year ago

Thanks. Strange. Could you please send me the files? Then I can see if I can find a difference between those and the one you send me last time.

jsmariegaard commented 1 year ago

I wonder if it could be due to the missing type/units of the static items?

image

jsmariegaard commented 1 year ago

It is actually surprising that the file "works" when you consider the names of the static items: It contains two items named "Z-coordinates" (4 and 5) and two items named "Nodes per element" (8 and 9). Item 5 should have been "code" and item 9 should have been "connectivity". But when the dfsu file is read by MIKE core, the name, type and unit are not checked, it just read the static items assuming that they are: 1:node id, 2:x, 3:y, 4:z, 5:code, 6:element id, 7:element type, 8:num of nodes, 9:connectivity.

Hendrik1987 commented 1 year ago

I wonder if it could be due to the missing type/units of the static items?

Good observation! This appears to have been fixed by the import and export through Mesh generator. Although MIKE seems to be more forgiving (.dfsu can be opened in MIKE Zero and used for MIKE 21 HD run), I would consider the file as incomplete / incorrect.

Hendrik1987 commented 1 year ago

It is actually surprising that the file "works" when you consider the names of the static items: [...]

I wonder if that happens in the mesh generator export to .dfsu functionality. The QGIS add-in does actually not accept .dfsu files exported from the mesh generator - only speculating but maybe that is related. The duplicated static items seem to be acceptable for MIKE core / mikeio, as the left file in your screenshot can be read. This might suggest that only the names of the static items are duplicated, but the data (values of 5: "code" and 9: "connectivity") are correct, right?

jsmariegaard commented 1 year ago

Status: @Hendrik1987 has a 2d dfsu file created a long time ago with a previous version of MeshGenerator. It can be opened in MIKE Zero and the MIKE FM engines also accept it. It cannot be opened with MIKE Core's DfsuFile.Open(). The problematic file had a single item with an empty string as name. All static items in the file have undefined type and unit. The static item names are non-unique and some a wrong compared to other dfsu files.

Even though the file is "wrong" in some sense, I still think MIKE Core should be able to read it (if MZ and the engines can).