diff --git a/jdaviz/__init__.py b/jdaviz/__init__.py index 716678364f..fdddfd2e84 100644 --- a/jdaviz/__init__.py +++ b/jdaviz/__init__.py @@ -19,6 +19,7 @@ from jdaviz.configs.cubeviz import Cubeviz # noqa: F401 from jdaviz.configs.imviz import Imviz # noqa: F401 from jdaviz.utils import enable_hot_reloading # noqa: F401 +from jdaviz.core.data_formats import open # noqa: F401 # Clean up namespace. del os diff --git a/jdaviz/configs/__init__.py b/jdaviz/configs/__init__.py index 957cbeb45f..eb078d8c5c 100644 --- a/jdaviz/configs/__init__.py +++ b/jdaviz/configs/__init__.py @@ -1,5 +1,6 @@ from .cubeviz import * # noqa from .specviz import * # noqa +from .specviz2d import * # noqa from .default import * # noqa from .mosviz import * # noqa from .imviz import * # noqa diff --git a/jdaviz/core/data_formats.py b/jdaviz/core/data_formats.py index 7caa29253b..495cde7f22 100644 --- a/jdaviz/core/data_formats.py +++ b/jdaviz/core/data_formats.py @@ -11,6 +11,7 @@ from stdatamodels import asdf_in_fits from jdaviz.core.config import list_configurations +from jdaviz import configs as jdaviz_configs __all__ = [ 'guess_dimensionality', @@ -272,3 +273,35 @@ def identify_helper(filename, ext=1): return 'imviz' raise ValueError(f"No helper could be auto-identified for {filename}.") + + +def open(filename, show=True, **kwargs): + ''' + Automatically detect the correct configuration based on a given file, + load the data, and display the configuration + + Parameters + ---------- + filename : str (path-like) + Name for a local data file. + show : bool + Determines whether to immediately show the application + + Returns + ------- + Jdaviz App : jdaviz.app.Application + The application, configured based on the automatic config detection + ''' + helper_str = identify_helper(filename) + viz_class = getattr(jdaviz_configs, helper_str.capitalize()) + + viz_helper = viz_class() + if helper_str == "specviz": + viz_helper.load_spectrum(filename, **kwargs) + else: + viz_helper.load_data(filename, **kwargs) + + if show: + viz_helper.show() + + return viz_helper