{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "This notebook demonstrates basic usage of the firefly_client API fto render tables, images and charts in a grid layout style.\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": [ "\n", "## Setup" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from firefly_client import FireflyClient\n", "import astropy.utils.data\n", "using_lab = True\n", "url = 'http://127.0.0.1:8080/firefly'\n", "#FireflyClient._debug= True" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fc = FireflyClient.make_lab_client() if using_lab else FireflyClient.make_client(url)\n", "fc.change_triview_layout( FireflyClient.BIVIEW_T_IChCov)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Display tables, images, XY charts, and Histograms in Window/Grid like layout\n", "\n", "Each rendered unit on Firefly Slate Viewer is called a'cell'. To render a cell and its content, the cell location (row, column, width, height), element type and cell ID are needed. (row, column) and (width, height) represent the position and size of the cell in terms of the grid blocks on Firefly Slate Viewer. Element types include types of 'tables', images', 'xyPlots', 'tableImageMeta' and 'coverageImage'. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We use astropy here for convenience, but firefly_client itself does not depend on astropy." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "## Display tables and catalogs\n", "\n", "\n", "Add some tables into cell 'main' (default cell id for tables)\n", "\n", "\n", "- add first table in cell 'main':\n", "- 'main' is the cell id currently supported by Firefly for element type 'tables'\n", "- this cell is shown at row = 0, col = 0 with width = 4, height = 2" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "tbl_name = astropy.utils.data.download_file(\"http://web.ipac.caltech.edu/staff/roby/demo/moving/MOST_results-sample.tbl\",\n", " timeout=120, cache=True)\n", "meta_info = {'datasetInfoConverterId': 'SimpleMoving','positionCoordColumns': 'ra_obj;dec_obj;EQ_J2000',\n", " 'datasource': 'image_url'}\n", "fc.show_table(fc.upload_file(tbl_name), tbl_id='movingtbl', title='A moving object table', page_size=15, meta=meta_info)\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- add 2nd table in cell 'main' for chart and histogram " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tbl_name = astropy.utils.data.download_file('http://web.ipac.caltech.edu/staff/roby/demo/WiseDemoTable.tbl',\n", " timeout=120, cache=True)\n", "fc.show_table(fc.upload_file(tbl_name), tbl_id='tbl_chart', title='table for xyplot and histogram', page_size=15)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- add 3rd table in cell 'main'" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tbl_name = astropy.utils.data.download_file(\"http://web.ipac.caltech.edu.s3-us-west-2.amazonaws.com/staff/roby/data-products-test/dp-test.tbl\", \n", " timeout=120, cache=True)\n", "meta_info = {'datasource': 'DP'}\n", "fc.show_table(fc.upload_file(tbl_name), title='A table of simple images', page_size=15, meta=meta_info)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- add 4th table in cell 'main'" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tbl_name = astropy.utils.data.download_file(\"http://web.ipac.caltech.edu/staff/roby/demo/test-table-m31.tbl\", \n", " timeout=120, cache=True)\n", "\n", "meta_info = {'positionCoordColumns': 'ra_obj;dec_obj;EQ_J2000', 'datasource': 'FITS'}\n", "fc.show_table(fc.upload_file(tbl_name), title='A table of m31 images', page_size=15, meta=meta_info)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Add different types of image displays\n", "\n", "- show cell with id 'image-meta' continaing image from the active table containing datasource column in cell 'main'\n", "- the cell is shown at row = 2, col = 0 with width = 4, height = 2 " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- show cell 'wise-content' containing fits at row = 0, col = 4 with width = 2, height = 2" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "image_name = astropy.utils.data.download_file('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", "fc.show_fits(file_on_server=fc.upload_file(image_name), title='WISE Cutout')\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- show 4 fits of moving objects in cell 'movingStff' at row = 2, col = 4 with width = 2, height = 2" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "fc.show_fits(plot_id='m49025b_143_2', OverlayPosition='330.347003;-2.774482;EQ_J2000',\n", " ZoomType='TO_WIDTH_HEIGHT', Title='49025b143-w2', plotGroupId='movingGroup',\n", " URL='http://web.ipac.caltech.edu/staff/roby/demo/moving/49025b143-w2-int-1b.fits')\n", "fc.show_fits(plot_id='m49273b_134_2', OverlayPosition='333.539702;-0.779310;EQ_J2000',\n", " ZoomType='TO_WIDTH_HEIGHT', Title='49273b134-w2', plotGroupId='movingGroup',\n", " URL='http://web.ipac.caltech.edu/staff/roby/demo/moving/49273b134-w2-int-1b.fits')\n", "fc.show_fits(plot_id='m49277b_135_1', OverlayPosition='333.589054;-0.747251;EQ_J2000',\n", " ZoomType='TO_WIDTH_HEIGHT', Title='49277b135-w1', plotGroupId='movingGroup',\n", " URL='http://web.ipac.caltech.edu/staff/roby/demo/moving/49277b135-w1-int-1b.fits')\n", "fc.show_fits(plot_id='m49289b_134_2', OverlayPosition='333.736578;-0.651222;EQ_J2000',\n", " ZoomType='TO_WIDTH_HEIGHT', Title='49289b134-w2', plotGroupId='movingGroup',\n", " URL='http://web.ipac.caltech.edu/staff/roby/demo/moving/49289b134-w2-int-1b.fits')\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Add charts (xy plot and histogram)\n", "\n", "- show the cell 'chart-cell-xy' with xy plot related to the table with id 'tbl_chart' in cell 'main'\n", "- this cell is shown at row = 4, col = 0 with width = 2, height = 3" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "trace1 = {\n", " 'tbl_id': 'tbl_chart',\n", " 'x': \"tables::ra1\",\n", " 'y': \"tables::dec1\",\n", " 'mode': 'markers',\n", " 'type': 'scatter', \n", " 'marker': {'size': 4}}\n", "trace_data=[trace1]\n", " \n", "layout_s = {'title': 'Coordinates', \n", " 'xaxis': {'title': 'ra1 (deg)'}, 'yaxis': {'title': 'dec1 (deg)'}} \n", "fc.show_chart( layout=layout_s, data=trace_data ) " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- show the cell with histogram related to the table with id 'tbl_chart' in cell 'main', \n", "- this cell is shown at row = 4, col = 2, with width = 2, height = 3 \n", "- the cell id is automatically created by FireflyClient in case it is not specified externally. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "histData = [\n", " {\n", " 'type': 'fireflyHistogram',\n", " 'name': 'magzp', \n", " 'marker': {'color': 'rgba(153, 51, 153, 0.8)'},\n", " 'firefly': {\n", " 'tbl_id': 'tbl_chart',\n", " 'options': {\n", " 'algorithm': 'fixedSizeBins',\n", " 'fixedBinSizeSelection': 'numBins',\n", " 'numBins': 30,\n", " 'columnOrExpr': 'magzp'\n", " }\n", " },\n", " }\n", " ]\n", "\n", "layout_hist = {'title': 'Magnitude Zeropoints',\n", " 'xaxis': {'title': 'magzp'}, 'yaxis': {'title': ''}} \n", "result = fc.show_chart(layout=layout_hist, data=histData ) " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Add more images\n", "\n", "- show coverage image associated with the active table in cell 'main'\n", "- ths cell is shown at row = 4, col = 4 with width = 2, height = 3" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- show image in random location without passing cell location and cell id (i.e. without calling add_cell)\n", "- the image is shown in the cell with id 'DEFAULT_FITS_VIEWER_ID' in default, \n", "- and the cell is automatically located by Firefly" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "img_name = astropy.utils.data.download_file('http://web.ipac.caltech.edu/staff/roby/demo/wise-m51-band2.fits', \n", " timeout=120, cache=True)\n", "fc.show_fits(file_on_server=fc.upload_file(img_name))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fc.show_fits(plot_id='zzz', file_on_server=fc.upload_file(img_name))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- show second image in random. it is shown in the same cell as the previous one " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fc.show_fits(plot_id='xxq', Service='TWOMASS', Title='2mass from service', ZoomType='LEVEL',\n", " initZoomLevel=2, SurveyKey='asky', SurveyKeyBand='k',\n", " WorldPt='10.68479;41.26906;EQ_J2000', SizeInDeg='.12')" ] } ], "metadata": { "anaconda-cloud": {}, "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.10.12" } }, "nbformat": 4, "nbformat_minor": 4 }