Skip to content

Commit

Permalink
feat: support for shared speed units
Browse files Browse the repository at this point in the history
Signed-off-by: F.N. Claessen <[email protected]>
  • Loading branch information
Flix6x committed Mar 5, 2025
1 parent 92c5a84 commit 1fdc33d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions flexmeasures/utils/unit_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,22 @@ def is_energy_price_unit(unit: str) -> bool:
return False


def is_speed_unit(unit: str) -> bool:
"""For example:
>>> is_speed_unit("m/s")
True
>>> is_speed_unit("km/h")
True
>>> is_speed_unit("W")
False
>>> is_speed_unit("m/s²")
False
"""
if not is_valid_unit(unit):
return False
return ur.Quantity(unit).dimensionality == ur.Quantity("m/s").dimensionality


def get_unit_dimension(unit: str) -> str:
"""For example:
>>> get_unit_dimension("kW")
Expand All @@ -271,6 +287,8 @@ def get_unit_dimension(unit: str) -> str:
'length'
>>> get_unit_dimension("h")
'time'
>>> get_unit_dimension("m/s")
'speed'
"""
if is_power_unit(unit):
return "power"
Expand All @@ -282,6 +300,8 @@ def get_unit_dimension(unit: str) -> str:
return "price"
if is_currency_unit(unit):
return "currency"
if is_speed_unit(unit):
return "speed"
if unit == "%":
return "percentage"
dimensions = ur.Quantity(unit).dimensionality
Expand Down

0 comments on commit 1fdc33d

Please sign in to comment.