From 9ea914e74e9d711e8d963a04ff5b939eb914757d Mon Sep 17 00:00:00 2001 From: "P. L. Lim" <2090236+pllim@users.noreply.github.com> Date: Mon, 24 Apr 2023 18:55:37 -0400 Subject: [PATCH] POC: Annulus support in Imviz that needs glue-viz/glue-astronomy#90 --- notebooks/concepts/imviz_annulus_region.ipynb | 135 ++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 notebooks/concepts/imviz_annulus_region.ipynb diff --git a/notebooks/concepts/imviz_annulus_region.ipynb b/notebooks/concepts/imviz_annulus_region.ipynb new file mode 100644 index 0000000000..96b50ab5b1 --- /dev/null +++ b/notebooks/concepts/imviz_annulus_region.ipynb @@ -0,0 +1,135 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "d9570264", + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "from glue_astronomy.translators.regions import _annulus_to_subset_state\n", + "from regions import CircleAnnulusPixelRegion, PixCoord\n", + "\n", + "from jdaviz import Imviz" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "070974fc", + "metadata": {}, + "outputs": [], + "source": [ + "a = np.arange(100).reshape((10, 10))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "048d90d3", + "metadata": {}, + "outputs": [], + "source": [ + "imviz = Imviz()\n", + "imviz.load_data(a)\n", + "imviz.show()" + ] + }, + { + "cell_type": "markdown", + "id": "5bf8cb48", + "metadata": {}, + "source": [ + "Add annulus region to Imviz. Maybe turn this into a plugin?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9c38c2d2", + "metadata": {}, + "outputs": [], + "source": [ + "data = imviz.app.data_collection[0]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b02e7ee0", + "metadata": {}, + "outputs": [], + "source": [ + "reg = CircleAnnulusPixelRegion(center=PixCoord(x=4.5, y=4.5), inner_radius=2, outer_radius=3)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "58717669", + "metadata": {}, + "outputs": [], + "source": [ + "sbst = _annulus_to_subset_state(reg, data)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "77e2a17b", + "metadata": {}, + "outputs": [], + "source": [ + "imviz.app.data_collection.new_subset_group(subset_state=sbst)" + ] + }, + { + "cell_type": "markdown", + "id": "139850a2", + "metadata": {}, + "source": [ + "Get annulus region back." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ad53d98b", + "metadata": {}, + "outputs": [], + "source": [ + "data.get_selection_definition(subset_id='Subset 1', format='astropy-regions')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e1c374a4", + "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.10.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}