Created
September 20, 2016 20:25
-
-
Save flimshaw/ff6d956944e03f49a243a6baf52c3808 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const DEG2RAD = Math.PI / 180; | |
fs.createReadStream(file) | |
.pipe(zlib.createGunzip()) | |
.pipe(csv()) | |
.on('data', d => { | |
// assume the first row is a list of headers, we can use this to do easy lookups of rows later | |
if(!headers) { | |
headers = d; | |
} else { | |
// only process rows that have a measurement for parallax | |
if(d[headers.indexOf('parallax')] !== '') { | |
// build an array of values for each of these keys, converting parallax to distance in parsecs | |
let rec = ['source_id', 'ra', 'dec', 'parallax', 'phot_g_mean_mag'].map( k => { | |
if(k !== 'parallax') { | |
return d[headers.indexOf(k)]; | |
} else { | |
return 1 / d[headers.indexOf(k)]; | |
} | |
}); | |
// add three more fields for the x,y and z position of each star | |
rec.push( Math.cos(rec[1] * DEG2RAD) * Math.cos(rec[2] * DEG2RAD) * rec[3] ); // x coord + dist | |
rec.push( Math.sin(rec[1] * DEG2RAD) * Math.cos(rec[2] * DEG2RAD) * rec[3] ); // y coord + dist | |
rec.push( Math.sin(rec[2] * DEG2RAD) * rec[3] ); // z coord + dist | |
// print a csv list to stdout, which should probably be going to a file like "node processCSVs.js >> final.csv" | |
console.log(rec.join(',')); | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment