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.
In [ ]:
%classpath add mvn commons-io commons-io 2.6
import org.apache.commons.io.FileUtils
stilUrl = "http://www.star.bristol.ac.uk/~mbt/stil/stil.jar"
stilFile = System.getProperty("java.io.tmpdir") + "/stilFiles/stil.jar"
FileUtils.copyURLToFile(new URL(stilUrl), new File(stilFile));
%classpath add dynamic stilFile
In [ ]:
import uk.ac.starlink.table.StarTable
import uk.ac.starlink.table.Tables
import jupyter.Displayer
import jupyter.Displayers
Displayers.register(StarTable.class, new Displayer<StarTable>() {
def getColumnNames(t){
names = []
nCol = t.getColumnCount();
for ( int icol = 0; icol < nCol; icol++ ) {
names.add(t.getColumnInfo(icol).getName())
}
names
}
@Override
public Map<String, String> display(StarTable table) {
columnNames = getColumnNames(table)
columnInfos = Tables.getColumnInfos(table)
MAXCHAR = 64
new TableDisplay(
(int)table.getRowCount(),
(int)table.getColumnCount(),
columnNames,
new TableDisplay.Element() {
@Override
public String get(int columnIndex, int rowIndex) {
Object cell = table.getCell(rowIndex, columnIndex);
return columnInfos[columnIndex].formatValue(cell, MAXCHAR)
}
}
).display();
return OutputCell.DISPLAYER_HIDDEN;
}
});
In [ ]:
import org.apache.commons.io.FileUtils
messierUrl = "http://andromeda.star.bristol.ac.uk/data/messier.csv"
messierFile = System.getProperty("java.io.tmpdir") + "/stilFiles/messier.csv"
FileUtils.copyURLToFile(new URL(messierUrl), new File(messierFile));
"Done"
In [ ]:
import uk.ac.starlink.table.StarTable
import uk.ac.starlink.table.StarTableFactory
import uk.ac.starlink.table.Tables
starTable = new StarTableFactory().makeStarTable( messierFile, "csv" );
starTable = Tables.randomTable(starTable)