GaiaTestGalactic.frink

Download or view GaiaTestGalactic.frink in plain text format


/* This program demonstrates graphing star positions with the Gaia satellite
   data, specifically the data release 2 data.  This is different than
   GaiaTest.frink in that it remaps the stars to "galactic" coordinates.

   It requires downloading the Gaia data (which is huge if you download it
   all; the whole database is about 550 GB, and those are mostly gzipped
   files!) from:
   http://cdn.gea.esac.esa.int/Gaia/gdr2/

   This program just uses the limited data set in gaia_source_with_rv which
   contains data for about 7.2 million stars.  The full data set contains about
   1.2 billion stars.

   The data for gaia_source_with_rv can be downloaded directly from
   http://cdn.gea.esac.esa.int/Gaia/gdr2/gaia_source_with_rv/csv/

   which is about 3.1 GB (gzipped!) of data; it's about 7.5 GB uncompressed.
   The new gunzip function in Frink will allow you to process gzip-compressed
   files in place.

   Description of the whole data release is available at:
   http://gea.esac.esa.int/archive/documentation/GDR2/

   More specifically, the description of the gaia_source table used in this
   program is available in section 14.1.1 of that document at:
   http://gea.esac.esa.int/archive/documentation/GDR2/Gaia_archive/chap_datamodel/sec_dm_main_tables/ssec_dm_gaia_source.html

   This attempts to plot semi-realistic colors for the stars.  Dimmer stars
   only have data in the green channel, so they are plotted as gray.  The
   sensors have a bias toward the green, as can be seen in the chart here:
   https://www.cosmos.esa.int/web/gaia/iow_20180316

   A reference image is available at:
   https://www.cosmos.esa.int/web/gaia/gaiadr2_gaiaskyincolour
*/


use sun.frink

// Modify this path to where your Gaia files reside
dir = "/home/eliasen/builds/Gaia/gdr2/gaia_source_with_rv/csv"

g = new graphics
g.backgroundColor[0,0,0]
neutral = new color[1,1,1,.5]

for url = select[fileURLs[dir], %r/\.csv\.gz/]
{
   println[url]
   lineNum = 0
   for line = lines[gunzip[url]]
   {
      if lineNum == 0
         [colToName, nameToCol] = makeColumnDictionaries[line]
      else
      {
         fields = split[",", line]
         ra = eval[fields@5] degrees
         decl = eval[fields@7] degrees
         // TODO:  Precess the coordinates to B1950.0 epoch
         // using the apparentPosition function.  Also parse
         // and handle proper motion columns.
         [l,b] = raDeclToGalactic[ra, decl]
         l = (l + 1/2 circle) mod circle

         redFlux   = fields@57  // phot_rp_mean_flux
         greenFlux = fields@47  // phot_g_mean_flux
         blueFlux  = fields@52  // phot_bp_mean_flux
         if redFlux == "" or greenFlux == "" or blueFlux == ""
            g.color[neutral]
         else
         {
            redFlux = eval[redFlux] * 1.3
            greenFlux = eval[greenFlux]
            blueFlux = eval[blueFlux] * 1.3
            
            sum = redFlux + greenFlux + blueFlux
            red = redFlux / sum
            green = greenFlux / sum
            blue = blueFlux / sum
            //println[type[redFlux] + "$redFlux $greenFlux $blueFlux"]
            g.color[red, green, blue, .5]
         }
         g.fillRectCenter[-l, -b, .075 degree, .075 degree]
      }
      lineNum = lineNum + 1
   }
}

println["Done reading.  About to render graphics to screen."]
g.show[]
println["Done showing."]

println["Rendering graphics."]
g.write["GaiaTestGalactic.jpg", 3840, undef]
println["Done rendering."]

println["Inverting grays."]
g2 = g.invertGrays[]
println["Done inverting grays.  Beginning printing"]
g2.print[]
println["Done printing."]

/** Makes two dictionaries that map column numbers to column
    names and vice versa.

   Returns:
    [colToName, nameToCol]
*/

makeColumnDictionaries[line, print=false] :=
{
   fields = split[%r/,/, line]
   colToName = new dict
   for i = rangeOf[fields]
      colToName@i = fields@i

   nameToCol = colToName.invert[]
   
   if print
   {
      for key = sort[keys[colToName]]
      println["$key\t" + colToName@key]

      println[]
      println[]
      for key = lexicalSort[keys[nameToCol]]
         println[nameToCol@key + "\t$key"]
   }

   return[colToName, nameToCol]
}


Download or view GaiaTestGalactic.frink in plain text format


This is a program written in the programming language Frink.
For more information, view the Frink Documentation or see More Sample Frink Programs.

Alan Eliasen was born 20143 days, 9 hours, 29 minutes ago.