Skip to content

Commit

Permalink
Merge branch 'master' into fix-1536
Browse files Browse the repository at this point in the history
  • Loading branch information
aulemahal authored Nov 30, 2023
2 parents d90c599 + 6efc676 commit ce2c565
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 24 deletions.
8 changes: 8 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,11 @@ python:
path: .
extra_requirements:
- dev

search:
ranking:

notebooks/*: 2
api_indicators.html: 1
indices.html: -1
_modules/*: -3
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ New features and enhancements
Bug fixes
^^^^^^^^^
* Fixed a bug with ``n_escore=-1`` in ``xclim.sdba.adjustment.NpdfTransform`` (:issue:`1515`, :pull:`1515`).
* In the documentaion, fix the tooltips in the indicator search results (:issue:`1524`, :pull:`1527`).
* If chunked inputs are passed to indicators ``mean_radiant_temperature`` and ``potential_evapotranspiration``, subcalculations of the solar angle will also use the same chunks, instead of a single one of the same size as the data (:issue:`1536`, :pull:`1542`).

Internal changes
^^^^^^^^^^^^^^^^
* Pinned `cf-xarray` below v0.8.5 in Python3.8 installation to further extend legacy support. (:pull:`1519`).
* `pip check` in conda builds in GitHub workflows have been temporarily set to always pass. (:pull:`1531`).
* Configure RtD search rankings to emphasize notebooks and indicators over indices and raw source code. (:pull:`1526`).

v0.46.0 (2023-10-24)
--------------------
Expand Down
30 changes: 18 additions & 12 deletions docs/_static/indsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,18 @@ fetch('indicators.json')
});


// Populate list of variables
//function getVariables() {
// fetch('variables.json')
// .then((res) => {
// return res.json();
// })
//}
//const variables = getVariables();

function escapeHTML(str){
/* Escape HTML characters in a string. */
var map =
{
'&': '&',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#039;'
};
return str.replace(/[&<>"']/g, function(m) {return map[m];});
}

function makeKeywordLabel(ind) {
/* Print list of keywords only if there is at least one. */
Expand All @@ -55,7 +58,10 @@ function makeKeywordLabel(ind) {
function makeVariableList(ind) {
/* Print list of variables and include mouse-hover tooltip with variable description. */
return Object.entries(ind.vars).map((kv) => {
const tooltip = `<button class="indVarname" title="${kv[1]}" alt="${kv[1]}">${kv[0]}</button>`;
/* kv[0] is the variable name, kv[1] is the variable description. */
/* Convert kv[1] to a string literal */
const text = escapeHTML(kv[1]);
const tooltip = `<button class="indVarname" title="${text}" alt="${text}">${kv[0]}</button>`;
return tooltip
}).join('');
}
Expand All @@ -66,13 +72,13 @@ function indTemplate(ind) {
return `
<div class="indElem" id="${ind.id}">
<div class="indHeader">
<b class="indTitle">${ind.title}</b>
<b class="indTitle">${escapeHTML(ind.title)}</b>
<a class="reference_internal indName" href="api_indicators.html#xclim.indicators.${ind.module}.${ind.name}" title="${ind.name}">
<code>${ind.module}.${ind.name}</code>
</a>
</div>
<div class="indVars">Uses: ${varlist}</div>
<div class="indDesc"><p>${ind.abstract}</p></div>
<div class="indDesc"><p>${escapeHTML(ind.abstract)}</p></div>
${makeKeywordLabel(ind)}
<div class="indID">Yaml ID: <code>${ind.id}</code></div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.46.5-beta
current_version = 0.46.7-beta
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+).(?P<patch>\d+)(\-(?P<release>[a-z]+))?
Expand Down
6 changes: 4 additions & 2 deletions tests/test_ensembles.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,9 @@ def test_robustness_fractions_empty():


def test_robustness_categories():
changed = xr.DataArray([0.5, 0.8, 1, 1])
agree = xr.DataArray([1, 0.5, 0.5, 1])
lat = xr.DataArray([1, 2, 3, 4], dims=("lat",), attrs={"axis": "Y"}, name="lat")
changed = xr.DataArray([0.5, 0.8, 1, 1], dims=("lat",), coords={"lat": lat})
agree = xr.DataArray([1, 0.5, 0.5, 1], dims=("lat",), coords={"lat": lat})

categories = ensembles.robustness_categories(changed, agree)
np.testing.assert_array_equal(categories, [2, 3, 3, 1])
Expand All @@ -753,6 +754,7 @@ def test_robustness_categories():
categories.flag_meanings
== "robust_signal no_change_or_no_signal conflicting_signal"
)
assert categories.lat.attrs["axis"] == "Y"


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

__author__ = """Travis Logan"""
__email__ = "[email protected]"
__version__ = "0.46.5-beta"
__version__ = "0.46.7-beta"


_module_data = _files("xclim.data")
Expand Down
21 changes: 13 additions & 8 deletions xclim/ensembles/_robustness.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ def robustness_fractions( # noqa: C901
)
out = out.assign(pvals=pvals)

# Keep attrs on non-modified coordinates
for ncrd, crd in fut.coords.items():
if ncrd in out.coords:
out[ncrd].attrs.update(crd.attrs)

return out


Expand Down Expand Up @@ -370,16 +375,16 @@ def robustness_categories(
Categorical (int) array following the flag variables CF conventions.
99 is used as a fill value for points that do not fall in any category.
"""
if isinstance(changed_or_fractions, xr.Dataset):
src = changed_or_fractions.copy() # Ensure no inplace changing of coords...
if isinstance(src, xr.Dataset):
# Output of robustness fractions
changed = changed_or_fractions.changed
agree = changed_or_fractions.agree
changed = src.changed
agree = src.agree
else:
changed = changed_or_fractions
changed = src

# Initial map is all 99, same shape as change_frac
robustness = changed * 0 + 99

robustness = (changed.copy() * 0).astype(int) + 99
# We go in reverse gear so that the first categories have precedence in the case of multiple matches.
for i, ((chg_op, agr_op), (chg_thresh, agr_thresh)) in reversed(
list(enumerate(zip(ops, thresholds), 1))
Expand All @@ -392,9 +397,9 @@ def robustness_categories(
cond = compare(changed, chg_op, chg_thresh) & compare(
agree, agr_op, agr_thresh
)
robustness = xr.where(cond, i, robustness)
robustness = xr.where(~cond, robustness, i, keep_attrs=True)

robustness = robustness.astype(np.uint8).assign_attrs(
robustness = robustness.assign_attrs(
flag_values=list(range(1, len(categories) + 1)),
_FillValue=99,
flag_descriptions=categories,
Expand Down

0 comments on commit ce2c565

Please sign in to comment.