Skip to content

Commit

Permalink
review comments from Ricky
Browse files Browse the repository at this point in the history
  • Loading branch information
bmorris3 committed Oct 3, 2024
1 parent 5a0e861 commit d4a1fb7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 31 deletions.
7 changes: 7 additions & 0 deletions jdaviz/configs/imviz/plugins/coords_info/coords_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ def _get_cube_value(self, image, arr, x, y, viewer):
# cubeviz case:
return arr[int(round(x)), int(round(y)), viewer.state.slices[-1]]
elif image.ndim == 2:
if isinstance(viewer, RampvizImageView):
x, y = y, x
return arr[int(round(y)), int(round(x))]
else: # pragma: no cover
raise ValueError(f'does not support ndim={image.ndim}')
Expand Down Expand Up @@ -379,6 +381,11 @@ def _image_viewer_update(self, viewer, x, y):
elif isinstance(viewer, RampvizImageView):
coords_status = False

slice_plugin = self.app._jdaviz_helper.plugins.get('Slice', None)
if slice_plugin is not None and len(image.shape) == 3:
# float to be compatible with default value of nan
self._dict['slice'] = float(viewer.slice)

elif isinstance(viewer, MosvizImageView):

if data_has_valid_wcs(image, ndim=2):
Expand Down
17 changes: 11 additions & 6 deletions jdaviz/configs/rampviz/plugins/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def move_group_axis_last(x):
# swap axes per the conventions of ramp cubes
# (group axis comes first) and the default in
# rampviz (group axis expected last)
return np.swapaxes(x, 0, -1)
return np.transpose(x, (1, 2, 0))


def _roman_3d_to_glue_data(
Expand Down Expand Up @@ -201,7 +201,7 @@ def _roman_3d_to_glue_data(
data_reshaped
)
app._jdaviz_helper.cube_cache[ramp_diff_data_label] = NDDataArray(
move_group_axis_last(diff_data)
diff_data_reshaped
)

if meta is not None:
Expand Down Expand Up @@ -254,9 +254,12 @@ def _parse_hdulist(
app._jdaviz_helper.create_image_viewer(viewer_name=new_viewer_name)

# add the SCI extension to the level-2 viewer:
if 'SCI' in ext:
if not ext:
idx = 1
elif ext and ('SCI' in ext or ext == '*'):
idx = len(ext) - ext.index('SCI')
app.add_data_to_viewer(new_viewer_name, app.data_collection[-idx].label)

app.add_data_to_viewer(new_viewer_name, app.data_collection[-idx].label)
return

elif hdu.header['NAXIS'] != 4:
Expand Down Expand Up @@ -301,8 +304,10 @@ def _parse_ramp_cube(app, ramp_cube_data, flux_unit, file_name,
np.diff(ramp_cube_data, axis=0)
])

ramp_data = move_group_axis_last(ramp_cube_data)
ramp_cube = NDDataArray(ramp_data, unit=flux_unit, meta=meta)
# ramp_data = move_group_axis_last(ramp_cube_data)
# ramp_cube = NDDataArray(ramp_data, unit=flux_unit, meta=meta)
# diff_cube = NDDataArray(move_group_axis_last(diff_data), unit=flux_unit, meta=meta)
ramp_cube = NDDataArray(move_group_axis_last(ramp_cube_data), unit=flux_unit, meta=meta)
diff_cube = NDDataArray(move_group_axis_last(diff_data), unit=flux_unit, meta=meta)

group_data_label = app.return_data_label(file_name, ext="DATA")
Expand Down
39 changes: 14 additions & 25 deletions jdaviz/configs/rampviz/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,23 @@ def test_load_rectangular_ramp(rampviz_helper, jwst_level_1b_rectangular_ramp):

parsed_cube_shape = rampviz_helper.app.data_collection[0].shape
assert parsed_cube_shape == (
original_cube_shape[2], original_cube_shape[1], original_cube_shape[0]
original_cube_shape[1], original_cube_shape[2], original_cube_shape[0]
)


def test_load_nirspec_irs2(rampviz_helper, jwst_level_1b_rectangular_ramp):
# update the Level1bModel to have the header cards that are
# expected for an exposure from NIRSpec in IRS2 readout mode
jwst_level_1b_rectangular_ramp.update(
{
'meta': {
'_primary_header': {
"TELESCOP": "JWST",
"INSTRUME": "NIRSPEC",
"READPATT": "NRSIRS2"
}
}
}
)
def test_load_level_1_and_2(
rampviz_helper,
jwst_level_1b_rectangular_ramp,
jwst_level_2c_rate_image
):
# load level 1 ramp and level 2 rate image
rampviz_helper.load_data(jwst_level_1b_rectangular_ramp)
rampviz_helper.load_data(jwst_level_2c_rate_image)

# drop the integration axis
original_cube_shape = jwst_level_1b_rectangular_ramp.shape[1:]

# on ramp cube load (1), the parser loads a diff cube (2) and
# the ramp extraction plugin produces a default extraction (3):
assert len(rampviz_helper.app.data_collection) == 3
# confirm that a "level-2" viewer is created, and that
# the rate image is loaded into it
assert len(rampviz_helper.viewers) == 4
assert 'level-2' in rampviz_helper.viewers

parsed_cube_shape = rampviz_helper.app.data_collection[0].shape
assert parsed_cube_shape == (
original_cube_shape[2], original_cube_shape[1], original_cube_shape[0]
)
layers = rampviz_helper.app.get_viewer('level-2').layers
assert len(layers) == 1
7 changes: 7 additions & 0 deletions jdaviz/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ def jwst_level_1b_rectangular_ramp():
return _make_jwst_ramp(shape=(1, 10, 32, 25))


@pytest.fixture
def jwst_level_2c_rate_image():
flux_hdu = fits.ImageHDU(np.ones((32, 25)))
flux_hdu.name = 'FLUX'
return fits.HDUList([fits.PrimaryHDU(), flux_hdu])


@pytest.fixture
def image_2d_wcs():
return WCS({'CTYPE1': 'RA---TAN', 'CUNIT1': 'deg', 'CDELT1': -0.0002777777778,
Expand Down

0 comments on commit d4a1fb7

Please sign in to comment.