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

TST: Fix failing tests in devdeps job #1877

Closed
pllim opened this issue Nov 29, 2022 · 3 comments · Fixed by #1881
Closed

TST: Fix failing tests in devdeps job #1877

pllim opened this issue Nov 29, 2022 · 3 comments · Fixed by #1881
Labels
bug Something isn't working specviz2d testing

Comments

@pllim
Copy link
Contributor

pllim commented Nov 29, 2022

As seen in #1873. Need to investigate failures of Specviz2d tests that use https://stsci.box.com/shared/static/exnkul627fcuhy5akf2gswytud5tazmw.fits . Maybe the file is too old and we need to use a real JWST 2D spectrum from MAST.

@pllim pllim added bug Something isn't working testing specviz2d labels Nov 29, 2022
@pllim
Copy link
Contributor Author

pllim commented Nov 30, 2022

I can reproduce the error when I install specreduce 1.2.1.dev36+g05a174d (as opposed to released version). There is no error from specreduce but it also does not show the collapsed spectrum.

@pllim
Copy link
Contributor Author

pllim commented Nov 30, 2022

Actually there is an extraction error but it was sent to snackbar, so automated test suite didn't catch it.

File .../jdaviz/configs/specviz2d/helper.py:195, in Specviz2d.load_data(self, spectrum_2d, spectrum_1d, spectrum_1d_label, spectrum_2d_label, show_in_viewer, ext, transpose)
    193 spext._trace_dataset_selected()
    194 try:
--> 195     spext.export_extract_spectrum(add_data=True)
    196 except Exception:
    197     raise

File .../jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py:892, in SpectralExtraction.export_extract_spectrum(self, add_data, **kwargs)
    882 def export_extract_spectrum(self, add_data=False, **kwargs):
    883     """
    884     Create an extracted 1D spectrum from the input parameters defined in the plugin.
    885 
   (...)
    890         defined in the plugin.
    891     """
--> 892     extract = self.export_extract(**kwargs)
    893     spectrum = extract.spectrum
    895     # Specreduce returns a spectral axis in pixels, so we'll replace with input spectral_axis
    896     # NOTE: this is currently disabled until proper handling of axes-limit linking between
    897     # the 2D spectrum image (plotted in pixels) and a 1D spectrum (plotted in freq or
    898     # wavelength) is implemented.
    899 
    900     # spectrum = Spectrum1D(spectral_axis=inp_sp2d.spectral_axis, flux=spectrum.flux)

File .../jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py:866, in SpectralExtraction.export_extract(self, **kwargs)
    863 if len(kwargs) and self.active_step != 'ext':
    864     self.update_marks(step='ext')
--> 866 trace = self._get_ext_trace()
    867 inp_sp2d = self._get_ext_input_spectrum()
    869 if self.ext_type_selected == 'Boxcar':

File .../jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py:831, in SpectralExtraction._get_ext_trace(self)
    829 def _get_ext_trace(self):
    830     if self.ext_trace_selected == 'From Plugin':
--> 831         return self.export_trace(add_data=False)
    832     else:
    833         return self.ext_trace.selected_obj

File .../jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py:654, in SpectralExtraction.export_trace(self, add_data, **kwargs)
    650         trace = tracing.ArrayTrace(self.trace_dataset.selected_obj.data,
    651                                    self.trace_trace.selected_obj.trace+self.trace_offset)
    653 elif self.trace_type_selected == 'Flat':
--> 654     trace = tracing.FlatTrace(self.trace_dataset.selected_obj.data,
    655                               self.trace_pixel)
    657 elif self.trace_type_selected == 'Auto':
    658     trace = tracing.KosmosTrace(self.trace_dataset.selected_obj.data,
    659                                 guess=self.trace_pixel,
    660                                 bins=int(self.trace_bins),
    661                                 window=self.trace_window,
    662                                 peak_method=self.trace_peak_method_selected.lower())

File <string>:5, in __init__(self, image, trace_pos)

File .../specreduce/tracing.py:100, in FlatTrace.__post_init__(self)
     99 def __post_init__(self):
--> 100     self.image = self._parse_image(self.image)
    102     self.set_position(self.trace_pos)

