From 0ed52d22096fb374488fd7c729a6fae420e446c6 Mon Sep 17 00:00:00 2001 From: "Brett M. Morris" Date: Wed, 11 Dec 2024 11:56:03 -0500 Subject: [PATCH] Backport PR #3346: Example Roman L2 notebook update since B16 --- CHANGES.rst | 2 + notebooks/concepts/imviz_roman_asdf.ipynb | 120 ++++++++++++++++------ 2 files changed, 91 insertions(+), 31 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 128539f823..a3b57d61c7 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -39,6 +39,8 @@ Imviz - Updates UI language in the orientation plugin to better match API. [#3276] +- Update Roman L2 example files in example notebook. [#3346] + Mosviz ^^^^^^ diff --git a/notebooks/concepts/imviz_roman_asdf.ipynb b/notebooks/concepts/imviz_roman_asdf.ipynb index 8b17de9dd8..4614e66bed 100644 --- a/notebooks/concepts/imviz_roman_asdf.ipynb +++ b/notebooks/concepts/imviz_roman_asdf.ipynb @@ -23,7 +23,9 @@ "cell_type": "code", "execution_count": null, "id": "0915bde6-e3cc-4038-aca1-c2ae852f7a69", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "import warnings\n", @@ -49,7 +51,9 @@ "cell_type": "code", "execution_count": null, "id": "53fb47da-0427-4a43-9d11-39567a12cdb0", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "%matplotlib inline" @@ -60,21 +64,30 @@ "id": "d1120d18-65a4-41ec-b831-bc3637718b90", "metadata": {}, "source": [ - "For now, we will use synthetic data for testing." + "For now, we will use synthetic data for testing. \n", + "\n", + "Before downloading the example data, which were generated with schema from `roman_datamodels` and `rad == 0.22.0`, check that the correct version of `roman_datamodels` is installed. Otherwise it may not be possible to open these example files:" ] }, { "cell_type": "code", "execution_count": null, "id": "68443a20", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ + "from packaging.version import Version\n", "from astropy.utils.data import download_file\n", + "from roman_datamodels import __version__ as rdm_version\n", "\n", - "# # Each of these files is ~1 GB:\n", - "image_model1 = download_file('https://stsci.box.com/shared/static/be2nfy4jovdhw1cxru99kdwnfnqxxlgo.asdf', cache=True)\n", - "image_model2 = download_file('https://stsci.box.com/shared/static/ktpt4li627kq4mipi3er5yd4qw6hq7ll.asdf', cache=True)" + "assert Version(rdm_version) >= Version('0.22.0'), 'Update roman_datamodels with `pip install -U roman_datamodels`'\n", + "\n", + "\n", + "# Each of these files is ~1 GB:\n", + "image_model1 = download_file('https://stsci.box.com/shared/static/oor05ut2u5e3xq4kcd244pq5md1el13h.asdf', cache=True)\n", + "image_model2 = download_file('https://stsci.box.com/shared/static/sw1jvu70q20w6czi8pmd9351f0yqkj5o.asdf', cache=True)" ] }, { @@ -107,7 +120,9 @@ "cell_type": "code", "execution_count": null, "id": "229d64f3-843f-4a7f-ac98-989f2a95d4c1", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "imviz.show('sidecar:split-right', height=1000)" @@ -125,7 +140,9 @@ "cell_type": "code", "execution_count": null, "id": "8427d4f9-8ea3-4d60-a8b7-3f3f63e3f3e0", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "orientation = imviz.plugins['Orientation']\n", @@ -149,7 +166,9 @@ "cell_type": "code", "execution_count": null, "id": "f117ebce-c7a0-44fa-82a4-0c0876663093", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "plot_options = imviz.plugins['Plot Options']\n", @@ -188,7 +207,9 @@ "cell_type": "code", "execution_count": null, "id": "1e369edd", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "regions = imviz.get_interactive_regions()" @@ -198,7 +219,9 @@ "cell_type": "code", "execution_count": null, "id": "a0385234", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "regions" @@ -216,7 +239,9 @@ "cell_type": "code", "execution_count": null, "id": "71e2191b", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "wcs = imviz.app.data_collection[-1].coords\n", @@ -227,7 +252,9 @@ "cell_type": "code", "execution_count": null, "id": "0a4e02ef", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "data = imviz.get_data(imviz.app.data_collection[0].label)" @@ -237,7 +264,9 @@ "cell_type": "code", "execution_count": null, "id": "164a1a40", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "plt.imshow(mask.to_image(data.data.shape), origin='lower')" @@ -255,7 +284,9 @@ "cell_type": "code", "execution_count": null, "id": "f2ce00c9-093c-4bc0-8cb7-b7c8fe38ec64", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "viewer = imviz.default_viewer" @@ -265,7 +296,9 @@ "cell_type": "code", "execution_count": null, "id": "5e908421", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "# Center the image on given pixel position.\n", @@ -276,7 +309,9 @@ "cell_type": "code", "execution_count": null, "id": "e68b6306", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "# Move the image with the given pixel offsets.\n", @@ -295,7 +330,9 @@ "cell_type": "code", "execution_count": null, "id": "05bc5603-9815-433f-8b4b-2556222ce6c5", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "center = regions['Subset 1'].center" @@ -305,11 +342,13 @@ "cell_type": "code", "execution_count": null, "id": "e0f3845a", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "# Center the image on given sky coordinates.\n", - "sky = SkyCoord(ra=79.91038, dec=29.95529, unit=('deg', 'deg'))\n", + "sky = SkyCoord(ra=269.89, dec=66.04, unit=('deg', 'deg'))\n", "viewer.center_on(sky)" ] }, @@ -317,7 +356,9 @@ "cell_type": "code", "execution_count": null, "id": "20f51452-1858-47f9-a421-2997f54f8433", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "# Move the image with the given sky offsets.\n", @@ -343,7 +384,9 @@ "cell_type": "code", "execution_count": null, "id": "1bad9bdf-b959-4b74-9a77-07212095c2ce", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "# Get the current zoom level.\n", @@ -354,7 +397,9 @@ "cell_type": "code", "execution_count": null, "id": "7a834bcf-7d5a-492b-bc54-740e1500a2f4", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "# Set the zoom level directly.\n", @@ -365,7 +410,9 @@ "cell_type": "code", "execution_count": null, "id": "32288b81-1817-4549-b2e4-5e7f55b0ee3d", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "# Set the relative zoom based on current zoom level.\n", @@ -384,7 +431,9 @@ "cell_type": "code", "execution_count": null, "id": "270a6dd2-ce21-457f-845e-19cf5405fee7", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "# Add 20 randomly generated X,Y (0-indexed) w.r.t. reference image\n", @@ -408,13 +457,18 @@ "cell_type": "code", "execution_count": null, "id": "9ecfd0f9-da9e-419b-99a8-cc6efc20568f", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "np.random.seed(42)\n", "# Mark some sky coordinates using updated marker properties.\n", - "t_sky = Table({'coord': [sky.spherical_offsets_by(*np.random.normal(scale=0.1, size=2) * u.arcsec)\n", - " for i in range(5)]})\n", + "t_sky = Table({'coord': [\n", + " sky.spherical_offsets_by(\n", + " *np.random.normal(scale=0.1, size=2) * u.arcsec\n", + " ) for i in range(5)\n", + "]})\n", "viewer.add_markers(t_sky, use_skycoord=True, marker_name='my_sky')\n", "t_sky" ] @@ -431,7 +485,9 @@ "cell_type": "code", "execution_count": null, "id": "776c3b75-a1a9-4141-9d6d-8aa766c58d21", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "viewer.remove_markers(marker_name='my_sky')" @@ -449,7 +505,9 @@ "cell_type": "code", "execution_count": null, "id": "046641de-b173-4377-92d3-344bd4ba48f3", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "viewer.reset_markers()"