Skip to content

Commit

Permalink
Rename Subset Tools Plugin (#3293)
Browse files Browse the repository at this point in the history
* Rename Subset Tools plugin

* Continue with renaming subset tools

* Fix codestyle and update docstring

* Add a change log

* Fix failing test

* Remove direct use of _obj in notebooks

* Remove _obj from tests

* Remove remaining _obj reference

* Continue with removing of redundant _obj

* Remove .selected from tests

* Clean up remaining redundant calls

* Revert removal _obj calls on unexposed api.s

* Fix tests

* Revert latest changes

* Fix tests enforcing non exposed apis with _obj

* Fix code syle

* Update CHANGES.rst

Co-authored-by: Kyle Conroy <[email protected]>

* Fix typo in notebooks

* Codestyle

* Suppress output
  • Loading branch information
haticekaratay authored Nov 18, 2024
1 parent f4923fd commit 8c93c74
Show file tree
Hide file tree
Showing 48 changed files with 360 additions and 336 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Specviz2d
API Changes
-----------
- Removed API access to plugins that have passed the deprecation period: Links Control, Canvas Rotation, Export Plot. [#3270]

- Renamed the ``Subset Tools`` plugin to ``Subsets`` which now exposes the ``subset``, ``combination_mode``, ``get_center``, and ``set_center`` in the user API. [#3293]

Cubeviz
^^^^^^^
Expand Down
4 changes: 2 additions & 2 deletions docs/cubeviz/import_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,15 @@ can load the regions into Cubeviz as follows:

.. code-block:: python
cubeviz.plugins['Subset Tools']._obj.import_region("/path/to/data/myregions.reg")
cubeviz.plugins['Subsets'].import_region("/path/to/data/myregions.reg")
Unsupported regions will be skipped and trigger a warning. Those that
failed to load, if any, can be returned as a list of tuples of the
form ``(region, reason)``:

.. code-block:: python
bad_regions = cubeviz.plugins['Subset Tools']._obj.import_region("/path/to/data/myregions.reg", return_bad_regions=True)
bad_regions = cubeviz.plugins['Subsets'].import_region("/path/to/data/myregions.reg", return_bad_regions=True)
.. note:: Sky regions are currently unsupported in Cubeviz, unlike Imviz.

Expand Down
6 changes: 3 additions & 3 deletions docs/cubeviz/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ Visualize data quality arrays for spectral cubes from JWST.

.. _cubeviz-subset-plugin:

Subset Tools
============
Subsets
=======

.. seealso::

:ref:`Subset Tools <imviz-subset-plugin>`
:ref:`Subsets <imviz-subset-plugin>`
Imviz documentation describing the concept of subsets in Jdaviz.


Expand Down
4 changes: 2 additions & 2 deletions docs/imviz/import_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,15 @@ can load the regions into Imviz as follows:

.. code-block:: python
imviz.plugins['Subset Tools']._obj.import_region("/path/to/data/myregions.reg")
imviz.plugins['Subsets'].import_region("/path/to/data/myregions.reg")
Unsupported regions will be skipped and trigger a warning. Those that
failed to load, if any, can be returned as a list of tuples of the
form ``(region, reason)``:

.. code-block:: python
bad_regions = imviz.plugins['Subset Tools']._obj.import_region("/path/to/data/myregions.reg", return_bad_regions=True)
bad_regions = imviz.plugins['Subsets'].import_region("/path/to/data/myregions.reg", return_bad_regions=True)
You could also define :ref:`regions:shapes` programmatically and load them; e.g.:

Expand Down
4 changes: 2 additions & 2 deletions docs/imviz/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ in the "Filter by bits" dropdown, or from the API we could:
.. _imviz-subset-plugin:

Subset Tools
============
Subsets
=======

This plugin allows you to select an existing subset to modify, or to select
:guilabel:`Create new` to create a new subset by selecting and using the region selector
Expand Down
6 changes: 3 additions & 3 deletions docs/mosviz/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ This plugin gives access to per-viewer and per-layer plotting options.

.. _mosviz-subset-plugin:

Subset Tools
============
Subsets
=======

.. seealso::

:ref:`Subset Tools <imviz-subset-plugin>`
:ref:`Subsets <imviz-subset-plugin>`
Imviz documentation describing the concept of subsets in Jdaviz.

.. _imviz_export_markers:
Expand Down
6 changes: 3 additions & 3 deletions docs/rampviz/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ To show axes on image viewers, toggle on the "Show axes" option at the bottom of

.. _rampviz-subset-plugin:

Subset Tools
============
Subsets
=======

.. seealso::

:ref:`Subset Tools <imviz-subset-plugin>`
:ref:`Subsets <imviz-subset-plugin>`
Imviz documentation describing the concept of subsets in Jdaviz.


Expand Down
6 changes: 3 additions & 3 deletions docs/specviz/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ Plot Options

.. _specviz-subset-plugin:

Subset Tools
============
Subsets
=======

.. seealso::

:ref:`Subset Tools <imviz-subset-plugin>`
:ref:`Subsets <imviz-subset-plugin>`
Imviz documentation describing the concept of subsets in Jdaviz. Subsets
in Specviz are strictly spectral subsets and do not support rotation or
recentering.
Expand Down
6 changes: 3 additions & 3 deletions docs/specviz2d/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ Plot Options

.. _specviz2d-subset-plugin:

Subset Tools
============
Subsets
=======

.. seealso::

:ref:`Subset Tools <imviz-subset-plugin>`
:ref:`Subsets <imviz-subset-plugin>`
Imviz documentation describing the concept of subsets in Jdaviz.

Markers
Expand Down
2 changes: 1 addition & 1 deletion jdaviz/components/data_menu_subset_edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<v-list dense style="width: 300px">
<v-list-item>
<v-list-item-content>
<j-tooltip :tooltipcontent="'Open '+subset_selected+' in Subset Tools plugin'">
<j-tooltip :tooltipcontent="'Open '+subset_selected+' in Subsets plugin'">
<span
style="cursor: pointer; width: 100%"
@click="() => {$emit('view-info')}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ def test_moment_frequency_unit_conversion(cubeviz_helper, spectrum1d_cube_larger
mm = cubeviz_helper.plugins['Moment Maps']

unit = u.Unit(uc.spectral_unit.selected)
cubeviz_helper.plugins['Subset Tools']._obj.import_region(SpectralRegion(4.624e-07 * unit,
4.627e-07 * unit))
cubeviz_helper.plugins['Subsets'].import_region(SpectralRegion(4.624e-07 * unit,
4.627e-07 * unit))

uc.spectral_unit = 'Hz'
mm.spectral_subset = 'Subset 1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_gauss_smooth_before_spec_extract(cubeviz_helper, spectrum1d_cube_with_u
# two-pixel region:
CirclePixelRegion(PixCoord(0.5, 0), radius=1.2)
]
cubeviz_helper.plugins['Subset Tools']._obj.import_region(regions, combination_mode='new')
cubeviz_helper.plugins['Subsets'].import_region(regions, combination_mode='new')

extract_plugin = cubeviz_helper.plugins['Spectral Extraction']
extract_plugin.function = "Sum"
Expand Down Expand Up @@ -123,7 +123,7 @@ def test_subset(
]

cubeviz_helper.load_data(spectrum1d_cube_with_uncerts)
cubeviz_helper.plugins['Subset Tools']._obj.import_region(regions, combination_mode='new')
cubeviz_helper.plugins['Subsets'].import_region(regions, combination_mode='new')

plg = cubeviz_helper.plugins['Spectral Extraction']
plg.function = function
Expand Down Expand Up @@ -174,7 +174,7 @@ def test_extracted_file_in_export_plugin(cubeviz_helper, spectrum1d_cube_with_un
def test_aperture_markers(cubeviz_helper, spectrum1d_cube):

cubeviz_helper.load_data(spectrum1d_cube)
cubeviz_helper.plugins['Subset Tools']._obj.import_region(
cubeviz_helper.plugins['Subsets'].import_region(
[CirclePixelRegion(PixCoord(0.5, 0), radius=1.2)])

extract_plg = cubeviz_helper.plugins['Spectral Extraction']
Expand Down Expand Up @@ -227,9 +227,9 @@ def test_cone_aperture_with_different_methods(cubeviz_helper, spectrum1d_cube_la
expected_flux_2400):
cubeviz_helper.load_data(spectrum1d_cube_largest)
center = PixCoord(5, 10)
cubeviz_helper.plugins['Subset Tools']._obj.import_region(
cubeviz_helper.plugins['Subsets'].import_region(
CirclePixelRegion(center, radius=2.5), combination_mode='new')
cubeviz_helper.plugins['Subset Tools']._obj.import_region(
cubeviz_helper.plugins['Subsets'].import_region(
EllipsePixelRegion(center, width=5, height=5), combination_mode='new')

extract_plg = cubeviz_helper.plugins['Spectral Extraction']
Expand Down Expand Up @@ -260,7 +260,7 @@ def test_cylindrical_aperture_with_different_methods(cubeviz_helper, spectrum1d_
subset, aperture_method, expected_flux_wav):
cubeviz_helper.load_data(spectrum1d_cube_largest, data_label="test")
center = PixCoord(5, 10)
cubeviz_helper.plugins['Subset Tools']._obj.import_region([
cubeviz_helper.plugins['Subsets'].import_region([
CirclePixelRegion(center, radius=2.5),
EllipsePixelRegion(center, width=5, height=5)], combination_mode='new')

Expand All @@ -284,7 +284,7 @@ def test_cylindrical_aperture_with_different_methods(cubeviz_helper, spectrum1d_
# NOTE: Not as thorough as circle and ellipse above but good enough.
def test_rectangle_aperture_with_exact(cubeviz_helper, spectrum1d_cube_largest):
cubeviz_helper.load_data(spectrum1d_cube_largest)
cubeviz_helper.plugins['Subset Tools']._obj.import_region(
cubeviz_helper.plugins['Subsets'].import_region(
RectanglePixelRegion(PixCoord(5, 10), width=4, height=4))

extract_plg = cubeviz_helper.plugins['Spectral Extraction']
Expand Down Expand Up @@ -312,7 +312,7 @@ def test_background_subtraction(cubeviz_helper, spectrum1d_cube_largest):
spectrum1d_cube_largest = spectrum1d_cube_largest + 1 * u.Jy

cubeviz_helper.load_data(spectrum1d_cube_largest)
cubeviz_helper.plugins['Subset Tools']._obj.import_region([
cubeviz_helper.plugins['Subsets'].import_region([
CirclePixelRegion(PixCoord(5, 10), radius=2.5),
EllipsePixelRegion(PixCoord(13, 10), width=3, height=5)], combination_mode='new')

Expand Down Expand Up @@ -365,7 +365,7 @@ def test_background_subtraction(cubeviz_helper, spectrum1d_cube_largest):
def test_cone_and_cylinder_errors(cubeviz_helper, spectrum1d_cube_largest):
cubeviz_helper.load_data(spectrum1d_cube_largest)
center = PixCoord(5, 10)
cubeviz_helper.plugins['Subset Tools']._obj.import_region([
cubeviz_helper.plugins['Subsets'].import_region([
CirclePixelRegion(center, radius=2.5),
CircleAnnulusPixelRegion(center, inner_radius=2.5, outer_radius=4)], combination_mode='new')

Expand All @@ -392,7 +392,7 @@ def test_cone_and_cylinder_errors(cubeviz_helper, spectrum1d_cube_largest):
def test_cone_aperture_with_frequency_units(cubeviz_helper, spectral_cube_wcs):
data = Spectrum1D(flux=np.ones((128, 129, 256)) * u.nJy, wcs=spectral_cube_wcs)
cubeviz_helper.load_data(data, data_label="Test Flux")
cubeviz_helper.plugins['Subset Tools']._obj.import_region(
cubeviz_helper.plugins['Subsets'].import_region(
[CirclePixelRegion(PixCoord(14, 15), radius=2.5)])

extract_plg = cubeviz_helper.plugins['Spectral Extraction']
Expand All @@ -413,7 +413,7 @@ def test_cube_extraction_with_nan(cubeviz_helper, image_cube_hdu_obj):
sp = extract_plg.extract() # Default settings (sum)
assert_allclose(sp.flux.value, 9.6E-16) # (10 x 10) - 4

cubeviz_helper.plugins['Subset Tools']._obj.import_region(
cubeviz_helper.plugins['Subsets'].import_region(
RectanglePixelRegion(PixCoord(1.5, 1.5), width=4, height=4))
extract_plg.aperture = 'Subset 1'
sp_subset = extract_plg.extract() # Default settings but on Subset
Expand All @@ -422,7 +422,7 @@ def test_cube_extraction_with_nan(cubeviz_helper, image_cube_hdu_obj):

def test_autoupdate_results(cubeviz_helper, spectrum1d_cube_largest):
cubeviz_helper.load_data(spectrum1d_cube_largest)
cubeviz_helper.plugins['Subset Tools']._obj.import_region(
cubeviz_helper.plugins['Subsets'].import_region(
CircularROI(xc=5, yc=5, radius=2))

extract_plg = cubeviz_helper.plugins['Spectral Extraction']
Expand All @@ -434,8 +434,8 @@ def test_autoupdate_results(cubeviz_helper, spectrum1d_cube_largest):
# orig_med_flux = np.median(cubeviz_helper.get_data('extracted').flux)

# replace Subset 1 with a larger subset, resulting fluxes should increase
cubeviz_helper.plugins['Subset Tools']._obj.combination_mode.selected = 'replace'
cubeviz_helper.plugins['Subset Tools']._obj.import_region(CircularROI(xc=5, yc=5, radius=3))
cubeviz_helper.plugins['Subsets'].combination_mode = 'replace'
cubeviz_helper.plugins['Subsets'].import_region(CircularROI(xc=5, yc=5, radius=3))

# update should take place automatically, but since its async, we'll call manually to ensure
# the update is complete before comparing results
Expand All @@ -449,7 +449,7 @@ def test_autoupdate_results(cubeviz_helper, spectrum1d_cube_largest):

def test_aperture_composite_detection(cubeviz_helper, spectrum1d_cube):
cubeviz_helper.load_data(spectrum1d_cube)
subset_plugin = cubeviz_helper.plugins['Subset Tools']._obj
subset_plugin = cubeviz_helper.plugins['Subsets']
spec_extr_plugin = cubeviz_helper.plugins['Spectral Extraction']._obj

# create a rectangular subset with all spaxels:
Expand All @@ -463,7 +463,7 @@ def test_aperture_composite_detection(cubeviz_helper, spectrum1d_cube):
# now remove from this subset a circular region in the center:
circle = CircularROI(0.5, 1.5, 1)

subset_plugin.combination_mode.selected = 'andnot'
subset_plugin.combination_mode = 'andnot'
subset_plugin.import_region(circle)

# now the subset is composite:
Expand All @@ -473,14 +473,14 @@ def test_aperture_composite_detection(cubeviz_helper, spectrum1d_cube):
def test_extraction_composite_subset(cubeviz_helper, spectrum1d_cube):
cubeviz_helper.load_data(spectrum1d_cube)

subset_plugin = cubeviz_helper.plugins['Subset Tools']._obj
subset_plugin = cubeviz_helper.plugins['Subsets']
spec_extr_plugin = cubeviz_helper.plugins['Spectral Extraction']._obj

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

subset_plugin.import_region(lower_aperture)
subset_plugin.combination_mode.selected = 'new'
subset_plugin.combination_mode = 'new'
subset_plugin.import_region(upper_aperture)

spec_extr_plugin.aperture_selected = 'Subset 1'
Expand All @@ -491,13 +491,13 @@ def test_extraction_composite_subset(cubeviz_helper, spectrum1d_cube):

rectangle = RectangularROI(-0.5, 3.5, -0.5, 1.5)

subset_plugin.combination_mode.selected = 'new'
subset_plugin.combination_mode = 'new'
subset_plugin.import_region(rectangle)

subset_plugin.subset_selected = 'Subset 3'
subset_plugin._obj.subset_selected = 'Subset 3'
circle = CircularROI(1.5, 0.5, 1.1)

subset_plugin.combination_mode.selected = 'andnot'
subset_plugin.combination_mode = 'andnot'
subset_plugin.import_region(circle)

spec_extr_plugin.aperture_selected = 'Subset 3'
Expand Down Expand Up @@ -533,7 +533,7 @@ def test_default_spectral_extraction(cubeviz_helper, spectrum1d_cube_fluxunit_jy
# for non-science pixels in the sums:
cubeviz_helper.load_data(spectrum1d_cube_fluxunit_jy_per_steradian)

subset_plugin = cubeviz_helper.plugins['Subset Tools']._obj
subset_plugin = cubeviz_helper.plugins['Subsets']

subset_plugin.import_region(CircularROI(1.5, 2, 5))

Expand Down Expand Up @@ -619,7 +619,7 @@ def test_spectral_extraction_scientific_validation(
cubeviz_helper.load_data(uri, cache=True)

# add a subset with an aperture centered on each source
subset_plugin = cubeviz_helper.plugins['Subset Tools']._obj
subset_plugin = cubeviz_helper.plugins['Subsets']
subset_plugin.import_region(CircularROI(*aperture))

# set the slice to the blue end of MIRI CH1
Expand Down
8 changes: 4 additions & 4 deletions jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_aperphot.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_cubeviz_aperphot_cube_orig_flux(cubeviz_helper, image_cube_hdu_obj_micr
solid_angle_unit = PIX2

aper = RectanglePixelRegion(center=PixCoord(x=1, y=2), width=3, height=5)
cubeviz_helper.plugins['Subset Tools']._obj.import_region(aper)
cubeviz_helper.plugins['Subsets'].import_region(aper)

# Make sure MASK is not an option even when shown in viewer.
cubeviz_helper.app.add_data_to_viewer("flux-viewer", "test[MASK]", visible=True)
Expand Down Expand Up @@ -112,7 +112,7 @@ def test_cubeviz_aperphot_generated_3d_gaussian_smooth(cubeviz_helper, image_cub
cubeviz_helper.app.add_data_to_viewer("uncert-viewer", "test[FLUX] spatial-smooth stddev-1.0")

aper = RectanglePixelRegion(center=PixCoord(x=1, y=2), width=3, height=5)
cubeviz_helper.plugins['Subset Tools']._obj.import_region(aper)
cubeviz_helper.plugins['Subsets'].import_region(aper)

plg = cubeviz_helper.plugins["Aperture Photometry"]._obj
plg.dataset_selected = "test[FLUX] spatial-smooth stddev-1.0"
Expand Down Expand Up @@ -210,7 +210,7 @@ def test_cubeviz_aperphot_cube_orig_flux_mjysr(cubeviz_helper, spectrum1d_cube_c

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.plugins['Subset Tools']._obj.import_region([aper, bg], combination_mode='new')
cubeviz_helper.plugins['Subsets'].import_region([aper, bg], combination_mode='new')

plg = cubeviz_helper.plugins["Aperture Photometry"]._obj
plg.dataset_selected = "test[FLUX]"
Expand Down Expand Up @@ -277,7 +277,7 @@ def test_cubeviz_aperphot_unit_conversion(cubeviz_helper, spectrum1d_cube_custom
bg = RectanglePixelRegion(center=PixCoord(x=1, y=2), width=1, height=1)

cubeviz_helper.load_data(mjy_sr_cube, data_label="test")
cubeviz_helper.plugins['Subset Tools']._obj.import_region([aper, bg], combination_mode='new')
cubeviz_helper.plugins['Subsets'].import_region([aper, bg], combination_mode='new')

ap = cubeviz_helper.plugins['Aperture Photometry']._obj

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_get_data_spatial_and_spectral(cubeviz_helper, spectrum1d_cube_larger):
cubeviz_helper._apply_interactive_region('bqplot:ellipse', (0, 0), (9, 8))

# Subset 2 (spectral)
subset_plugin = cubeviz_helper.plugins['Subset Tools']._obj
subset_plugin = cubeviz_helper.plugins['Subsets']
unit = spectrum1d_cube_larger.spectral_axis.unit
subset_plugin.import_region(SpectralRegion(4.62440061e-07 * unit, 4.62520112e-07 * unit))

Expand Down
4 changes: 2 additions & 2 deletions jdaviz/configs/cubeviz/plugins/tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def test_spectrum1d_with_fake_fixed_units(spectrum1d, cubeviz_helper):

cubeviz_helper.app.add_data_to_viewer('spectrum-viewer', 'test')
unit = u.Unit(cubeviz_helper.plugins['Unit Conversion'].spectral_unit.selected)
cubeviz_helper.plugins['Subset Tools']._obj.import_region(SpectralRegion(6600 * unit,
7400 * unit))
cubeviz_helper.plugins['Subsets'].import_region(SpectralRegion(6600 * unit,
7400 * unit))

subsets = cubeviz_helper.app.get_subsets()
reg = subsets.get('Subset 1')
Expand Down
Loading

0 comments on commit 8c93c74

Please sign in to comment.