Opened 6 years ago

Closed 6 years ago

#1952 closed defect (fixed)

is numpy always needed?

Reported by: Dimitar Misev Owned by: Bang Pham Huu
Priority: major Milestone: 9.8
Component: wcst_import Version: development
Keywords: Cc:
Complexity: Medium

Description

I get this error while importing tiff files with petascope_insertdemo.sh. Why is numpy needed in this case, and why does netcdf_to_coverage_converter.py appear in the stacktrace? This should be improved.

petascope_insertdemo.sh: Ingesting AverageChlorophyll to petascope by wcst_import...Traceback (most recent call last):
  File "/opt/rasdaman/share/rasdaman/wcst_import/wcst_import.py", line 183, in <module>
    main()
  File "/opt/rasdaman/share/rasdaman/wcst_import/wcst_import.py", line 159, in main
    reg = RecipeRegistry()
  File "/opt/rasdaman/share/rasdaman/wcst_import/master/recipe/recipe_registry.py", line 43, in __init__
    self._init_registry()
  File "/opt/rasdaman/share/rasdaman/wcst_import/master/recipe/recipe_registry.py", line 58, in _init_registry
    util.import_submodules(recipes.general_coverage)
  File "/opt/rasdaman/share/rasdaman/wcst_import/util/reflection_util.py", line 49, in import_submodules
    results[full_name] = importlib.import_module(full_name)
  File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/opt/rasdaman/share/rasdaman/wcst_import/recipes/general_coverage/netcdf_to_coverage_converter.py", line 44, in <module>
    import numpy
ImportError: No module named numpy

Change History (3)

comment:1 by Bang Pham Huu, 6 years ago

Even though Numpy is not always needed (like importing with old recipes), but because of using reflection /opt/rasdaman/share/rasdaman/wcst_import/util/reflection_util.py", line 49, in import_submodules to register all recipes

class ReflectionUtil:

    def __init__(self):
        """
        Utility class to help with reflection in python
        :return:
        """
        pass

    def import_submodules(self, package, recursive=True):
        """
        Import all submodules of a module, recursively, including subpackages
        :param package: package (name or actual module)
        :type package: str | module
        :rtype: dict[str, types.ModuleType]
        """
        if isinstance(package, str):
            package = importlib.import_module(package)
        results = {}
        for loader, name, is_pkg in pkgutil.walk_packages(package.__path__):
            full_name = package.__name__ + '.' + name
            results[full_name] = importlib.import_module(full_name)
            if recursive and is_pkg:
                results.update(self.import_submodules(full_name))
        return results

Then, it throws an error when loading Numpy dependency for netCDF recipe. I think the way to solve this problem is hiding import Numpy in methods which use it instead of importing globally.

comment:2 by Dimitar Misev, 6 years ago

yes, and maybe also lazy recipe registration?

Last edited 6 years ago by Dimitar Misev (previous) (diff)

comment:3 by Bang Pham Huu, 6 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.