spacetelescope / jdaviz

JWST astronomical data analysis tools in the Jupyter platform
https://jdaviz.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
134 stars 71 forks source link

Specviz Application does not start either from command line or from jupyter notebook #2299

Open xnaxe29 opened 1 year ago

xnaxe29 commented 1 year ago

I tried to run specviz from command line -

>>> from specutils import Spectrum1D
>>> from jdaviz import Specviz
>>> specviz = Specviz()
>>> specviz.show()

It gives the error -

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/adarshranjan/opt/anaconda3/envs/stenv/lib/python3.9/site-packages/jdaviz/core/helpers.py", line 393, in show
    show_widget(self.app, loc=loc, title=title)
  File "/Users/adarshranjan/opt/anaconda3/envs/stenv/lib/python3.9/site-packages/jdaviz/core/template_mixin.py", line 56, in show_widget
    raise RuntimeError("\nYou are currently running Jdaviz from an unsupported "
RuntimeError: 
You are currently running Jdaviz from an unsupported shell (NoneType). Jdaviz is intended to be run within a Jupyter notebook, or directly from the command line.

To run from Jupyter, call <your viz>.show() from a notebook cell.
To see how to run from the command line, run: 'jdaviz --help' outside of Python.

To learn more, see our documentation at: https://jdaviz.readthedocs.io

Using jupyter notebook -

# This ensures that our notebook is using the full width of the browser

from IPython.core.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))

# Import the packages and modules we'll need

from jdaviz import Specviz

from astropy.utils.data import download_file
from astropy.table import QTable
import astropy.units as u

specviz = Specviz()
specviz.app

It outputs only this statement ->

