Skip to content

Unit conversion factor #857

Description

@AL89

Is your feature request related to a problem? Please describe.
My suggestion is related to EUMType and EUMUnit.

Describe the solution you'd like
An example explanation: When a time series object (DataArray) has an EUMType "Precipitation" and related EUMUnit "mm_per_day" and I want my time series object to be in "mm_per_hour", how do I convert the values into that unit. For that reason, it could be nice if there were some kind of conversion tool between units. That would be a conversion factor that is multiplied to the values. Of course, there would be some restrictions, like if it is not possible for some reason, the function (or whatever is going to be made) should return None or throw an error. In my example, the function should return a multiplication value of 1/24.

Describe alternatives you've considered
Self-made function with input values being "from_unit" and "to_unit". The function should return a multiplication value (scale factor).

Activity

  1. ecomodeller commented on Nov 13, 2025

    @ecomodeller
    Member

    This should be possible, since all conversion functions are stored in EUM.xml (which you can find in the bin folder of the MIKE installation), but not sure how easy it is to expose this in an elegant and robust way in MIKE IO.

    ...
        <Rows>
          <R Ident="eumUmeter" MzId="1000" Desc="meter" Abbr="m" Expr="Length"/>
          <R Ident="eumUkilometer" MzId="1001" Desc="kilometer" Abbr="km" Expr="1000*eumUmeter"/>
          <R Ident="eumUmillimeter" MzId="1002" Desc="millimeter" Abbr="mm" Expr="0.001*eumUmeter"/>
          <R Ident="eumUinch" MzId="1004" Desc="inch" Abbr="in" Expr="0.0254*eumUmeter"/>
          <R Ident="eumUfeet" MzId="1003" Desc="feet" Abbr="ft" Expr="12*eumUinch"/>
    ...

    Unit conversions are common in engineering, are you aware of the pint library?
    Is it something like this you are looking for?

    >>> from pint import UnitRegistry
    >>> u = UnitRegistry()
    >>> (12.0 * (u.millimeter/u.d)).to(u.millimeter/u.h)
    <Quantity(0.5, 'millimeter / hour')>
    >>> (1.0 * (u.millimeter/u.d)).to(u.millimeter/u.h).magnitude
    0.041666666666666664

    And keep in mind that some unit conversion are not simple multiplication factors, e.g. Fahrenheit to Celsius.

  2. locked and limited conversation to collaborators on Nov 13, 2025
  3. converted this issue into a discussion #858 on Nov 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions