Skip to content

Commit

Permalink
rename args and update docstring for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Nov 19, 2024
1 parent e22aa08 commit 2381f25
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 30 deletions.
40 changes: 22 additions & 18 deletions jdaviz/configs/imviz/plugins/orientation/orientation.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,61 +535,65 @@ def _on_viewer_change(self, msg={}):
if ref_data.label in self.orientation.choices:
self.orientation.selected = ref_data.label

def _create_north_up_east_left(self, label="North-up, East-left", set_on_create=False,
def _create_north_up_east_left(self, label="North-up, East-left", set_as_orientation=False,
from_ui=False):
if label not in self.orientation.choices:
degn = self._get_wcs_angles()[-3]
self._add_orientation(rotation_angle=degn, east_left=True,
label=label, set_on_create=set_on_create,
label=label, set_on_create=set_as_orientation,
from_ui=from_ui)
elif set_on_create:
elif set_as_orientation:

Check warning on line 545 in jdaviz/configs/imviz/plugins/orientation/orientation.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/imviz/plugins/orientation/orientation.py#L545

Added line #L545 was not covered by tests
self.orientation.selected = label

def create_north_up_east_left(self, label="North-up, East-left",
set_on_create=True):
set_as_orientation=True):
"""
Set the rotation angle and flip to achieve North up and East left
according to the reference image WCS.
Parameters
----------
label : str
Data label for this new orientation layer.
set_on_create : bool
Whether to set the created option as the current orientation.
Data label for the orientation layer. If already exists, will be set as the
current orientation layer according to ``set_as_orientation``. Otherwise,
a new layer will be created with this label.
set_as_orientation : bool
Whether to set as the current orientation.
"""
self._create_north_up_east_left(label=label, set_on_create=set_on_create)
self._create_north_up_east_left(label=label, set_as_orientation=set_as_orientation)

def _create_north_up_east_right(self, label="North-up, East-right", set_on_create=False,
def _create_north_up_east_right(self, label="North-up, East-right", set_as_orientation=False,
from_ui=False):
if label not in self.orientation.choices:
degn = self._get_wcs_angles()[-3]
self._add_orientation(rotation_angle=180 - degn, east_left=False,
label=label, set_on_create=set_on_create,
label=label, set_on_create=set_as_orientation,
from_ui=from_ui)
elif set_on_create:
elif set_as_orientation:

Check warning on line 572 in jdaviz/configs/imviz/plugins/orientation/orientation.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/imviz/plugins/orientation/orientation.py#L572

Added line #L572 was not covered by tests
self.orientation.selected = label

def create_north_up_east_right(self, label="North-up, East-right",
set_on_create=True):
set_as_orientation=True):
"""
Set the rotation angle and flip to achieve North up and East right
according to the reference image WCS.
Parameters
----------
label : str
Data label for this new orientation layer.
set_on_create : bool
Whether to set the created option as the current orientation.
Data label for the orientation layer. If already exists, will be set as the
current orientation layer according to ``set_as_orientation``. Otherwise,
a new layer will be created with this label.
set_as_orientation : bool
Whether to set as the current orientation.
"""
self._create_north_up_east_right(label=label, set_on_create=set_on_create)
self._create_north_up_east_right(label=label, set_as_orientation=set_as_orientation)

def vue_select_north_up_east_left(self, *args, **kwargs):
self._create_north_up_east_left(set_on_create=True, from_ui=True)
self._create_north_up_east_left(set_as_orientation=True, from_ui=True)

Check warning on line 593 in jdaviz/configs/imviz/plugins/orientation/orientation.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/imviz/plugins/orientation/orientation.py#L593

Added line #L593 was not covered by tests

def vue_select_north_up_east_right(self, *args, **kwargs):
self._create_north_up_east_right(set_on_create=True, from_ui=True)
self._create_north_up_east_right(set_as_orientation=True, from_ui=True)

Check warning on line 596 in jdaviz/configs/imviz/plugins/orientation/orientation.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/imviz/plugins/orientation/orientation.py#L596

Added line #L596 was not covered by tests

def vue_select_default_orientation(self, *args, **kwargs):
self.orientation.selected = base_wcs_layer_label
Expand Down
2 changes: 1 addition & 1 deletion jdaviz/configs/imviz/tests/test_delete_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_delete_wcs_layer_with_subset(self):
lc_plugin.align_by = 'WCS'

