Skip to content

Commit

Permalink
Update both io interface and postprocessign interface
Browse files Browse the repository at this point in the history
- importer and diagnostic plugins correctly recognized in entry points
- cleaning: removed unused import modules
  • Loading branch information
Felix Erdmann committed Jan 30, 2025
1 parent 13922fc commit cb2529c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
15 changes: 6 additions & 9 deletions pysteps/io/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@
"""
import importlib

from pkg_resources import iter_entry_points

from pysteps import io
from pysteps.decorators import postprocess_import
from pysteps.io import importers, exporters
from pysteps.io import importers, exporters, interface
from pprint import pprint

_importer_methods = dict(
Expand Down Expand Up @@ -58,7 +55,7 @@ def discover_importers():
importlib.reload(pkg_resources)

for entry_point in pkg_resources.iter_entry_points(
group="pysteps.plugins.importers", name=None
group="pysteps.plugins.importer", name=None
):
_importer = entry_point.load()

Expand Down Expand Up @@ -91,22 +88,22 @@ def importers_info():

# Importers available in the `io.importers` module
available_importers = [
attr for attr in dir(io.importers) if attr.startswith("import_")
attr for attr in dir(importers) if attr.startswith("import_")
]

print("\nImporters available in the pysteps.io.importers module")
pprint(available_importers)

# Importers declared in the pysteps.io.get_method interface
importers_in_the_interface = [
f.__name__ for f in io.interface._importer_methods.values()
f.__name__ for f in interface._importer_methods.values()
]

print("\nImporters available in the pysteps.io.get_method interface")
pprint(
[
(short_name, f.__name__)
for short_name, f in io.interface._importer_methods.items()
for short_name, f in interface._importer_methods.items()
]
)

Expand All @@ -117,7 +114,7 @@ def importers_info():

difference = available_importers ^ importers_in_the_interface
if len(difference) > 0:
print("\nIMPORTANT:")
#print("\nIMPORTANT:")
_diff = available_importers - importers_in_the_interface
if len(_diff) > 0:
print(
Expand Down
19 changes: 11 additions & 8 deletions pysteps/postprocessing/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"""
import importlib

import pysteps.postprocessing
from pysteps.postprocessing import diagnostics, ensemblestats
from pprint import pprint

Expand Down Expand Up @@ -127,7 +126,7 @@ def print_postprocessors_info(module_name, interface_methods, module_methods):
interface_methods: dict
Dictionary of the postprocessors declared in the interface, for example _diagnostics_methods.
module_methods: list
List of the postprocessors available in the module, for example 'postprocessors_diagnostics_example1'.
List of the postprocessors available in the module, for example 'diagnostic_example1'.
"""
print(f"\npostprocessors available in the {module_name} module")
Expand All @@ -143,7 +142,7 @@ def print_postprocessors_info(module_name, interface_methods, module_methods):

difference = module_methods_set ^ interface_methods_set
if len(difference) > 0:
print("\nIMPORTANT:")
#print("\nIMPORTANT:")
_diff = module_methods_set - interface_methods_set
if len(_diff) > 0:
print(
Expand All @@ -166,19 +165,23 @@ def postprocessors_info():
postprocessors_in_the_interface = set()
# List the plugins that have been added to the postprocessing.[plugintype] module
for plugintype in ["diagnostics", "ensemblestats"]:
# in the dictionary and found by get_methods() function
interface_methods = (
_diagnostics_methods
if plugintype == "diagnostics"
else _ensemblestats_methods
)
# in the pysteps.postprocessing module
module_name = f"pysteps.postprocessing.{plugintype}"
available_module_methods = [
attr
for attr in dir(importlib.import_module(module_name))
if attr.startswith(plugintype[:-1])
]
# add the pre-existing ensemblestats functions (see _ensemblestats_methods above)
if "ensemblestats" in plugintype: available_module_methods += ["mean","excprob","banddepth"]
# that do not follow the convention to start with "ensemblestat_" as the plugins
if "ensemblestats" in plugintype:
available_module_methods += [em for em in _ensemblestats_methods.keys() if not em.startswith('ensemblestat_')]
print_postprocessors_info(
module_name, interface_methods, available_module_methods
)
Expand Down Expand Up @@ -209,10 +212,10 @@ def get_method(name, method_type):
+---------------+-------------------------------------------------------+
| Name | Description |
+===============+=======================================================+
| Diagnostics | Example that returns a string |
| Diagnostic | Example that returns a string |
| Example1 | |
+---------------+-------------------------------------------------------+
| Diagnostics | Example that returns an array |
| Diagnostic | Example that returns an array |
| Example3 | |
+---------------+-------------------------------------------------------+
Expand All @@ -223,10 +226,10 @@ def get_method(name, method_type):
+---------------+-------------------------------------------------------+
| Name | Description |
+===============+=======================================================+
| EnsembleStats | Example that returns a string |
| EnsembleStat | Example that returns a string |
| Example1 | |
+---------------+-------------------------------------------------------+
| EnsembleStats | Example that returns an array |
| EnsembleStat | Example that returns an array |
| Example3 | |
+---------------+-------------------------------------------------------+
Expand Down

0 comments on commit cb2529c

Please sign in to comment.