File .../specreduce/core.py:78, in _ImageParser._parse_image(self, image, disp_axis)
     73 unit = getattr(image, 'unit', u.Unit('DN'))
     75 spectral_axis = getattr(image, 'spectral_axis',
     76                         np.arange(img.shape[disp_axis]) * u.pix)
---> 78 return Spectrum1D(img * unit, spectral_axis=spectral_axis,
     79                   uncertainty=uncertainty, mask=mask)

File .../specutils/spectra/spectrum1d.py:268, in Spectrum1D.__init__(self, flux, spectral_axis, wcs, velocity_convention, rest_value, redshift, radial_velocity, bin_specification, **kwargs)
    265     size = flux.shape[-1] if not flux.isscalar else 1
    266     wcs = gwcs_from_array(np.arange(size) * u.Unit(""))
--> 268 super().__init__(
    269     data=flux.value if isinstance(flux, u.Quantity) else flux,
    270     wcs=wcs, **kwargs)
    272 # If no spectral_axis was provided, create a SpectralCoord based on
    273 # the WCS
    274 if spectral_axis is None:
    275     # If the WCS doesn't have a spectral attribute, we assume it's the
    276     # dummy GWCS we created or a solely spectral WCS

File .../ndcube/ndcube.py:208, in NDCubeBase.__init__(self, data, wcs, uncertainty, mask, meta, unit, copy, **kwargs)
    205 def __init__(self, data, wcs=None, uncertainty=None, mask=None, meta=None,
    206              unit=None, copy=False, **kwargs):
--> 208     super().__init__(data, uncertainty=uncertainty, mask=mask,
    209                      meta=meta, unit=unit, copy=copy, **kwargs)
    210     if not self.wcs:
    211         self.wcs = wcs  # This line is required as a patch for an astropy bug.

File .../astropy/nddata/nddata.py:251, in NDData.__init__(self, data, uncertainty, mask, wcs, meta, unit, copy, psf)
    249 # Store the attributes
    250 self._data = data
--> 251 self.mask = mask
    252 self._wcs = None
    253 if wcs is not None:
    254     # Validate the wcs

File .../specutils/spectra/spectrum1d.py:538, in Spectrum1D.mask(self, value)
    536     value = np.array(value)
    537     if not self.data.shape == value.shape:
--> 538         raise ValueError(
    539             "Flux axis ({}) and mask ({}) shapes must be the "
    540             "same.".format(self.data.shape, value.shape))
    541 self._mask = value

ValueError: Flux axis ((44, 387)) and mask (()) shapes must be the same.

@pllim
Copy link
Contributor Author

pllim commented Nov 30, 2022

I submitted astropy/specreduce#151 for the upstream portion.

After speaking with @kecnry , the rest of the errors in jdaviz is not worth fixing right now and should wait for these:

Since specreduce dev is going through a lot of API changes right now, we should not test against it. Instead, I have advised specreduce dev to test locally against jdaviz (with --remote-data) during development and definitely before release.

FWIW, this will let you see the error:

--- a/jdaviz/configs/specviz2d/helper.py
+++ b/jdaviz/configs/specviz2d/helper.py
@@ -194,6 +194,7 @@ class Specviz2d(ConfigHelper, LineListMixin):
                 try:
                     spext.export_extract_spectrum(add_data=True)
                 except Exception:
+                    raise

And this fixed 3 of the 4 errors (together with the upstream patch mentioned above):

--- a/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py
+++ b/jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py
@@ -814,9 +814,12 @@ class SpectralExtraction(PluginTemplateMixin):
             defined in the plugin.
         """
         bg = self.export_bg(**kwargs)
-
-        bg_sub_spec = Spectrum1D(spectral_axis=self.bg_dataset.selected_obj.spectral_axis,
-                                 flux=bg.sub_image()*self.bg_dataset.selected_obj.flux.unit)
+        bg_sub_img = bg.sub_image()
+        if isinstance(bg_sub_img, Spectrum1D):
+            bg_sub_spec = bg_sub_img
+        else:
+            bg_sub_spec = Spectrum1D(spectral_axis=self.bg_dataset.selected_obj.spectral_axis,
+                                     flux=bg_sub_img*self.bg_dataset.selected_obj.flux.unit)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working specviz2d testing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant