Skip to content

Commit

Permalink
dOTC small fix (#1890)
Browse files Browse the repository at this point in the history
<!--Please ensure the PR fulfills the following requirements! -->
<!-- If this is your first PR, make sure to add your details to the
AUTHORS.rst! -->
### Pull Request Checklist:
- [ ] This PR addresses an already opened issue (for bug fixes /
features)
    - This PR fixes #xyz
- [ ] Tests for the changes have been added (for bug fixes / features)
- [ ] (If applicable) Documentation has been added / updated (for bug
fixes / features)
- [x] CHANGELOG.rst has been updated (with summary of main changes)
- [x] Link to issue (:issue:`number`) and pull request (:pull:`number`)
has been added

### What kind of change does this PR introduce?

* Fix an inefficiency in OTC

### Does this PR introduce a breaking change?
No

### Other information:
Bin groups are in the same order as P.
We don't need to find the cell row.
  • Loading branch information
LamAdr authored Aug 22, 2024
2 parents ab50716 + e442c19 commit 67e14e9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
Changelog
=========

v0.53.0
--------------------
Contributors to this version: Adrien Lamarche (:user:`LamAdr`).

Bug fixes
^^^^^^^^^
* Fixed a small inefficiency in ``_otc_adjust`` (:pull:`1890`).

v0.52.0 (2024-08-08)
--------------------
Contributors to this version: David Huard (:user:`huard`), Trevor James Smith (:user:`Zeitsperre`), Hui-Min Wang (:user:`Hem-W`), Éric Dupuis (:user:`coxipi`), Sarah Gammon (:user:`SarahG-579462`), Pascal Bourgault (:user:`aulemahal`), Juliette Lavoie (:user:`juliettelavoie`), Adrien Lamarche (:user:`LamAdr`).
Expand Down
4 changes: 1 addition & 3 deletions xclim/sdba/_adjustment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,10 +1031,8 @@ def _otc_adjust(
rng = np.random.default_rng()
# The plan row corresponding to a source bin indicates its probabilities to be transported to every target bin
for i, binX_group in enumerate(binX_groups):
# Get the plan row of this bin
pi = np.where((binX[binX_group[0]] == gridX).all(1))[0][0]
# Pick as much target bins for this source bin as there are points in the source bin
choice = rng.choice(range(muY.size), p=plan[pi, :], size=binX_count[i])
choice = rng.choice(range(muY.size), p=plan[i, :], size=binX_count[i])
out[binX_group] = (gridY[choice] + 1 / 2) * bin_width + bin_origin

if jitter_inside_bins:
Expand Down

0 comments on commit 67e14e9

Please sign in to comment.