From 08de5984ea3c5ace456c74c0d55d2837173fdc0c Mon Sep 17 00:00:00 2001 From: Loickemajou <88109303+Loickemajou@users.noreply.github.com> Date: Thu, 8 Aug 2024 11:19:12 +0200 Subject: [PATCH 01/22] adding the dgmr model to be directly imported by pysteps.nowcasts --- pysteps/nowcasts/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pysteps/nowcasts/__init__.py b/pysteps/nowcasts/__init__.py index 71d5e73c8..235315778 100644 --- a/pysteps/nowcasts/__init__.py +++ b/pysteps/nowcasts/__init__.py @@ -1,3 +1,8 @@ """Implementations of deterministic and ensemble nowcasting methods.""" from pysteps.nowcasts.interface import get_method + +try: + from dgmr_module_plugin import dgmr +except ImportError: + dgmr=None From f26bef52c49f84029873ab6e1b9fc9735e444aa6 Mon Sep 17 00:00:00 2001 From: Loickemajou <88109303+Loickemajou@users.noreply.github.com> Date: Thu, 8 Aug 2024 11:22:46 +0200 Subject: [PATCH 02/22] added the discover nowcasts and the nowcasts_info methods --- pysteps/nowcasts/interface.py | 105 +++++++++++++++++++++++++++++++++- 1 file changed, 104 insertions(+), 1 deletion(-) diff --git a/pysteps/nowcasts/interface.py b/pysteps/nowcasts/interface.py index 19b01a523..97717160a 100644 --- a/pysteps/nowcasts/interface.py +++ b/pysteps/nowcasts/interface.py @@ -29,7 +29,9 @@ get_method """ - +from pprint import pprint +from pysteps import nowcasts +import importlib from pysteps.extrapolation.interface import eulerian_persistence from pysteps.nowcasts import ( anvil, @@ -39,7 +41,11 @@ steps, sseps, ) + from pysteps.nowcasts import lagrangian_probability +import os + + _nowcast_methods = dict() _nowcast_methods["anvil"] = anvil.forecast @@ -54,7 +60,98 @@ _nowcast_methods["steps"] = steps.forecast + +def discover_nowcasts(): + """ + Search for installed nowcasts plugins in the entrypoint 'pysteps.plugin.nowcasts' + + The nowcasts method found are added to the `pysteps.nowcasts.interface_nowcasts_methods` + dictionary containing the available nowcasts_methods. + """ + + # The pkg resources needs to be reload to detect new packages installed during + # the execution of the python application. For example, when the plugins are + # installed during the tests + import pkg_resources + + importlib.reload(pkg_resources) + + for entry_point in pkg_resources.iter_entry_points( + group="pysteps.plugin.nowcasts", name=None + ): + _nowcast_module_name=entry_point.name + + if _nowcast_module_name not in _nowcast_methods: + + module = importlib.import_module(entry_point.module_name) + + _nowcast_methods[_nowcast_module_name] =module.forecast + + else: + RuntimeWarning( + f"The Nowcasts methode '{_nowcast_module_name}' is already available in" + "'pysteps.nowcasts._nowcasts_methods'.\n" + f"Skipping {entry_point.module_name}:{'.'.join(entry_point.attrs)}" + ) + + + def nowcasts_info(): + + + """Print all the available importers.""" + + # nowcasts methods available in the `nowcasts` package + available_nowcasts = [ + attr.split('.')[0] for attr in os.listdir(' '.join(nowcasts.__path__)) if not attr.startswith("__") + and attr!='interface.py' + ] + + print("\nMethods available in the pysteps.nowcasts") + pprint(available_nowcasts) + # nowcasts declared in the pysteps.nowcast interface + + nowcasts_in_the_interface = [ + f for f in _nowcast_methods.keys() + ] + + print("\nMethods available in the pysteps.nowcasts.get_method interface") + pprint( + [ + (short_name, f.__name__) + for short_name, f in _nowcast_methods.items() + ] + ) + + # Let's use sets to find out if there are importers present in the importer module + # but not declared in the interface, and viceversa. + available_nowcasts = set(available_nowcasts) + nowcasts_in_the_interface = set(nowcasts_in_the_interface ) + + difference = available_nowcasts ^ nowcasts_in_the_interface + if len(difference) > 0: + print("\nIMPORTANT:") + _diff = available_nowcasts - nowcasts_in_the_interface + if len(_diff) > 0: + print( + "\nIMPORTANT:\nThe following importers are available in pysteps.nowcasts module " + "but not in the pysteps.nowcasts.get_method interface" + ) + pprint(_diff) + _diff = nowcasts_in_the_interface - available_nowcasts + if len(_diff) > 0: + print( + "\nWARNING:\n" + "The following importers are available in the pysteps.nowcasts.get_method " + "interface but not in the pysteps.nowcasts module" + ) + pprint(_diff) + + return available_nowcasts, nowcasts_in_the_interface + + + def get_method(name): + """ Return a callable function for computing nowcasts. @@ -89,7 +186,13 @@ def get_method(name): +-----------------+-------------------------------------------------------+ | sseps | short-space ensemble prediction system (SSEPS). | | | Essentially, this is a localization of STEPS | + +-----------------+-------------------------------------------------------+ + | dgmr | a deep generative model for the probabilistic . | + | | nowcasting of precipitation from radar developed by | + | | researchers from DeepMind | +-----------------+-------------------------------------------------------+ + + """ if isinstance(name, str): name = name.lower() From ab1b082710dbc1aa59699c5d9e5cbff88d8cac3b Mon Sep 17 00:00:00 2001 From: Loickemajou <88109303+Loickemajou@users.noreply.github.com> Date: Thu, 8 Aug 2024 11:25:51 +0200 Subject: [PATCH 03/22] added the discover nowcasts at the end so that the new nowcasts methods should be discovered by pysteps --- pysteps/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pysteps/__init__.py b/pysteps/__init__.py index 43fa20533..b7a18c879 100644 --- a/pysteps/__init__.py +++ b/pysteps/__init__.py @@ -218,3 +218,4 @@ def load_config_file(params_file=None, verbose=False, dryrun=False): # After the sub-modules are loaded, register the discovered importers plugin. io.interface.discover_importers() +nowcasts.discover_nowcasts() From 08ea3cd25173feaa5152d8028b5cd930cda2b85c Mon Sep 17 00:00:00 2001 From: Loickemajou <88109303+Loickemajou@users.noreply.github.com> Date: Thu, 8 Aug 2024 12:11:51 +0200 Subject: [PATCH 04/22] added the discover nowcasts and the nowcasts_info methods, to discover and view the available nowcasts methods --- pysteps/nowcasts/interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pysteps/nowcasts/interface.py b/pysteps/nowcasts/interface.py index 97717160a..0f8e2bec7 100644 --- a/pysteps/nowcasts/interface.py +++ b/pysteps/nowcasts/interface.py @@ -95,7 +95,7 @@ def discover_nowcasts(): ) - def nowcasts_info(): +def nowcasts_info(): """Print all the available importers.""" From bcb7ba919dbd0f92756b292ef7688e6d78f404a4 Mon Sep 17 00:00:00 2001 From: Loickemajou <88109303+Loickemajou@users.noreply.github.com> Date: Thu, 8 Aug 2024 12:41:57 +0200 Subject: [PATCH 05/22] corrected the discover_nowcast method import --- pysteps/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pysteps/__init__.py b/pysteps/__init__.py index b7a18c879..b06870292 100644 --- a/pysteps/__init__.py +++ b/pysteps/__init__.py @@ -218,4 +218,4 @@ def load_config_file(params_file=None, verbose=False, dryrun=False): # After the sub-modules are loaded, register the discovered importers plugin. io.interface.discover_importers() -nowcasts.discover_nowcasts() +nowcasts.interface.discover_nowcasts() From 6f36867a660a22c1b3fde80b89560717ea35b483 Mon Sep 17 00:00:00 2001 From: Loickemajou <88109303+Loickemajou@users.noreply.github.com> Date: Thu, 8 Aug 2024 13:45:01 +0200 Subject: [PATCH 06/22] reformatted interface.py --- pysteps/nowcasts/interface.py | 53 ++++++++++++++--------------------- 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/pysteps/nowcasts/interface.py b/pysteps/nowcasts/interface.py index 0f8e2bec7..eca49301e 100644 --- a/pysteps/nowcasts/interface.py +++ b/pysteps/nowcasts/interface.py @@ -29,6 +29,7 @@ get_method """ + from pprint import pprint from pysteps import nowcasts import importlib @@ -46,7 +47,6 @@ import os - _nowcast_methods = dict() _nowcast_methods["anvil"] = anvil.forecast _nowcast_methods["eulerian"] = eulerian_persistence @@ -60,7 +60,6 @@ _nowcast_methods["steps"] = steps.forecast - def discover_nowcasts(): """ Search for installed nowcasts plugins in the entrypoint 'pysteps.plugin.nowcasts' @@ -79,14 +78,14 @@ def discover_nowcasts(): for entry_point in pkg_resources.iter_entry_points( group="pysteps.plugin.nowcasts", name=None ): - _nowcast_module_name=entry_point.name - + _nowcast_module_name = entry_point.name + if _nowcast_module_name not in _nowcast_methods: - + module = importlib.import_module(entry_point.module_name) - - _nowcast_methods[_nowcast_module_name] =module.forecast - + + _nowcast_methods[_nowcast_module_name] = module.forecast + else: RuntimeWarning( f"The Nowcasts methode '{_nowcast_module_name}' is already available in" @@ -96,48 +95,40 @@ def discover_nowcasts(): def nowcasts_info(): - - """Print all the available importers.""" - + # nowcasts methods available in the `nowcasts` package available_nowcasts = [ - attr.split('.')[0] for attr in os.listdir(' '.join(nowcasts.__path__)) if not attr.startswith("__") - and attr!='interface.py' + attr.split(".")[0] + for attr in os.listdir(" ".join(nowcasts.__path__)) + if not attr.startswith("__") and attr != "interface.py" ] print("\nMethods available in the pysteps.nowcasts") pprint(available_nowcasts) # nowcasts declared in the pysteps.nowcast interface - - nowcasts_in_the_interface = [ - f for f in _nowcast_methods.keys() - ] + + nowcasts_in_the_interface = [f for f in _nowcast_methods.keys()] print("\nMethods available in the pysteps.nowcasts.get_method interface") - pprint( - [ - (short_name, f.__name__) - for short_name, f in _nowcast_methods.items() - ] - ) + pprint([(short_name, f.__name__) for short_name, f in _nowcast_methods.items()]) # Let's use sets to find out if there are importers present in the importer module # but not declared in the interface, and viceversa. available_nowcasts = set(available_nowcasts) - nowcasts_in_the_interface = set(nowcasts_in_the_interface ) + nowcasts_in_the_interface = set(nowcasts_in_the_interface) - difference = available_nowcasts ^ nowcasts_in_the_interface + difference = available_nowcasts ^ nowcasts_in_the_interface if len(difference) > 0: print("\nIMPORTANT:") - _diff = available_nowcasts - nowcasts_in_the_interface + _diff = available_nowcasts - nowcasts_in_the_interface if len(_diff) > 0: print( "\nIMPORTANT:\nThe following importers are available in pysteps.nowcasts module " "but not in the pysteps.nowcasts.get_method interface" ) pprint(_diff) - _diff = nowcasts_in_the_interface - available_nowcasts + _diff = nowcasts_in_the_interface - available_nowcasts if len(_diff) > 0: print( "\nWARNING:\n" @@ -146,12 +137,10 @@ def nowcasts_info(): ) pprint(_diff) - return available_nowcasts, nowcasts_in_the_interface - + return available_nowcasts, nowcasts_in_the_interface def get_method(name): - """ Return a callable function for computing nowcasts. @@ -186,12 +175,12 @@ def get_method(name): +-----------------+-------------------------------------------------------+ | sseps | short-space ensemble prediction system (SSEPS). | | | Essentially, this is a localization of STEPS | - +-----------------+-------------------------------------------------------+ + +-----------------+-------------------------------------------------------+ | dgmr | a deep generative model for the probabilistic . | | | nowcasting of precipitation from radar developed by | | | researchers from DeepMind | +-----------------+-------------------------------------------------------+ - + """ if isinstance(name, str): From 24d6c411a3c363d6429b9e4229c93091fc96e2a5 Mon Sep 17 00:00:00 2001 From: Loickemajou <88109303+Loickemajou@users.noreply.github.com> Date: Thu, 8 Aug 2024 13:46:54 +0200 Subject: [PATCH 07/22] reformatted __init__.py --- pysteps/nowcasts/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pysteps/nowcasts/__init__.py b/pysteps/nowcasts/__init__.py index 235315778..ce2681e0a 100644 --- a/pysteps/nowcasts/__init__.py +++ b/pysteps/nowcasts/__init__.py @@ -1,8 +1,8 @@ """Implementations of deterministic and ensemble nowcasting methods.""" -from pysteps.nowcasts.interface import get_method +from pysteps.nowcasts.interface import * try: from dgmr_module_plugin import dgmr except ImportError: - dgmr=None + dgmr = None From 3f5d31abd18c15f6b951529268b91da024f2cfae Mon Sep 17 00:00:00 2001 From: Loickemajou <88109303+Loickemajou@users.noreply.github.com> Date: Thu, 8 Aug 2024 16:01:48 +0200 Subject: [PATCH 08/22] reformatted interface.py --- pysteps/nowcasts/interface.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pysteps/nowcasts/interface.py b/pysteps/nowcasts/interface.py index eca49301e..909c59ce3 100644 --- a/pysteps/nowcasts/interface.py +++ b/pysteps/nowcasts/interface.py @@ -79,13 +79,9 @@ def discover_nowcasts(): group="pysteps.plugin.nowcasts", name=None ): _nowcast_module_name = entry_point.name - if _nowcast_module_name not in _nowcast_methods: - module = importlib.import_module(entry_point.module_name) - _nowcast_methods[_nowcast_module_name] = module.forecast - else: RuntimeWarning( f"The Nowcasts methode '{_nowcast_module_name}' is already available in" @@ -103,7 +99,6 @@ def nowcasts_info(): for attr in os.listdir(" ".join(nowcasts.__path__)) if not attr.startswith("__") and attr != "interface.py" ] - print("\nMethods available in the pysteps.nowcasts") pprint(available_nowcasts) # nowcasts declared in the pysteps.nowcast interface @@ -181,7 +176,6 @@ def get_method(name): | | researchers from DeepMind | +-----------------+-------------------------------------------------------+ - """ if isinstance(name, str): name = name.lower() From b37ce1de031b3591c6da0f3d8e583f4cb106ab03 Mon Sep 17 00:00:00 2001 From: Loickemajou <88109303+Loickemajou@users.noreply.github.com> Date: Mon, 12 Aug 2024 14:08:02 +0200 Subject: [PATCH 09/22] added the test for the modified nowccast interfaces --- pysteps/tests/test_interfaces.py | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/pysteps/tests/test_interfaces.py b/pysteps/tests/test_interfaces.py index c490b2539..e77fb2e63 100644 --- a/pysteps/tests/test_interfaces.py +++ b/pysteps/tests/test_interfaces.py @@ -360,3 +360,43 @@ def test_tracking_interface(): invalid_names = ["lucas-kanade", "dating"] _generic_interface_test(method_getter, valid_names_func_pair, invalid_names) + + +def test_nowcasts_interface(): + """Test the discover_nowcasts and nowcasts_info function.""" + from pysteps.nowcasts.interface import discover_nowcasts + from pysteps.nowcasts.interface import nowcasts_info + + # Clear the existing methods to test the discovery process + global _nowcast_methods + # Call the function to get nowcasts info + available_nowcasts, nowcasts_in_interface = nowcasts_info() + + # Call the function to discover nowcasts + discover_nowcasts() + + # Check if the expected methods are added + expected_methods = [ + "anvil", + "eulerian", + "extrapolation", + "lagrangian", + "lagrangian_probability", + "linda", + "probability", + "sprog", + "sseps", + "steps", + "dgmr", + ] + + for method in expected_methods: + if method == "dgmr": + assert ( + method in nowcasts_in_interface + ), f"Method {method} not found in discovered nowcasts. Please intall dgmr_plugin through 'pip install dgmr_plugin'" + assert ( + method in nowcasts_in_interface + ), f"Method {method} not found in discovered nowcasts." + + print("All expected nowcast methods discovered successfully.") From cd36341c1677841eae4a8441335bf99bd12d7e8d Mon Sep 17 00:00:00 2001 From: Loickemajou <88109303+Loickemajou@users.noreply.github.com> Date: Mon, 12 Aug 2024 14:17:28 +0200 Subject: [PATCH 10/22] adding the test for the modified nowcasts methods --- pysteps/tests/test_interfaces.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pysteps/tests/test_interfaces.py b/pysteps/tests/test_interfaces.py index e77fb2e63..509e48633 100644 --- a/pysteps/tests/test_interfaces.py +++ b/pysteps/tests/test_interfaces.py @@ -366,9 +366,6 @@ def test_nowcasts_interface(): """Test the discover_nowcasts and nowcasts_info function.""" from pysteps.nowcasts.interface import discover_nowcasts from pysteps.nowcasts.interface import nowcasts_info - - # Clear the existing methods to test the discovery process - global _nowcast_methods # Call the function to get nowcasts info available_nowcasts, nowcasts_in_interface = nowcasts_info() From 0cd6aa2f7819cdf7a95e39bd72e80834f57da4d5 Mon Sep 17 00:00:00 2001 From: Loickemajou <88109303+Loickemajou@users.noreply.github.com> Date: Mon, 12 Aug 2024 14:22:00 +0200 Subject: [PATCH 11/22] reformatted interface.py --- pysteps/tests/test_interfaces.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pysteps/tests/test_interfaces.py b/pysteps/tests/test_interfaces.py index 509e48633..52c0eda56 100644 --- a/pysteps/tests/test_interfaces.py +++ b/pysteps/tests/test_interfaces.py @@ -366,8 +366,9 @@ def test_nowcasts_interface(): """Test the discover_nowcasts and nowcasts_info function.""" from pysteps.nowcasts.interface import discover_nowcasts from pysteps.nowcasts.interface import nowcasts_info + # Call the function to get nowcasts info - available_nowcasts, nowcasts_in_interface = nowcasts_info() + _, nowcasts_in_interface = nowcasts_info() # Call the function to discover nowcasts discover_nowcasts() From b9dc46d9bb1b770816d114f2581209f1999558fc Mon Sep 17 00:00:00 2001 From: Loickemajou <88109303+Loickemajou@users.noreply.github.com> Date: Mon, 12 Aug 2024 15:17:51 +0200 Subject: [PATCH 12/22] testing the modified nowcasts interface --- pysteps/tests/test_interfaces.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pysteps/tests/test_interfaces.py b/pysteps/tests/test_interfaces.py index 52c0eda56..2bbeb0f2e 100644 --- a/pysteps/tests/test_interfaces.py +++ b/pysteps/tests/test_interfaces.py @@ -390,9 +390,11 @@ def test_nowcasts_interface(): for method in expected_methods: if method == "dgmr": - assert ( - method in nowcasts_in_interface - ), f"Method {method} not found in discovered nowcasts. Please intall dgmr_plugin through 'pip install dgmr_plugin'" + if method not in nowcasts_in_interface: + print( + f"Warning: Method {method} not found in discovered nowcasts. Please install dgmr_plugin through 'pip install dgmr_plugin'" + ) + continue assert ( method in nowcasts_in_interface ), f"Method {method} not found in discovered nowcasts." From a8a401f8bd93710e0290682fc3922a42ebfa0bc6 Mon Sep 17 00:00:00 2001 From: Loickemajou <88109303+Loickemajou@users.noreply.github.com> Date: Mon, 19 Aug 2024 11:17:25 +0200 Subject: [PATCH 13/22] fix some bugs in the discover nowcasts --- pysteps/nowcasts/interface.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/pysteps/nowcasts/interface.py b/pysteps/nowcasts/interface.py index 909c59ce3..5bf16eb89 100644 --- a/pysteps/nowcasts/interface.py +++ b/pysteps/nowcasts/interface.py @@ -78,16 +78,26 @@ def discover_nowcasts(): for entry_point in pkg_resources.iter_entry_points( group="pysteps.plugin.nowcasts", name=None ): - _nowcast_module_name = entry_point.name - if _nowcast_module_name not in _nowcast_methods: - module = importlib.import_module(entry_point.module_name) - _nowcast_methods[_nowcast_module_name] = module.forecast + _module = entry_point.load() + nowcast_module_name = entry_point.name + + if nowcast_module_name not in _nowcast_methods: + _nowcast_methods[nowcast_module_name] = _module + else: RuntimeWarning( - f"The Nowcasts methode '{_nowcast_module_name}' is already available in" + f"The Nowcasts methode '{nowcast_module_name}' is already available in" "'pysteps.nowcasts._nowcasts_methods'.\n" f"Skipping {entry_point.module_name}:{'.'.join(entry_point.attrs)}" ) + if hasattr(nowcasts, nowcast_module_name): + RuntimeWarning( + f"The nowcasts method '{nowcast_module_name}' is already an attribute" + "of 'pysteps.nowcasts'.\n" + f"Skipping {entry_point.module_name}:{'.'.join(entry_point.attrs)}" + ) + else: + setattr(nowcasts, nowcast_module_name, _module) def nowcasts_info(): From d50b78c233310086247885a96b3bf02d1f885228 Mon Sep 17 00:00:00 2001 From: Loickemajou <88109303+Loickemajou@users.noreply.github.com> Date: Mon, 19 Aug 2024 11:37:41 +0200 Subject: [PATCH 14/22] added some test to pass the code coverage --- pysteps/tests/test_interfaces.py | 54 +++++++++----------------------- 1 file changed, 14 insertions(+), 40 deletions(-) diff --git a/pysteps/tests/test_interfaces.py b/pysteps/tests/test_interfaces.py index 2bbeb0f2e..fd0cf1337 100644 --- a/pysteps/tests/test_interfaces.py +++ b/pysteps/tests/test_interfaces.py @@ -260,6 +260,20 @@ def test_nowcasts_interface(): for i in range(num_timesteps): assert numpy.all(forecast[i] == precip) + # Test for invalid method types + with pytest.raises(ValueError): + pysteps.nowcasts.interface.get_method("linear") + + assert isinstance( + pysteps.nowcasts.interface.nowcasts_info()[0], + set, + ) + + assert isinstance( + pysteps.nowcasts.interface.nowcasts_info()[1], + set, + ) + def test_utils_interface(): """Test utils module interface.""" @@ -360,43 +374,3 @@ def test_tracking_interface(): invalid_names = ["lucas-kanade", "dating"] _generic_interface_test(method_getter, valid_names_func_pair, invalid_names) - - -def test_nowcasts_interface(): - """Test the discover_nowcasts and nowcasts_info function.""" - from pysteps.nowcasts.interface import discover_nowcasts - from pysteps.nowcasts.interface import nowcasts_info - - # Call the function to get nowcasts info - _, nowcasts_in_interface = nowcasts_info() - - # Call the function to discover nowcasts - discover_nowcasts() - - # Check if the expected methods are added - expected_methods = [ - "anvil", - "eulerian", - "extrapolation", - "lagrangian", - "lagrangian_probability", - "linda", - "probability", - "sprog", - "sseps", - "steps", - "dgmr", - ] - - for method in expected_methods: - if method == "dgmr": - if method not in nowcasts_in_interface: - print( - f"Warning: Method {method} not found in discovered nowcasts. Please install dgmr_plugin through 'pip install dgmr_plugin'" - ) - continue - assert ( - method in nowcasts_in_interface - ), f"Method {method} not found in discovered nowcasts." - - print("All expected nowcast methods discovered successfully.") From 998d076605ab61a0883c199ec30c86baeb823768 Mon Sep 17 00:00:00 2001 From: Loickemajou <88109303+Loickemajou@users.noreply.github.com> Date: Mon, 19 Aug 2024 12:54:26 +0200 Subject: [PATCH 15/22] fi --- pysteps/nowcasts/interface.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pysteps/nowcasts/interface.py b/pysteps/nowcasts/interface.py index 5bf16eb89..e169adf57 100644 --- a/pysteps/nowcasts/interface.py +++ b/pysteps/nowcasts/interface.py @@ -74,9 +74,15 @@ def discover_nowcasts(): import pkg_resources importlib.reload(pkg_resources) + entry_points = list( + pkg_resources.iter_entry_points(group="pysteps.plugins.nowcasts", name=None) + ) + if not entry_points: + print("No entry points found in 'pysteps.plugins.nowcasts'.") + return for entry_point in pkg_resources.iter_entry_points( - group="pysteps.plugin.nowcasts", name=None + group="pysteps.plugins.nowcasts", name=None ): _module = entry_point.load() nowcast_module_name = entry_point.name From aa81fe83bd23dcdd91e3f64fe85b4afba1ef7ddd Mon Sep 17 00:00:00 2001 From: Loickemajou <88109303+Loickemajou@users.noreply.github.com> Date: Mon, 19 Aug 2024 12:55:14 +0200 Subject: [PATCH 16/22] fix some bugs in the discover nowcasts From 54e2dd85585c26db754eeb8cd99259830ea722d0 Mon Sep 17 00:00:00 2001 From: Loickemajou <88109303+Loickemajou@users.noreply.github.com> Date: Mon, 26 Aug 2024 15:34:49 +0200 Subject: [PATCH 17/22] remove the dgmr module package --- pysteps/nowcasts/__init__.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pysteps/nowcasts/__init__.py b/pysteps/nowcasts/__init__.py index ce2681e0a..eb5b931ff 100644 --- a/pysteps/nowcasts/__init__.py +++ b/pysteps/nowcasts/__init__.py @@ -1,8 +1,4 @@ """Implementations of deterministic and ensemble nowcasting methods.""" -from pysteps.nowcasts.interface import * +from pysteps.nowcasts.interface import discover_nowcasts, nowcasts_info, get_method -try: - from dgmr_module_plugin import dgmr -except ImportError: - dgmr = None From 4b12402b7a56d3bd42cbc8740642b2fa047ddf1a Mon Sep 17 00:00:00 2001 From: Loickemajou <88109303+Loickemajou@users.noreply.github.com> Date: Mon, 26 Aug 2024 15:36:52 +0200 Subject: [PATCH 18/22] removed the dgmr in the implimented methods --- pysteps/nowcasts/interface.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pysteps/nowcasts/interface.py b/pysteps/nowcasts/interface.py index e169adf57..bd3f93de5 100644 --- a/pysteps/nowcasts/interface.py +++ b/pysteps/nowcasts/interface.py @@ -187,10 +187,6 @@ def get_method(name): | sseps | short-space ensemble prediction system (SSEPS). | | | Essentially, this is a localization of STEPS | +-----------------+-------------------------------------------------------+ - | dgmr | a deep generative model for the probabilistic . | - | | nowcasting of precipitation from radar developed by | - | | researchers from DeepMind | - +-----------------+-------------------------------------------------------+ """ if isinstance(name, str): From c063be569b08e76c6cd60e2a925198468c9b75a0 Mon Sep 17 00:00:00 2001 From: Loickemajou <88109303+Loickemajou@users.noreply.github.com> Date: Mon, 26 Aug 2024 15:48:33 +0200 Subject: [PATCH 19/22] adding a test for the nowcast pluging discovery --- pysteps/tests/test_plugins_support.py | 44 ++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/pysteps/tests/test_plugins_support.py b/pysteps/tests/test_plugins_support.py index bbf3bcf5b..54b629b2e 100644 --- a/pysteps/tests/test_plugins_support.py +++ b/pysteps/tests/test_plugins_support.py @@ -10,7 +10,6 @@ import sys import tempfile - __ = pytest.importorskip("cookiecutter") from cookiecutter.main import cookiecutter @@ -79,3 +78,46 @@ def test_importers_plugins(): with _create_and_install_plugin("test_importer_bbb", "importer_bbb"): _check_installed_plugin("importer_aaa_xxx") _check_installed_plugin("importer_bbb_xxx") + + +def test_nowcasts_plugin_discovery(): + """Testing the discover_nowcast method to effectively see whether the plugin has been installed.""" + + from unittest.mock import Mock, patch + + # Ensure we patch the correct location where iter_entry_points is used + + with patch("pkg_resources.iter_entry_points") as mock_iter_entry_points: + # Create mock plugins + mock_plugin = Mock() + mock_plugin.name = "nowcast_method" + mock_plugin.load.return_value = "mock_module" + + # Set the return value of iter_entry_points to include the mock plugins + mock_iter_entry_points.return_value = [mock_plugin] + + # Clear the _nowcast_methods dictionary before the test + pysteps.nowcasts.interface._nowcast_methods.clear() + + # Call the function under test + pysteps.nowcasts.interface.discover_nowcasts() + + # Print the call arguments for debugging + print( + "mock_iter_entry_points.call_args_list:", + mock_iter_entry_points.call_args_list, + ) + + # Assert that the entry point was called + mock_iter_entry_points.assert_called_with( + group="pysteps.plugins.nowcasts", name=None + ) + + # Assert that the _nowcast_methods dictionary is updated correctly + assert ( + mock_plugin.name in pysteps.nowcasts.interface._nowcast_methods + ), "Expected 'nowcast_method' to be in _nowcast_methods, but it was not found." + assert ( + pysteps.nowcasts.interface._nowcast_methods[mock_plugin.name] + == mock_plugin.load + ), "Expected the value of 'nowcast_method' to be 'mock_module'." From c790b02748729e5c1d78a28704a6c8b93f1bbbe4 Mon Sep 17 00:00:00 2001 From: Loickemajou <88109303+Loickemajou@users.noreply.github.com> Date: Mon, 26 Aug 2024 15:55:07 +0200 Subject: [PATCH 20/22] reformatted __init__.py --- pysteps/nowcasts/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pysteps/nowcasts/__init__.py b/pysteps/nowcasts/__init__.py index eb5b931ff..30d9720a9 100644 --- a/pysteps/nowcasts/__init__.py +++ b/pysteps/nowcasts/__init__.py @@ -1,4 +1,3 @@ """Implementations of deterministic and ensemble nowcasting methods.""" from pysteps.nowcasts.interface import discover_nowcasts, nowcasts_info, get_method - From ac9f65e0e84228542ee43099e0e5113d14b54b4c Mon Sep 17 00:00:00 2001 From: Lesley De Cruz Date: Tue, 27 Aug 2024 16:30:41 +0200 Subject: [PATCH 21/22] Remove nowcast plugin testing code. The code can be tested from the dgmr plugin itself. --- pysteps/tests/test_plugins_support.py | 43 --------------------------- 1 file changed, 43 deletions(-) diff --git a/pysteps/tests/test_plugins_support.py b/pysteps/tests/test_plugins_support.py index 54b629b2e..91f9f8de5 100644 --- a/pysteps/tests/test_plugins_support.py +++ b/pysteps/tests/test_plugins_support.py @@ -78,46 +78,3 @@ def test_importers_plugins(): with _create_and_install_plugin("test_importer_bbb", "importer_bbb"): _check_installed_plugin("importer_aaa_xxx") _check_installed_plugin("importer_bbb_xxx") - - -def test_nowcasts_plugin_discovery(): - """Testing the discover_nowcast method to effectively see whether the plugin has been installed.""" - - from unittest.mock import Mock, patch - - # Ensure we patch the correct location where iter_entry_points is used - - with patch("pkg_resources.iter_entry_points") as mock_iter_entry_points: - # Create mock plugins - mock_plugin = Mock() - mock_plugin.name = "nowcast_method" - mock_plugin.load.return_value = "mock_module" - - # Set the return value of iter_entry_points to include the mock plugins - mock_iter_entry_points.return_value = [mock_plugin] - - # Clear the _nowcast_methods dictionary before the test - pysteps.nowcasts.interface._nowcast_methods.clear() - - # Call the function under test - pysteps.nowcasts.interface.discover_nowcasts() - - # Print the call arguments for debugging - print( - "mock_iter_entry_points.call_args_list:", - mock_iter_entry_points.call_args_list, - ) - - # Assert that the entry point was called - mock_iter_entry_points.assert_called_with( - group="pysteps.plugins.nowcasts", name=None - ) - - # Assert that the _nowcast_methods dictionary is updated correctly - assert ( - mock_plugin.name in pysteps.nowcasts.interface._nowcast_methods - ), "Expected 'nowcast_method' to be in _nowcast_methods, but it was not found." - assert ( - pysteps.nowcasts.interface._nowcast_methods[mock_plugin.name] - == mock_plugin.load - ), "Expected the value of 'nowcast_method' to be 'mock_module'." From 45070d4530ddd1b0b942f5cbd4c05fd18dbd2228 Mon Sep 17 00:00:00 2001 From: Lesley De Cruz Date: Mon, 9 Sep 2024 20:07:35 +0200 Subject: [PATCH 22/22] Remove debug message in discover_nowcasts(); fix comment. --- pysteps/nowcasts/interface.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/pysteps/nowcasts/interface.py b/pysteps/nowcasts/interface.py index bd3f93de5..8a659250e 100644 --- a/pysteps/nowcasts/interface.py +++ b/pysteps/nowcasts/interface.py @@ -74,12 +74,6 @@ def discover_nowcasts(): import pkg_resources importlib.reload(pkg_resources) - entry_points = list( - pkg_resources.iter_entry_points(group="pysteps.plugins.nowcasts", name=None) - ) - if not entry_points: - print("No entry points found in 'pysteps.plugins.nowcasts'.") - return for entry_point in pkg_resources.iter_entry_points( group="pysteps.plugins.nowcasts", name=None @@ -107,7 +101,7 @@ def discover_nowcasts(): def nowcasts_info(): - """Print all the available importers.""" + """Print all the available nowcast methods.""" # nowcasts methods available in the `nowcasts` package available_nowcasts = [