Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define footprints (Ellipse/Circle/Polyline/Line) when drawing Catalog/ProgressiveCatalog sources #149

Merged
merged 9 commits into from
Apr 22, 2024

Conversation

bmatthieu3
Copy link
Collaborator

This PR has for aim the ability for the user to draw catalogs with a draw function callback that output a footprint. This can be used to draw for example:

  • proper motion
  • galaxy ellipses

Example:

aladin.addCatalog(A.catalogFromVizieR("VII/237/pgc", "M31", 3, {
        limit: 1000,
        //orderBy: 'nb_ref',
        onClick: 'showTable',
        color: 'yellow',
        hoverColor: 'blue',
        shape: (s) => {
          let coo = A.coo();
          coo.parse(s.data['RAJ2000'] + ' ' + s.data['DEJ2000'])

          let a = (0.1 * Math.pow(10, +s.data.logD25)) / 60;
          let b = (1.0 / Math.pow(10, +s.data.logR25)) * a

          return A.ellipse(coo.lon, coo.lat, a, b, +s.data.PA, {lineWidth: 3});
        }
}));

Output:
image

What still needs to be done:

  • Fix the grid drawing label because I removed the gridCanvas to only have 2 canvas: imageCanvas (webgl) and catalogCanvas (2d). The grid labels are drawn into the catalogCanvas
  • Create/adapt the Line class and expose it in the API. Line could have all the option parameter listed here: Visualize proper motion #91
  • Enhance the drawing performance (this will be for another PR and may only concern Polyline/Line rendering first).

The PR addresses those issues:

@bmatthieu3
Copy link
Collaborator Author

@imbasimba @pmatsson - Here is an example for drawing proper motion over the LMC. These do have been computed from GaiaDR2 with a TAP query returning mean proper motion vectors for all the HEALPix cells on the LMC. The query is the following:

SELECT avg(ra) as ra, avg(dec) as dec, avg(pmra) as pmra, avg(pmdec) as pmdec,
   avg(parallax) as parallax, avg(radial_velocity) as radial_velocity, healpix(ra, dec, 8) AS h
FROM "I/345/gaia2"
WHERE CONTAINS(POINT('ICRS',ra,dec),CIRCLE('ICRS',80.8942,-69.7561,2.5))=1 
   AND sqrt(pmra*pmra+pmdec*pmdec)<30
GROUP BY h

It gives a votable.

And here is the Aladin Lite code snippet that opens that VOTable and define the pm vector over the sources:

let pmraMean = null, pmdecMean = null;
const pmCat = A.catalogFromURL('<my pm votable>', {
  onClick: 'showTable',
  name: 'mean pm over HPX cells around LMC from GaiaDR2',
  hoverColor: 'yellow',
  // Footprint associated to sources
  shape: (s) => {
    // compute the mean of pm over the catalog sources
    if (!pmraMean || !pmdecMean) {
      pmraMean = 0, pmdecMean = 0;
      for (var s of pmCat.getSources()) {
        pmraMean += +s.data.pmra;
        pmdecMean += +s.data.pmdec;
      }

      const numSources = pmCat.getSources().length;

      pmraMean /= numSources
      pmdecMean /= numSources
    }

    let dra = +s.data.pmra - pmraMean;
    let ddec = +s.data.pmdec - pmdecMean;

    let mag = Math.sqrt(dra * dra + ddec * ddec);
    // discard drawing a vector for big pm
    if (mag > 1) {
      return;
    }

    let color = rainbowColorMap(mag * 2)

    return A.line(
      s.ra,
      s.dec,
      s.ra + dra,
      s.dec + ddec,
      null,
      {lineWidth: 3, arrow: true, color}
    )
  }
});
aladin.addCatalog(pmCat);

Result:

image

Do not hesitate to comment if you have ideas for a generic API, options etc...

@bmatthieu3
Copy link
Collaborator Author

cds-astro/ipyaladin#39

@bmatthieu3 bmatthieu3 merged commit 63aebf7 into develop Apr 22, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant