Skip to content

Commit

Permalink
Add open method to automatically detect config and load data
Browse files Browse the repository at this point in the history
  • Loading branch information
duytnguyendtn committed May 31, 2023
1 parent d86fd9a commit a937636
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions jdaviz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions jdaviz/configs/__init__.py
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions jdaviz/core/data_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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

0 comments on commit a937636

Please sign in to comment.