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

Debug cubeviz spectrum1d parser #3133

Merged
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -196,6 +196,8 @@ Bug Fixes
Cubeviz
^^^^^^^

- No longer incorrectly swap RA and Dec axes when loading Spectrum1D objects. [#3133]

Imviz
^^^^^

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def test_moment_calculation(cubeviz_helper, spectrum1d_cube, tmp_path):
)

result = dc[-1].get_object(cls=CCDData)
assert result.shape == (4, 2) # Cube shape is (2, 2, 4)
assert result.shape == (2, 4) # Cube shape is (2, 2, 4), moment transposes
rosteen marked this conversation as resolved.
Show resolved Hide resolved
assert isinstance(dc[-1].coords, WCS)

# Make sure coordinate display now show moment map info (no WCS)
Expand Down
2 changes: 0 additions & 2 deletions jdaviz/configs/cubeviz/plugins/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,6 @@ def _parse_spectrum1d_3d(app, file_obj, data_label=None,
else:
flux = val

flux = np.moveaxis(flux, 1, 0)

with warnings.catch_warnings():
warnings.filterwarnings(
'ignore', message='Input WCS indicates that the spectral axis is not last',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,8 @@ def test_extraction_composite_subset(cubeviz_helper, spectrum1d_cube):
subset_plugin = cubeviz_helper.plugins['Subset Tools']._obj
spec_extr_plugin = cubeviz_helper.plugins['Spectral Extraction']._obj

lower_aperture = RectangularROI(-0.5, 1.5, -0.5, 0.5)
upper_aperture = RectangularROI(-0.5, 1.5, 2.5, 3.5)
lower_aperture = RectangularROI(-0.5, 0.5, -0.5, 1.5)
upper_aperture = RectangularROI(2.5, 3.5, -0.5, 1.5)

flux_viewer.toolbar.active_tool = flux_viewer.toolbar.tools['bqplot:rectangle']
flux_viewer.apply_roi(lower_aperture)
Expand All @@ -514,14 +514,14 @@ def test_extraction_composite_subset(cubeviz_helper, spectrum1d_cube):
spectrum_2 = spec_extr_plugin.extract()

subset_plugin.subset_selected = 'Create New'
rectangle = RectangularROI(-0.5, 1.5, -0.5, 3.5)
rectangle = RectangularROI(-0.5, 3.5, -0.5, 1.5)
flux_viewer.toolbar.active_tool = flux_viewer.toolbar.tools['bqplot:rectangle']
flux_viewer.apply_roi(rectangle)

flux_viewer.toolbar.active_tool = flux_viewer.toolbar.tools['bqplot:truecircle']
subset_plugin.subset_selected = 'Subset 3'
cubeviz_helper.app.session.edit_subset_mode.mode = AndNotMode
circle = CircularROI(0.5, 1.5, 1.1)
circle = CircularROI(1.5, 0.5, 1.1)
flux_viewer.apply_roi(circle)

spec_extr_plugin.aperture_selected = 'Subset 3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ def test_cubeviz_aperphot_cube_orig_flux_mjysr(cubeviz_helper, spectrum1d_cube_c
cube = spectrum1d_cube_custom_fluxunit(fluxunit=u.MJy / u.sr)
cubeviz_helper.load_data(cube, data_label="test")

aper = RectanglePixelRegion(center=PixCoord(x=1, y=3), width=1, height=1)
bg = RectanglePixelRegion(center=PixCoord(x=0, y=2), width=1, height=1)
aper = RectanglePixelRegion(center=PixCoord(x=3, y=1), width=1, height=1)
bg = RectanglePixelRegion(center=PixCoord(x=2, y=0), width=1, height=1)
cubeviz_helper.load_regions([aper, bg])

plg = cubeviz_helper.plugins["Aperture Photometry"]._obj
Expand All @@ -183,8 +183,8 @@ def test_cubeviz_aperphot_cube_orig_flux_mjysr(cubeviz_helper, spectrum1d_cube_c
row = cubeviz_helper.get_aperture_photometry_results()[0]

# Basically, we should recover the input rectangle here, minus background.
assert_allclose(row["xcenter"], 1 * u.pix)
assert_allclose(row["ycenter"], 3 * u.pix)
assert_allclose(row["xcenter"], 3 * u.pix)
assert_allclose(row["ycenter"], 1 * u.pix)
assert_allclose(row["sum"], 1.1752215e-12 * u.MJy) # (15 - 10) MJy/sr x 2.3504431e-13 sr
assert_allclose(row["sum_aper_area"], 1 * (u.pix * u.pix))
assert_allclose(row["pixarea_tot"], 2.350443053909789e-13 * u.sr)
Expand Down
4 changes: 2 additions & 2 deletions jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ def test_get_data_spatial_and_spectral(cubeviz_helper, spectrum1d_cube_larger):
assert spatial_with_spec.flux.ndim == 1
assert list(spatial_with_spec.mask) == [True, True, False, False, True,
True, True, True, True, True]
assert max(list(spatial_with_spec.flux.value)) == 157.
assert min(list(spatial_with_spec.flux.value)) == 13.
assert max(list(spatial_with_spec.flux.value)) == 232.
assert min(list(spatial_with_spec.flux.value)) == 16.
2 changes: 1 addition & 1 deletion jdaviz/configs/cubeviz/plugins/tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def test_spectrum3d_no_wcs_parse(cubeviz_helper):
data = cubeviz_helper.app.data_collection[0]
flux = data.get_component('flux')
assert data.label.endswith('[FLUX]')
assert data.shape == (3, 2, 4) # y, x, z
assert data.shape == (2, 3, 4) # y, x, z
rosteen marked this conversation as resolved.
Show resolved Hide resolved
rosteen marked this conversation as resolved.
Show resolved Hide resolved
assert isinstance(data.coords, PaddedSpectrumWCS)
assert_array_equal(flux.data, 1)
assert flux.units == 'nJy'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ def test_spatial_convolution(cubeviz_helper, spectrum1d_cube):

assert len(dc) == 3
assert dc[-1].label == f'{data_label}[FLUX] spatial-smooth stddev-3.0'
assert dc[-1].shape == (2, 4, 2) # specutils moved spectral axis to last
assert dc[-1].shape == (4, 2, 2) # specutils moved spectral axis to last
assert (dc[f'{data_label}[FLUX] spatial-smooth stddev-3.0'].get_object(cls=Spectrum1D,
statistic=None).shape
== (2, 4, 2))
== (4, 2, 2))


def test_specviz_smooth(specviz_helper, spectrum1d):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ def test_parameter_retrieval(cubeviz_helper, spectral_cube_wcs):
plugin.calculate_fit()

params = cubeviz_helper.get_model_parameters()
slope_res = np.zeros((4, 3))
slope_res = np.zeros((3, 4))
slope_res[2, 2] = 1.0
slope_res = slope_res * u.nJy / u.Hz
intercept_res = np.ones((4, 3))
intercept_res = np.ones((3, 4))
intercept_res[2, 2] = 0
intercept_res = intercept_res * u.nJy
assert_quantity_allclose(params['model']['slope'], slope_res,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def test_fit_cube_no_wcs(cubeviz_helper):
assert len(fitted_model) == 56 # ny * nx
# Make sure shapes are all self-consistent within Cubeviz instance.
fitted_data = cubeviz_helper.app.data_collection["model"]
assert fitted_data.shape == (8, 7, 9) # nx, ny, nz
assert fitted_data.shape == (7, 8, 9) # nx, ny, nz
pllim marked this conversation as resolved.
Show resolved Hide resolved
assert fitted_data.shape == cubeviz_helper.app.data_collection[0].shape
assert fitted_data.shape == output_cube.shape

Expand Down
4 changes: 2 additions & 2 deletions jdaviz/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ def spectrum1d_cube_largest():
"CDELT1": 8e-11, "CDELT2": 0.0001, "CDELT3": -0.0001,
"CRPIX1": 0, "CRPIX2": 0, "CRPIX3": 0}
w = WCS(wcs_dict)
flux = np.zeros((30, 20, 3001), dtype=np.float32) # nx=20 ny=30 nz=3001
flux[5:15, 1:11, :] = 1 # Bright corner
flux = np.zeros((20, 30, 3001), dtype=np.float32) # nx=20 ny=30 nz=3001
flux[1:11, 5:15, :] = 1 # Bright corner
return Spectrum1D(flux=flux * u.Jy, wcs=w, meta=wcs_dict)


Expand Down