diff --git a/jdaviz/configs/mosviz/helper.py b/jdaviz/configs/mosviz/helper.py index 213abf648b..1530b9a85e 100644 --- a/jdaviz/configs/mosviz/helper.py +++ b/jdaviz/configs/mosviz/helper.py @@ -154,7 +154,11 @@ def _zoom_to_slit_params(self, msg): imview = self.app.get_viewer("image-viewer") specview = self.app.get_viewer("spectrum-2d-viewer") - sky_region = jwst_header_to_skyregion(specview.layers[0].layer.meta) + try: + sky_region = jwst_header_to_skyregion(specview.layers[0].layer.meta) + except KeyError: + # If the header didn't have slit params, can't zoom to it. + return None, None ra = sky_region.center.ra.deg dec = sky_region.center.dec.deg @@ -254,6 +258,9 @@ def load_data(self, spectra_1d=None, spectra_2d=None, images=None, msg = SnackbarMessage(msg, color='warning', sender=self) self.app.hub.broadcast(msg) + # Load the first object into the viewers automatically + self.app.get_viewer("table-viewer").figure_widget.highlighted = 0 + def load_spectra(self, spectra_1d, spectra_2d): """ Load 1D and 2D spectra using lists or strings to represent each. @@ -287,9 +294,6 @@ def load_spectra_from_directory(self, directory, instrument): """ self.load_data(directory=directory, instrument=instrument) - # Load the first object into the viewers automatically - self.app.get_viewer("table-viewer").figure_widget.highlighted = 0 - def load_metadata(self, data_obj): """ Load and parse a set of FITS objects to extract any relevant metadata. @@ -340,8 +344,6 @@ def load_2d_spectra(self, data_obj, data_labels=None): def load_niriss_data(self, data_obj, data_labels=None): super().load_data(data_obj, parser_reference="mosviz-niriss-parser") - # Load the first object into the viewers automatically - self.app.get_viewer("table-viewer").figure_widget.highlighted = 0 def load_images(self, data_obj, data_labels=None, share_image=0): """ diff --git a/notebooks/MosvizNIRISSExample.ipynb b/notebooks/MosvizNIRISSExample.ipynb index cea3e65ea3..ae647501fa 100644 --- a/notebooks/MosvizNIRISSExample.ipynb +++ b/notebooks/MosvizNIRISSExample.ipynb @@ -116,7 +116,7 @@ "source": [ "mosviz.load_data(directory=data_dir, instrument=\"niriss\")" ] - }, + } ], "metadata": { "kernelspec": {