From 379decc89b99f87de22d1aee720ceaa10756f62d Mon Sep 17 00:00:00 2001 From: Marco Braun Date: Thu, 12 Oct 2023 17:25:56 -0400 Subject: [PATCH 01/11] filter indicator list for variables available in a dataset --- xscen/indicators.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/xscen/indicators.py b/xscen/indicators.py index 6f1cbc9d..048326ec 100644 --- a/xscen/indicators.py +++ b/xscen/indicators.py @@ -231,6 +231,46 @@ def _infer_freq_from_meta(ind): return out_dict +def select_inds_for_avail_vars( + ds: xr.Dataset, + indicators: Union[ + str, Path, Sequence[Indicator], Sequence[tuple[str, Indicator]], ModuleType + ], +) -> Sequence[Indicator]: + """Filter the indicators from a YAML file for which the necessary variables are available. + + Parameters + ---------- + ds : xr.Dataset + Dataset to use for the indicators. + indicators : Union[str, Path, Sequence[Indicator], Sequence[Tuple[str, Indicator]]] + Path to a YAML file that instructs on how to calculate missing variables. + Can also be only the "stem", if translations and custom indices are implemented. + Can be the indicator module directly, or a sequence of indicators or a sequence of + tuples (indicator name, indicator) as returned by `iter_indicators()`. + + Returns + ------- + Sequence[Indicator] + A sequence of tuples of (indicator name, indicator). + + See Also + -------- + xclim.indicators, xclim.core.indicator.build_indicator_module_from_yaml + """ + if isinstance(indicators, (str, Path)): + logger.debug("Loading indicator module.") + indicators = load_xclim_module(indicators, reload=True) + + if hasattr(indicators, "iter_indicators"): + indicators = [(name, ind) for name, ind in indicators.iter_indicators()] + + available_vars = {var for var in ds.data_vars if var in xc.core.utils.VARIABLES.keys()} + available_ind = [(name, ind) for var in available_vars + for name, ind in indicators if var in ind.parameters.keys()] + return available_ind + + def registry_from_module( module, registry=None, variable_column="variable" ) -> DerivedVariableRegistry: From ffdcb087cc8cce30c5a0f89b454bb3ba114b314b Mon Sep 17 00:00:00 2001 From: Marco Braun Date: Sun, 15 Oct 2023 21:40:33 -0400 Subject: [PATCH 02/11] test for select_inds_for_avail_vars, first draft --- tests/test_indicators.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/test_indicators.py b/tests/test_indicators.py index 6cdd48b9..3661be20 100644 --- a/tests/test_indicators.py +++ b/tests/test_indicators.py @@ -150,3 +150,35 @@ def test_as_jul(self, restrict_years): assert len(out.time) == 4 assert out.time[0].dt.strftime("%Y-%m-%d").item() == "2000-07-01" assert out.time[-1].dt.strftime("%Y-%m-%d").item() == "2003-07-01" + + def test_select_inds_for_avail_vars(self): + # Test that select_inds_for_avail_vars filters a list of indicators to only those that can be computed with the + # variables available in the input dataset. + ds = xs.testing.datablock_3d( + np.ones((365, 3, 3)), + variable="tas", + x="lon", + x_start=-75, + y="lat", + y_start=45, + x_step=1, + y_step=1, + start="2001-01-01", + freq="D", + units="K", + as_dataset=True, + ) + indicators = [ + xclim.core.indicator.Indicator.from_dict( + data={"base": "tg_min", "parameters": {"freq": "QS-DEC"}}, + identifier="tg_min_qs", + module="tests"), + xclim.core.indicator.Indicator.from_dict( + data={"base": "precip_average", "parameters": {"freq": "MS"}}, + identifier="precip_average_ms", + module="tests") + ] + inds = xs.indicators.select_inds_for_avail_vars(ds=ds, indicators=indicators) + assert len(inds) == 1 # the precip-based indicator must be skipped + assert inds[0][0] == "tg_min_qs" + assert inds[0][1] == indicators[0] From f21aa053218b145ef3b10ca8feca17dff3527357 Mon Sep 17 00:00:00 2001 From: Marco Braun Date: Thu, 9 Nov 2023 16:57:19 -0500 Subject: [PATCH 03/11] debug test_indicators --- tests/test_indicators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_indicators.py b/tests/test_indicators.py index 3661be20..8354c61e 100644 --- a/tests/test_indicators.py +++ b/tests/test_indicators.py @@ -174,7 +174,7 @@ def test_select_inds_for_avail_vars(self): identifier="tg_min_qs", module="tests"), xclim.core.indicator.Indicator.from_dict( - data={"base": "precip_average", "parameters": {"freq": "MS"}}, + data={"base": "days_over_precip_thresh", "parameters": {"freq": "MS"}}, identifier="precip_average_ms", module="tests") ] From 75babcf19d2055795043b274b411c82b5b3021a1 Mon Sep 17 00:00:00 2001 From: Marco Braun Date: Wed, 22 Nov 2023 12:02:58 -0500 Subject: [PATCH 04/11] Update select_ind_for_avail_vars and test. --- tests/test_indicators.py | 34 +++++++++++++++++++++++++++++ xscen/indicators.py | 46 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/tests/test_indicators.py b/tests/test_indicators.py index 6cdd48b9..904e8132 100644 --- a/tests/test_indicators.py +++ b/tests/test_indicators.py @@ -150,3 +150,37 @@ def test_as_jul(self, restrict_years): assert len(out.time) == 4 assert out.time[0].dt.strftime("%Y-%m-%d").item() == "2000-07-01" assert out.time[-1].dt.strftime("%Y-%m-%d").item() == "2003-07-01" + + def test_select_inds_for_avail_vars(self): + # Test that select_inds_for_avail_vars filters a list of indicators to only those that can be computed with the + # variables available in the input dataset. + ds = xs.testing.datablock_3d( + np.ones((365, 3, 3)), + variable="tas", + x="lon", + x_start=-75, + y="lat", + y_start=45, + x_step=1, + y_step=1, + start="2001-01-01", + freq="D", + units="K", + as_dataset=True, + ) + indicators = [ + xclim.core.indicator.Indicator.from_dict( + data={"base": "tg_min", "parameters": {"freq": "QS-DEC"}}, + identifier="tg_min_qs", + module="tests", + ), + xclim.core.indicator.Indicator.from_dict( + data={"base": "days_over_precip_thresh", "parameters": {"freq": "MS"}}, + identifier="precip_average_ms", + module="tests", + ), + ] + inds = xs.indicators.select_inds_for_avail_vars(ds=ds, indicators=indicators) + assert len(inds) == 1 # the precip-based indicator must be skipped + assert inds[0][0] == "tg_min_qs" + assert inds[0][1] == indicators[0] diff --git a/xscen/indicators.py b/xscen/indicators.py index bab6d28d..583b5b10 100644 --- a/xscen/indicators.py +++ b/xscen/indicators.py @@ -291,3 +291,49 @@ def func(ds, *, ind, nout): func.__name__ = ind.identifier return partial(func, ind=ind, nout=nout) + + +def select_inds_for_avail_vars( + ds: xr.Dataset, + indicators: Union[ + str, Path, Sequence[Indicator], Sequence[tuple[str, Indicator]], ModuleType + ], +) -> Sequence[Indicator]: + """Filter the indicators from a YAML file for which the necessary variables are available. + + Parameters + ---------- + ds : xr.Dataset + Dataset to use for the indicators. + indicators : Union[str, Path, Sequence[Indicator], Sequence[Tuple[str, Indicator]]] + Path to a YAML file that instructs on how to calculate missing variables. + Can also be only the "stem", if translations and custom indices are implemented. + Can be the indicator module directly, or a sequence of indicators or a sequence of + tuples (indicator name, indicator) as returned by `iter_indicators()`. + + Returns + ------- + Sequence[Indicator] + A sequence of tuples of (indicator name, indicator). + + See Also + -------- + xclim.indicators, xclim.core.indicator.build_indicator_module_from_yaml + """ + if isinstance(indicators, (str, Path)): + logger.debug("Loading indicator module.") + indicators = load_xclim_module(indicators, reload=True) + + if hasattr(indicators, "iter_indicators"): + indicators = [(name, ind) for name, ind in indicators.iter_indicators()] + + available_vars = { + var for var in ds.data_vars if var in xc.core.utils.VARIABLES.keys() + } + available_ind = [ + (name, ind) + for var in available_vars + for name, ind in indicators + if var in ind.parameters.keys() + ] + return available_ind From d5fa3545b915dd40f409a7fc6d1ea8e3fcde9835 Mon Sep 17 00:00:00 2001 From: Marco Braun Date: Thu, 23 Nov 2023 14:13:00 -0500 Subject: [PATCH 05/11] Test select_inds_for_avail_vars; draft --- tests/test_indicators.py | 56 +++++++++++++++++++++++++++++++++++----- xscen/indicators.py | 19 +++++++++----- 2 files changed, 62 insertions(+), 13 deletions(-) diff --git a/tests/test_indicators.py b/tests/test_indicators.py index 904e8132..6b64e282 100644 --- a/tests/test_indicators.py +++ b/tests/test_indicators.py @@ -152,8 +152,8 @@ def test_as_jul(self, restrict_years): assert out.time[-1].dt.strftime("%Y-%m-%d").item() == "2003-07-01" def test_select_inds_for_avail_vars(self): - # Test that select_inds_for_avail_vars filters a list of indicators to only those that can be computed with the - # variables available in the input dataset. + # Test that select_inds_for_avail_vars filters a list of indicators to only those + # that can be computed with the variables available in a dataset. ds = xs.testing.datablock_3d( np.ones((365, 3, 3)), variable="tas", @@ -180,7 +180,51 @@ def test_select_inds_for_avail_vars(self): module="tests", ), ] - inds = xs.indicators.select_inds_for_avail_vars(ds=ds, indicators=indicators) - assert len(inds) == 1 # the precip-based indicator must be skipped - assert inds[0][0] == "tg_min_qs" - assert inds[0][1] == indicators[0] + # indicators as different types + inds_for_avail_vars_from_list = xs.indicators.select_inds_for_avail_vars( + ds=ds, indicators=indicators + ) + module = xclim.core.indicator.build_indicator_module( + "indicators", {i.base: i for i in indicators}, reload=True + ) + inds_for_avail_vars_from_module = xs.indicators.select_inds_for_avail_vars( + ds=ds, indicators=module + ) + inds_for_avail_vars_from_list_of_tuples = ( + xs.indicators.select_inds_for_avail_vars( + ds=ds, indicators=[(n, i) for n, i in module.iter_indicators()] + ) + ) + + for inds_for_avail_vars in [ + inds_for_avail_vars_from_list, + inds_for_avail_vars_from_module, + inds_for_avail_vars_from_list_of_tuples, + ]: + assert len(list(inds_for_avail_vars.iter_indicators())) == 1 + assert [n for n, _ in inds_for_avail_vars.iter_indicators()] == ["tg_min"] + assert [i for _, i in inds_for_avail_vars.iter_indicators()] == [ + indicators[0] + ] + + # assert len(list(inds_for_avail_vars.iter_indicators())) == 1 + # assert [n for n, _ in inds_for_avail_vars.iter_indicators()] == ["tg_min"] + # assert [i for _, i in inds_for_avail_vars.iter_indicators()] == [indicators[0]] + + # inds_for_avail_vars = xs.indicators.select_inds_for_avail_vars(ds=ds, indicators=self.yaml_file) + # assert len(list(inds_for_avail_vars.iter_indicators())) == 2 + # assert (sorted([n for n, _ in inds_for_avail_vars.iter_indicators()]) == + # sorted(['tg_min', 'growing_degree_days'])) + + # indicators as module + + # assert len(list(inds_for_avail_vars.iter_indicators())) == 1 + # assert [n for n, _ in inds_for_avail_vars.iter_indicators()] == ["tg_min"] + # assert [i for _, i in inds_for_avail_vars.iter_indicators()] == [indicators[0]] + # + # # indicators as list of tuples + # inds_for_avail_vars = xs.indicators.select_inds_for_avail_vars( + # ds=ds, indicators=[(n, i) for n, i in module.iter_indicators()]) + # assert len(list(inds_for_avail_vars.iter_indicators())) == 1 + # assert [n for n, _ in inds_for_avail_vars.iter_indicators()] == ["tg_min"] + # assert [i for _, i in inds_for_avail_vars.iter_indicators()] == [indicators[0]] diff --git a/xscen/indicators.py b/xscen/indicators.py index 583b5b10..60bc0f04 100644 --- a/xscen/indicators.py +++ b/xscen/indicators.py @@ -20,7 +20,6 @@ logger = logging.getLogger(__name__) - __all__ = ["compute_indicators", "load_xclim_module"] @@ -299,7 +298,7 @@ def select_inds_for_avail_vars( str, Path, Sequence[Indicator], Sequence[tuple[str, Indicator]], ModuleType ], ) -> Sequence[Indicator]: - """Filter the indicators from a YAML file for which the necessary variables are available. + """Filter the indicators for which the necessary variables are available. Parameters ---------- @@ -313,27 +312,33 @@ def select_inds_for_avail_vars( Returns ------- - Sequence[Indicator] - A sequence of tuples of (indicator name, indicator). + ModuleType – An indicator module. See Also -------- xclim.indicators, xclim.core.indicator.build_indicator_module_from_yaml """ + # transform indicator input into a list of tuples (name, indicator) + is_list_of_tuples = isinstance(indicators, list) and all( + isinstance(i, tuple) for i in indicators + ) if isinstance(indicators, (str, Path)): logger.debug("Loading indicator module.") indicators = load_xclim_module(indicators, reload=True) - if hasattr(indicators, "iter_indicators"): indicators = [(name, ind) for name, ind in indicators.iter_indicators()] + elif isinstance(indicators, (list, tuple)) and not is_list_of_tuples: + indicators = [(ind.base, ind) for ind in indicators] available_vars = { var for var in ds.data_vars if var in xc.core.utils.VARIABLES.keys() } - available_ind = [ + available_inds = [ (name, ind) for var in available_vars for name, ind in indicators if var in ind.parameters.keys() ] - return available_ind + return xc.core.indicator.build_indicator_module( + "inds_for_avail_vars", available_inds + ) From 0d4ca1f8ec4e193f154b4109e640610e7c9bd8bc Mon Sep 17 00:00:00 2001 From: Marco Braun Date: Thu, 23 Nov 2023 14:15:53 -0500 Subject: [PATCH 06/11] Test select_inds_for_avail_vars passes. --- tests/test_indicators.py | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/tests/test_indicators.py b/tests/test_indicators.py index 6b64e282..8678bd92 100644 --- a/tests/test_indicators.py +++ b/tests/test_indicators.py @@ -206,25 +206,3 @@ def test_select_inds_for_avail_vars(self): assert [i for _, i in inds_for_avail_vars.iter_indicators()] == [ indicators[0] ] - - # assert len(list(inds_for_avail_vars.iter_indicators())) == 1 - # assert [n for n, _ in inds_for_avail_vars.iter_indicators()] == ["tg_min"] - # assert [i for _, i in inds_for_avail_vars.iter_indicators()] == [indicators[0]] - - # inds_for_avail_vars = xs.indicators.select_inds_for_avail_vars(ds=ds, indicators=self.yaml_file) - # assert len(list(inds_for_avail_vars.iter_indicators())) == 2 - # assert (sorted([n for n, _ in inds_for_avail_vars.iter_indicators()]) == - # sorted(['tg_min', 'growing_degree_days'])) - - # indicators as module - - # assert len(list(inds_for_avail_vars.iter_indicators())) == 1 - # assert [n for n, _ in inds_for_avail_vars.iter_indicators()] == ["tg_min"] - # assert [i for _, i in inds_for_avail_vars.iter_indicators()] == [indicators[0]] - # - # # indicators as list of tuples - # inds_for_avail_vars = xs.indicators.select_inds_for_avail_vars( - # ds=ds, indicators=[(n, i) for n, i in module.iter_indicators()]) - # assert len(list(inds_for_avail_vars.iter_indicators())) == 1 - # assert [n for n, _ in inds_for_avail_vars.iter_indicators()] == ["tg_min"] - # assert [i for _, i in inds_for_avail_vars.iter_indicators()] == [indicators[0]] From ffabb745f492fbc0f295c624da48b771304496bc Mon Sep 17 00:00:00 2001 From: Marco Braun Date: Thu, 23 Nov 2023 17:30:19 -0500 Subject: [PATCH 07/11] Updated HISTORY.rst --- HISTORY.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/HISTORY.rst b/HISTORY.rst index 55477e79..7c365439 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -12,6 +12,7 @@ Announcements New features and enhancements ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +* New function ``xscen.indicators.select_inds_for_avail_vars`` to filter the indicators that can be calculated with the variables available in a ``xarray.Dataset``. (:pull:`xyz`). * Replaced aggregation function ``climatological_mean()`` with ``climatological_op()`` offering more types of operations to aggregate over climate periods. (:pull:`290`) * Added the ability to search for simulations that reach a given warming level. (:pull:`251`). * ``xs.spatial_mean`` now accepts the ``region="global"`` keyword to perform a global average (:issue:`94`, :pull:`260`). From e8ef834a925924874c777919f9c41b04a680bde4 Mon Sep 17 00:00:00 2001 From: Marco Braun <43412203+vindelico@users.noreply.github.com> Date: Fri, 1 Dec 2023 13:07:12 -0500 Subject: [PATCH 08/11] Update HISTORY.rst --- HISTORY.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HISTORY.rst b/HISTORY.rst index 7c365439..245acc14 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -12,7 +12,7 @@ Announcements New features and enhancements ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -* New function ``xscen.indicators.select_inds_for_avail_vars`` to filter the indicators that can be calculated with the variables available in a ``xarray.Dataset``. (:pull:`xyz`). +* New function ``xscen.indicators.select_inds_for_avail_vars`` to filter the indicators that can be calculated with the variables available in a ``xarray.Dataset``. (:pull:`291`). * Replaced aggregation function ``climatological_mean()`` with ``climatological_op()`` offering more types of operations to aggregate over climate periods. (:pull:`290`) * Added the ability to search for simulations that reach a given warming level. (:pull:`251`). * ``xs.spatial_mean`` now accepts the ``region="global"`` keyword to perform a global average (:issue:`94`, :pull:`260`). From 9b629e620b425a137a3b801abcdd23d323091fac Mon Sep 17 00:00:00 2001 From: Marco Braun <43412203+vindelico@users.noreply.github.com> Date: Fri, 1 Dec 2023 13:08:59 -0500 Subject: [PATCH 09/11] Apply suggestions from code review Co-authored-by: RondeauG <38501935+RondeauG@users.noreply.github.com> --- xscen/indicators.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/xscen/indicators.py b/xscen/indicators.py index 60bc0f04..9f61b32f 100644 --- a/xscen/indicators.py +++ b/xscen/indicators.py @@ -295,16 +295,16 @@ def func(ds, *, ind, nout): def select_inds_for_avail_vars( ds: xr.Dataset, indicators: Union[ - str, Path, Sequence[Indicator], Sequence[tuple[str, Indicator]], ModuleType + str, os.PathLike, Sequence[Indicator], Sequence[tuple[str, Indicator]], ModuleType ], -) -> Sequence[Indicator]: +) -> ModuleType: """Filter the indicators for which the necessary variables are available. Parameters ---------- ds : xr.Dataset Dataset to use for the indicators. - indicators : Union[str, Path, Sequence[Indicator], Sequence[Tuple[str, Indicator]]] + indicators : Union[str, os.PathLike, Sequence[Indicator], Sequence[Tuple[str, Indicator]]] Path to a YAML file that instructs on how to calculate missing variables. Can also be only the "stem", if translations and custom indices are implemented. Can be the indicator module directly, or a sequence of indicators or a sequence of @@ -318,11 +318,11 @@ def select_inds_for_avail_vars( -------- xclim.indicators, xclim.core.indicator.build_indicator_module_from_yaml """ - # transform indicator input into a list of tuples (name, indicator) + # Transform the 'indicators' input into a list of tuples (name, indicator) is_list_of_tuples = isinstance(indicators, list) and all( isinstance(i, tuple) for i in indicators ) - if isinstance(indicators, (str, Path)): + if isinstance(indicators, (str, os.PathLike)): logger.debug("Loading indicator module.") indicators = load_xclim_module(indicators, reload=True) if hasattr(indicators, "iter_indicators"): From d74adcc7cb7aef1fb522b626c473075dcdc63f44 Mon Sep 17 00:00:00 2001 From: Marco Braun Date: Fri, 1 Dec 2023 16:41:32 -0500 Subject: [PATCH 10/11] Review comments integrated, test for empty module returned added. --- tests/test_indicators.py | 42 +++++++++++++++++++++------------------- xscen/indicators.py | 10 +++++++--- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/tests/test_indicators.py b/tests/test_indicators.py index 8678bd92..ad4c2503 100644 --- a/tests/test_indicators.py +++ b/tests/test_indicators.py @@ -151,7 +151,8 @@ def test_as_jul(self, restrict_years): assert out.time[0].dt.strftime("%Y-%m-%d").item() == "2000-07-01" assert out.time[-1].dt.strftime("%Y-%m-%d").item() == "2003-07-01" - def test_select_inds_for_avail_vars(self): + @pytest.mark.parametrize("indicator_iter", ["list", "tuples", "module"]) + def test_select_inds_for_avail_vars(self, indicator_iter): # Test that select_inds_for_avail_vars filters a list of indicators to only those # that can be computed with the variables available in a dataset. ds = xs.testing.datablock_3d( @@ -180,29 +181,30 @@ def test_select_inds_for_avail_vars(self): module="tests", ), ] + # indicators as different types - inds_for_avail_vars_from_list = xs.indicators.select_inds_for_avail_vars( - ds=ds, indicators=indicators - ) module = xclim.core.indicator.build_indicator_module( "indicators", {i.base: i for i in indicators}, reload=True ) - inds_for_avail_vars_from_module = xs.indicators.select_inds_for_avail_vars( - ds=ds, indicators=module - ) - inds_for_avail_vars_from_list_of_tuples = ( - xs.indicators.select_inds_for_avail_vars( + if indicator_iter == "list": + inds_for_avail_vars = xs.indicators.select_inds_for_avail_vars( + ds=ds, indicators=indicators + ) + elif indicator_iter == "tuples": + inds_for_avail_vars = xs.indicators.select_inds_for_avail_vars( ds=ds, indicators=[(n, i) for n, i in module.iter_indicators()] ) - ) + elif indicator_iter == "module": + inds_for_avail_vars = xs.indicators.select_inds_for_avail_vars( + ds=ds, indicators=module + ) - for inds_for_avail_vars in [ - inds_for_avail_vars_from_list, - inds_for_avail_vars_from_module, - inds_for_avail_vars_from_list_of_tuples, - ]: - assert len(list(inds_for_avail_vars.iter_indicators())) == 1 - assert [n for n, _ in inds_for_avail_vars.iter_indicators()] == ["tg_min"] - assert [i for _, i in inds_for_avail_vars.iter_indicators()] == [ - indicators[0] - ] + assert len(list(inds_for_avail_vars.iter_indicators())) == 1 + assert [n for n, _ in inds_for_avail_vars.iter_indicators()] == ["tg_min"] + assert [i for _, i in inds_for_avail_vars.iter_indicators()] == [indicators[0]] + # no indicators found + inds_for_avail_vars = xs.indicators.select_inds_for_avail_vars( + ds=ds, indicators=indicators[1:] + ) + assert len(list(inds_for_avail_vars.iter_indicators())) == 0 + assert [(n, i) for n, i in inds_for_avail_vars.iter_indicators()] == [] diff --git a/xscen/indicators.py b/xscen/indicators.py index 37ffe9a8..3ea0737d 100644 --- a/xscen/indicators.py +++ b/xscen/indicators.py @@ -297,7 +297,11 @@ def func(ds, *, ind, nout): def select_inds_for_avail_vars( ds: xr.Dataset, indicators: Union[ - str, os.PathLike, Sequence[Indicator], Sequence[tuple[str, Indicator]], ModuleType + str, + os.PathLike, + Sequence[Indicator], + Sequence[tuple[str, Indicator]], + ModuleType, ], ) -> ModuleType: """Filter the indicators for which the necessary variables are available. @@ -314,7 +318,7 @@ def select_inds_for_avail_vars( Returns ------- - ModuleType – An indicator module. + ModuleType – An indicator module of 'length' ∈ [0, n]. See Also -------- @@ -342,5 +346,5 @@ def select_inds_for_avail_vars( if var in ind.parameters.keys() ] return xc.core.indicator.build_indicator_module( - "inds_for_avail_vars", available_inds + "inds_for_avail_vars", available_inds, reload=True ) From 256a3338dfc5577ef953b6d13d3cc92a577c10a0 Mon Sep 17 00:00:00 2001 From: Marco Braun <43412203+vindelico@users.noreply.github.com> Date: Tue, 5 Dec 2023 15:13:29 -0500 Subject: [PATCH 11/11] Correct docstring select_inds_for_avail_vars --- xscen/indicators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xscen/indicators.py b/xscen/indicators.py index 3ea0737d..f198c3fa 100644 --- a/xscen/indicators.py +++ b/xscen/indicators.py @@ -311,7 +311,7 @@ def select_inds_for_avail_vars( ds : xr.Dataset Dataset to use for the indicators. indicators : Union[str, os.PathLike, Sequence[Indicator], Sequence[Tuple[str, Indicator]]] - Path to a YAML file that instructs on how to calculate missing variables. + Path to a YAML file that instructs on how to calculate indicators. Can also be only the "stem", if translations and custom indices are implemented. Can be the indicator module directly, or a sequence of indicators or a sequence of tuples (indicator name, indicator) as returned by `iter_indicators()`.