From 35b208d71b560c011a496073bbdf27823c0db849 Mon Sep 17 00:00:00 2001 From: "Pey Lian Lim (Github)" <2090236+pllim@users.noreply.github.com> Date: Mon, 23 May 2022 17:57:48 -0400 Subject: [PATCH] WIP: Early POC --- docs/imviz/plugins.rst | 13 ++ jdaviz/configs/imviz/imviz.yaml | 1 + jdaviz/configs/imviz/plugins/__init__.py | 1 + .../imviz/plugins/rotate_image/__init__.py | 1 + .../plugins/rotate_image/rotate_image.py | 9 + .../plugins/rotate_image/rotate_image.vue | 9 + .../imviz_link_north_up_east_left.ipynb | 203 ++++++++++++++++++ 7 files changed, 237 insertions(+) create mode 100644 jdaviz/configs/imviz/plugins/rotate_image/__init__.py create mode 100644 jdaviz/configs/imviz/plugins/rotate_image/rotate_image.py create mode 100644 jdaviz/configs/imviz/plugins/rotate_image/rotate_image.vue create mode 100644 notebooks/concepts/imviz_link_north_up_east_left.ipynb diff --git a/docs/imviz/plugins.rst b/docs/imviz/plugins.rst index 66cd58cad5..5040bacdc8 100644 --- a/docs/imviz/plugins.rst +++ b/docs/imviz/plugins.rst @@ -251,3 +251,16 @@ The columns are as follow: Once you have the results in a table, you can further manipulated them as documented in :ref:`astropy:astropy-table`. + + +.. _rotate-image-simple: + +Simple Image Rotation +===================== + +.. warning:: + + Distortion is ignore, so using this plugin on distorted data is + not recommended. + +This plugins rotates an image North-up and East-left. diff --git a/jdaviz/configs/imviz/imviz.yaml b/jdaviz/configs/imviz/imviz.yaml index d53dbd9736..b3826643c6 100644 --- a/jdaviz/configs/imviz/imviz.yaml +++ b/jdaviz/configs/imviz/imviz.yaml @@ -25,6 +25,7 @@ tray: - imviz-compass - imviz-line-profile-xy - imviz-aper-phot-simple + - imviz-rotate-image - g-export-plot viewer_area: - container: col diff --git a/jdaviz/configs/imviz/plugins/__init__.py b/jdaviz/configs/imviz/plugins/__init__.py index 0b0f93a12c..674fa02a5e 100644 --- a/jdaviz/configs/imviz/plugins/__init__.py +++ b/jdaviz/configs/imviz/plugins/__init__.py @@ -7,3 +7,4 @@ from .compass import * # noqa from .aper_phot_simple import * # noqa from .line_profile_xy import * # noqa +from .rotate_image import * # noqa diff --git a/jdaviz/configs/imviz/plugins/rotate_image/__init__.py b/jdaviz/configs/imviz/plugins/rotate_image/__init__.py new file mode 100644 index 0000000000..11ffcbe2ff --- /dev/null +++ b/jdaviz/configs/imviz/plugins/rotate_image/__init__.py @@ -0,0 +1 @@ +from .rotate_image import * # noqa diff --git a/jdaviz/configs/imviz/plugins/rotate_image/rotate_image.py b/jdaviz/configs/imviz/plugins/rotate_image/rotate_image.py new file mode 100644 index 0000000000..7eca23c3fd --- /dev/null +++ b/jdaviz/configs/imviz/plugins/rotate_image/rotate_image.py @@ -0,0 +1,9 @@ +from jdaviz.core.registries import tray_registry +from jdaviz.core.template_mixin import TemplateMixin + +__all__ = ['RotateImageSimple'] + + +@tray_registry('imviz-rotate-image', label="Simple Image Rotation") +class RotateImageSimple(TemplateMixin): + template_file = __file__, "rotate_image.vue" diff --git a/jdaviz/configs/imviz/plugins/rotate_image/rotate_image.vue b/jdaviz/configs/imviz/plugins/rotate_image/rotate_image.vue new file mode 100644 index 0000000000..8e87a40b99 --- /dev/null +++ b/jdaviz/configs/imviz/plugins/rotate_image/rotate_image.vue @@ -0,0 +1,9 @@ + diff --git a/notebooks/concepts/imviz_link_north_up_east_left.ipynb b/notebooks/concepts/imviz_link_north_up_east_left.ipynb new file mode 100644 index 0000000000..a3a9c03d32 --- /dev/null +++ b/notebooks/concepts/imviz_link_north_up_east_left.ipynb @@ -0,0 +1,203 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "206e73ce", + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "from astropy.io import fits\n", + "from astropy.nddata import NDData\n", + "from astropy.wcs import WCS\n", + "\n", + "from jdaviz import Imviz" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6e816343", + "metadata": {}, + "outputs": [], + "source": [ + "# Image of interest (HST/ACS FLT)\n", + "a = np.random.random((2048, 4096))\n", + "w = WCS({'WCSAXES': 2,\n", + " 'CRPIX1': 2100.0,\n", + " 'CRPIX2': 1024.0,\n", + " 'PC1_1': -1.14852e-05,\n", + " 'PC1_2': 7.01477e-06,\n", + " 'PC2_1': 7.75765e-06,\n", + " 'PC2_2': 1.20927e-05,\n", + " 'CDELT1': 1.0,\n", + " 'CDELT2': 1.0,\n", + " 'CUNIT1': 'deg',\n", + " 'CUNIT2': 'deg',\n", + " 'CTYPE1': 'RA---TAN',\n", + " 'CTYPE2': 'DEC--TAN',\n", + " 'CRVAL1': 3.581704851882,\n", + " 'CRVAL2': -30.39197867265,\n", + " 'LONPOLE': 180.0,\n", + " 'LATPOLE': -30.39197867265,\n", + " 'MJDREF': 0.0,\n", + " 'RADESYS': 'ICRS'})\n", + "hdu = fits.ImageHDU(a, name='SCI')\n", + "hdu.header.update(w.to_header())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9a69e6b9", + "metadata": {}, + "outputs": [], + "source": [ + "print(w)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3069a91e", + "metadata": {}, + "outputs": [], + "source": [ + "# What about JWST GWCS?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b72a0049", + "metadata": {}, + "outputs": [], + "source": [ + "# Just a dummy array to hold the WCS.\n", + "a_dummy = fits.ImageHDU(np.ones((3, 3), dtype=np.int16))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a526d9a9", + "metadata": {}, + "outputs": [], + "source": [ + "# WCS with N-up/E-left\n", + "w_ref = WCS({'CTYPE1': 'RA---TAN',\n", + " 'CUNIT1': 'deg',\n", + " 'CDELT1': -0.0002777777778,\n", + " 'CRPIX1': 1,\n", + " 'NAXIS1': 3,\n", + " 'CTYPE2': 'DEC--TAN',\n", + " 'CUNIT2': 'deg',\n", + " 'CDELT2': 0.0002777777778,\n", + " 'CRPIX2': 1,\n", + " 'NAXIS2': 3}) \n", + "w_ref.wcs.crval = w.wcs.crval" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "55b2cc04", + "metadata": {}, + "outputs": [], + "source": [ + "w_ref" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "84d06406", + "metadata": {}, + "outputs": [], + "source": [ + "ndd = NDData(a_dummy.data, wcs=w_ref)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "93fcdb1b", + "metadata": {}, + "outputs": [], + "source": [ + "imviz = Imviz(verbosity='warning')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e3585cda", + "metadata": {}, + "outputs": [], + "source": [ + "imviz.load_data(ndd, data_label='wcs_ref')\n", + "imviz.load_data(hdu, data_label='jb5g05ubq_flt')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bc2cf21c", + "metadata": {}, + "outputs": [], + "source": [ + "imviz.link_data(link_type='wcs')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "022cc29f", + "metadata": {}, + "outputs": [], + "source": [ + "imviz.app" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "31fefe0a", + "metadata": {}, + "outputs": [], + "source": [ + "imviz.default_viewer.zoom_level = 2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c86aed70", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.7" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}