Allowing for lazy loading of optional wradlib modules or dependencies.

This function removes the need to satisfy all dependencies of wradlib before being able to work with it.


module (str) – name of the module


mod (object) – if module is present, returns the module object, on ImportError returns an instance of OptionalModuleStub which will raise an AttributeError as soon as any attribute is accessed.


Trying to import a module that exists makes the module available as normal. You can even use an alias. You cannot use the ‘*’ notation, or import only select functions, but you can simulate most of the standard import syntax behavior. >>> m = import_optional(‘math’) >>> m.log10(100) 2.0

Trying to import a module that does not exist, does not produce any errors. Only when some function is used, the code triggers an error >>> m = import_optional(‘nonexistentmodule’) # noqa >>> m.log10(100) #doctest: +ELLIPSIS Traceback (most recent call last): … AttributeError: Module ‘nonexistentmodule’ is not installed. <BLANKLINE> You tried to access function/module/attribute ‘log10’ from module ‘nonexistentmodule’. This module is optional right now in wradlib. You need to separately install this dependency. Please refer to https://docs.wradlib.org/en/stable/installation.html#optional-dependencies for further instructions.