From 524f538d06ede2e92650d6c181aa1234bc358dbf Mon Sep 17 00:00:00 2001 From: zcernigoj <54022976+zcernigoj@users.noreply.github.com> Date: Wed, 12 Jun 2024 10:10:37 +0200 Subject: [PATCH] Update PlanetScope scripts (#308) * PlanetScope true color: use dataMask to make no-data pixels transparent * PlanetScope false color: use dataMask to make no-data pixels transparent * PlanetScope NDWI simple visualization: use dataMask to make no-data pixels transparent * PlanetScope NDWI raw values: add script * PlanetScope NDWI EOB visualization: add script * PlanetScope NDWI: add scripts to readme.md * add dataMask only at the end for PS NDWI script * rename samples to sample in PS NDWI script * remove unused dataMask band in PS NDWI raw script * avoid returning infinite number in PS NDWI raw script * rename samples to sample in PS NDWIeob script * add dataMask only at the end for PS NDWI eob script * avoid returning infinite number in PS NDWI eob script * rename samples to sample in PS NDWIraw script * improve eob script for PS NDWI --------- Co-authored-by: Jonas <53001455+jonasViehweger@users.noreply.github.com> --- planet_scope/ndwi/README.md | 9 ++++--- planet_scope/ndwi/raw.js | 16 +++++++++++++ planet_scope/ndwi/script.js | 39 ++++++++++++++++++++----------- planet_scope/true_color/script.js | 2 +- 4 files changed, 49 insertions(+), 17 deletions(-) create mode 100644 planet_scope/ndwi/raw.js diff --git a/planet_scope/ndwi/README.md b/planet_scope/ndwi/README.md index a2f65ff8..6a89e1c1 100644 --- a/planet_scope/ndwi/README.md +++ b/planet_scope/ndwi/README.md @@ -6,9 +6,12 @@ layout: script permalink: /planet_scope/ndwi/ nav_exclude: true scripts: -scripts: - - [Visualization, script.js] - - [EO Browser, eob.js] +- - Visualization + - script.js +- - EO Browser + - eob.js +- - Raw Values + - raw.js --- diff --git a/planet_scope/ndwi/raw.js b/planet_scope/ndwi/raw.js new file mode 100644 index 00000000..7955731c --- /dev/null +++ b/planet_scope/ndwi/raw.js @@ -0,0 +1,16 @@ +//VERSION=3 +//NDWI + +function setup() { + return { + input: [{ bands: ["green", "nir"] }], + output: [ + { id: "default", bands: 1, sampleType: "FLOAT32" }, + ] + } +} + +function evaluatePixel(sample) { + let ndwi = index(sample.green, sample.nir); + return { default: [isFinite(ndwi) ? ndwi : NaN] }; +} \ No newline at end of file diff --git a/planet_scope/ndwi/script.js b/planet_scope/ndwi/script.js index 05c6a90f..3e56a725 100644 --- a/planet_scope/ndwi/script.js +++ b/planet_scope/ndwi/script.js @@ -1,17 +1,30 @@ +//VERSION=3 //NDWI -let ndwi = index(green, nir); +function setup() { + return { + input: [{ bands: ["green", "nir", "dataMask"] }], + output: [ + { id: "default", bands: 4 }, + ] + } +} -return colorBlend(ndwi, - [-1, -0.5, -0.2, 0, 0.2, 0.5, 1.0], - [ - [1, 0, 1], - [1, 0.5, 0], - [1, 1, 0], - [0.2, 1, 0.5], - [0, 0, 1], - [0, 0, 0.3], - [0, 0, 0], - ] -); +function evaluatePixel(sample) { + let ndwi = index(green, nir); + let id_default = colorBlend(ndwi, + [-1, -0.5, -0.2, 0, 0.2, 0.5, 1.0], + [ + [1, 0, 1], + [1, 0.5, 0], + [1, 1, 0], + [0.2, 1, 0.5], + [0, 0, 1], + [0, 0, 0.3], + [0, 0, 0], + ] + ); + + return { default: [...id_default, sample.dataMask] }; +} diff --git a/planet_scope/true_color/script.js b/planet_scope/true_color/script.js index 8b451d33..ae79f7f2 100644 --- a/planet_scope/true_color/script.js +++ b/planet_scope/true_color/script.js @@ -10,4 +10,4 @@ function setup() { function evaluatePixel(sample) { return [sample.red / 3000, sample.green / 3000, sample.blue / 3000, sample.dataMask]; -} \ No newline at end of file +}