Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Cubeviz spectral extraction to ignore NaNs by masking them out #2737

Merged
merged 2 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ Bug Fixes
Cubeviz
^^^^^^^

- Spectral extraction now ignores NaNs. [#2737]

Imviz
^^^^^

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ def collapse_to_spectrum(self, add_data=True, **kwargs):
else:
wcs = spectral_cube.coords.spectral

# Filter out NaNs (False = good)
mask = np.logical_or(mask, np.isnan(flux))

nddata_reshaped = NDDataArray(
flux, mask=mask, uncertainty=uncertainties, wcs=wcs, meta=nddata.meta
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,16 @@ def test_cone_aperture_with_frequency_units(cubeviz_helper, spectral_cube_wcs):

with pytest.raises(ValueError, match="Spectral axis unit physical type is"):
extract_plg.collapse_to_spectrum()


def test_cube_extraction_with_nan(cubeviz_helper, image_cube_hdu_obj):
image_cube_hdu_obj[1].data[:, :2, :2] = np.nan
cubeviz_helper.load_data(image_cube_hdu_obj, data_label="with_nan")
extract_plg = cubeviz_helper.plugins['Spectral Extraction']
sp = extract_plg.collapse_to_spectrum() # Default settings (sum)
assert_allclose(sp.flux.value, 96) # (10 x 10) - 4

cubeviz_helper.load_regions(RectanglePixelRegion(PixCoord(1.5, 1.5), width=4, height=4))
extract_plg.aperture = 'Subset 1'
sp_subset = extract_plg.collapse_to_spectrum() # Default settings but on Subset
assert_allclose(sp_subset.flux.value, 12) # (4 x 4) - 4
Loading