{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "This notebook demonstrates basic usage of the firefly_client API to render tables, images and charts in a grid layout style. \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": "markdown", "metadata": {}, "source": [ "Open a browser to the firefly server in a new tab. Only works when running the notebook locally." ] }, { "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": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "#os.environ" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Display tables, images, and charts 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' or 'coverageImage'. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Entering a target to search the catalog and image. The coordinates are in decimal hours and decimal degrees for EQ_J2000. The Galactic coordinates are in degrees" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "target = '10.68479;41.26906;EQ_J2000' #Galaxy M31\n", "# other notable targets to try\n", "#target = '148.88822;69.06529;EQ_J2000' #Galaxy M81\n", "#target = '202.48417;47.23056;EQ_J2000' #Galaxy M51\n", "#target = '136.9316774;+1.1195886;galactic' # W5 star-forming region" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "## Display tables, images and charts by using plotly\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- All plots are added in one notebook cell to better simulate an application\n", "- Before re-executing this cell (perhaps with a different target selected), reload the Firefly browser window to clear out the existing plots." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "\n", "# Add 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 = 4 with width = 2, height = 2\n", "\n", "r = fc.add_cell(0, 4, 2, 2, 'tables', 'main')\n", "\n", "if r['success']:\n", " \n", " fc.show_table(tbl_id='wiseCatTbl', title='WISE catalog', \n", " target_search_info={'catalogProject': 'WISE', 'catalog': 'allwise_p3as_psd',\n", " 'position': target, 'SearchMethod': 'Cone', 'radius': 1200},\n", " options={'removable': True, 'showUnits': False, 'showFilters': True})\n", " \n", " \n", "# Add first chart - scatter (plot.ly direct plot)\n", "# in cell 0, 0, 2, 2, \n", "viewer_id = 'newChartContainer'\n", "r = fc.add_cell(0, 0, 2, 2,'xyPlots', viewer_id)\n", "\n", "if r['success']:\n", " trace1 = {\n", " 'tbl_id': 'wiseCatTbl',\n", " 'x': \"tables::w1mpro-w2mpro\",\n", " 'y': \"tables::w2mpro-w3mpro\",\n", " 'mode': 'markers',\n", " 'type': 'scatter', \n", " 'marker': {'size': 4}}\n", " trace_data=[trace1]\n", " \n", " layout_s = {'title': 'Color-Color', \n", " 'xaxis': {'title': 'w1mpro-w2mpro (mag)'}, 'yaxis': {'title': 'w2mpro-w3mpro (mag)'}} \n", " fc.show_chart(group_id=viewer_id, layout=layout_s, data=trace_data )\n", " \n", "# Add second chart - heatmap (plot.ly direct plot) \n", "# in cell 2, 0, 2, 3\n", "viewer_id = 'heatMapContainer'\n", "r = fc.add_cell(2, 0, 2, 3,'xyPlots', viewer_id)\n", "print(r)\n", "\n", "if r['success']:\n", " dataHM = [\n", " {\n", " 'type': 'fireflyHeatmap',\n", " 'name': 'w1 vs. w2',\n", " 'tbl_id': 'wiseCatTbl',\n", " 'x': \"tables::w1mpro\",\n", " 'y': \"tables::w2mpro\",\n", " 'colorscale': 'Blues'\n", " },\n", " {\n", " 'type': 'fireflyHeatmap',\n", " 'name': 'w1 vs. w3',\n", " 'tbl_id': 'wiseCatTbl',\n", " 'x': \"tables::w1mpro\",\n", " 'y': \"tables::w3mpro\",\n", " 'colorscale': 'Reds',\n", " 'reversescale': True\n", " },\n", " {\n", " 'type': 'fireflyHeatmap',\n", " 'name': 'w1 vs. w4',\n", " 'tbl_id': 'wiseCatTbl',\n", " 'x': \"tables::w1mpro\",\n", " 'y': \"tables::w4mpro\",\n", " 'colorscale': 'Greens'\n", " }]\n", "\n", " layout_hm = {'title': 'Magnitude-magnitude densities', \n", " 'xaxis': {'title': 'w1 photometry (mag)'}, 'yaxis': {'title': ''},\n", " 'firefly': {'xaxis': {'min': 5, 'max': 20}, 'yaxis': {'min': 4, 'max': 18}}} \n", "\n", " fc.show_chart(group_id=viewer_id, layout=layout_hm, data=dataHM) \n", " \n", "# Add third chart - histogram (plot.ly direct plot) \n", "# in cell 2, 2, 2, 3\n", "viewer_id = 'histContainer'\n", "r = fc.add_cell(2, 2, 2, 3, 'xyPlots', viewer_id)\n", "\n", "if r['success']:\n", " dataH = [\n", " {\n", " 'type': 'fireflyHistogram',\n", " 'name': 'w1mpro', \n", " 'marker': {'color': 'rgba(153, 51, 153, 0.8)'},\n", " 'firefly': {\n", " 'tbl_id': 'wiseCatTbl',\n", " 'options': {\n", " 'algorithm': 'fixedSizeBins',\n", " 'fixedBinSizeSelection': 'numBins',\n", " 'numBins': 30,\n", " 'columnOrExpr': 'w1mpro'\n", " }\n", " },\n", " },\n", " {\n", " 'type': 'fireflyHistogram',\n", " 'name': 'w2mpro', \n", " 'marker': {'color': 'rgba(102, 153, 0, 0.7)'},\n", " 'firefly': {\n", " 'tbl_id': 'wiseCatTbl',\n", " 'options': {\n", " 'algorithm': 'fixedSizeBins',\n", " 'fixedBinSizeSelection': 'numBins',\n", " 'numBins': 40,\n", " 'columnOrExpr': 'w2mpro' \n", " }\n", " }\n", " }\n", " ]\n", "\n", " layout_hist = {'title': 'Photometry histogram',\n", " 'xaxis': {'title': 'photometry (mag)'}, 'yaxis': {'title': ''}} \n", " result = fc.show_chart(group_id=viewer_id, layout=layout_hist, data=dataH ) \n", " \n", "# Add fourth chart - 3D plot (plot.ly direct plot)\n", "# in cell 2, 4, 2, 3, \n", "viewer_id = '3dChartContainer'\n", "r = fc.add_cell(2, 4, 2, 3, 'xyPlots', viewer_id)\n", "\n", "if r['success']:\n", " data3d = [\n", " {\n", " 'type': 'scatter3d',\n", " 'name': 'w1-w2-w3',\n", " 'tbl_id': 'wiseCatTbl',\n", " 'x': \"tables::w1mpro\",\n", " 'y': \"tables::w2mpro\",\n", " 'z': \"tables::w3mpro\",\n", " 'mode' : 'markers',\n", " 'marker' : {\n", " 'size': 3,\n", " 'color': 'rgba(127, 127, 127, 1)',\n", " 'line': {\n", " 'color': 'rgba(127, 127, 127, 0.5)',\n", " 'width': 1}\n", " },\n", " 'hoverinfo': 'x+y+z'\n", " }]\n", "\n", " fsize = {'size': 11}\n", " layout3d = {\n", " 'title': 'Photometry in band 1, 2, 3',\n", " 'scene':{\n", " 'xaxis': {\n", " 'title': 'w1 (mag)',\n", " 'titlefont': fsize\n", " },\n", " 'yaxis': {\n", " 'title': 'w2 (mag)',\n", " 'titlefont': fsize\n", " },\n", " 'zaxis': {\n", " 'title': 'w3 (mag)',\n", " 'titlefont': fsize\n", " }\n", " }\n", " }\n", " \n", " fc.show_chart(group_id=viewer_id, is_3d=True, layout=layout3d, data=data3d ) \n", " \n", "# Add a three color fits\n", "# in cell 0, 2, 2, 2\n", "viewer_id = '3C'\n", "r = fc.add_cell(0, 2, 2, 2, 'images', viewer_id)\n", "rv = '92,-2,92,8,NaN,2,44,25,600,120'\n", "if r['success']:\n", " threeC= [\n", " {\n", " 'Type' : 'SERVICE',\n", " 'Service' : 'WISE',\n", " 'Title' : '3 color',\n", " 'SurveyKey' : 'Atlas',\n", " 'SurveyKeyBand': '1',\n", " 'WorldPt' : target,\n", " 'RangeValues': rv,\n", " 'SizeInDeg' : '1'\n", " },\n", " {\n", " 'Type' : 'SERVICE',\n", " 'Service' : 'WISE',\n", " 'Title' : '3 color',\n", " 'SurveyKey' : 'Atlas',\n", " 'SurveyKeyBand': '2',\n", " 'WorldPt' : target,\n", " 'RangeValues': rv,\n", " 'SizeInDeg' : '1'\n", " },\n", " {\n", " 'Type' : 'SERVICE',\n", " 'Service' : 'WISE',\n", " 'Title' : '3 color',\n", " 'SurveyKey' : 'Atlas',\n", " 'SurveyKeyBand': '3',\n", " 'WorldPt' : target,\n", " 'RangeValues': rv,\n", " 'SizeInDeg' : '1'\n", " }] \n", " fc.show_fits_3color(threeC, viewer_id=viewer_id)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fc.change_triview_layout( FireflyClient.BIVIEW_IChCov_T)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "rv = '92,-2,92,8,NaN,2,44,25,600,120'\n", "threeC= [\n", " {\n", " 'Type' : 'SERVICE',\n", " 'Service' : 'WISE',\n", " 'Title' : '3 color',\n", " 'SurveyKey' : 'Atlas',\n", " 'SurveyKeyBand': '1',\n", " 'WorldPt' : target,\n", " 'RangeValues': rv,\n", " 'SizeInDeg' : '1'\n", " },\n", " {\n", " 'Type' : 'SERVICE',\n", " 'Service' : 'WISE',\n", " 'Title' : '3 color',\n", " 'SurveyKey' : 'Atlas',\n", " 'SurveyKeyBand': '2',\n", " 'WorldPt' : target,\n", " 'RangeValues': rv,\n", " 'SizeInDeg' : '1'\n", " },\n", " {\n", " 'Type' : 'SERVICE',\n", " 'Service' : 'WISE',\n", " 'Title' : '3 color',\n", " 'SurveyKey' : 'Atlas',\n", " 'SurveyKeyBand': '3',\n", " 'WorldPt' : target,\n", " 'RangeValues': rv,\n", " 'SizeInDeg' : '1'\n", " }] \n", "fc.show_fits_3color(threeC)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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 }