{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# STIL Integration\n", "\n", "[STIL](http://www.star.bristol.ac.uk/~mbt/stil/), the Starlink Tables Infrastructure Library, is a Java API for working with astronomical data, including VOTable, FITS, SQL, ASCII, CSV, CDF, and GBIN formats. This notebook shows how to load STIL, and configure BeakerX to display STIL StarTables with the BeakerX interactive table widget." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%classpath add mvn commons-io commons-io 2.6\n", "\n", "import org.apache.commons.io.FileUtils\n", "\n", "stilUrl = \"http://www.star.bristol.ac.uk/~mbt/stil/stil.jar\"\n", "stilFile = System.getProperty(\"java.io.tmpdir\") + \"/stilFiles/stil.jar\"\n", "FileUtils.copyURLToFile(new URL(stilUrl), new File(stilFile));\n", "\n", "%classpath add dynamic stilFile" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import uk.ac.starlink.table.formats.StreamStarTable\n", "import jupyter.Displayer\n", "import jupyter.Displayers\n", "\n", "Displayers.register(StreamStarTable.class, new Displayer() {\n", " \n", " def getArray(t){\n", " nCol = t.getColumnCount()\n", " rseq = t.getRowSequence()\n", " tableAsArray = []\n", " while ( rseq.next() ) {\n", " row = rseq.getRow();\n", " tableAsArray.add(row)\n", " }\n", " rseq.close();\n", " tableAsArray.toArray()\n", " }; \n", " \n", " def getColumnNames(t){\n", " names = []\n", " nCol = t.getColumnCount();\n", " for ( int icol = 0; icol < nCol; icol++ ) {\n", " names.add(t.getColumnInfo(icol).getName())\n", " }\n", " names \n", " }\n", " \n", " @Override\n", " public Map display(StreamStarTable table) {\n", " \n", " array = getArray(table) \n", " columnNames = getColumnNames(table)\n", " \n", " new TableDisplay(\n", " (int)table.getRowCount(),\n", " (int)table.getColumnCount(),\n", " columnNames,\n", " new TableDisplay.Element() {\n", " @Override\n", " public String get(int columnIndex, int rowIndex) {\n", " return array[rowIndex][columnIndex];\n", " }\n", " }\n", " ).display();\n", " return OutputCell.DISPLAYER_HIDDEN;\n", " }\n", " });" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import org.apache.commons.io.FileUtils\n", "\n", "messierUrl = \"http://andromeda.star.bristol.ac.uk/data/messier.csv\"\n", "messierFile = System.getProperty(\"java.io.tmpdir\") + \"/stilFiles/messier.csv\"\n", "FileUtils.copyURLToFile(new URL(messierUrl), new File(messierFile));\n", "\"Done\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import uk.ac.starlink.table.StarTableFactory\n", "\n", "starTable= new StarTableFactory().makeStarTable( messierFile, \"csv\" );" ] } ], "metadata": { "kernelspec": { "display_name": "Groovy", "language": "groovy", "name": "groovy" }, "language_info": { "codemirror_mode": "groovy", "file_extension": ".groovy", "mimetype": "", "name": "Groovy", "nbconverter_exporter": "", "version": "2.4.3" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 2 }