diff --git a/examples/basic-demo-tableload.ipynb b/examples/basic-demo-tableload.ipynb index cae926d..0cb692c 100644 --- a/examples/basic-demo-tableload.ipynb +++ b/examples/basic-demo-tableload.ipynb @@ -187,7 +187,7 @@ "metadata": { "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -201,7 +201,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.9" + "version": "3.10.12" } }, "nbformat": 4, diff --git a/examples/basic_3color.ipynb b/examples/demo-3color.ipynb similarity index 65% rename from examples/basic_3color.ipynb rename to examples/demo-3color.ipynb index 93bdbe5..70067a1 100644 --- a/examples/basic_3color.ipynb +++ b/examples/demo-3color.ipynb @@ -2,21 +2,29 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from firefly_client import FireflyClient\n", - "\n", - "url='https://irsa.ipac.caltech.edu/irsaviewer'\n", - "# url=http://127.0.0.1:8080/firefly # if you have firefly server running locally\n", - "\n", - "fc = FireflyClient.make_client(url)" + "using_lab = False\n", + "#url='https://irsa.ipac.caltech.edu/irsaviewer'\n", + "url = 'http://127.0.0.1:8080/firefly'\n", + "#FireflyClient._debug= True" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "fc = FireflyClient.make_lab_client() if using_lab else FireflyClient.make_client(url)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -64,9 +72,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'success': True,\n", + " 'rv_lst': ['88,1.000000,88,99.000000,4.200000,2.000000,50,25,600,120,1,NaN,0.150000',\n", + " '88,1.000000,88,99.000000,4.200000,2.000000,50,25,600,120,1,NaN,1.000000',\n", + " '88,1.000000,88,99.000000,4.200000,2.000000,50,25,600,120,1,NaN,0.400000']}" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Set stretch using hue-preserving algorithm with scaling coefficients .15 for RED, 1.0 for GREEN, and .4 for BLUE.\n", "fc.set_stretch_hprgb(plot_id='wise_m101', asinh_q_value=4.2, scaling_k=[.15,1,.4])" @@ -74,9 +96,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'success': True,\n", + " 'rv_string': '88,1.000000,88,99.000000,NaN,2.000000,50,25,600,120,0,NaN,1.000000'}" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Set per-band stretch\n", "fc.set_stretch(plot_id='wise_m101', stype='ztype', algorithm='asinh', band='ALL')" @@ -84,9 +118,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'success': True}" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Set contrast and bias for each band\n", "fc.set_rgb_colors(plot_id='wise_m101', bias=[0.4, 0.6, 0.5], contrast=[1.5, 1, 2]) " @@ -94,9 +139,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'success': True}" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Set to use red and blue band only, with default bias and contrast\n", "fc.set_rgb_colors(plot_id='wise_m101', use_green=False) " @@ -112,7 +168,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -126,7 +182,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.9" + "version": "3.10.12" } }, "nbformat": 4, diff --git a/examples/demo-HiPS.ipynb b/examples/demo-HiPS.ipynb new file mode 100644 index 0000000..e478c27 --- /dev/null +++ b/examples/demo-HiPS.ipynb @@ -0,0 +1,173 @@ +{ + "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 firefly_client" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from firefly_client import FireflyClient\n", + "using_lab = False\n", + "url = 'http://127.0.0.1:8080/firefly'\n", + "#FireflyClient._debug= True" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Settings for a WISE image for M81 at a selected band in HiPS format:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "fc = FireflyClient.make_lab_client() if using_lab else FireflyClient.make_client(url)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "target='148.892;69.0654;EQ_J2000'\n", + "fov_deg=0.5\n", + "size=0.2\n", + "\n", + "image_basic_req = {\n", + " 'Service': 'WISE',\n", + " 'Title': 'Wise',\n", + " 'SurveyKey': '3a',\n", + " 'SurveyKeyBand': '2'\n", + "}\n", + "\n", + "hips_basic_req = {\n", + " 'title': 'A HiPS - 0.2',\n", + " 'hipsRootUrl': 'http://alasky.u-strasbg.fr/AllWISE/RGB-W4-W2-W1'\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Show HiPS " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "A HiPS is displayed based on HiPS url" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "viewer_id = 'hipsDIV1'\n", + "r = fc.add_cell(0, 0, 4, 2, 'images', viewer_id)\n", + "if r['success']:\n", + " hips_url = 'http://alasky.u-strasbg.fr/DSS/DSSColor';\n", + " status = fc.show_hips(viewer_id=viewer_id, plot_id='aHipsID1-1', hips_root_url = hips_url, \n", + " Title='HiPS-DSS', WorldPt=target)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Change color attributes in this image:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "fc.set_color('aHipsID1-1', colormap_id=6, bias=0.6, contrast=1.5)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Two more HiPS in the same viewer" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "hips_url = 'http://alasky.u-strasbg.fr/DSS/DSS2Merged';\n", + "status = fc.show_hips(plot_id='aHipsID1-2', hips_root_url = hips_url, \n", + " Title='HiPS-DSS2', WorldPt=target)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "hips_url = 'http://alasky.u-strasbg.fr/AllWISE/RGB-W4-W2-W1'\n", + "status = fc.show_hips(plot_id='aHipsID2', hips_root_url=hips_url)" + ] + } + ], + "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 +} diff --git a/examples/slate-demo-explicit2.ipynb b/examples/demo-advanced-all.ipynb similarity index 83% rename from examples/slate-demo-explicit2.ipynb rename to examples/demo-advanced-all.ipynb index bab3944..95991a2 100644 --- a/examples/slate-demo-explicit2.ipynb +++ b/examples/demo-advanced-all.ipynb @@ -4,8 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "This notebook demonstrates basic usage of the firefly_client API for Firefly Slate Viewer to render tables, images and charts in a grid layout style. This notebook shows the same layout content as what ffapi-api-slate2.html renders in Firefly. \n", - "\n", + "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." ] }, @@ -17,13 +16,6 @@ "## Setup" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Imports for firefly_client" - ] - }, { "cell_type": "code", "execution_count": null, @@ -31,17 +23,17 @@ "outputs": [], "source": [ "from firefly_client import FireflyClient\n", - "\n", - "import astropy.utils.data" + "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": [ - "This example uses http://127.0.0.1:8080/firefly as the server, and 'slate.html' as the html file which is a template made for grid view.\n", - "\n", - "Both of these are passed by default if there are no corresponding environment variables set, but we're still passing them explicitly for clarity." + "Open a browser to the firefly server in a new tab. Only works when running the notebook locally." ] }, { @@ -50,10 +42,18 @@ "metadata": {}, "outputs": [], "source": [ - "url='http://127.0.0.1:8080/firefly' # you can also use public server: https://irsa.ipac.caltech.edu/irsaviewer/\n", - "html = 'slate.html'\n", - "\n", - "fc = FireflyClient.make_client(url, html_file=html)" + "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" ] }, { @@ -107,7 +107,7 @@ "metadata": {}, "outputs": [], "source": [ - "fc.reinit_viewer()\n", + "\n", "\n", "# Add table in cell 'main'. \n", "# 'main' is the cell id currently supported by Firefly for element type 'tables'\n", @@ -146,6 +146,7 @@ "# 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", @@ -304,11 +305,60 @@ " 'WorldPt' : target,\n", " 'RangeValues': rv,\n", " 'SizeInDeg' : '1'\n", - " }]\n", - " \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, @@ -320,7 +370,7 @@ "metadata": { "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -334,7 +384,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.9" + "version": "3.10.12" } }, "nbformat": 4, diff --git a/examples/slate-demo-explicit.ipynb b/examples/demo-advanced-steps.ipynb similarity index 69% rename from examples/slate-demo-explicit.ipynb rename to examples/demo-advanced-steps.ipynb index 80291be..ac27066 100644 --- a/examples/slate-demo-explicit.ipynb +++ b/examples/demo-advanced-steps.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "This notebook demonstrates basic usage of the firefly_client API for Firefly Slate Viewer to render tables, images and charts in a grid layout style. This notebook shows the same layout content as what ffapi-api-slate.html renders in Firefly. \n", + "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." ] @@ -17,29 +17,17 @@ "## Setup" ] }, - { - "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": [ - "This example uses http://127.0.0.1:8080/firefly as the server, and 'slate.html' as the html file which is a template made for grid view.\n", - "\n", - "Both of these are passed by default if there are no corresponding environment variables set, but we're still passing them explicitly for clarity." + "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" ] }, { @@ -48,10 +36,8 @@ "metadata": {}, "outputs": [], "source": [ - "url='http://127.0.0.1:8080/firefly' # you can also use public server: https://irsa.ipac.caltech.edu/irsaviewer/\n", - "html = 'slate.html'\n", - "\n", - "fc = FireflyClient.make_client(url, html_file=html)" + "fc = FireflyClient.make_lab_client() if using_lab else FireflyClient.make_client(url)\n", + "fc.change_triview_layout( FireflyClient.BIVIEW_T_IChCov)" ] }, { @@ -70,47 +56,6 @@ "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": [ - "Instantiating FireflyClient should open a browser to the firefly server in a new tab. You can also achieve this using the following method. The browser open only works when running the notebook locally." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# fc.launch_browser()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "re-init Firefly completely and clean the viewer. You may restart the viewer instead of launching a new browser to repeat rendering cells. " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "fc.reinit_viewer()" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -133,14 +78,12 @@ "metadata": {}, "outputs": [], "source": [ - "r = fc.add_cell(0, 0, 4, 2, 'tables', 'main')\n", "\n", - "if r['success']:\n", - " tbl_name = astropy.utils.data.download_file(\"http://web.ipac.caltech.edu/staff/roby/demo/moving/MOST_results-sample.tbl\",\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", + "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", + "fc.show_table(fc.upload_file(tbl_name), tbl_id='movingtbl', title='A moving object table', page_size=15, meta=meta_info)\n", " " ] }, @@ -175,9 +118,9 @@ "metadata": {}, "outputs": [], "source": [ - "tbl_name = astropy.utils.data.download_file(\"http://web.ipac.caltech.edu/staff/roby/demo/test-table4.tbl\", \n", + "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': 'FITS'}\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)" ] }, @@ -216,12 +159,7 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [ - "r = fc.add_cell(2, 0, 4, 2, 'tableImageMeta', 'image-meta')\n", - "if r['success']:\n", - " fc.show_image_metadata(viewer_id=r['cell_id'])\n", - " " - ] + "source": [] }, { "cell_type": "markdown", @@ -236,11 +174,10 @@ "metadata": {}, "outputs": [], "source": [ - "r = fc.add_cell(0, 4, 2, 2, 'images', 'wise-cutout')\n", - "if r['success']:\n", - " image_name = astropy.utils.data.download_file('http://irsa.ipac.caltech.edu/ibe/data/wise/allsky/4band_p1bm_frm/6a/02206a' +\n", + "\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), viewer_id=r['cell_id'], title='WISE Cutout')\n", + "fc.show_fits(file_on_server=fc.upload_file(image_name), title='WISE Cutout')\n", " " ] }, @@ -257,19 +194,17 @@ "metadata": {}, "outputs": [], "source": [ - "r = fc.add_cell(2, 4, 2, 2, 'images', 'movingStuff')\n", - "if r['success']:\n", - " v_id = r['cell_id']\n", - " fc.show_fits(plot_id='m49025b_143_2', viewer_id=v_id, OverlayPosition='330.347003;-2.774482;EQ_J2000',\n", + "\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', viewer_id=v_id, OverlayPosition='333.539702;-0.779310;EQ_J2000',\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', viewer_id=v_id, OverlayPosition='333.589054;-0.747251;EQ_J2000',\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', viewer_id=v_id, OverlayPosition='333.736578;-0.651222;EQ_J2000',\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", " " @@ -291,20 +226,19 @@ "metadata": {}, "outputs": [], "source": [ - "r = fc.add_cell(4, 0, 2, 3, 'xyPlots', 'chart-cell-xy')\n", - "if r['success']:\n", - " trace1 = {\n", + "\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", + "trace_data=[trace1]\n", " \n", - " layout_s = {'title': 'Coordinates', \n", + "layout_s = {'title': 'Coordinates', \n", " 'xaxis': {'title': 'ra1 (deg)'}, 'yaxis': {'title': 'dec1 (deg)'}} \n", - " fc.show_chart(group_id=r['cell_id'], layout=layout_s, data=trace_data ) " + "fc.show_chart( layout=layout_s, data=trace_data ) " ] }, { @@ -322,9 +256,8 @@ "metadata": {}, "outputs": [], "source": [ - "r = fc.add_cell(4, 2, 2, 3, 'xyPlots')\n", - "if r['success']:\n", - " histData = [\n", + "\n", + "histData = [\n", " {\n", " 'type': 'fireflyHistogram',\n", " 'name': 'magzp', \n", @@ -341,9 +274,9 @@ " }\n", " ]\n", "\n", - " layout_hist = {'title': 'Magnitude Zeropoints',\n", + "layout_hist = {'title': 'Magnitude Zeropoints',\n", " 'xaxis': {'title': 'magzp'}, 'yaxis': {'title': ''}} \n", - " result = fc.show_chart(group_id=r['cell_id'], layout=layout_hist, data=histData ) " + "result = fc.show_chart(layout=layout_hist, data=histData ) " ] }, { @@ -361,11 +294,7 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [ - "r = fc.add_cell(4, 4, 2, 3, 'coverageImage', 'image-coverage')\n", - "if r['success']:\n", - " fc.show_coverage(viewer_id=r['cell_id'])" - ] + "source": [] }, { "cell_type": "markdown", @@ -387,6 +316,15 @@ "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": {}, @@ -404,19 +342,12 @@ " initZoomLevel=2, SurveyKey='asky', SurveyKeyBand='k',\n", " WorldPt='10.68479;41.26906;EQ_J2000', SizeInDeg='.12')" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -430,7 +361,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.9" + "version": "3.10.12" } }, "nbformat": 4, diff --git a/examples/slate-demo.ipynb b/examples/demo-advanced-table-images.ipynb similarity index 84% rename from examples/slate-demo.ipynb rename to examples/demo-advanced-table-images.ipynb index a18ba6b..dbcb27f 100644 --- a/examples/slate-demo.ipynb +++ b/examples/demo-advanced-table-images.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "This notebook demonstrates basic usage of the firefly_client API for Firefly Slate Viewer to render tables, images and charts in a grid layout style. This notebook shows the same layout content as what ffapi-api-slate.html renders in Firefly.\n", + "This notebook demonstrates basic usage of the firefly_client API for Firefly Slate Viewer to 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." ] @@ -26,18 +26,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ - "from firefly_client import FireflyClient" + "from firefly_client import FireflyClient\n", + "using_lab = False\n", + "url = 'http://127.0.0.1:8080/firefly'\n", + "#FireflyClient._debug= True" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "This example uses http://127.0.0.1:8080/firefly as the server, and 'slate.html' as the html file which is a template made for grid view.\n", + "This example uses http://127.0.0.1:8080/firefly as the server.\n", "\n", "Both of these are passed by default if there are no corresponding environment variables set, but we're still passing them explicitly for clarity." ] @@ -48,10 +51,7 @@ "metadata": {}, "outputs": [], "source": [ - "url='http://127.0.0.1:8080/firefly' # you can also use public server: https://irsa.ipac.caltech.edu/irsaviewer/\n", - "html = 'slate.html'\n", - "\n", - "fc = FireflyClient.make_client(url, html_file=html)" + "fc = FireflyClient.make_lab_client() if using_lab else FireflyClient.make_client(url)" ] }, { @@ -60,7 +60,7 @@ "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'.\n" + "Each rendered unit on Firefly." ] }, { @@ -249,19 +249,12 @@ "# show second image in random location. This image is located in the same cell as the previous one \n", "fs.load_second_image_in_random(fc)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -275,7 +268,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.9" + "version": "3.10.12" } }, "nbformat": 4, diff --git a/examples/demo-advanced-tables-images-upload.ipynb b/examples/demo-advanced-tables-images-upload.ipynb new file mode 100644 index 0000000..1825c59 --- /dev/null +++ b/examples/demo-advanced-tables-images-upload.ipynb @@ -0,0 +1,294 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This notebook demonstrates basic usage of the firefly_client API for Firefly to 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": "markdown", + "metadata": {}, + "source": [ + "Imports for firefly_client" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from firefly_client import FireflyClient\n", + "import astropy.utils.data\n", + "using_lab = False\n", + "url = 'http://127.0.0.1:8080/firefly'\n", + "#FireflyClient._debug= True" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This example tentatively uses 127.0.0.1:8080 as the server " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "fc = FireflyClient.make_lab_client() if using_lab else FireflyClient.make_client(url)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Dispaly tables, images, XY charts, and Histograms in Window/Grid like layout\n", + "\n", + "Each rendered unit on Firefly." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Please refer to firefly_slate_demo.py which contains functions to render cells with element tables, images, xy charts or histograms onto Firefly Slate Viewer by using firefly_client API. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import firefly_slate_demo as fs" + ] + }, + { + "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. Only works when running the notebook locally." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Add some tables into cell 'main' (default grid viewer id for tables)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# first table in cell 'main' \n", + "fs.load_moving_table(0,0,4,2, fc)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# add table in cell 'main' for chart and histogram \n", + "fs.add_table_for_chart(fc)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# add table in cell 'main'\n", + "fs.add_simple_image_table(fc)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# add table in cell 'main'\n", + "fs.add_simple_m31_image_table(fc)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "f= '/Users/roby/fits/2mass-m31-2412rows.tbl'\n", + "file= fc.upload_file(f);" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "fc.show_table(file)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "fc.show_table('${cache-dir}/upload_2482826742890803252.fits')\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Add different types of image displays" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# show cell containing the image from the active table with datasource column in cell 'main'\n", + "fs.load_image_metadata(2, 0, 4, 2, fc, 'image-meta')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# show cell containing FITS in cell 'wise-cutout'\n", + "fs.load_image(0, 4, 2, 2, fc, 'wise-cutout') # load an image" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# show cell with 4 FITS of moving objects in cell 'movingStff'\n", + "fs.load_moving(2, 4, 2, 2, fc, 'movingStuff')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Add charts (xy plot and histogram)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# show xy plot in cell 'chart-cell-xy' associated with the table for chart in cell 'main'\n", + "fs.load_xy(4, 0, 2, 3, fc, 'chart-cell-xy')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# show histogram associated with the table for chart in cell 'main', the cell id is generated by firefly_client\n", + "fs.load_histogram(4, 2, 2, 3, fc)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Add more images" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# show cell containing coverage image associated with the active table in cell 'main'\n", + "fs.load_coverage_image(4, 4, 3, 3, fc, 'image-coverage')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# show cell containing image in ranmon location without passing the location and cell id\n", + "fs.load_first_image_in_random(fc)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# show second image in random location. This image is located in the same cell as the previous one \n", + "fs.load_second_image_in_random(fc)" + ] + } + ], + "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 +} diff --git a/examples/basic-demo.ipynb b/examples/demo-basic.ipynb similarity index 95% rename from examples/basic-demo.ipynb rename to examples/demo-basic.ipynb index 66f6a94..343fe79 100644 --- a/examples/basic-demo.ipynb +++ b/examples/demo-basic.ipynb @@ -36,7 +36,12 @@ "metadata": {}, "outputs": [], "source": [ - "from firefly_client import FireflyClient" + "from firefly_client import FireflyClient\n", + "import astropy.utils.data\n", + "using_lab = False\n", + "#url = 'https://irsa.ipac.caltech.edu/irsaviewer'\n", + "url = 'http://127.0.0.1:8080/firefly'\n", + "#FireflyClient._debug= True" ] }, { @@ -46,15 +51,6 @@ "The firefly_client needs to connect to a firefly server. In this example, we use the IRSA Viewer application for the server:" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "url = 'https://irsa.ipac.caltech.edu/irsaviewer'" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -68,7 +64,7 @@ "metadata": {}, "outputs": [], "source": [ - "fc = FireflyClient.make_client(url)" + "fc = FireflyClient.make_lab_client() if using_lab else FireflyClient.make_client(url)" ] }, { @@ -85,15 +81,6 @@ "For the following example, we download a sample image and table by using astropy (it's used only for convenience, 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": {}, @@ -399,7 +386,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.9" + "version": "3.10.12" } }, "nbformat": 4, diff --git a/examples/lsst_footprint_demo.ipynb b/examples/demo-lsst-footprint.ipynb similarity index 88% rename from examples/lsst_footprint_demo.ipynb rename to examples/demo-lsst-footprint.ipynb index cbe3575..2b63fab 100644 --- a/examples/lsst_footprint_demo.ipynb +++ b/examples/demo-lsst-footprint.ipynb @@ -36,16 +36,11 @@ "metadata": {}, "outputs": [], "source": [ - "from firefly_client import FireflyClient" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import astropy.utils.data" + "from firefly_client import FireflyClient\n", + "import astropy.utils.data\n", + "using_lab = False\n", + "url = 'http://127.0.0.1:8080/firefly'\n", + "#FireflyClient._debug= True" ] }, { @@ -55,16 +50,6 @@ "In this example, we use local firefly server (you can also use public server - irsaviewer instead):" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "url = 'http://127.0.0.1:8080/firefly'\n", - "# url = 'https://irsa.ipac.caltech.edu/irsaviewer'" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -78,7 +63,7 @@ "metadata": {}, "outputs": [], "source": [ - "fc = FireflyClient.make_client(url)" + "fc = FireflyClient.make_lab_client() if using_lab else FireflyClient.make_client(url)" ] }, { @@ -169,19 +154,12 @@ " style='fill', \n", " color='rgba(74,144,226,0.30)')" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -195,7 +173,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.9" + "version": "3.10.12" } }, "nbformat": 4, diff --git a/examples/region-text-demo.ipynb b/examples/demo-region.ipynb similarity index 89% rename from examples/region-text-demo.ipynb rename to examples/demo-region.ipynb index 065c9cc..25d3679 100644 --- a/examples/region-text-demo.ipynb +++ b/examples/demo-region.ipynb @@ -36,7 +36,11 @@ "metadata": {}, "outputs": [], "source": [ - "from firefly_client import FireflyClient" + "from firefly_client import FireflyClient\n", + "import astropy.utils.data\n", + "using_lab = False\n", + "url = 'http://127.0.0.1:8080/firefly'\n", + "#FireflyClient._debug= True" ] }, { @@ -46,15 +50,6 @@ "In this example, we use the IRSA Viewer application for firefly server:" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "url='https://irsa.ipac.caltech.edu/irsaviewer'" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -68,7 +63,7 @@ "metadata": {}, "outputs": [], "source": [ - "fc = FireflyClient.make_client(url)" + "fc = FireflyClient.make_lab_client() if using_lab else FireflyClient.make_client(url)" ] }, { @@ -87,15 +82,6 @@ "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": {}, @@ -192,19 +178,12 @@ "status = fc.add_region_data(region_data=text_regions, region_layer_id='layerTextRegion',\n", " plot_id='region test')" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -218,7 +197,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.9" + "version": "3.10.12" } }, "nbformat": 4, diff --git a/examples/demo-show-image.ipynb b/examples/demo-show-image.ipynb new file mode 100644 index 0000000..9c42e65 --- /dev/null +++ b/examples/demo-show-image.ipynb @@ -0,0 +1,56 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from firefly_client import FireflyClient\n", + "using_lab = False\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", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "fc.show_fits(URL='http://web.ipac.caltech.edu/staff/roby/demo/wise-m51-band2.fits')\n" + ] + } + ], + "metadata": { + "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 +} diff --git a/examples/plot-interface.ipynb b/examples/plot-interface.ipynb index e9c3b27..881a65b 100644 --- a/examples/plot-interface.ipynb +++ b/examples/plot-interface.ipynb @@ -35,7 +35,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ @@ -54,7 +54,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -77,9 +77,22 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "Open your web browser to this link" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "ffplt.display_url()" ] @@ -95,7 +108,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -120,7 +133,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [ @@ -129,7 +142,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, "outputs": [], "source": [ @@ -145,7 +158,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, "outputs": [], "source": [ @@ -161,7 +174,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ @@ -179,7 +192,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, "outputs": [], "source": [ @@ -195,7 +208,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": {}, "outputs": [], "source": [ @@ -211,7 +224,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": {}, "outputs": [], "source": [ @@ -234,9 +247,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "astropy.io.fits.hdu.hdulist.HDUList" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "import astropy.io.fits as fits\n", "m31_image_fname = astropy.utils.data.download_file(\n", @@ -255,9 +279,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Image-1'" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "ffplt.upload_image(hdu)" ] @@ -278,9 +313,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "numpy.ndarray" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "data = hdu[0].data\n", "type(data)" @@ -295,9 +341,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Image-2'" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "ffplt.upload_image(data)" ] @@ -318,7 +375,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ @@ -335,7 +392,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ @@ -352,13 +409,31 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'WISE Demo Table'" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "ffplt.upload_table(wise_table, title='WISE Demo Table')" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "code", "execution_count": null, @@ -369,7 +444,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -383,7 +458,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.9" + "version": "3.10.12" } }, "nbformat": 4, diff --git a/examples/slate_hips_test.ipynb b/examples/slate_hips_test.ipynb deleted file mode 100644 index bc5f163..0000000 --- a/examples/slate_hips_test.ipynb +++ /dev/null @@ -1,315 +0,0 @@ -{ - "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 firefly_client" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from firefly_client import FireflyClient" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Settings for a WISE image for M81 at a selected band in HiPS format:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "target='148.892;69.0654;EQ_J2000'\n", - "fov_deg=0.5\n", - "size=0.2\n", - "\n", - "image_basic_req = {\n", - " 'Service': 'WISE',\n", - " 'Title': 'Wise',\n", - " 'SurveyKey': '3a',\n", - " 'SurveyKeyBand': '2'\n", - "}\n", - "\n", - "hips_basic_req = {\n", - " 'title': 'A HiPS - 0.2',\n", - " 'hipsRootUrl': 'http://alasky.u-strasbg.fr/AllWISE/RGB-W4-W2-W1'\n", - "}" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In this example we use irsaviewer as firefly server (slate.html is the default template used)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "url='https://irsa.ipac.caltech.edu/irsaviewer/'\n", - "\n", - "fc = FireflyClient.make_client(url)\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "fc.reinit_viewer()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Show HiPS " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "A HiPS is displayed based on HiPS url" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "viewer_id = 'hipsDIV1'\n", - "r = fc.add_cell(0, 0, 4, 2, 'images', viewer_id)\n", - "if r['success']:\n", - " hips_url = 'http://alasky.u-strasbg.fr/DSS/DSSColor';\n", - " status = fc.show_hips(viewer_id=viewer_id, plot_id='aHipsID1-1', hips_root_url = hips_url, \n", - " Title='HiPS-DSS', WorldPt=target)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Change color attributes in this image:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "fc.set_color('aHipsID1-1', colormap_id=6, bias=0.6, contrast=1.5)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Show another HiPS in the same viewer" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "if r['success']:\n", - " hips_url = 'http://alasky.u-strasbg.fr/DSS/DSS2Merged';\n", - " status = fc.show_hips(viewer_id=viewer_id, plot_id='aHipsID1-2', hips_root_url = hips_url, \n", - " Title='HiPS-DSS2', WorldPt=target)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Show HiP with hips to image conversion info" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Show a HiPS converted to image" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "hiconversion = {\n", - " 'imageRequestRoot': dict(hips_basic_req),\n", - " 'fovDegFallOver': fov_deg\n", - "}\n", - "\n", - "viewer_id = 'hipsDiv2'\n", - "r = fc.add_cell(0, 4, 2, 2, 'images', viewer_id)\n", - "if r['success']:\n", - " hips_url = 'http://alasky.u-strasbg.fr/AllWISE/RGB-W4-W2-W1'\n", - " status = fc.show_hips(viewer_id=viewer_id, plot_id='aHipsID2', hips_root_url=hips_url, \n", - " hips_image_conversion=hiconversion)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Show Image or HiPS\n", - "\n", - "Either HiPS or image is displayed per info, such as size or target, defined in image_request, hips_request or allsky_request. " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "HiPS is displayed => hips_requst: {size:no, target:no}, image_request: {size:no, target:yes} " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "viewer_id = 'hipsDiv3'\n", - "r = fc.add_cell(2, 0, 2, 2, 'images', viewer_id)\n", - "if r['success']:\n", - " status = fc.show_image_or_hips(viewer_id=viewer_id, image_request=dict(image_basic_req),\n", - " hips_request=dict(hips_basic_req), fov_deg_fallover=fov_deg)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "HiPS is displayed => hips_request: {size:no, target:no}, image_request: {target:yes, size:no} " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "viewer_id = 'hipsDiv4'\n", - "r = fc.add_cell(2, 2, 2, 2, 'images', viewer_id)\n", - "if r['success']:\n", - " image_r = dict(image_basic_req)\n", - " image_r.update({'WorldPt': target})\n", - " status = fc.show_image_or_hips(viewer_id=viewer_id, \n", - " image_request=image_r,\n", - " hips_request=dict(hips_basic_req), fov_deg_fallover=fov_deg)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Regular image is displayed => image_request: {size:yes, target:yes} " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "viewer_id = 'hipsDiv5'\n", - "r = fc.add_cell(2, 4, 2, 2, 'images', viewer_id)\n", - "if r['success']:\n", - " image_r = dict(image_basic_req)\n", - " image_r.update({'WorldPt': target, 'SizeInDeg': size})\n", - " status=fc.show_image_or_hips(viewer_id=viewer_id, \n", - " image_request=image_r,\n", - " hips_request=dict(hips_basic_req), fov_deg_fallover=fov_deg)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "All sky is displayed => allsky_request is passed and plot_allsky_first is passed as 'True'" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "viewer_id = 'hipsDiv6'\n", - "r = fc.add_cell(4, 0, 4, 2, 'images', viewer_id)\n", - "if r['success']:\n", - " status=fc.show_image_or_hips(viewer_id=viewer_id, \n", - " image_request=dict(image_basic_req),\n", - " hips_request=dict(hips_basic_req), allsky_request={'Type': 'ALL_SKY'}, \n", - " fov_deg_fallover=fov_deg, plot_allsky_first=True)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "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.8.9" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/firefly_client/env.py b/firefly_client/env.py index 0831f85..dd80692 100644 --- a/firefly_client/env.py +++ b/firefly_client/env.py @@ -29,7 +29,7 @@ class Env: firefly_url_lab = os.environ.get(ENV_FF_URL_LAB) firefly_url = os.environ.get(ENV_FF_URL) firefly_channel_from_env = os.environ.get(ENV_FF_CHANNEL) - firefly_html = os.environ.get(ENV_FF_HTML, 'slate.html') + firefly_html = os.environ.get(ENV_FF_HTML, '') user = os.environ.get(ENV_USER, '') @classmethod diff --git a/firefly_client/fc_utils.py b/firefly_client/fc_utils.py index cd8ccab..a6559e4 100644 --- a/firefly_client/fc_utils.py +++ b/firefly_client/fc_utils.py @@ -83,6 +83,9 @@ def ensure3(val, name): 'PlotMask': 'ImagePlotCntlr.plotMask', 'DeleteOverlayMask': 'ImagePlotCntlr.deleteOverlayPlot', 'AddCell': 'layout.addCell', + 'SetLayoutMode': 'layout.setLayoutMode', + 'UpdateLayout': 'layout.updateLayout', + 'TriviewLayout': 'layout.triviewLayout', 'ShowCoverage': 'layout.enableSpecialViewer', 'ShowImageMetaData': 'layout.enableSpecialViewer', 'ReinitViewer': 'app_data.reinitApp', diff --git a/firefly_client/firefly_client.py b/firefly_client/firefly_client.py index 02ae68b..8308261 100644 --- a/firefly_client/firefly_client.py +++ b/firefly_client/firefly_client.py @@ -57,7 +57,7 @@ class FireflyClient: WebSocket channel ID. Default is None which auto-generates a unique string. html_file : `str` HTML file that is the 'landing page' for users, appended to the URL. - Defaults to 'slate.html'. + Defaults to ''. If the landing page in 'slate.html' it puts FireflyClient into slate mode. make_default : `bool` If True, make this the default FireflyClient instance. Default False. use_lab_env : `bool` @@ -74,6 +74,41 @@ class FireflyClient: in the sessions attribute. """ + TAB_ID = 'firefly-viewer-tab-id' + TRIVIEW_ICov_Ch_T = 'TRIVIEW_ICov_Ch_T' + TRIVIEW_I_ChCov_T = 'TRIVIEW_I_ChCov_T' + BIVIEW_ICov_Ch = 'BIVIEW_ICov_Ch' + BIVIEW_I_ChCov = 'BIVIEW_I_ChCov' + BIVIEW_T_IChCov = 'BIVIEW_T_IChCov' + BIVIEW_IChCov_T = 'BIVIEW_IChCov_T' + tri_view_types_list = [ + TRIVIEW_ICov_Ch_T, + TRIVIEW_I_ChCov_T, + BIVIEW_ICov_Ch, + BIVIEW_I_ChCov, + BIVIEW_T_IChCov, + BIVIEW_IChCov_T + ] + + tri_view_layout_desc = { + TRIVIEW_ICov_Ch_T: 'top left: image/cov, top right: charts, bottom: tables', + TRIVIEW_I_ChCov_T: 'top left: image, top right: charts/cov, bottom: tables', + BIVIEW_ICov_Ch: 'left: image/cov, right: charts', + BIVIEW_I_ChCov: 'left: image, right: charts/cov', + BIVIEW_T_IChCov: 'left: tables, right: image/charts/cov', + BIVIEW_IChCov_T: 'left: image/charts/cov, right: tables', + } + + # viewer modes + TRIVIEW_VIEWER = 'FireflyViewer' + SLATE_VIEWER = 'FireflySlate' + NO_VIEWER = 'NO_VIEWER' + _viewer_modes = [TRIVIEW_VIEWER,SLATE_VIEWER,NO_VIEWER] + + # viewer ids + PINNED_CHART_VIEWER_ID = 'PINNED_CHART_VIEWER_ID' + PINNED_IMAGE_VIEWER_ID = 'DEFAULT_FITS_VIEWER_ID' + _debug = False # Keep track of instances. instances = [] @@ -102,12 +137,12 @@ def make_lab_client(cls, start_browser_tab=False, html_file=_def_html_file, star Chrome: look at the right side of the address bar Firefox: a preference bar appears at the top Safari: shows an animation to follow on the left side bar - html_file : `str`, optional + html_file: `str`, optional HTML file that is the 'landing page' for users, appended to the URL. - You should almost always take the default, e.g. 'slate.html'. Defaults to the value of the environment variable 'FIREFLY_URL' if - it is defined: otherwise defaults to None. - start_tab : `bool`, optional + it is defined: otherwise defaults to ''. + If the landing page in 'slate.html' it puts FireflyClient into slate mode. + start_tab: `bool`, optional If True, bring up a Jupyterlab or a browser tab for Firefly. You should almost always take the default. token: `str` or None A token for connecting to a Firefly server that requires @@ -127,12 +162,12 @@ def make_lab_client(cls, start_browser_tab=False, html_file=_def_html_file, star fc = cls(url, channel, html_file, token) if tab_type: verbose and tab_type == BROWSER and Env.show_start_browser_tab_msg(fc.get_firefly_url()) - fc._lab_env_tab_start(tab_type) + fc._lab_env_tab_start(tab_type, html_file) return fc @classmethod def make_client(cls, url=_default_url, html_file=_def_html_file, launch_browser=True, - channel_override=None, verbose=False, token=None): + channel_override=None, verbose=False, token=None, viewer_override=None): """ Factory method to create a Firefly client in a plain Python, IPython, or notebook session, and attempt to open a display. If a display cannot be @@ -140,16 +175,17 @@ def make_client(cls, url=_default_url, html_file=_def_html_file, launch_browser= Parameters ---------- - url : `str`, optional + url: `str`, optional URL of the Firefly server. The default is determined by checking environment variables 'fireflyURLLab' and 'FIREFLY_URL'; if these are undefined, then the default is 'http://localhost:8080/firefly' for the case of a user running a Firefly server on their desktop. - html_file : `str`, optional + html_file: `str`, optional HTML file that is the 'landing page' for users, appended to the URL. - The default is the value of the environment variable 'FIREFLY_HTML' - if it is defined; otherwise 'slate.html'. - launch_browser : `bool`, optional + Defaults to the value of the environment variable 'FIREFLY_URL' if + it is defined: otherwise defaults to ''. + If the landing page in 'slate.html' it puts FireflyClient into slate mode. + launch_browser: `bool`, optional If True, attempt to launch a browser tab for the Firefly viewer. If that attempt is unsuccessful, a link for the Firefly viewer is displayed. @@ -166,18 +202,23 @@ def make_client(cls, url=_default_url, html_file=_def_html_file, launch_browser= authentication. The provided token will be appended to the string "Bearer " to form the value of the "Authorization" header in the sessions attribute. + viewer_override: `str` + This parameter is almost never used, default to None. + It is only for those special circumstances that you would use + firefly_client to control a custom created interface that is not a triview ora slate view. + maybe one of FireflyClient.TRIVIEW_VIEWER, FireflyClient.SLATE_VIEWER, FireflyClient.NO_VIEWER, Returns ------- fc : `FireflyClient` A FireflyClient that works in the lab environment """ - fc = cls(url, Env.resolve_client_channel(channel_override), html_file, token) + fc = cls(url, Env.resolve_client_channel(channel_override), html_file, token, viewer_override) verbose and Env.show_start_browser_tab_msg(fc.get_firefly_url()) launch_browser and fc.launch_browser() return fc - def __init__(self, url, channel, html_file=_def_html_file, token=None): + def __init__(self, url, channel, html_file=_def_html_file, token=None, viewer_override=None): DebugMarker.firefly_client_debug = FireflyClient._debug FireflyClient.instances.append(weakref.ref(self)) @@ -199,30 +240,46 @@ def __init__(self, url, channel, html_file=_def_html_file, token=None): self.session = requests.Session() token and ssl and self.session.headers.update(self.auth_headers) not ssl and token and warn('token ignored: should be None when url starts with http://') + self.firefly_viewer = FireflyClient.get_viewer_mode(html_file,viewer_override) debug('new instance: %s' % url) - def _lab_env_tab_start(self, tab_type): + def _lab_env_tab_start(self, tab_type, html_file): """start a tab in the lab environment, tab_type must be 'lab' or 'browser' """ self.lab_env_tab_type = tab_type if tab_type == BROWSER: idx = self.channel.find('__viewer') c = self.channel[0:idx] if idx > -1 else self.channel # the ext will add '__viewer' so I have to remove it - self.dispatch(ACTION_DICT['StartBrowserTab'], {'channel': c}, Env.firefly_channel_lab) + self.dispatch(ACTION_DICT['StartBrowserTab'], + {'channel': c, 'fireflyHtmlFile': _def_html_file}, Env.firefly_channel_lab) elif tab_type == LAB: if not self.render_tree_id: - self.render_tree_id = 'slateClient-%s-%s' % (len(self.instances), round(time.time())) - self.show_lab_tab() + self.render_tree_id = FireflyClient.TAB_ID # no longer generating redner_tree_id + # self.render_tree_id = 'slateClient-%s-%s' % (len(self.instances), round(time.time())) + self.show_lab_tab(html_file) - def show_lab_tab(self): + def show_lab_tab(self, html_file): """If using a jupyter lab tab- show it or reopen it. If not using a lab tab then noop""" - self.lab_env_tab_type = LAB and self.dispatch(ACTION_DICT['StartLabWindow'], {}) + self.lab_env_tab_type = (LAB and + self.dispatch(ACTION_DICT['StartLabWindow'], + {'fireflyHtmlFile': html_file})) + + @staticmethod + def get_viewer_mode(html_file, viewer_override): + if viewer_override: + if viewer_override in _viewer_modes: + return viewer_override + else: + warn('viewer_override mode: {} is not a recognized mode, using {}'.format(viewer_override, UNKNOWN)) + return UNKNOWN + else: + return FireflyClient.SLATE_VIEWER if html_file == 'slate.html' else FireflyClient.TRIVIEW_VIEWER def _send_url_as_get(self, url): return self.call_response(self.session.get(url, headers=self.header_from_ws)) def _send_url_as_post(self, data): return self.call_response(self.session.post(self.url_cmd_service, data=data, headers=self.header_from_ws)) - + def call_response(self, response): if response.status_code != 200: raise ValueError(Env.failed_net_message(self.url, response.status_code)) @@ -247,6 +304,10 @@ def _is_page_connected(self): retval = self._send_url_as_get(url) return retval['active'] + def is_triview(self): return self.firefly_viewer == FireflyClient.TRIVIEW_VIEWER + + def is_slate(self): return self.firefly_viewer == FireflyClient.SLATE_VIEWER + @staticmethod def _make_pid_param(plot_id): return ','.join(plot_id) if isinstance(plot_id, list) else plot_id @@ -294,7 +355,7 @@ def remove_listener(self, callback, name=ALL): ------- out : none - .. note:: `callback` in listener list is removed if all events are removed from the callback. + .. note:: `callback` in the listener list is removed if all events are removed from the callback. """ FFWs.remove_listener(self.channel, self.location, callback, name) @@ -348,7 +409,7 @@ def display_url(self, url=None): ipy_str = '' if 'zmqshell' in ipy_str: from IPython.display import display, HTML - display( HTML('Open your web browser to this link'.format(url))) + display(HTML('Open your web browser to this link'.format(url))) else: print('Open your web browser to {}'.format(url)) @@ -517,7 +578,7 @@ def dispatch(self, action_type, payload, override_channel=None): Parameters ---------- action_type : `str` - Action type, one of actions from FireflyClient's attribute, `ACTION_DICT`. + Action type, one of the actions from FireflyClient's attribute, `ACTION_DICT`. payload : `dict` Payload, the content varies based on the value of `action_type`. override_channel : `str` @@ -526,7 +587,7 @@ def dispatch(self, action_type, payload, override_channel=None): Returns ------- out : `dict` - Status of remotely dispatch, like {'success': True}. + Status of the remote dispatch, like {'success': True}. """ if payload is None: @@ -549,6 +610,31 @@ def dispatch(self, action_type, payload, override_channel=None): # showing fits, tables, XYPlot, adding extension, and adding mask # ------------------------------------------------------------------------- + def change_triview_layout(self, layout): + """ + Change the tri view layout + + Parameters + ---------- + layout : `str` + should be one of + FireflyClient.TRIVIEW_ICov_Ch_T - top left: image/cov, top right: charts, bottom: tables + FireflyClient.TRIVIEW_I_ChCov_T - top left: image, top right: charts/cov, bottom: tables + FireflyClient.BIVIEW_ICov_Ch - left: image/cov, right: charts + FireflyClient.BIVIEW_I_ChCov - left: image, right: charts/cov + FireflyClient.BIVIEW_T_IChCov- left: tables, right: image/charts/cov + FireflyClient.BIVIEW_IChCov_T- left: image/charts/cov, right: tables + """ + + if not self.is_triview(): + return {'success': True, 'warning': 'change_triview_layout ignored when not in triview mode'} + if layout not in FireflyClient.tri_view_types_list: + warning = '{} is an unknown layout type, valid types: {}'.format(layout, FireflyClient.tri_view_types_list) + return {'success': False, 'warning': warning} + + self.dispatch(ACTION_DICT['TriviewLayout'], {'triviewLayout': layout}) + return {'success': True, 'description': FireflyClient.tri_view_layout_desc[layout]} + def add_cell(self, row, col, width, height, element_type, cell_id=None): """ Add a slate viewer cell. @@ -573,6 +659,9 @@ def add_cell(self, row, col, width, height, element_type, cell_id=None): out : `dict` Status of the request, like {'success': True, 'cell_id': 'Cell-1'}. """ + if not self.is_slate(): + return {'success': True, 'cell_id': cell_id if cell_id else 'noop', + 'warning': 'add_cell ignored when not in slate mode'} # force the cell_id to be 'main' for table's case if element_type == LO_VIEW_DICT['table']: @@ -647,17 +736,19 @@ def show_fits(self, file_on_server=None, plot_id=None, viewer_id=None, **additio payload = {'wpRequest': wp_request, 'useContextModifications': True} - if not viewer_id: - viewer_id = 'DEFAULT_FITS_VIEWER_ID' - if self.render_tree_id: - viewer_id += '_' + self.render_tree_id + warning = None + if not viewer_id or self.is_triview(): + warning = 'viewer_id unnecessary and ignored in triview mode' if self.is_triview() and viewer_id else None + viewer_id = FireflyClient.PINNED_IMAGE_VIEWER_ID payload.update({'viewerId': viewer_id}) plot_id and payload['wpRequest'].update({'plotId': plot_id}) file_on_server and payload['wpRequest'].update({'file': file_on_server}) additional_params and payload['wpRequest'].update(additional_params) - return self.dispatch(ACTION_DICT['ShowFits'], payload) + r = self.dispatch(ACTION_DICT['ShowFits'], payload) + warning and r.update({'warning': warning}) + return r def show_fits_3color(self, three_color_params, plot_id=None, viewer_id=None): """ @@ -691,13 +782,15 @@ def show_fits_3color(self, three_color_params, plot_id=None, viewer_id=None): item.update({'plotId': plot_id}) payload = {'wpRequest': three_color, 'threeColor': True, 'useContextModifications': True} - if not viewer_id: - viewer_id = 'DEFAULT_FITS_VIEWER_ID' - if self.render_tree_id: - viewer_id += '_' + self.render_tree_id + warning = None + if not viewer_id or self.is_triview(): + warning = 'viewer_id unnecessary and ignored in triview mode' if self.is_triview() and viewer_id else None + viewer_id = FireflyClient.PINNED_IMAGE_VIEWER_ID payload.update({'viewerId': viewer_id}) - return self.dispatch(ACTION_DICT['ShowFits'], payload) + r = self.dispatch(ACTION_DICT['ShowFits'], payload) + warning and r.update({'warning': warning}) + return r def show_table(self, file_on_server=None, tbl_id=None, title=None, page_size=100, is_catalog=True, meta=None, target_search_info=None, options=None, table_index=None, @@ -912,16 +1005,22 @@ def show_xyplot(self, tbl_id, standalone=False, group_id=None, **chart_params): cid = gen_item_id('XYPlot') - if not group_id: + warning = None + if self.is_triview(): + warning = 'group_id unnecessary and ignored in triview mode' if group_id else None + group_id = FireflyClient.PINNED_CHART_VIEWER_ID + elif not group_id: group_id = 'default' if standalone else tbl_id payload = {'chartId': cid, 'chartType': 'scatter', 'groupId': group_id, 'viewerId': group_id, 'params': {'tbl_id': tbl_id, **chart_params}} - return self.dispatch(ACTION_DICT['ShowXYPlot'], payload) + r = self.dispatch(ACTION_DICT['ShowXYPlot'], payload) + warning and r.update({'warning': warning}) + return r - def show_histogram(self, tbl_id, group_id='default', **histogram_params): + def show_histogram(self, tbl_id, group_id=PINNED_CHART_VIEWER_ID, **histogram_params): """ Show a histogram @@ -957,15 +1056,22 @@ def show_histogram(self, tbl_id, group_id='default', **histogram_params): .. note:: For the histogram parameters, `col` is required. """ + warning = None + if self.is_triview(): + warning = 'group_id unnecessary and ignored in triview mode' if group_id else None + group_id = FireflyClient.PINNED_CHART_VIEWER_ID + cid = gen_item_id('Histogram') payload = {'chartId': cid, 'chartType': 'histogram', 'groupId': group_id, 'viewerId': group_id, 'params': {'tbl_id': tbl_id, **histogram_params}} - return self.dispatch(ACTION_DICT['ShowXYPlot'], payload) + r = self.dispatch(ACTION_DICT['ShowXYPlot'], payload) + warning and r.update({'warning': warning}) + return r - def show_chart(self, group_id='default', **chart_params): + def show_chart(self, group_id=PINNED_CHART_VIEWER_ID, **chart_params): """ Show a plot.ly chart @@ -1001,6 +1107,10 @@ def show_chart(self, group_id='default', **chart_params): """ chart_id = chart_params.get('chartId') if 'chartId' in chart_params else gen_item_id('Plotly') + warning = None + if self.is_triview(): + warning = 'group_id unnecessary and ignored in triview mode' if group_id else None + group_id = FireflyClient.PINNED_CHART_VIEWER_ID payload = {'chartId': chart_id, 'groupId': group_id, 'viewerId': group_id, @@ -1010,7 +1120,9 @@ def show_chart(self, group_id='default', **chart_params): for item in ['data', 'layout']: (item in chart_params) and payload.update({item: chart_params.get(item)}) - return self.dispatch(ACTION_DICT['ShowPlot'], payload) + r = self.dispatch(ACTION_DICT['ShowPlot'], payload) + warning and r.update({'warning': warning}) + return r def show_coverage(self, viewer_id=None, table_group='main'): """ @@ -1028,6 +1140,8 @@ def show_coverage(self, viewer_id=None, table_group='main'): out : `dict` Status of the request, like {'success': True} """ + if self.is_triview(): + return {'success': True, 'warning': 'show_coverage ignored in triview mode'} view_type = 'coverImage' cid = viewer_id if viewer_id else ("%s-%s" % (LO_VIEW_DICT[view_type], table_group)) @@ -1050,6 +1164,9 @@ def show_image_metadata(self, viewer_id=None, table_group='main'): out : `dict` Status of the request, like {'success': True} """ + if self.is_triview(): + return {'success': True, 'warning': 'show_image_metadata ignored in triview mode'} + view_type = 'imageMeta' cid = viewer_id if viewer_id else ("%s-%s" % (LO_VIEW_DICT[view_type], table_group)) payload = {'viewerType': LO_VIEW_DICT[view_type], 'cellId': cid} @@ -1190,17 +1307,19 @@ def show_hips(self, plot_id=None, viewer_id=None, hips_root_url=None, hips_image payload.update({'plotId': plot_id}) wp_request.update({'plotId': plot_id}) - if not viewer_id: - viewer_id = 'DEFAULT_FITS_VIEWER_ID' - if self.render_tree_id: - viewer_id += '_' + self.render_tree_id + warning = None + if not viewer_id or self.is_triview(): + warning = 'viewer_id unnecessary and ignored in triview mode' if self.is_triview() and viewer_id else None + viewer_id = FireflyClient.PINNED_IMAGE_VIEWER_ID payload.update({'viewerId': viewer_id}) if hips_image_conversion and type(hips_image_conversion) is dict: payload.update({'hipsImageConversion': hips_image_conversion}) - return self.dispatch(ACTION_DICT['ShowHiPS'], payload) + r = self.dispatch(ACTION_DICT['ShowHiPS'], payload) + warning and r.update({'warning': warning}) + return r def show_image_or_hips(self, plot_id=None, viewer_id=None, image_request=None, hips_request=None, fov_deg_fallover=0.12, allsky_request=None, plot_allsky_first=False): @@ -1237,10 +1356,10 @@ def show_image_or_hips(self, plot_id=None, viewer_id=None, image_request=None, h if not plot_id: plot_id = gen_item_id('Image') - if not viewer_id: - viewer_id = 'DEFAULT_FITS_VIEWER_ID' - if self.render_tree_id: - viewer_id += '_' + self.render_tree_id + warning = None + if not viewer_id or self.is_triview(): + warning = 'viewer_id unnecessary and ignored in triview mode' if self.is_triview() and viewer_id else None + viewer_id = FireflyClient.PINNED_IMAGE_VIEWER_ID payload = {'fovDegFallOver': fov_deg_fallover, 'plotAllSkyFirst': plot_allsky_first, 'plotId': plot_id, 'viewerId': viewer_id} @@ -1256,7 +1375,9 @@ def show_image_or_hips(self, plot_id=None, viewer_id=None, image_request=None, h hips_request and payload.update({'hipsRequest': hips_request}) allsky_request and payload.update({'allSkyRequest': allsky_request}) - return self.dispatch(ACTION_DICT['ShowImageOrHiPS'], payload) + r = self.dispatch(ACTION_DICT['ShowImageOrHiPS'], payload) + warning and r.update({'warning': warning}) + return r # ---------------------------- # actions on image diff --git a/setup.py b/setup.py index 9c6e8dc..139110c 100755 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ setup( name='firefly_client', - version='2.9.0', + version='3.0.0', description='Python API for Firefly', author='IPAC LSST SUIT', license='BSD',