diff --git a/gwcs/__init__.py b/gwcs/__init__.py index 18d5c3c8..1867ae93 100644 --- a/gwcs/__init__.py +++ b/gwcs/__init__.py @@ -65,8 +65,12 @@ # package is not installed pass # pragma: no cover - -from .wcs import * # noqa -from .wcstools import * # noqa -from .coordinate_frames import * # noqa -from .selector import * # noqa +def __getattr__(name): + for sub_module in ("wcs", "wcstools", "coordinate_frames", "selector"): + module = __import__(f"gwcs.{sub_module}", fromlist=['*']) + globals().update({name: getattr(module, name) for name in module.__all__}) + + try: + return globals()[name] + except KeyError: + raise AttributeError(f"module 'gwcs' has no attribute '{name}'") from None diff --git a/gwcs/converters/selector.py b/gwcs/converters/selector.py index bd543dba..f4743fbd 100644 --- a/gwcs/converters/selector.py +++ b/gwcs/converters/selector.py @@ -2,12 +2,7 @@ # -*- coding: utf-8 -*- from collections import OrderedDict -import numpy as np -from astropy.modeling import models -from astropy.modeling.core import Model -from astropy.utils.misc import isiterable -from asdf.tags.core.ndarray import NDArrayType from asdf_astropy.converters.transform.core import TransformConverterBase @@ -20,6 +15,12 @@ class LabelMapperConverter(TransformConverterBase): "gwcs.selector.LabelMapperRange", "gwcs.selector.LabelMapper"] def from_yaml_tree_transform(self, node, tag, ctx): + from asdf.tags.core.ndarray import NDArrayType + from astropy.modeling import models + from astropy.modeling.core import Model + from astropy.utils.misc import isiterable + import numpy as np + from ..selector import (LabelMapperArray, LabelMapperDict, LabelMapperRange, LabelMapper) inputs_mapping = node.get('inputs_mapping', None) @@ -52,6 +53,7 @@ def from_yaml_tree_transform(self, node, tag, ctx): return LabelMapperDict(inputs, dict_mapper, inputs_mapping, atol=atol) def to_yaml_tree_transform(self, model, tag, ctx): + from astropy.utils.misc import isiterable from ..selector import (LabelMapperArray, LabelMapperDict, LabelMapperRange, LabelMapper) node = OrderedDict() @@ -91,6 +93,7 @@ class RegionsSelectorConverter(TransformConverterBase): def from_yaml_tree_transform(self, node, tag, ctx): from ..selector import RegionsSelector + inputs = node['inputs'] outputs = node['outputs'] label_mapper = node['label_mapper'] diff --git a/gwcs/converters/spectroscopy.py b/gwcs/converters/spectroscopy.py index 8b762503..cb595f3b 100644 --- a/gwcs/converters/spectroscopy.py +++ b/gwcs/converters/spectroscopy.py @@ -2,7 +2,6 @@ ASDF tags for spectroscopy related models. """ -from astropy import units as u from asdf_astropy.converters.transform.core import ( TransformConverterBase, parameter_to_value ) @@ -84,6 +83,7 @@ def from_yaml_tree_transform(self, node, tag, ctx): return model def to_yaml_tree_transform(self, model, tag, ctx): + from astropy import units as u from ..spectroscopy import (AnglesFromGratingEquation3D, WavelengthFromGratingEquation) if model.groove_density.unit is not None: