Skip to content

Replace ItemInfo with fmskill.Quantity#191

Merged
ecomodeller merged 25 commits intomainfrom
iteminfo
May 12, 2023
Merged

Replace ItemInfo with fmskill.Quantity#191
ecomodeller merged 25 commits intomainfrom
iteminfo

Conversation

@ecomodeller
Copy link
Copy Markdown
Member

No description provided.

@ecomodeller ecomodeller marked this pull request as ready for review May 5, 2023 08:31
@ecomodeller
Copy link
Copy Markdown
Member Author

fmskill aims to be a general purpose model skill assessment library, not limited to MIKE by DHI models.

This PR aims to loosen up the connection to the EUM system. The EUM information available in {Dfs0, Dfsu} files are still read, but for other model types, you are free to supply this information as strings for the name of the quantity and unit.

>>> from fmskill import Quantity
>>> wl = Quantity(name="Water level", unit="m")
>>> wl
Quantity(name='Water level', unit='m')
>>> uq = Quantity.undefined()
>>> uq
Quantity(name='Undefined', unit='Undefined')
>>> wl2 = Quantity(name="Water level", unit="m")
>>> wl == wl2
True
>>> wl == uq
False
>>> wl.is_compatible(uq)
True

@ecomodeller ecomodeller requested a review from jsmariegaard May 5, 2023 08:42
@ecomodeller
Copy link
Copy Markdown
Member Author

ecomodeller commented May 8, 2023

And the addition of a new TimeSeries class

classDiagram
    Observation <|-- PointObservation
    Observation <|-- TrackObservation
    TimeSeries <|-- Observation
   TimeSeries <|-- PointModelResult

class TimeSeries{
+  str name
+  dataframe data
+  Quantity quantity
+ plot()
+ hist()
}

class PointModelResult{
+ float x
+ float y
}

class Observation{
+ float weight
+ str color
}

class PointObservation{
+ float x
+ float y
}

class TrackObservation{
+ float[] x
+ float[] y
}

class Quantity{
+ str name
+ str unit
}
Loading

ItemType = Optional[Union[str, int]]


@dataclass(frozen=True)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it 😍

fmskill/types.py Outdated
@@ -1,7 +1,10 @@
from datetime import datetime
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used?

itemInfo : Optional[mikeio.ItemInfo], optional
Optionally, a MIKE IO ItemInfo (MIKE EUM system) can be given
to set or override the type and unit of the quantity, by default None
quantity : Optional[str], optional
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional[Quantity]

Copy link
Copy Markdown
Member

@jsmariegaard jsmariegaard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot. This looks great. A few things to consider:

  • Generally I think it's great to have a class "Quantity" that we can use when the source is not dfs, but I was also thinking that we maybe should support providing a str also and then potentially use mikeio.ItemInfo to try to pass that string to get a default unit or otherwise just leave the unit blank? I just think it is nice to allow simple inputs for new users.
  • I guess we could also allow for ItemInfo as input to quantity... because a user may have a mix of csv and dfs´s and the ItemInfo may therefore be nearby...
  • Some places the docstring still says that the type is str: quantity : Optional[str] (and the text below says "A string to identify the quantity") - try to search for it.
  • So far the Quantity disappears when the comparison is made (it's stored in the attrs) - should we keep it this way?
  • Would it make sense in the future (not this PR) to extend the Quantity with short_name etc?
  • I think it would be nice somehow to be able to restore the origin of the data (filename and item_name where applicable) - could that be stored in attrs?
  • I like the .plot etc a lot. But please note that the .plot.timeseries for track observations will give 3 red series (x,y and values).

image

@ecomodeller ecomodeller merged commit 2fa5c8b into main May 12, 2023
@ecomodeller ecomodeller deleted the iteminfo branch May 12, 2023 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants