Skip to content

Commit

Permalink
Concept notebook for composite subset
Browse files Browse the repository at this point in the history
for spatial subsets

Add specviz pondering, update imviz
  • Loading branch information
pllim committed Dec 10, 2024
1 parent 6c946d3 commit 89cffa5
Show file tree
Hide file tree
Showing 3 changed files with 473 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ htmlcov
MANIFEST
.ipynb_checkpoints
notebooks/*.fits
notebooks/*.ecsv

# Sphinx
docs/api
Expand Down
214 changes: 214 additions & 0 deletions notebooks/concepts/imviz_composite_subset_api.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "98cfb0f9-9995-4530-b6d0-3cbe41055d9c",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from regions import CirclePixelRegion, PixCoord\n",
"\n",
"from jdaviz import Imviz"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "473cf04d-0550-4c16-afce-f26d87d91002",
"metadata": {},
"outputs": [],
"source": [
"a = np.random.random((100, 100))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e8096c7b-d3e1-472b-935d-770af8c0fd07",
"metadata": {},
"outputs": [],
"source": [
"imviz = Imviz()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d2b7b2b4-215e-4f58-b01c-c65a7eabc1fe",
"metadata": {},
"outputs": [],
"source": [
"imviz.load_data(a, data_label=\"a\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dc3dd6fb-6d1f-4792-9199-3742e60849f8",
"metadata": {},
"outputs": [],
"source": [
"imviz.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4dfbfc9a-20bc-43fb-95b5-75a008785708",
"metadata": {},
"outputs": [],
"source": [
"imviz.default_viewer.reset_limits()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "00e0b637-983e-4eb9-9941-c88115a56baf",
"metadata": {},
"outputs": [],
"source": [
"aper_1 = CirclePixelRegion(center=PixCoord(x=42, y=43), radius=4.2)\n",
"aper_2 = CirclePixelRegion(center=PixCoord(x=10, y=20), radius=3)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9b075437-bb24-449c-b87f-fec42d5ff2a8",
"metadata": {},
"outputs": [],
"source": [
"plg_subset = imviz.plugins[\"Subset Tools\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "42d35bcb-1855-4b1b-8843-d6324e3836af",
"metadata": {},
"outputs": [],
"source": [
"plg_subset.import_region([aper_1, aper_2], combination_mode=\"or\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6806b7b0-4252-4c75-a306-09b6cc756e37",
"metadata": {},
"outputs": [],
"source": [
"plg_export = imviz.plugins[\"Export\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b8fe64fa-02d5-4b96-a6fc-41a1a4828bb2",
"metadata": {},
"outputs": [],
"source": [
"plg_export.subset = \"Subset 1\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ef01d881-712b-4f19-ad81-ac6c627df64c",
"metadata": {},
"outputs": [],
"source": [
"plg_export.subset_format = \"reg\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d408fe0f-12e4-4f89-8aff-1e1abc61862d",
"metadata": {},
"outputs": [],
"source": [
"# NotImplementedError: Subset can not be exported - Export for composite subsets not yet supported.\n",
"plg_export.export()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "aac2f285-a7ab-4177-8d92-bea6cb7e1306",
"metadata": {},
"outputs": [],
"source": [
"# {'Subset 1': [\n",
"# <CirclePixelRegion(center=PixCoord(x=42, y=43), radius=4.2)>,\n",
"# <CirclePixelRegion(center=PixCoord(x=10, y=20), radius=3)>]}\n",
"imviz.app.get_subsets(object_only=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "80e4b0be-21ff-474b-b3e0-3251a8bd1e0e",
"metadata": {},
"outputs": [],
"source": [
"# {'Subset 1': [{'name': 'CircularROI',\n",
"# 'glue_state': 'RoiSubsetState',\n",
"# 'region': <CirclePixelRegion(center=PixCoord(x=42, y=43), radius=4.2)>,\n",
"# 'sky_region': None,\n",
"# 'subset_state': <glue.core.subset.RoiSubsetState at ...>},\n",
"# {'name': 'CircularROI',\n",
"# 'glue_state': 'OrState',\n",
"# 'region': <CirclePixelRegion(center=PixCoord(x=10, y=20), radius=3)>,\n",
"# 'sky_region': None,\n",
"# 'subset_state': <glue.core.subset.RoiSubsetState at ...>}]}\n",
"imviz.app.get_subsets()"
]
},
{
"cell_type": "markdown",
"id": "3bc553f9-c0fe-4989-82fe-7688d3c0ceed",
"metadata": {},
"source": [
"### Additional work\n",
"\n",
"How to store `glue_state` into a file? How will this conflict with existing `regions` I/O support? We cannot ask `regions` to support `glue_state` natively because it is a property very specific to `glue` only.\n",
"\n",
"However, we could utilize [compound region](https://astropy-regions.readthedocs.io/en/latest/compound.html).\n",
"\n",
"* Pros: Out of the box support from `regions` for AND, OR (a.k.a. ADD), XOR.\n",
"* Cons: No concept of REPLACE and REMOVE. `photutils` does not understand compound apertures, so even if `regions` can load them, they are useless for photometry (not a new problem).\n",
"\n",
"### Recommendations\n",
"\n",
"1. Acknowledge that this feature will never be used for aperture photometry.\n",
"2. Create follow-up ticket to add support for [compound region](https://astropy-regions.readthedocs.io/en/latest/compound.html).\n",
"3. Create follow-up ticket to then investigate REPLACE and REMOVE, after (1) is implemented."
]
}
],
"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.12.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit 89cffa5

Please sign in to comment.