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

cast high to float in jitter #1864

Merged
merged 8 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Changelog

v0.52.0 (unreleased)
--------------------
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`).
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`).

New features and enhancements
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -26,6 +26,7 @@ Bug fixes
* Fixed the indexer bug in the ``xclim.indices.standardized_index_fit_params`` when multiple or non-array indexers are specified and fitted parameters are reloaded from netCDF. (:issue:`1842`, :pull:`1843`).
* Addressed a bug found in ``wet_spell_*`` indicators that was contributing to erroneous results. A new generic spell length statistic function ``xclim.indices.generic.spell_length_statistics`` is now used in wet and dry spells indicators. (:issue:`1834`, :pull:`1838`).
* Syntax for ``nan`` and ``inf`` was adapted to support ``numpy>=2.0.0``. (:pull:`1814`, :issue:`1785`).
* Force type in `jitter` to work with new version of dask. (:pull:`1864`)

Internal changes
^^^^^^^^^^^^^^^^
Expand Down
20 changes: 13 additions & 7 deletions xclim/sdba/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,17 @@ def jitter(
out: xr.DataArray = x
notnull = x.notnull()
if lower is not None:
jitter_lower = np.array(convert_units_to(lower, x)).astype(float)
jitter_min = np.array(
jitter_lower = float(convert_units_to(lower, x))
jitter_min = float(
convert_units_to(minimum, x) if minimum is not None else 0
).astype(float)
)
jitter_min = jitter_min + np.finfo(x.dtype).eps
if uses_dask(x):
jitter_dist = dsk.random.uniform(
low=jitter_min, high=jitter_lower, size=x.shape, chunks=x.chunks
low=jitter_min,
high=jitter_lower,
size=x.shape,
chunks=x.chunks,
)
else:
jitter_dist = np.random.uniform(
Expand All @@ -237,11 +240,14 @@ def jitter(
if upper is not None:
if maximum is None:
raise ValueError("If 'upper' is given, so must 'maximum'.")
jitter_upper = np.array(convert_units_to(upper, x)).astype(float)
jitter_max = np.array(convert_units_to(maximum, x)).astype(float)
jitter_upper = float(convert_units_to(upper, x))
jitter_max = float(convert_units_to(maximum, x))
if uses_dask(x):
jitter_dist = dsk.random.uniform(
low=jitter_upper, high=jitter_max, size=x.shape, chunks=x.chunks
low=jitter_upper,
high=jitter_max,
size=x.shape,
chunks=x.chunks,
)
else:
jitter_dist = np.random.uniform(
Expand Down
Loading