Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jdaviz Launcher #2257

Merged
merged 14 commits into from
Jul 3, 2023
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ New Features

- The ``specviz.load_spectrum`` method is deprecated; use ``specviz.load_data`` instead. [#2273]

- Add first-pass launcher to select config and auto-identify data. [#2257]

Cubeviz
^^^^^^^

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ from a terminal, type:
.. code-block:: bash

jdaviz --help
jdaviz specviz /path/to/data/spectral_file
jdaviz --layout=specviz /path/to/data/spectral_file

For more information on the command line interfaces for each tool, see the
`Jdaviz docs <https://jdaviz.readthedocs.io/en/latest/index.html>`_.
Expand Down
2 changes: 1 addition & 1 deletion docs/cubeviz/import_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ a data product is optional:

.. code-block:: bash

jdaviz cubeviz /my/directory/cube.fits
jdaviz --layout=cubeviz /my/directory/cube.fits

.. _cubeviz-import-gui:

Expand Down
2 changes: 1 addition & 1 deletion docs/imviz/import_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Multiple data files may be provided:

.. code-block:: bash

jdaviz imviz /my/image/data1.fits /my/image/data2.fits
jdaviz --layout=imviz /my/image/data1.fits /my/image/data2.fits

.. _imviz-import-gui:

Expand Down
4 changes: 2 additions & 2 deletions docs/mosviz/import_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ Similarly, an instrument keyword can be specified by the command line. For NIRSp

.. code-block:: bash

jdaviz mosviz /path/to/my/data --instrument=nirspec
jdaviz --layout=mosviz /path/to/my/data --instrument=nirspec

and for NIRISS:

.. code-block:: bash

jdaviz mosviz /path/to/my/data --instrument=niriss
jdaviz --layout=mosviz /path/to/my/data --instrument=niriss

Specifying a data directory and an instrument are required to start Mosviz from the command line.
If a directory is entered without specifying an instrument, Mosviz will
Expand Down
2 changes: 1 addition & 1 deletion docs/mosviz/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ To load a sample `NIRISS Nirspec Data Set <https://stsci.box.com/shared/static/o

.. code-block:: bash

jdaviz mosviz /path/to/mosviz_nirspec_data_0.3/level3
jdaviz --layout=mosviz /path/to/mosviz_nirspec_data_0.3/level3

Or to load in a Jupyter notebook, see the :gh-notebook:`MosvizExample` or :gh-notebook:`MosvizNIRISSExample`.

Expand Down
2 changes: 1 addition & 1 deletion docs/specviz/import_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ a data file is optional, and multiple data files may be provided:

.. code-block:: bash

jdaviz specviz /my/directory/spectrum1.fits /my/directory/spectrum2.fits
jdaviz --layout=specviz /my/directory/spectrum1.fits /my/directory/spectrum2.fits

.. _specviz-import-gui:

Expand Down
2 changes: 1 addition & 1 deletion docs/specviz2d/import_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ spectrum object and will automatically extract the 1D spectrum):

.. code-block:: bash

jdaviz specviz2d /my/directory/spectrum1.fits /my/directory/spectrum2.fits
jdaviz --layout=specviz2d /my/directory/spectrum1.fits /my/directory/spectrum2.fits


.. _specviz2d-import-gui:
Expand Down
11 changes: 8 additions & 3 deletions jdaviz/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ def main(filepaths=None, layout='default', instrument=None, browser='default',
else:
file_list = []

with open(JDAVIZ_DIR / "jdaviz_cli.ipynb") as f:
if len(file_list) == 0 and layout == '':
notebook = "jdaviz_cli_launcher.ipynb"
else:
notebook = "jdaviz_cli.ipynb"

with open(JDAVIZ_DIR / notebook) as f:
notebook_template = f.read()

start_dir = os.path.abspath('.')
Expand Down Expand Up @@ -111,8 +116,8 @@ def _main(config=None):
'loaded from FILENAME.')
filepaths_nargs = '*'
if config is None:
parser.add_argument('layout', choices=['cubeviz', 'specviz', 'specviz2d',
'mosviz', 'imviz'],
parser.add_argument('--layout', default='', choices=['cubeviz', 'specviz', 'specviz2d',
duytnguyendtn marked this conversation as resolved.
Show resolved Hide resolved
Comment on lines -114 to +119
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this definitely deserves to be quite "loud" in the change log entry as it technically is a breaking change to the CLI.

Discussed offline: after the launcher is more finalized and ready for public use, we might want to update the docs to suggest jdaviz filename directly and only keeping --layout as advanced functionality. But that can (and should) be deferred.

'mosviz', 'imviz'],
help='Configuration to use.')
if (config == "mosviz") or ("mosviz" in sys.argv):
filepaths_nargs = 1
Expand Down
51 changes: 51 additions & 0 deletions jdaviz/core/launcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import ipyvuetify as v
from ipywidgets import jslink

from jdaviz import configs as jdaviz_configs
from jdaviz.core.data_formats import open as jdaviz_open


def show_launcher(configs=['imviz', 'specviz', 'mosviz', 'cubeviz', 'specviz2d']):
pllim marked this conversation as resolved.
Show resolved Hide resolved
main = v.Sheet(class_="mx-4", _metadata={'mount_id': 'content'})
main.children = []

# Create Intro Row
intro_row = v.Row()
welcome_text = v.Html(tag='h1', attributes={'title': 'a title'},
children=['Welcome to Jdaviz'])
intro_row.children = [welcome_text]

# Filepath row
filepath_row = v.Row()
text_field = v.TextField(label="File Path", v_model=None)

def load_file(filepath):
if filepath:
helper = jdaviz_open(filepath, show=False)
main.children = [helper.app]

open_data_btn = v.Btn(class_="ma-2", outlined=True, color="primary",
children=[v.Icon(children=["mdi-upload"])])
open_data_btn.on_event('click', lambda btn, event, data: load_file(btn.value))
jslink((text_field, 'v_model'), (open_data_btn, 'value'))

filepath_row.children = [text_field, open_data_btn]

# Config buttons
def create_config(config):
viz_class = getattr(jdaviz_configs, config.capitalize())
main.children = [viz_class().app]

btns = []
for config in configs:
config_btn = v.Btn(class_="ma-2", outlined=True, color="primary",
children=[config.capitalize()])
config_btn.on_event('click', lambda btn, event, data: create_config(btn.children[0]))
btns.append(config_btn)

# Create button row
btn_row = v.Row()
btn_row.children = btns
main.children = [intro_row, filepath_row, btn_row]

return main
41 changes: 41 additions & 0 deletions jdaviz/jdaviz_cli_launcher.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from jdaviz.core.launcher import show_launcher\n",
"\n",
"show_launcher()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.10.10 ('envmain': venv)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.10"
},
"vscode": {
"interpreter": {
"hash": "f917e879dca01012f092e44ceeb72fc316d3b188a12a493299dc2bd49905dadb"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ jdaviz = [
"configs/*/*/*/*.vue",
"configs/*/*.yaml",
"jdaviz_cli.ipynb",
"jdaviz_cli_launcher.ipynb",
]
"jdaviz.configs.imviz.tests" = [
"data/*",
Expand Down