# Should automatically be applied as reference to first viewer.
lc_plugin._obj.create_north_up_east_left(set_on_create=True)
lc_plugin.create_north_up_east_left(set_as_orientation=True)

# Create a rotated ellipse.
reg = EllipsePixelRegion(
Expand Down
4 changes: 2 additions & 2 deletions jdaviz/configs/imviz/tests/test_footprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ def test_footprint_updates_on_rotation(imviz_helper):
assert np.concatenate([marks[0].y, marks[1].y]).min() < -3

# now rotate to north-up east-left:
orientation = imviz_helper.plugins['Orientation']._obj
orientation.create_north_up_east_left(set_on_create=True)
orientation = imviz_helper.plugins['Orientation']
orientation.create_north_up_east_left(set_as_orientation=True)

# If all footprint orientations have been updated, the lowest
# mark should still be centered low. If the footprint
Expand Down
18 changes: 9 additions & 9 deletions jdaviz/configs/imviz/tests/test_orientation.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ def test_N_up_multi_viewer(self):
lc_plugin.align_by = 'WCS'

# Should automatically be applied as reference to first viewer.
lc_plugin._obj.create_north_up_east_left(set_on_create=True)
lc_plugin.create_north_up_east_left(set_as_orientation=True)

# This would set a different reference to second viewer.
viewer_2 = self.imviz.create_image_viewer()
self.imviz.app.add_data_to_viewer("imviz-1", "has_wcs_1[SCI,1]")
lc_plugin.viewer = "imviz-1"

lc_plugin._obj.create_north_up_east_right(set_on_create=True)
lc_plugin.create_north_up_east_right(set_as_orientation=True)

assert self.viewer.state.reference_data.label == "North-up, East-left"
assert viewer_2.state.reference_data.label == "North-up, East-right"
Expand All @@ -157,8 +157,8 @@ def test_custom_orientation(self):
lc_plugin.viewer = "imviz-0"

lc_plugin.rotation_angle = 42 # Triggers auto-label
lc_plugin._obj.add_orientation(rotation_angle=None, east_left=True, label=None,
set_on_create=True, wrt_data=None)
lc_plugin.add_orientation(rotation_angle=None, east_left=True, label=None,
set_on_create=True, wrt_data=None)
assert self.viewer.state.reference_data.label == "CCW 42.00 deg (E-left)"


Expand All @@ -169,7 +169,7 @@ def test_delete_orientation_multi_viewer(self):
lc_plugin.align_by = 'WCS'

# Should automatically be applied as reference to first viewer.
lc_plugin._obj.create_north_up_east_left(set_on_create=True)
lc_plugin.create_north_up_east_left(set_as_orientation=True)

# This would set a different reference to second viewer.
viewer_2 = self.imviz.create_image_viewer()
Expand All @@ -192,15 +192,15 @@ def test_delete_orientation_with_subset(self, klass, angle, sbst_theta):
lc_plugin.align_by = 'WCS'

# Should automatically be applied as reference to first viewer.
lc_plugin._obj.create_north_up_east_left(set_on_create=True)
lc_plugin.create_north_up_east_left(set_as_orientation=True)

# Create rotated shape
reg = klass(center=SkyCoord(ra=337.51931488, dec=-20.83187472, unit="deg"),
width=2.4 * u.arcsec, height=1.2 * u.arcsec, angle=angle)
self.imviz.plugins['Subsets'].import_region(reg)

# Switch to N-up E-right
lc_plugin._obj.create_north_up_east_right(set_on_create=True)
lc_plugin.create_north_up_east_right(set_as_orientation=True)

self.imviz.app.vue_data_item_remove({"item_name": "North-up, East-left"})

Expand Down Expand Up @@ -234,13 +234,13 @@ def test_create_no_data(self):
lc_plugin.viewer = "imviz-1"

with pytest.raises(ValueError, match="Viewer must have data loaded"):
lc_plugin._obj.create_north_up_east_left(set_on_create=True)
lc_plugin.create_north_up_east_left(set_as_orientation=True)

def test_select_no_data(self):
lc_plugin = self.imviz.plugins['Orientation']
lc_plugin.align_by = 'WCS'

lc_plugin._obj.create_north_up_east_left(set_on_create=True)
lc_plugin.create_north_up_east_left(set_as_orientation=True)

self.imviz.create_image_viewer()
lc_plugin.viewer = "imviz-1"
Expand Down

0 comments on commit 2381f25

Please sign in to comment.