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

`EUMType.Sun_radiation` with `EUMUnit.undefined` -> DFS error code 2020 #614

Closed tpilz closed 8 months ago

tpilz commented 8 months ago

Describe the bug When I compile a new dataset with EUMType.Sun_radiation and EUMUnit.undefined and want to write the dataset with dfs.write() I get Exception: DFS error code 2020 : EUM unit and type does not match. Not sure if this is intentional but to me it comes a bit unexpected.

NB: I use EUMUnit.undefined because my desired unit J/cm2 is not availble.

Expected behavior Allow for EUMUnit.undefined to be used with any EUMType.

System information:

ecomodeller commented 8 months ago

The EUM system used by DFS files only accepts certain combinations of types and units.

To get the list of acceptable unit for each type you can inspect the type like this, the first unit in the list if the default which you will get if you only specify a type without a unit.

Sun radiation is an energy flux, thus $J/cm^2$ is not an appropriate unit.

>>> import mikeio
>>> mikeio.EUMType.Sun_radiation
Sun radiation
>>> mikeio.EUMType.Sun_radiation.units
[watt per meter pow 2, joule per meter pow 2 per day, kJ per meter pow 2 per hour, kJ per meter pow 2 per day, MJ per meter pow 2 per day]
>>> mikeio.EUMType.Sun_radiation.units[0]
watt per meter pow 2

The rules of which types and units that can be used together will be the same irrespective of how you create a dfs file, thus this is outside the scope of MIKE IO (which only acts as a friendly wrapper to the underlying core dfs library).

tpilz commented 8 months ago

The unit is implicitly referring to resolution, which is daily in this case, so the unit actually is J/cm2/day (in general J/cm2/resolution is the standard unit for radiation data from the German Weather Service).

Anyway, my point is that I would rather leave it "undefined" if the actual unit I need is not available and don't want to convert the values. But I guess this would have to be requested from core dfs if I got you right?

ecomodeller commented 8 months ago

The unit is implicitly referring to resolution, which is daily in this case, so the unit actually is J/cm2/day (in general J/cm2/resolution is the standard unit for radiation data from the German Weather Service).

Anyway, my point is that I would rather leave it "undefined" if the actual unit I need is not available and don't want to convert the values. But I guess this would have to be requested from core dfs if I got you right?

Yes, correct. But if you prefer to use an undefined unit, you also have to accept that the type is undefined.