Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scale data in Comparer #490

Open
jsmariegaard opened this issue Dec 18, 2024 · 3 comments
Open

Scale data in Comparer #490

jsmariegaard opened this issue Dec 18, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@jsmariegaard
Copy link
Member

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_unit argument 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)
@jsmariegaard jsmariegaard added the enhancement New feature or request label Dec 18, 2024
@ecomodeller
Copy link
Member

ecomodeller commented Dec 18, 2024

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)

@jsmariegaard
Copy link
Member Author

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", "-")

@ecomodeller
Copy link
Member

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).

@ecomodeller ecomodeller closed this as not planned Won't fix, can't repro, duplicate, stale Mar 11, 2025
@jsmariegaard jsmariegaard reopened this Mar 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants