-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new optional dependency of reproject package.
- Loading branch information
Showing
9 changed files
with
138 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .reproject import * # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from traitlets import Bool | ||
|
||
from jdaviz.core.events import SnackbarMessage | ||
from jdaviz.core.registries import tray_registry | ||
from jdaviz.core.template_mixin import PluginTemplateMixin, DatasetSelectMixin | ||
|
||
try: | ||
from reproject import reproject_interp | ||
from reproject.mosaicking import find_optimal_celestial_wcs | ||
except ImportError: | ||
HAS_REPROJECT = False | ||
else: | ||
HAS_REPROJECT = True | ||
|
||
__all__ = ['Reproject'] | ||
|
||
|
||
@tray_registry('imviz-reproject', label="Reproject") | ||
class Reproject(PluginTemplateMixin, DatasetSelectMixin): | ||
template_file = __file__, "reproject.vue" | ||
|
||
reproject_in_progress = Bool(False).tag(sync=True) | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
if not HAS_REPROJECT: | ||
self.disabled_msg = 'Please install reproject and restart Jdaviz to use this plugin' | ||
return | ||
|
||
def vue_do_reproject(self, *args, **kwargs): | ||
if (not HAS_REPROJECT or self.dataset_selected not in self.data_collection | ||
or self.reproject_in_progress): | ||
return | ||
|
||
data = self.data_collection[self.dataset_selected] | ||
wcs_in = data.coords | ||
if wcs_in is None: | ||
return | ||
|
||
from astropy.nddata import NDData | ||
|
||
self.reproject_in_progress = True | ||
try: | ||
# TODO: Support GWCS (https://github.com/astropy/reproject/issues/328) | ||
# Find WCS where North is pointing up. | ||
wcs_out, shape_out = find_optimal_celestial_wcs([(data.shape, wcs_in)], frame='icrs') | ||
|
||
# Reproject image to new WCS. | ||
comp = data.get_component(data.main_components[0]) | ||
new_arr = reproject_interp((comp.data, wcs_in), wcs_out, shape_out=shape_out, | ||
return_footprint=False) | ||
|
||
# TODO: Let user customize new label; have default label not be so ugly. | ||
new_label = f'{self.dataset_selected} (reprojected)' | ||
|
||
# Stuff it back into Imviz. | ||
# We don't want to inherit input metadata because it might have wrong (unrotated) | ||
# WCS info in the header metadata. | ||
ndd = NDData(new_arr, wcs=wcs_out) | ||
self.app._jdaviz_helper.load_data(ndd, data_label=new_label) | ||
|
||
except Exception as e: | ||
self.hub.broadcast(SnackbarMessage( | ||
f"Failed to reproject {self.dataset_selected}: {repr(e)}", | ||
color='error', sender=self)) | ||
|
||
finally: | ||
self.reproject_in_progress = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<template> | ||
<j-tray-plugin | ||
description='Perform reprojection for a single image.' | ||
:link="'https://jdaviz.readthedocs.io/en/'+vdocs+'/'+config+'/plugins.html#reproject'" | ||
:disabled_msg="disabled_msg" | ||
:popout_button="popout_button"> | ||
|
||
<plugin-dataset-select | ||
:items="dataset_items" | ||
:selected.sync="dataset_selected" | ||
:show_if_single_entry="false" | ||
label="Data" | ||
hint="Select the data for reprojection." | ||
/> | ||
|
||
<div v-if='dataset_selected'> | ||
<v-row justify="end"> | ||
<v-btn color="primary" text @click="do_reproject">Reproject</v-btn> | ||
</v-row> | ||
</div> | ||
|
||
<div v-if="reproject_in_progress" | ||
class="text-center" | ||
style="grid-area: 1/1; | ||
z-index:2; | ||
margin-left: -24px; | ||
margin-right: -24px; | ||
padding-top: 60px; | ||
background-color: rgb(0 0 0 / 20%)"> | ||
<v-progress-circular | ||
indeterminate | ||
color="spinner" | ||
size="50" | ||
width="6" | ||
></v-progress-circular> | ||
</div> | ||
</j-tray-plugin> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,8 @@ test = | |
docs = | ||
sphinx-rtd-theme | ||
sphinx-astropy | ||
all = | ||
reproject>=0.10 | ||
|
||
[options.package_data] | ||
jdaviz = | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters