Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Ouranosinc/xclim into spi_loc2
Browse files Browse the repository at this point in the history
  • Loading branch information
coxipi committed Apr 22, 2024
2 parents 7ee0aa9 + defaa18 commit adddfaf
Show file tree
Hide file tree
Showing 17 changed files with 62 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bump-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
files.pythonhosted.org:443
github.com:443
pypi.org:443
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
with:
persist-credentials: false
- uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cache-cleaner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
objects.githubusercontent.com:443
- name: Check out code
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3

- name: Cleanup
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
pypi.org:443
uploads.github.com:443
- name: Checkout repository
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@1245696032ecf7d39f87d54daa406e22ddf769a8
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
github.com:443
- name: 'Checkout Repository'
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3

- name: 'Dependency Review'
uses: actions/dependency-review-action@5bbc3ba658137598168acb2ab73b21c432dd411b
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
files.pythonhosted.org:443
github.com:443
pypi.org:443
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
- name: Set up Python${{ matrix.python-version }}
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
with:
Expand Down Expand Up @@ -91,7 +91,7 @@ jobs:
github.com:443
pypi.org:443
raw.githubusercontent.com:443
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
- name: Set up Python${{ matrix.python-version }}
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
with:
Expand Down Expand Up @@ -169,7 +169,7 @@ jobs:
ppa.launchpadcontent.net:443
pypi.org:443
raw.githubusercontent.com:443
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
- name: Install Eigen3
if: contains(matrix.tox-env, 'sbck')
run: |
Expand Down Expand Up @@ -223,7 +223,7 @@ jobs:
pypi.org:443
raw.githubusercontent.com:443
repo.anaconda.com:443
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
- name: Setup Conda (Micromamba) with Python${{ matrix.python-version }}
uses: mamba-org/setup-micromamba@422500192359a097648154e8db4e39bdb6c6eed7 # v1.8.1
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-mastodon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
github.com:443
- name: Checkout
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3

- name: Current Version
if: ${{ !github.event.inputs.version-tag }}
Expand Down Expand Up @@ -68,7 +68,7 @@ jobs:
- name: Prepare Message
id: render_template
uses: chuhlomin/render-template@a473db625a96c98e519d188812dc22bcaf54ffba # v1.9
uses: chuhlomin/render-template@807354a04d9300c9c2ac177c0aa41556c92b3f75 # v1.10
with:
template: .github/publish-mastodon.template.md
vars: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
github.com:443
pypi.org:443
upload.pypi.org:443
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
- name: Set up Python3
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
egress-policy: audit

- name: "Checkout code"
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f
with:
persist-credentials: false

Expand All @@ -59,7 +59,7 @@ jobs:
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: "Upload artifact"
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3
uses: actions/upload-artifact@1746f4ab65b179e0ea60a494b83293b640dd5bba
with:
name: SARIF file
path: results.sarif
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tag-testpypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
github.com:443
pypi.org:443
test.pypi.org:443
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
- name: Set up Python3
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/testdata-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
allowed-endpoints: >
api.github.com:443
github.com:443
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
- name: Find xclim-testdata Tag and CI Testing Branch
run: |
XCLIM_TESTDATA_TAG="$( \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/upstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
pypi.org:443
raw.githubusercontent.com:443
repo.anaconda.com:443
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
with:
fetch-depth: 0 # Fetch all history for all branches and tags.
- name: Setup Conda (Micromamba) with Python${{ matrix.python-version }}
Expand Down
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Bug fixes
* Fixed and adapted ``time_bnds`` to the newest xarray. (:pull:`1700`).
* Fixed "agreement fraction" in ``robustness_fractions`` to distinguish between negative change and no change. Added "negative" and "changed negative" fractions (:issue:`1690`, :pull:`1711`).
* ``make_criteria`` now skips columns with NaNs across all realizations. (:pull:`1713`).
* Fixed bug QuantileDeltaMapping adjustment not working for seasonal grouping (:issue:`1704`, :pull:`1716`).

Internal changes
^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ target-version = [
]

[tool.bumpversion]
current_version = "0.48.3-dev.11"
current_version = "0.48.3-dev.12"
commit = true
commit_args = "--no-verify"
tag = false
Expand Down
30 changes: 30 additions & 0 deletions tests/test_sdba/test_adjustment.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,36 @@ def test_mon_U(
# Test predict
np.testing.assert_allclose(p, ref.transpose(*p.dims), rtol=0.1, atol=0.2)

def test_seasonal(self, series, random):
u = random.random(10000)
kind = "+"
name = "tas"
# Define distributions
xd = uniform(loc=1, scale=1)
yd = uniform(loc=2, scale=4)

# Generate random numbers with u so we get exact results for comparison
x = xd.ppf(u)
y = yd.ppf(u)

# Test train
hist = sim = series(x, name)
ref = series(y, name)

QDM = QuantileDeltaMapping.train(
ref.astype("float32"),
hist.astype("float32"),
kind=kind,
group="time.season",
nquantiles=10,
)
p = QDM.adjust(sim.astype("float32"), interp="linear")

# Test predict
# Accept discrepancies near extremes
middle = (u > 1e-2) * (u < 0.99)
np.testing.assert_array_almost_equal(p[middle], ref[middle], 1)

def test_cannon_and_diagnostics(self, cannon_2015_dist, cannon_2015_rvs):
ref, hist, sim = cannon_2015_rvs(15000, random=False)

Expand Down
2 changes: 1 addition & 1 deletion xclim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

__author__ = """Travis Logan"""
__email__ = "[email protected]"
__version__ = "0.48.3-dev.11"
__version__ = "0.48.3-dev.12"


_module_data = _files("xclim.data")
Expand Down
2 changes: 2 additions & 0 deletions xclim/sdba/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ def get_index(
ind = da.indexes[self.dim]
if self.prop == "week":
i = da[self.dim].copy(data=ind.isocalendar().week).astype(int)
elif self.prop == "season":
i = da[self.dim].copy(data=ind.month % 12 // 3)
else:
i = getattr(ind, self.prop)

Expand Down
12 changes: 11 additions & 1 deletion xclim/sdba/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,11 @@ def _interp_on_quantiles_2D(newx, newg, oldx, oldy, oldg, method, extrap): # no
return out


SEASON_MAP = {"DJF": 0, "MAM": 1, "JJA": 2, "SON": 3}

map_season_to_int = np.vectorize(SEASON_MAP.get)


@parse_group
def interp_on_quantiles(
newx: xr.DataArray,
Expand Down Expand Up @@ -429,12 +434,17 @@ def interp_on_quantiles(
)
return out

# else:
if prop not in xq.dims:
xq = xq.expand_dims({prop: group.get_coordinate()})
if prop not in yq.dims:
yq = yq.expand_dims({prop: group.get_coordinate()})

# Adding the cyclic bounds fails for string coordinates like seasons
# That's why we map the seasons to integers
if prop == "season":
xq = xq.assign_coords(season=map_season_to_int(xq.season))
yq = yq.assign_coords(season=map_season_to_int(yq.season))

xq = add_cyclic_bounds(xq, prop, cyclic_coords=False)
yq = add_cyclic_bounds(yq, prop, cyclic_coords=False)
newg = group.get_index(newx, interp=method != "nearest")
Expand Down

0 comments on commit adddfaf

Please sign in to comment.