From fd6ac8082891bf5a651c5acf43683c56edbe5eec Mon Sep 17 00:00:00 2001 From: "Brett M. Morris" Date: Tue, 6 Feb 2024 15:23:25 -0500 Subject: [PATCH] updates for latest jdaviz, latest example roman data --- notebooks/concepts/imviz_roman_asdf.ipynb | 88 +++++++++++++++-------- 1 file changed, 58 insertions(+), 30 deletions(-) diff --git a/notebooks/concepts/imviz_roman_asdf.ipynb b/notebooks/concepts/imviz_roman_asdf.ipynb index 7d03ba9886..e7d595838d 100644 --- a/notebooks/concepts/imviz_roman_asdf.ipynb +++ b/notebooks/concepts/imviz_roman_asdf.ipynb @@ -70,9 +70,11 @@ "metadata": {}, "outputs": [], "source": [ - "from astropy.utils.data import get_pkg_data_filename\n", + "from astropy.utils.data import download_file\n", "\n", - "image_model = get_pkg_data_filename('data/roman_wfi_image_model.asdf', package='jdaviz.configs.imviz.tests')" + "# # 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)" ] }, { @@ -89,7 +91,8 @@ "\n", "with warnings.catch_warnings():\n", " warnings.simplefilter('ignore') # ErfaWarning\n", - " imviz.load_data(image_model, ext='data')" + " imviz.load_data(image_model1, ext='data', data_label='exposure 1')\n", + " imviz.load_data(image_model2, ext='data', data_label='exposure 2')" ] }, { @@ -107,7 +110,27 @@ "metadata": {}, "outputs": [], "source": [ - "imviz.show()" + "imviz.show('sidecar:split-right', height=1000)" + ] + }, + { + "cell_type": "markdown", + "id": "52adc3d4-7f44-43aa-af46-6acb390d56e2", + "metadata": {}, + "source": [ + "We have loaded two sequential exposures with the same pointing. Let's orient both images by their WCS:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8427d4f9-8ea3-4d60-a8b7-3f3f63e3f3e0", + "metadata": {}, + "outputs": [], + "source": [ + "orientation = imviz.plugins['Orientation']\n", + "\n", + "orientation.link_type = 'WCS'" ] }, { @@ -129,16 +152,20 @@ "metadata": {}, "outputs": [], "source": [ + "plot_options = imviz.plugins['Plot Options']\n", + "\n", "for viewer_name in imviz.app.get_viewer_reference_names():\n", " viewer = imviz.app.get_viewer(viewer_name)\n", - "\n", - " # set colormap and stretch:\n", - " viewer.stretch = 'log'\n", - " viewer.set_colormap('Viridis')\n", - " viewer.cuts = [1, 1e4]\n", + " plot_options.viewer = viewer_name\n", " \n", - " # set zoom level\n", - " viewer.zoom(1.25)" + " for data in viewer.data():\n", + " plot_options.layer = data.label\n", + " \n", + " # set colormap and stretch for this layer:\n", + " plot_options.stretch_function = 'arcsinh'\n", + " plot_options.image_colormap = 'Viridis'\n", + " plot_options.stretch_vmin = 0\n", + " plot_options.stretch_vmax = 20" ] }, { @@ -192,7 +219,8 @@ "metadata": {}, "outputs": [], "source": [ - "mask = regions['Subset 1'].to_mask(mode='subpixels')" + "wcs = imviz.app.data_collection[-1].coords\n", + "mask = regions['Subset 1'].to_pixel(wcs).to_mask(mode='subpixels')" ] }, { @@ -223,6 +251,16 @@ "You can use Astrowidgets API." ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "f2ce00c9-093c-4bc0-8cb7-b7c8fe38ec64", + "metadata": {}, + "outputs": [], + "source": [ + "viewer = imviz.default_viewer" + ] + }, { "cell_type": "code", "execution_count": null, @@ -260,8 +298,7 @@ "metadata": {}, "outputs": [], "source": [ - "center = regions['Subset 1'].center\n", - "data.wcs.pixel_to_world([center.x], [center.y]).to_string('hmsdms')" + "center = regions['Subset 1'].center" ] }, { @@ -272,7 +309,7 @@ "outputs": [], "source": [ "# Center the image on given sky coordinates.\n", - "sky = SkyCoord(ra=\"13h11m34.25069521s\", dec=\"-01d21m55.92127995s\")\n", + "sky = SkyCoord(ra=79.91038, dec=29.95529, unit=('deg', 'deg'))\n", "viewer.center_on(sky)" ] }, @@ -321,7 +358,7 @@ "outputs": [], "source": [ "# Set the zoom level directly.\n", - "viewer.zoom_level = 1" + "viewer.zoom_level = 100" ] }, { @@ -332,7 +369,7 @@ "outputs": [], "source": [ "# Set the relative zoom based on current zoom level.\n", - "viewer.zoom(2)" + "viewer.zoom(1.5)" ] }, { @@ -355,6 +392,7 @@ "image_shape = data.data.shape\n", "t_xy = Table({'x': np.random.randint(0, image_shape[1], 20),\n", " 'y': np.random.randint(0, image_shape[0], 20)})\n", + "\n", "viewer.add_markers(t_xy)" ] }, @@ -366,16 +404,6 @@ "You could customize marker color, alpha, size, and fill with values that Glue supports." ] }, - { - "cell_type": "code", - "execution_count": null, - "id": "7c8edb6f-c928-4aee-8e64-73a34ab020d0", - "metadata": {}, - "outputs": [], - "source": [ - "viewer.marker = {'color': 'green', 'alpha': 0.8, 'markersize': 10, 'fill': False}" - ] - }, { "cell_type": "code", "execution_count": null, @@ -488,7 +516,7 @@ "outputs": [], "source": [ "# Show the first image in the second viewer.\n", - "imviz.app.add_data_to_viewer(viewer_2_name, \"roman_wfi_image_model[DATA]\")" + "imviz.app.add_data_to_viewer(viewer_2_name, \"exposure 1[DATA]\")" ] }, { @@ -518,7 +546,7 @@ "metadata": {}, "outputs": [], "source": [ - "viewer_2.center_on((5, 1))" + "viewer_2.center_on((1500, 1000))" ] }, { @@ -564,7 +592,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.8" + "version": "3.11.5" } }, "nbformat": 4,