Application(config='specviz', events=['call_viewer_method', 'close_snackbar_message', 'data_item_remove', 'dat…

But the application does not start.

Do you know what is wrong?

I am using a Macbook Pro M2 pro (13.4.1) with 'stenv' recommended conda environment. Python 3.9.16, jdaviz 3.5.0.

Please let me know if someone has faced this problem and knows how to solve this.

Thanks Adarsh

pllim commented 1 year ago

Hello!

  1. You cannot run Jdaviz from Python interpreter. Hence the "unsupported shell" error.
  2. You are supposed to be able to run Jdaviz in notebook but calling specviz.app is not the way to do it anymore (where did you get that notebook?). Try specviz.show() and let us know if it works or still the same error.

Thank you.

pllim commented 1 year ago

p.s. Jdaviz support in stenv is not guaranteed, as that env is mainly used for pipeline processing, not post-pipeline data analysis. I would actually recommend trying this in a new env altogether.

conda deactivate
conda create -n jdaviz python=3.11
conda activate jdaviz
pip install jdaviz --no-cache-dir --upgrade

Then start a notebook:

jupyter notebook

Then inside the notebook, run this:

from jdaviz import Specviz
specviz = Specviz()
specviz.show()

Do you see the app now?

duytnguyendtn commented 1 year ago

Thanks for using Jdaviz, Adarsh!

To expand on @pllim's comment earlier on the first point, to launch from the command line, you can launch jdaviz by running jdaviz rather than python. For more information, take a look at https://jdaviz.readthedocs.io/en/latest/specviz/import_data.html#importing-data-through-the-command-line

xnaxe29 commented 1 year ago

Hello,

Thanks for your response. I got the notebook from the STScI youtube video -

https://www.youtube.com/watch?v=fQcI9lHVB2Y&list=PLTOSd8OgUP5p4pRLTiVFY0kIRSw04xDP6&index=9

https://github.com/spacetelescope/jwebbinar_prep/blob/webbinar2/jdat_session/Specviz_Webbinar_solutions.ipynb

I will try the suggested solutions.

Thanks Adarsh

Hello!

  1. You cannot run Jdaviz from Python interpreter. Hence the "unsupported shell" error.
  2. You are supposed to be able to run Jdaviz in notebook but calling specviz.app is not the way to do it anymore (where did you get that notebook?). Try specviz.show() and let us know if it works or still the same error.

Thank you.

-- Reply to this email directly or view it on GitHub: https://github.com/spacetelescope/jdaviz/issues/2299#issuecomment-1638394878 You are receiving this because you authored the thread.

Message ID: @.***>

xnaxe29 commented 1 year ago

Hi [pllim],

I am trying to follow the JWebbinar series. - https://www.youtube.com/watch?v=fQcI9lHVB2Y&list=PLTOSd8OgUP5p4pRLTiVFY0kIRSw04xDP6&index=9 https://github.com/spacetelescope/jwebbinar_prep/blob/webbinar2/jdat_session/Specviz_Webbinar_solutions.ipynb

xnaxe29 commented 1 year ago

p.s. Jdaviz support in stenv is not guaranteed, as that env is mainly used for pipeline processing, not post-pipeline data analysis. I would actually recommend trying this in a new env altogether.

conda deactivate conda create -n jdaviz python=3.11 conda activate jdaviz pip install jdaviz --no-cache-dir --upgrade Then start a notebook:

jupyter notebook Then inside the notebook, run this:

from jdaviz import Specviz specviz = Specviz() specviz.show() Do you see the app now?

Thanks. This solution works from within a jupyter notebook. PS: Both - 'specviz.show()' and 'specviz.app' seem to work. FYI.

xnaxe29 commented 1 year ago

Thanks for using Jdaviz, Adarsh!

To expand on @pllim's comment earlier on the first point, to launch from the command line, you can launch jdaviz by running jdaviz rather than python. For more information, take a look at https://jdaviz.readthedocs.io/en/latest/specviz/import_data.html#importing-data-through-the-command-line

Hi [duytnguyendtn],

Thanks for the suggestion. I tried - 'jdaviz --layout=specviz galaxy_jwst.fits' from the command line and it outputs an error - usage: jdaviz [-h] [--instrument INSTRUMENT] [--browser BROWSER] [--theme {light,dark}] [--verbosity {debug,info,warning,error}] [--history-verbosity {debug,info,warning,error}] [--hotreload | --no-hotreload] [--version] {cubeviz,specviz,specviz2d,mosviz,imviz} [filepaths ...] jdaviz: error: argument layout: invalid choice: 'galaxy_jwst.fits' (choose from 'cubeviz', 'specviz', 'specviz2d', 'mosviz', 'imviz')

Same error when I try - "jdaviz --layout='specviz' galaxy_jwst.fits" or "jdaviz --layout=specviz galaxy_jwst.fits galaxy_jwst.fits"

Am I using the syntax incorrectly?

duytnguyendtn commented 1 year ago

Hi @xnaxe29,

I believe I know the problem. Could you try jdaviz specviz galaxy_jwst.fits? (do not use --layout=).

I suspect you may be on our stable release, which is version 3.5. (which you can confirm by running pip freeze and searching for your version of jdaviz). The link I sent you is for our latest documentation which hasn't been released yet. Here is the appropriate documentation for our latest stable release: https://jdaviz.readthedocs.io/en/stable/specviz/import_data.html#importing-data-through-the-command-line

Once we update to version 3.6, the other command I sent you will be the correct syntax (including --layout=)

Sorry about that confusion! Duy

xnaxe29 commented 1 year ago

Hi @xnaxe29,

I believe I know the problem. Could you try jdaviz specviz galaxy_jwst.fits? (do not use --layout=).

I suspect you may be on our stable release, which is version 3.5. (which you can confirm by running pip freeze and searching for your version of jdaviz). The link I sent you is for our latest documentation which hasn't been released yet. Here is the appropriate documentation for our latest stable release: https://jdaviz.readthedocs.io/en/stable/specviz/import_data.html#importing-data-through-the-command-line

Once we update to version 3.6, the other command I sent you will be the correct syntax (including --layout=)

Sorry about that confusion! Duy

Here is the new error after I run "jdaviz specviz galaxy_jwst.fits" -

Traceback (most recent call last):
  File "/opt/homebrew/bin/jdaviz", line 8, in <module>
    sys.exit(_main())
             ^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/jdaviz/cli.py", line 144, in _main
    main(filepaths=args.filepaths, layout=layout, instrument=args.instrument, browser=args.browser,
  File "/opt/homebrew/lib/python3.11/site-packages/jdaviz/cli.py", line 99, in main
    sys.exit(Voila().launch_instance(argv=[]))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/traitlets/config/application.py", line 1042, in launch_instance
    app.initialize(argv)
  File "/opt/homebrew/lib/python3.11/site-packages/voila/app.py", line 407, in initialize
    self.setup_template_dirs()
  File "/opt/homebrew/lib/python3.11/site-packages/voila/app.py", line 413, in setup_template_dirs
    self.template_paths = collect_template_paths(['voila', 'nbconvert'], template_name, prune=True)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/voila/paths.py", line 24, in collect_template_paths
    return collect_paths(app_names, template_name, include_root_paths=True, prune=prune, root_dirs=root_dirs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/voila/paths.py", line 90, in collect_paths
    raise ValueError(
ValueError: No template sub-directory with name 'base' found in the following paths:
duytnguyendtn commented 1 year ago

@xnaxe29 A template traceback is usually the sign of a broken installation. Could you detail how you installed Jdaviz?

I would try to reinstall jdaviz by running:

pip uninstall jdaviz
pip install jdaviz

and hopefully the templates will be copied to the right place.