use of uk.ac.starlink.table.StarTableFactory in project gaiasky by langurmonkey.
the class StarClusterLoader method loadClustersStil.
/**
* Loads clusters from a STIL data source.
* @param ds The data source.
* @param clusters The clusters list.
* @throws IOException
*/
private void loadClustersStil(DataSource ds, Array<StarCluster> clusters) throws IOException {
// Add extra builders
StarTableFactory factory = new StarTableFactory();
List builders = factory.getDefaultBuilders();
builders.add(new CsvTableBuilder());
builders.add(new AsciiTableBuilder());
// Try to load
StarTable table = factory.makeStarTable(ds);
Map<ClusterProperties, Integer> indices = parseHeader(table);
if (!checkIndices(indices)) {
logger.error("At least 'ra', 'dec', 'pllx'|'dist', 'radius' and 'name' are needed, please check your columns!");
return;
}
RowSequence rs = table.getRowSequence();
while (rs.next()) {
Object[] row = rs.getRow();
String[] names = parseName(row[indices.get(ClusterProperties.NAME)].toString());
double ra = getDouble(row, ClusterProperties.RA, indices, table, "deg");
double rarad = Math.toRadians(ra);
double dec = getDouble(row, ClusterProperties.DEC, indices, table, "deg");
double decrad = Math.toRadians(dec);
double distpc = 0;
if (indices.containsKey(ClusterProperties.DIST)) {
distpc = getDouble(row, ClusterProperties.DIST, indices, table, "pc");
} else if (indices.containsKey(ClusterProperties.PLLX)) {
distpc = 1000d / getDouble(row, ClusterProperties.PLLX, indices, table, "mas");
}
double dist = distpc * Constants.PC_TO_U;
double mualphastar = getDouble(row, ClusterProperties.PMRA, indices, table, "mas/yr");
double mudelta = getDouble(row, ClusterProperties.PMDE, indices, table, "mas/yr");
double radvel = getDouble(row, ClusterProperties.RV, indices, table, "km/s");
double radius = getDouble(row, ClusterProperties.RADIUS, indices, table, "deg");
int nstars = getInteger(row, ClusterProperties.NSTARS, indices);
addCluster(names, ra, rarad, dec, decrad, dist, distpc, mualphastar, mudelta, radvel, radius, nstars, clusters);
}
for (StarCluster c : clusters) {
c.initialize();
}
}
Aggregations