diff --git a/jdaviz/configs/imviz/plugins/coords_info/coords_info.py b/jdaviz/configs/imviz/plugins/coords_info/coords_info.py index 8ab0874571..07b805baab 100644 --- a/jdaviz/configs/imviz/plugins/coords_info/coords_info.py +++ b/jdaviz/configs/imviz/plugins/coords_info/coords_info.py @@ -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}') @@ -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): diff --git a/jdaviz/configs/rampviz/plugins/parsers.py b/jdaviz/configs/rampviz/plugins/parsers.py index 7b02443082..c8d9b08884 100644 --- a/jdaviz/configs/rampviz/plugins/parsers.py +++ b/jdaviz/configs/rampviz/plugins/parsers.py @@ -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( @@ -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: @@ -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: @@ -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") diff --git a/jdaviz/configs/rampviz/tests/test_parser.py b/jdaviz/configs/rampviz/tests/test_parser.py index f0d7aa4b6a..570026db3e 100644 --- a/jdaviz/configs/rampviz/tests/test_parser.py +++ b/jdaviz/configs/rampviz/tests/test_parser.py @@ -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 diff --git a/jdaviz/conftest.py b/jdaviz/conftest.py index a5f2e11b8c..ec1fdc7a32 100644 --- a/jdaviz/conftest.py +++ b/jdaviz/conftest.py @@ -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,