DHI / mikeio

Read, write and manipulate dfs0, dfs1, dfs2, dfs3, dfsu and mesh files.
https://dhi.github.io/mikeio
BSD 3-Clause "New" or "Revised" License
136 stars 53 forks source link

mikeio fails when reading preprocessed layer information #618

Closed TroelsNV closed 7 months ago

TroelsNV commented 8 months ago

Describe the bug MIKEIO returns an exception when reading preprocessed dfs2 filer containing layer information. The bug occures in the function _valid_timesteps because the time_step_file is set to 0 (line 138 in mikeio.dfs._dfs.py). when creating the time variable in line 142 pandas.date_range fails because the length is set to 0.

To Reproduce import mikeio

read geolenses:

mikeio.read('NVFyn_MST_SceTillad_GeoLenses.dfs2')

Expected behavior Expected return of mikeio.Dataset

Screenshots image

System information:

**dataset: NB! remove .txt extension NVFyn_MST_SceTillad_GeoLenses.dfs2.txt

ecomodeller commented 8 months ago

Hi @TroelsNV the error occurs because the TimeStep defined in the file is 0.0 seconds. image

Since the file only contains a single timestep it is somewhat useless information what the spacing in time is.

TroelsNV commented 8 months ago

agreed, but MIKEIO raises an exception when reading these files. I have made a quick-fix in the code ( time_step_file = 1 if it is 0.). but i guess it should be fixed at some point.

Thanks for the fast reply.

ecomodeller commented 8 months ago

I haven't encountered this problem before, but I agree that it should be readable by MIKE IO.

What tool created the file?

TroelsNV commented 8 months ago

The files were created by MIKESHE during preprocessing.

ecomodeller commented 8 months ago

It is not possible to create such a file with MIKE Zero. image

ecomodeller commented 8 months ago

@watermain any comments from someone familiar with MIKE She?

TroelsNV commented 8 months ago

@ecomodeller I just checked with my colleague (I didn't create the files). The files were created by MIKE She as a part of the preprocessing.

watermain commented 8 months ago

I can confirm that MIKE She creates this file (and at least a few others) with a 0 length time step. The whole time axis does not have a meaning here, this is a strictly static grid. We could make changes to the MIKE She code, not a big deal, but

The mikeio code shown above is just trying to get a start and end date, right? Would it be an option to use the start date only if there is just a single time anyway?

ecomodeller commented 8 months ago

I can confirm that MIKE She creates this file (and at least a few others) with a 0 length time step. The whole time axis does not have a meaning here, this is a strictly static grid. We could make changes to the MIKE She code, not a big deal, but

  • this would only be released some time mid or end next year
  • If the dfs API allows this I would consider it a valid setting, even if the GUI doesn´t. If it is not considered to be valid then the dfs API should throw an error.

The mikeio code shown above is just trying to get a start and end date, right? Would it be an option to use the start date only if there is just a single time anyway?

I agree, for static data it would be preferable not having to specify anything related to time, but that is not how the dfs format is designed. I am suggesting to handle it in #620.