Created
June 14, 2016 20:32
-
-
Save mappingvermont/e43279288f1acd9389e164f31eb33fef to your computer and use it in GitHub Desktop.
Given an rgb value, return date, confidence, and intensity for GLAD alerts
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
var decode_date = function(rgba) { | |
// find the total days of the pixel by | |
// multiplying the red band by 255 and adding | |
// the green band to that | |
var total_days = rgba[0] * 255 + rgba[1]; | |
// take the total days value and divide by 365 to | |
// get the year_offset. Add 15 to this (i.e 0 + 15 = 2015) | |
// or 1 + 15 = 2016 | |
var year_int = parseInt(total_days / 365) + 15; | |
// Multiply by 1000 to give us year in YYDDD format | |
// (i.e. 15000 or 16000) | |
var year = parseInt((year_int * 1000)) | |
// Find the remaining days to get the julian day for | |
// that year | |
var julian_day = total_days % 365; | |
// Add to get YYDDD date val | |
var date_val = year + julian_day; | |
// Convert the blue band to string, leading | |
// zeros if it's not currently three digits | |
// this occurs very rarely; where there's an intensity | |
// value but no date/confidence for it. Due to bilinear | |
// resampling | |
var band3_str = pad(rgba[2].toString()); | |
// Grab confidence (the first value) from this string | |
// confidence is stored as 1/2, subtract one to make it 0/1 | |
var confidence = parseInt(band3_str[0]) - 1 | |
// Grab the raw intensity value from the pixel; ranges from 1 - 55 | |
var intensity_raw = parseInt(band3_str.slice(1, 3)) | |
// Scale the intensity to make it visible | |
var intensity = intensity_raw * 50 | |
// Set intensity to 255 if it's > than that value | |
if (intensity > 255) { | |
intensity = 255 | |
} | |
return [date_val, confidence, intensity] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment