jdaviz
jdaviz copied to clipboard
[BUG] MOSVIZ raises an exception on loading a JWST S2D file.
Jdaviz component
Mosviz
Description
If mosvis.load_data() is run with directory=(path to a directory containing a single JWST NIRSpec S2D file), and instrument=nirspec, it crashes in the load_data() function with an error about not being able to find the 1D spectra. In particular, it raises an exception at:
"site-packages/jdaviz/configs/mosviz/plugins/parsers.py" line 131, with the error: KeyError: 'ComponentID not found or not unique: 1D Spectra'
Tracing the issue, I see that, in the load_data function, in site-packages/jdaviz/configs/mosviz/helper.py lines 333-346, if directory is specified, then Mosviz automatically runs, at line 417, the link_table function, which fails because it tries to link together 2D and 1D spectra, but an S2D file only contains 2D spectra.
Elsewhere in the helper.py file, if only 2D spectra are specified when running load_data, the variable "allow_link_table" is set to False, which would also solve this particular issue.
How to Reproduce
- Install Jdaviz 4.0.0 with "pip install jdaviz"
- Download the JWST NIRSpec S2D file jw01211013001_08101_00001_nrs2_s2d.fits from MAST, and put it in a directory by itself.
- Run python, import Jdaviz, and import Mosviz
- Create a Mosviz() object
- Run `mosviz.load_data(directory="directory created in step 2", instrument="nirspec")
- An error occurs.
Expected behavior
There should not be an exception, and the mosviz object should be able to load the directory. It probably won't be a very satisfying output, because there's no image and no 1D spectra, but it will at least exist, and be possible to display.
Browser
No response
Jupyter
N/A
Software versions
>>> import platform; print(platform.platform())
macOS-14.7.1-arm64-arm-64bit
>>> import sys; print("Python", sys.version)
Python 3.11.10 | packaged by conda-forge | (main, Oct 16 2024, 01:26:25) [Clang 17.0.6 ]
>>> import numpy; print("Numpy", numpy.__version__)
Numpy 1.26.4
>>> import astropy; print("astropy", astropy.__version__)
astropy 6.1.6
>>> import matplotlib; print("matplotlib", matplotlib.__version__)
matplotlib 3.9.2
>>> import scipy; print("scipy", scipy.__version__)
scipy 1.14.1
>>> import skimage; print("scikit-image", skimage.__version__)
scikit-image 0.24.0
>>> import asdf; print("asdf", asdf.__version__)
asdf 3.5.0
>>> import stdatamodels; print("stdatamodels", stdatamodels.__version__)
stdatamodels 2.1.2
>>> import gwcs; print("gwcs", gwcs.__version__)
gwcs 0.21.0
>>> import regions; print("regions", regions.__version__)
regions 0.10
>>> import specutils; print("specutils", specutils.__version__)
specutils 1.19.0
>>> import specreduce; print("specreduce", specreduce.__version__)
specreduce 1.4.1
>>> import photutils; print("photutils", photutils.__version__)
photutils 2.0.2
>>> import astroquery; print("astroquery", astroquery.__version__)
astroquery 0.4.7
>>> import yaml; print("pyyaml", yaml.__version__)
pyyaml 6.0.1
>>> import asteval; print("asteval", asteval.__version__)
asteval 1.0.5
>>> import idna; print("idna", idna.__version__)
idna 3.4
>>> import traitlets; print("traitlets", traitlets.__version__)
traitlets 5.14.3
>>> import bqplot; print("bqplot", bqplot.__version__)
bqplot 0.12.43
>>> import bqplot_image_gl; print("bqplot-image-gl", bqplot_image_gl.__version__)
bqplot-image-gl 1.5.0
>>> import glue; print("glue-core", glue.__version__)
glue-core 1.21.1
>>> import glue_jupyter; print("glue-jupyter", glue_jupyter.__version__)
glue-jupyter 0.23.1
>>> import glue_astronomy; print("glue-astronomy", glue_astronomy.__version__)
glue-astronomy 0.10.0
>>> import echo; print("echo", echo.__version__)
echo 0.9.0
>>> import ipyvue; print("ipyvue", ipyvue.__version__)
ipyvue 1.11.0
>>> import ipyvuetify; print("ipyvuetify", ipyvuetify.__version__)
ipyvuetify 1.10.0
>>> import ipysplitpanes; print("ipysplitpanes", ipysplitpanes.__version__)
ipysplitpanes 0.2.0
>>> import ipygoldenlayout; print("ipygoldenlayout", ipygoldenlayout.__version__)
ipygoldenlayout 0.4.0
>>> import ipypopout; print("ipypopout", ipypopout.__version__)
ipypopout 2.0.0
>>> import jinja2; print("Jinja2", jinja2.__version__)
Jinja2 3.1.2
>>> import solara; print("solara", solara.__version__)
solara 1.40.0
>>> import vispy; print("vispy", vispy.__version__)
vispy 0.14.3
>>> import sidecar; print("sidecar", sidecar.__version__)
sidecar 0.7.0
>>> import jdaviz; print("Jdaviz", jdaviz.__version__)
Jdaviz 4.0.0
Can I work on this?
The issue with "allow_link_table" not being set to False occurs because:
- When the method is called, only path to directory and instrument are provided, while other parameters remain None.
- Since path to directory is not None, the if block at line 334 executes, skipping all linked elif statements.
- The skipped elif statements contain the logic to set "allow_link_table" to False, which is why it remains unchanged.
If it helps, what I did in my quick patch was trying to build the link table in a try/except block around line 334, and set allow_link_table to False if there was an exception (because, of course, when given a directory, there may or may not be linked 2D and 1D spectra provided).
Because of the current way that we're using jdaviz in our quicklook, where we're investigating individual files, we're currently bypassing the entire thing by treating an s2d file as a list of 2D spectra, where we use a Solara dropdown menu to let the user decide which spectrum to look at, and only load that slit using Specviz2d (because in our normal use case, getting a spectrum up quickly is more important than having everything loaded, because the user will tend to only want to see a couple of slits anyway).
Hope I'm not telling you too many things you already know.
@MarianConstantinMarica - sure, that would be great! No one is actively working on this at the moment, so feel free to open a PR if you find a solution (or reach out here if you have any questions).
@kecnry @york-stsci I fixed it. There were two additional errors (ValueError: No data found with the label 'MOS Table') on add_redshift_column and app.get_viewer methods that I also fixed.