Scale data in Comparer
I propose a new method scale() in Comparer and ComparerCollection that should scale all primary variables (not aux data) by a factor and set a new unit. The use case is e.g. that want to show all my plots, tables etc with "cm" unit instead of "meter" but all the data files are in meter so it is a bit cumbersome to change the units before the comparison (it would require me to load all the data in the dfsu).
- The ComparerCollection should only allow scale if unit is the same across all contained comparers.
- Signature should be
scale(factor=None, *, offset=None, new_unit=None) - The
new_unitargument should be required if factor is not None and old unit is not undefined. - Optionally, we could allow the same functionality on Timeseries (for completeness)
Quick suggestion before 🎅🎄
I think you want to apply the unit conversion to all variables of a specfied quantity.
Example of syntax:
from typing import Callable
import modelskill as ms
def convert_units(quantity: ms.quantity, new_unit:str, func:Callable[[float],float]) -> ms.Comparer:
"""
Convert values for a quantity to new units
Parameters
----------
quantity : ms.quantity
The quantity to convert
new_unit : str
The new unit to convert to
func : Callable[[float],float]
Conversion function """
...
cmp.convert_units(ms.Quantity('Water level', 'm'), new_unit="cm", func=lambda x: x*100)
I wonder if this should rather be a transform_values function that could also be used for e.g. log transforming values
cmp.transform_values(func=lambda x: np.log(x), new_quantity = ms.Quantity("log concentration", "-")
It can certainly be useful to scale data in a comparison between model and observation, but can already be handled in a pre-processing step by the data processing library (pandas, mikeio, xarray).