diff --git a/.gitignore b/.gitignore index f722e2e..997c8a1 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ RELIC-INFO relic/ *.wpr *wpu +.ipynb_checkpoints/ \ No newline at end of file diff --git a/general/Ginga_ASDF_Demo_1.ipynb b/general/Ginga_ASDF_Demo_1.ipynb new file mode 100644 index 0000000..0bc1b56 --- /dev/null +++ b/general/Ginga_ASDF_Demo_1.ipynb @@ -0,0 +1,212 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Viewing JWST ASDF in Ginga" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This is a basic example to view JWST ASDF datamodel using Ginga viewer in a Jupyter notebook. Image used in this example is from NIRCam but the general concept should be instrument-agnostic.\n", + "\n", + "**TODO**\n", + "\n", + "* Add GWCS support (pending upstream fixes). Currently, Ginga would report \"bad WCS\"; ignore that until this is addressed.\n", + "* Polish the example based on PR review." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "import warnings\n", + "from jwst import datamodels\n", + "\n", + "filename = ('/grp/jwst/ssb/test_build7.1/examples_for_dms/'\n", + " 'level3/calwebb_image3/sources/nircam_sim/'\n", + " 'jw99999001002_03101_00001_nrcalong_cal.fits')\n", + "\n", + "# Open JWST ASDF data model, ignoring warnings\n", + "with warnings.catch_warnings():\n", + " warnings.simplefilter('ignore')\n", + " im = datamodels.open(filename)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "from ginga.web.pgw import ipg\n", + "\n", + "# Set to some large number\n", + "portnum = 9914\n", + "\n", + "# Set this to True if you have a non-buggy python OpenCv bindings;\n", + "# it greatly speeds up some operations\n", + "use_opencv = False\n", + "\n", + "# Set up Ginga local server\n", + "server = ipg.make_server(\n", + " host='localhost', port=portnum, use_opencv=use_opencv)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "# Start viewer server\n", + "# IMPORTANT: if running in an IPython/Jupyter notebook,\n", + "# use the no_ioloop=True option\n", + "server.start(no_ioloop=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "# Get a viewer\n", + "# This will get a handle to the viewer \"v1\"\n", + "v1 = server.get_viewer('v1')" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'http://localhost:9914/app?id=v1'" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Where is my viewer?\n", + "v1.url" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now copy and paste the link given by `.url` to open viewer in a separate browser tab/window." + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "# Change this to match datamodel as needed\n", + "ext_map = {1: 'data', 2: 'err', 3: 'dq'}\n", + "\n", + "# Define a function for the slider\n", + "def change_ext(ext):\n", + " \"\"\"\n", + " Change displayed extension when it slides.\n", + " \n", + " Parameters\n", + " ----------\n", + " ext : int\n", + " Integer value of the extension.\n", + " \n", + " \"\"\"\n", + " v1.load_data(getattr(im, ext_map[ext]))\n", + " v1.show()" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "04fc907486d347f495f7e9545bf0baed", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "A Jupyter Widget" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "import ipywidgets as widgets\n", + "from ipywidgets import interact\n", + "\n", + "# Initialize and display the slider\n", + "interact(change_ext, ext=widgets.IntSlider(min=1,max=3,step=1,value=1));" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "When you are done, run this last cell to close the datamodel handler." + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "im.close()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}