{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "This notebook demonstrates basic usage of the firefly_client API.\n", "\n", "Note that it may be necessary to wait for some cells (like those displaying an image) to complete before executing later cells." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Setup" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Imports for Python 2/3 compatibility" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from __future__ import print_function, division, absolute_import" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Imports for firefly_client" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from firefly_client import FireflyClient" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this example we use the irsaviewer application for the server." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "url='https://irsa.ipac.caltech.edu/irsaviewer'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Instantiate `FireflyClient`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fc = FireflyClient(url)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Download some data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Download a sample image and table.\n", "\n", "We use astropy here for convenience, but firefly_client itself does not depend on astropy." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import astropy.utils.data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Download a cutout of a WISE band 1 image." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "image_url = ('http://irsa.ipac.caltech.edu/ibe/data/wise/allsky/4band_p1bm_frm/6a/02206a' + \n", " '/149/02206a149-w1-int-1b.fits?center=70,20&size=200pix')\n", "filename = astropy.utils.data.download_file(image_url, cache=True, timeout=120)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Download a 2MASS catalog" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "table_url = (\"http://irsa.ipac.caltech.edu/TAP/sync?FORMAT=IPAC_TABLE&\" +\n", " \"QUERY=SELECT+*+FROM+fp_psc+WHERE+CONTAINS(POINT('J2000',ra,dec),\" +\n", " \"CIRCLE('J2000',70.0,20.0,0.1))=1\")\n", "tablename = astropy.utils.data.download_file(table_url, timeout=120, cache=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Display tables and catalogs" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Open a browser to the firefly server in a new tab. The browser open only works when running the notebook locally, otherwise a link is displayed." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "localbrowser, browser_url = fc.launch_browser()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Display the web browser link" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fc.display_url()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Alternatively, uncomment the lines below to display the browser application in the notebook." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#from IPython.display import IFrame\n", "#print('url: %s' % fc.get_firefly_url())\n", "#IFrame(fc.get_firefly_url(), 1100, 1000)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A local file can be uploaded to the server and then displayed." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "imval = fc.upload_file(filename)\n", "status = fc.show_fits(file_on_server=imval, plot_id=\"wise-cutout\", title='WISE Cutout')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`show_fits` can also display an image from a URL" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "status = fc.show_fits(file_on_server=None, plot_id=\"wise-fullimage\", \n", " URL='http://irsa.ipac.caltech.edu/ibe/data/wise/allsky/4band_p1bm_frm/6a/02206a' + \n", " '/149/02206a149-w1-int-1b.fits')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A catalog (with coordinates) will overlay the image by default." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "file= fc.upload_file(tablename)\n", "status = fc.show_table(file, tbl_id='tablemass', title='My 2MASS Catalog', page_size=50)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "An xy plot can be added using the uploaded table data." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "status = fc.show_xyplot(tbl_id='tablemass', xCol='j_m', yCol='h_m-k_m')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Zoom the full image." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "status = fc.set_zoom('wise-fullimage', 2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Pan the image to a celestial coordinate." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "status = fc.set_pan('wise-fullimage', 70, 20, coord='J2000')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Set the stretch" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "status = fc.set_stretch('wise-fullimage', stype='zscale', algorithm='linear')" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "Add region data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "my_regions= ['image;polygon 125 25 160 195 150 150 #color=cyan',\n", " 'icrs;circle 69.95d 20d 30i # color=orange text={region 5/7}']\n", "status = fc.add_region_data(region_data=my_regions, region_layer_id='layer1',\n", " plot_id='wise-cutout')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Remove the second region" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fc.remove_region_data(region_data=my_regions[1], region_layer_id='layer1')" ] } ], "metadata": { "anaconda-cloud": {}, "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.2" } }, "nbformat": 4, "nbformat_minor": 1 }