use of gaiasky.scenegraph.StarCluster in project gaiasky by langurmonkey.
the class StarClusterLoader method addCluster.
private void addCluster(String[] names, double ra, double rarad, double dec, double decrad, double dist, double distpc, double mualphastar, double mudelta, double radvel, double radius, int nstars, Array<StarCluster> clusters) {
Vector3b pos = Coordinates.sphericalToCartesian(rarad, decrad, new Apfloat(dist, Constants.PREC), new Vector3b());
Vector3d pm = AstroUtils.properMotionsToCartesian(mualphastar, mudelta, radvel, Math.toRadians(ra), Math.toRadians(dec), distpc, new Vector3d());
Vector3d posSph = new Vector3d((float) ra, (float) dec, (float) dist);
Vector3 pmSph = new Vector3((float) (mualphastar), (float) (mudelta), (float) radvel);
StarCluster c = new StarCluster(names, parentName != null ? parentName : "MWSC", pos, pm, posSph, pmSph, radius, nstars);
clusters.add(c);
}
use of gaiasky.scenegraph.StarCluster in project gaiasky by langurmonkey.
the class StarClusterLoader method loadData.
@Override
public Array<StarCluster> loadData() {
Array<StarCluster> clusters = new Array<>();
if (active) {
if (files != null) {
for (String file : files) {
FileHandle f = Settings.settings.data.dataFileHandle(file);
InputStream is = f.read();
try {
loadClustersCsv(is, clusters);
} catch (IOException e) {
logger.error(e);
} finally {
try {
is.close();
} catch (IOException e) {
logger.error(e);
}
}
}
} else if (dataSource != null) {
try {
loadClustersStil(dataSource, clusters);
} catch (IOException e) {
logger.error(e);
}
}
}
logger.info(I18n.txt("notif.catalog.init", clusters.size));
return clusters;
}
use of gaiasky.scenegraph.StarCluster 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();
}
}
use of gaiasky.scenegraph.StarCluster in project gaiasky by langurmonkey.
the class StarClusterLoader method loadClustersCsv.
/**
* Loads clusters from a CSV file directly.
* @param data The CSV file input stream.
* @param clusters The clusters list.
* @throws IOException
*/
private void loadClustersCsv(InputStream data, Array<StarCluster> clusters) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(data));
String header = br.readLine();
Map<ClusterProperties, Integer> indices = parseHeader(header);
if (!checkIndices(indices)) {
logger.error("At least 'ra', 'dec', 'pllx'|'dist', 'radius' and 'name' are needed, please check your columns!");
return;
}
String line;
while ((line = br.readLine()) != null) {
// Add galaxy
String[] tokens = line.split(",");
String[] names = parseName(tokens[indices.get(ClusterProperties.NAME)]);
double ra = getDouble(tokens, ClusterProperties.RA, indices);
double rarad = Math.toRadians(ra);
double dec = getDouble(tokens, ClusterProperties.DEC, indices);
double decrad = Math.toRadians(dec);
double distpc = 0;
if (indices.containsKey(ClusterProperties.DIST)) {
distpc = getDouble(tokens, ClusterProperties.DIST, indices);
} else if (indices.containsKey(ClusterProperties.PLLX)) {
distpc = 1000d / getDouble(tokens, ClusterProperties.PLLX, indices);
}
double dist = distpc * Constants.PC_TO_U;
double mualphastar = getDouble(tokens, ClusterProperties.PMRA, indices);
double mudelta = getDouble(tokens, ClusterProperties.PMDE, indices);
double radvel = getDouble(tokens, ClusterProperties.RV, indices);
double radius = getDouble(tokens, ClusterProperties.RADIUS, indices);
int nstars = getInteger(tokens, ClusterProperties.NSTARS, indices);
addCluster(names, ra, rarad, dec, decrad, dist, distpc, mualphastar, mudelta, radvel, radius, nstars, clusters);
}
for (StarCluster c : clusters) {
c.initialize();
}
}
use of gaiasky.scenegraph.StarCluster in project gaiasky by langurmonkey.
the class SAMPClient method notify.
@Override
public void notify(final Event event, Object source, final Object... data) {
switch(event) {
case FOCUS_CHANGED:
if (!preventProgrammaticEvents) {
if (conn != null && conn.isConnected()) {
if (data[0] instanceof ParticleGroup) {
ParticleGroup pg = (ParticleGroup) data[0];
if (idToNode.containsValue(pg)) {
String id = idToNode.getBackward(pg);
String url = idToUrl.get(id);
int row = pg.getCandidateIndex();
Message msg = new Message("table.highlight.row");
msg.addParam("row", Integer.toString(row));
msg.addParam("table-id", id);
msg.addParam("url", url);
try {
conn.getConnection().notifyAll(msg);
} catch (SampException e) {
logger.error(e);
}
}
} else if (data[0] instanceof StarCluster) {
StarCluster sc = (StarCluster) data[0];
if (sc.parent instanceof FadeNode) {
// Comes from a catalog
FadeNode parent = (FadeNode) sc.parent;
if (idToNode.containsValue(parent)) {
String id = idToNode.getBackward(parent);
String url = idToUrl.get(id);
int row = parent.children.indexOf(sc, true);
Message msg = new Message("table.highlight.row");
msg.addParam("row", Integer.toString(row));
msg.addParam("table-id", id);
msg.addParam("url", url);
try {
conn.getConnection().notifyAll(msg);
} catch (SampException e) {
logger.error(e);
}
}
}
}
}
}
break;
case CATALOG_REMOVE:
String dsName = (String) data[0];
if (idToNode.containsKey(dsName)) {
idToNode.removeKey(dsName);
}
idToUrl.remove(dsName);
break;
case DISPOSE:
if (conn != null) {
conn.setActive(false);
}
break;
}
}
Aggregations