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'.
We use astropy here for convenience, but firefly_client itself does not depend on astropy.
import astropy.utils.data
Open a browser to the firefly server in a new tab. Only works when running the notebook locally.
fc.launch_browser()
re-init Firefly completely and clean the viewer. You may restart the viewer instead of launching a new browser to repeat rendering cells.
fc.reinit_viewer()
Add some tables into cell 'main' (default cell id for tables)
r = fc.add_cell(0, 0, 4, 2, 'tables', 'main')
if r['success']:
tbl_name = astropy.utils.data.download_file("http://web.ipac.caltech.edu/staff/roby/demo/moving/MOST_results-sample.tbl",
timeout=120, cache=True)
meta_info = {'datasetInfoConverterId': 'SimpleMoving','positionCoordColumns': 'ra_obj;dec_obj;EQ_J2000',
'datasource': 'image_url'}
fc.show_table(fc.upload_file(tbl_name), tbl_id='movingtbl', title='A moving object table', page_size=15, meta=meta_info)
tbl_name = astropy.utils.data.download_file('http://web.ipac.caltech.edu/staff/roby/demo/WiseDemoTable.tbl',
timeout=120, cache=True)
fc.show_table(fc.upload_file(tbl_name), tbl_id='tbl_chart', title='table for xyplot and histogram', page_size=15)
tbl_name = astropy.utils.data.download_file("http://web.ipac.caltech.edu/staff/roby/demo/test-table4.tbl",
timeout=120, cache=True)
meta_info = {'datasource': 'FITS'}
fc.show_table(fc.upload_file(tbl_name), title='A table of simple images', page_size=15, meta=meta_info)
tbl_name = astropy.utils.data.download_file("http://web.ipac.caltech.edu/staff/roby/demo/test-table-m31.tbl",
timeout=120, cache=True)
meta_info = {'positionCoordColumns': 'ra_obj;dec_obj;EQ_J2000', 'datasource': 'FITS'}
fc.show_table(fc.upload_file(tbl_name), title='A table of m31 images', page_size=15, meta=meta_info)
r = fc.add_cell(2, 0, 4, 2, 'tableImageMeta', 'image-meta')
if r['success']:
fc.show_image_metadata(viewer_id=r['cell_id'])
r = fc.add_cell(0, 4, 2, 2, 'images', 'wise-cutout')
if r['success']:
image_name = astropy.utils.data.download_file('http://irsa.ipac.caltech.edu/ibe/data/wise/allsky/4band_p1bm_frm/6a/02206a' +
'/149/02206a149-w1-int-1b.fits?center=70,20&size=200pix')
fc.show_fits(file_on_server=fc.upload_file(image_name), viewer_id=r['cell_id'], title='WISE Cutout')
r = fc.add_cell(2, 4, 2, 2, 'images', 'movingStuff')
if r['success']:
v_id = r['cell_id']
fc.show_fits(plot_id='m49025b_143_2', viewer_id=v_id, OverlayPosition='330.347003;-2.774482;EQ_J2000',
ZoomType='TO_WIDTH_HEIGHT', Title='49025b143-w2', plotGroupId='movingGroup',
URL='http://web.ipac.caltech.edu/staff/roby/demo/moving/49025b143-w2-int-1b.fits')
fc.show_fits(plot_id='m49273b_134_2', viewer_id=v_id, OverlayPosition='333.539702;-0.779310;EQ_J2000',
ZoomType='TO_WIDTH_HEIGHT', Title='49273b134-w2', plotGroupId='movingGroup',
URL='http://web.ipac.caltech.edu/staff/roby/demo/moving/49273b134-w2-int-1b.fits')
fc.show_fits(plot_id='m49277b_135_1', viewer_id=v_id, OverlayPosition='333.589054;-0.747251;EQ_J2000',
ZoomType='TO_WIDTH_HEIGHT', Title='49277b135-w1', plotGroupId='movingGroup',
URL='http://web.ipac.caltech.edu/staff/roby/demo/moving/49277b135-w1-int-1b.fits')
fc.show_fits(plot_id='m49289b_134_2', viewer_id=v_id, OverlayPosition='333.736578;-0.651222;EQ_J2000',
ZoomType='TO_WIDTH_HEIGHT', Title='49289b134-w2', plotGroupId='movingGroup',
URL='http://web.ipac.caltech.edu/staff/roby/demo/moving/49289b134-w2-int-1b.fits')
r = fc.add_cell(4, 0, 2, 3, 'xyPlots', 'chart-cell-xy')
if r['success']:
trace1 = {
'tbl_id': 'tbl_chart',
'x': "tables::ra1",
'y': "tables::dec1",
'mode': 'markers',
'type': 'scatter',
'marker': {'size': 4}}
trace_data=[trace1]
layout_s = {'title': 'Coordinates',
'xaxis': {'title': 'ra1 (deg)'}, 'yaxis': {'title': 'dec1 (deg)'}}
fc.show_chart(group_id=r['cell_id'], layout=layout_s, data=trace_data )
r = fc.add_cell(4, 2, 2, 3, 'xyPlots')
if r['success']:
histData = [
{
'type': 'fireflyHistogram',
'name': 'magzp',
'marker': {'color': 'rgba(153, 51, 153, 0.8)'},
'firefly': {
'tbl_id': 'tbl_chart',
'options': {
'algorithm': 'fixedSizeBins',
'fixedBinSizeSelection': 'numBins',
'numBins': 30,
'columnOrExpr': 'magzp'
}
},
}
]
layout_hist = {'title': 'Magnitude Zeropoints',
'xaxis': {'title': 'magzp'}, 'yaxis': {'title': ''}}
result = fc.show_chart(group_id=r['cell_id'], layout=layout_hist, data=histData )
r = fc.add_cell(4, 4, 2, 3, 'coverageImage', 'image-coverage')
if r['success']:
fc.show_coverage(viewer_id=r['cell_id'])
img_name = astropy.utils.data.download_file('http://web.ipac.caltech.edu/staff/roby/demo/wise-m51-band2.fits',
timeout=120, cache=True)
fc.show_fits(file_on_server=fc.upload_file(img_name))
fc.show_fits(plot_id='xxq', Service='TWOMASS', Title='2mass from service', ZoomType='LEVEL',
initZoomLevel=2, SurveyKey='asky', SurveyKeyBand='k',
WorldPt='10.68479;41.26906;EQ_J2000', SizeInDeg='.12')