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.
Note that it may be necessary to wait for some cells (like those displaying an image) to complete before executing later cells.
Imports for Python 2/3 compatibility
from __future__ import print_function, division, absolute_import
Imports for firefly_client
from firefly_client import FireflyClient
This example uses http://127.0.0.1:8080/firefly as the server.
'slate.html' is a template made for grid view
url='http://127.0.0.1:8080/firefly'
html = 'slate.html'
fc = FireflyClient(url, html_file=html)
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'.
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.
import firefly_slate_demo as fs
Open a browser to the firefly server in a new tab. The browser open only works when running the notebook locally, otherwise the browser url will be displayed.
localbrowser, browser_url = fc.launch_browser()
Add some tables into cell 'main' (default grid viewer id for tables)
# first table in cell 'main'
fs.load_moving_table(0,0,4,2, fc)
# add table in cell 'main' for chart and histogram
fs.add_table_for_chart(fc)
# add table in cell 'main'
fs.add_simple_image_table(fc)
# add table in cell 'main'
fs.add_simple_m31_image_table(fc)
# show cell containing the image from the active table with datasource column in cell 'main'
fs.load_image_metadata(2, 0, 4, 2, fc, 'image-meta')
# show cell containing FITS in cell 'wise-cutout'
fs.load_image(0, 4, 2, 2, fc, 'wise-cutout') # load an image
# show cell with 4 FITS of moving objects in cell 'movingStff'
fs.load_moving(2, 4, 2, 2, fc, 'movingStuff')
# show xy plot in cell 'chart-cell-xy' associated with the table for chart in cell 'main'
fs.load_xy(4, 0, 2, 3, fc, 'chart-cell-xy')
# show histogram associated with the table for chart in cell 'main', the cell id is generated by firefly_client
fs.load_histogram(4, 2, 2, 3, fc)
# show cell containing coverage image associated with the active table in cell 'main'
fs.load_coverage_image(4, 4, 3, 3, fc, 'image-coverage')
# show cell containing image in ranmon location without passing the location and cell id
fs.load_first_image_in_random(fc)
# show second image in random location. This image is located in the same cell as the previous one
fs.load_second_image_in_random(fc)