-
Notifications
You must be signed in to change notification settings - Fork 74
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
Add ability to load 2D flux arrays in Specviz #3229
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3229 +/- ##
==========================================
- Coverage 88.62% 88.61% -0.01%
==========================================
Files 125 125
Lines 18775 18794 +19
==========================================
+ Hits 16639 16655 +16
- Misses 2136 2139 +3 ☔ View full report in Codecov by Sentry. |
elif path.is_file(): | ||
try: | ||
data = [Spectrum1D.read(str(path), format=format)] | ||
data_label = [app.return_data_label(data_label, alt_name="specviz_data")] | ||
data = Spectrum1D.read(str(path), format=format) | ||
if data.flux.ndim == 2: | ||
data, data_label = split_spectrum_with_2D_flux_array(data, data_label, app) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In our file case, there are 2 data extensions, with the 1st having a 1d flux array, and the 2nd one having the nd flux array. Without the load_as_list
flag, this block only loads the first extension and never reaches line 97. With load_as_list
set, which is the way I think we need to load these files, I get the error
File [~/Work/jdaviz/jdaviz/configs/specviz/plugins/parsers.py:129](http://localhost:8888/lab/workspaces/auto-b/tree/~/Work/jdaviz/jdaviz/configs/specviz/plugins/parsers.py#line=128), in specviz_spectrum1d_parser(app, data, data_label, format, show_in_viewer, concat_by_file, cache, local_path, timeout, load_as_list)
127 for wlind in range(len(spec.spectral_axis)):
128 wlallorig.append(spec.spectral_axis[wlind].value)
--> 129 fnuallorig.append(spec.flux[wlind].value)
131 # because some spec in the list might have uncertainties and
132 # others may not, if uncert is None, set to list of NaN. later,
133 # if the concatenated list of uncertanties is all nan (meaning
134 # they were all nan to begin with, or all None), it will be set
135 # to None on the final Spectrum1D
136 if spec.uncertainty[wlind] is not None:
File [~/anaconda3/envs/newsv/lib/python3.11/site-packages/astropy/units/quantity.py:1302](http://localhost:8888/lab/workspaces/auto-b/tree/~/anaconda3/envs/newsv/lib/python3.11/site-packages/astropy/units/quantity.py#line=1301), in Quantity.__getitem__(self, key)
1297 return self._new_view(
1298 self.view(np.ndarray)[key], self.unit[key], propagate_info=False
1299 )
1301 try:
-> 1302 out = super().__getitem__(key)
1303 except IndexError:
1304 # We want zero-dimensional Quantity objects to behave like scalars,
1305 # so they should raise a TypeError rather than an IndexError.
1306 if self.isscalar:
IndexError: index 1 is out of bounds for axis 0 with size 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think what I've done should fix this bug. It occurs when there's 2D spectra in a SpectrumList
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, with your PR it loads correctly, but your PR is basically unpacking the nd arrays into individual Spectrum1D objects, which this draft code is also doing. In principle, with the change here, we don't need to manually unpack the nd fluxes inside the loader.
This draft code should work loading nd-flux data more generally, outside of the specific mwm loader
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I've already reverted that back to how it was initially, see specutils#1185, ca4d8c
Should Most of the multi-extension default loaders are only implemented as |
Also on metadata -- we could make the 2D-to-1D converter split list-like metadata objects with the same length as |
Closes #3223, opening as draft to see if this will fix the desired use case based on upstream changes. This splits a Spectrum1D with 2D flux into separate Spectrum1D objects before loading into Specviz.