Skip to content

Commit

Permalink
Merge pull request #253 from CSHS-CWRA/use_xclim_v040
Browse files Browse the repository at this point in the history
Use xclim v040
  • Loading branch information
Zeitsperre authored Jan 23, 2023
2 parents 018259f + 673b810 commit 5f2d897
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Setup miniconda with mamba
uses: conda-incubator/setup-miniconda@v2.1.1
uses: conda-incubator/setup-miniconda@v2
with:
python-version: "3.9"
mamba-version: "*"
miniforge-variant: Mambaforge
channels: conda-forge,defaults
channel-priority: true
activate-environment: ravenpy-env
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ dependencies:
- spotpy
- statsmodels
- xarray <2022.11.0 # Pinned due to incompatibility with climpred @ 2.2.0
- xclim >=0.39
- xclim >=0.40
- xskillscore
- wheel
8 changes: 5 additions & 3 deletions ravenpy/utilities/coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def infer_scale_and_offset(da: xr.DataArray, data_type: str) -> (float, float):
return scale, offset


def units_transform(source, target):
def units_transform(source, target, context="hydro"):
"""Return linear transform parameters to convert one unit to another.
If the target unit is given by `y = ax + b`, where `x` is the value of the source unit, then this function
Expand All @@ -105,10 +105,12 @@ def units_transform(source, target):
Source unit string, pint-recognized.
target : str
Target unit string, pint-recognized.
context : str, optional
Context of unit conversion. Default: "hydro".
"""
from xclim.core.units import convert_units_to, units

b = convert_units_to(0 * source, target)
a = convert_units_to(1 * source, target) - b
b = convert_units_to(0 * source, target, context)
a = convert_units_to(1 * source, target, context) - b

return round(a, 9), round(b, 9)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"statsmodels",
"wheel",
"xarray<2022.11.0", # Pinned due to incompatibility with climpred @ 2.2.0
"xclim>=0.39.0",
"xclim>=0.40.0",
"xskillscore",
]

Expand Down

0 comments on commit 5f2d897

Please sign in to comment.