Search in sources :

Example 1 with StarCluster

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);
}
Also used : Vector3b(gaiasky.util.math.Vector3b) Vector3d(gaiasky.util.math.Vector3d) Vector3(com.badlogic.gdx.math.Vector3) StarCluster(gaiasky.scenegraph.StarCluster) Apfloat(org.apfloat.Apfloat)

Example 2 with StarCluster

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;
}
Also used : Array(com.badlogic.gdx.utils.Array) FileHandle(com.badlogic.gdx.files.FileHandle) InputStream(java.io.InputStream) IOException(java.io.IOException) StarCluster(gaiasky.scenegraph.StarCluster)

Example 3 with StarCluster

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();
    }
}
Also used : AsciiTableBuilder(uk.ac.starlink.table.formats.AsciiTableBuilder) CsvTableBuilder(uk.ac.starlink.table.formats.CsvTableBuilder) RowSequence(uk.ac.starlink.table.RowSequence) StarTableFactory(uk.ac.starlink.table.StarTableFactory) StarTable(uk.ac.starlink.table.StarTable) List(java.util.List) StarCluster(gaiasky.scenegraph.StarCluster)

Example 4 with StarCluster

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();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) StarCluster(gaiasky.scenegraph.StarCluster)

Example 5 with StarCluster

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;
    }
}
Also used : Message(org.astrogrid.samp.Message) ParticleGroup(gaiasky.scenegraph.ParticleGroup) FadeNode(gaiasky.scenegraph.FadeNode) StarCluster(gaiasky.scenegraph.StarCluster)

Aggregations

StarCluster (gaiasky.scenegraph.StarCluster)5 FileHandle (com.badlogic.gdx.files.FileHandle)1 Vector3 (com.badlogic.gdx.math.Vector3)1 Array (com.badlogic.gdx.utils.Array)1 FadeNode (gaiasky.scenegraph.FadeNode)1 ParticleGroup (gaiasky.scenegraph.ParticleGroup)1 Vector3b (gaiasky.util.math.Vector3b)1 Vector3d (gaiasky.util.math.Vector3d)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 List (java.util.List)1 Apfloat (org.apfloat.Apfloat)1 Message (org.astrogrid.samp.Message)1 RowSequence (uk.ac.starlink.table.RowSequence)1 StarTable (uk.ac.starlink.table.StarTable)1 StarTableFactory (uk.ac.starlink.table.StarTableFactory)1 AsciiTableBuilder (uk.ac.starlink.table.formats.AsciiTableBuilder)1 CsvTableBuilder (uk.ac.starlink.table.formats.CsvTableBuilder)1