Skip to content

Commit

Permalink
expose create_north_up_east_left/right
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Nov 18, 2024
1 parent 7e5ddfa commit f9a10ae
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 17 deletions.
56 changes: 42 additions & 14 deletions jdaviz/configs/imviz/plugins/orientation/orientation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

__all__ = ['Orientation']

base_wcs_layer_label = 'Default orientation'
base_wcs_layer_label = 'Default Orientation'
align_by_msg_to_trait = {'pixels': 'Pixels', 'wcs': 'WCS'}


Expand All @@ -52,15 +52,20 @@ class Orientation(PluginTemplateMixin, ViewerSelectMixin):
* :meth:`~jdaviz.core.template_mixin.PluginTemplateMixin.close_in_tray`
* ``align_by`` (`~jdaviz.core.template_mixin.SelectPluginComponent`)
* ``wcs_fast_approximation``
* ``delete_subsets``
* :meth:`delete_subsets``
* ``viewer``
* ``orientation``
* ``rotation_angle``
* ``east_left``
* ``add_orientation``
* :meth:`add_orientation`
* :meth:`create_north_up_east_left`
* :meth:`create_north_up_east_right`
"""
template_file = __file__, "orientation.vue"

# defined as traitlet to allow access from UI - leave fixed
base_wcs_layer_label = Unicode(base_wcs_layer_label).tag(sync=True)

align_by_items = List().tag(sync=True)
align_by_selected = Unicode().tag(sync=True)
wcs_use_fallback = Bool(True).tag(sync=True)
Expand Down Expand Up @@ -146,7 +151,8 @@ def user_api(self):
expose=(
'align_by', 'link_type', 'wcs_fast_approximation', 'wcs_use_affine',
'delete_subsets', 'viewer', 'orientation',
'rotation_angle', 'east_left', 'add_orientation'
'rotation_angle', 'east_left', 'add_orientation',
'create_north_up_east_left', 'create_north_up_east_right',
)
)

Expand Down Expand Up @@ -526,12 +532,8 @@ 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_on_create=False,
from_ui=False):
"""
Set the rotation angle and flip to achieve North up and East left
according to the reference image WCS.
"""
if label not in self.orientation.choices:
degn = self._get_wcs_angles()[-3]
self._add_orientation(rotation_angle=degn, east_left=True,
Expand All @@ -540,12 +542,23 @@ def create_north_up_east_left(self, label="North-up, East-left", set_on_create=F
elif set_on_create:
self.orientation.selected = label

def create_north_up_east_right(self, label="North-up, East-right", set_on_create=False,
from_ui=False):
def create_north_up_east_left(self, label="North-up, East-left",
set_on_create=False):
"""
Set the rotation angle and flip to achieve North up and East right
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.
"""
self._create_north_up_east_left(label=label, set_on_create=set_on_create)

def _create_north_up_east_right(self, label="North-up, East-right", set_on_create=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,
Expand All @@ -554,11 +567,26 @@ def create_north_up_east_right(self, label="North-up, East-right", set_on_create
elif set_on_create:
self.orientation.selected = label

def create_north_up_east_right(self, label="North-up, East-right",
set_on_create=False):
"""
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.
"""
self._create_north_up_east_right(label=label, set_on_create=set_on_create)

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_on_create=True, from_ui=True)

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_on_create=True, from_ui=True)

def vue_select_default_orientation(self, *args, **kwargs):
self.orientation.selected = base_wcs_layer_label
Expand Down
33 changes: 30 additions & 3 deletions jdaviz/configs/imviz/plugins/orientation/orientation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,45 @@
<span style="line-height: 36px">Presets:</span>
<!-- NOTE: changes to icons here should be manually reflected in layer_icons in app.py -->
<j-tooltip tooltipcontent="Default orientation">
<v-btn icon @click="select_default_orientation">
<v-btn
:icon="!api_hints_enabled"
:class="api_hints_enabled ? 'api-hint' : null"
@click="select_default_orientation"
>
<v-icon>mdi-image-outline</v-icon>
{{ api_hints_enabled ?
'plg.orientation = \''+base_wcs_layer_label+'\''
:
null
}}
</v-btn>
</j-tooltip>
<j-tooltip tooltipcontent="north up, east left">
<v-btn icon @click="select_north_up_east_left">
<v-btn
:icon="!api_hints_enabled"
:class="api_hints_enabled ? 'api-hint' : null"
@click="select_north_up_east_left"
>
<img :src="icons['nuel']" width="24" class="invert-if-dark" style="opacity: 0.65"/>
{{ api_hints_enabled ?
'plg.create_north_up_east_left()'
:
null
}}
</v-btn>
</j-tooltip>
<j-tooltip tooltipcontent="north up, east right">
<v-btn icon @click="select_north_up_east_right">
<v-btn
:icon="!api_hints_enabled"
:class="api_hints_enabled ? 'api-hint' : null"
@click="select_north_up_east_right"
>
<img :src="icons['nuer']" width="24" class="invert-if-dark" style="opacity: 0.65"/>
{{ api_hints_enabled ?
'plg.create_north_up_east_right()'
:
null
}}
</v-btn>
</j-tooltip>
</v-row>
Expand Down

0 comments on commit f9a10ae

Please sign in to comment.