-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:sentinel-hub/custom-scripts into main
- Loading branch information
Showing
14 changed files
with
468 additions
and
1 deletion.
There are no files selected for viewing
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
33 changes: 33 additions & 0 deletions
33
...les/land-surface-temperature/land-surface-temperature-backward-average/index.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
title: Land Surface Temperature Backward Average | ||
grand_parent: Planetary Variables | ||
parent: Land Surface Temperature | ||
layout: script | ||
nav_exclude: false | ||
scripts: | ||
- [Visualization, script.js] | ||
- [Raw Values, raw.js] | ||
examples: | ||
- zoom: '11' | ||
lat: '44.8398' | ||
lng: '-0.5294' | ||
datasetId: '8d977093-cf9e-4351-8159-90f2522c29c1' | ||
fromTime: '2022-12-01T00:00:00.000Z' | ||
toTime: '2022-12-30T23:59:59.999Z' | ||
platform: | ||
- EOB | ||
evalscripturl: https://custom-scripts.sentinel-hub.com/custom-scripts/planetary-variables/land-surface-temperature/land-surface-temperature-backward-average/script.js | ||
additionalQueryParams: | ||
- - themeId | ||
- PLANET_SANDBOX | ||
--- | ||
## General description | ||
The Land Surface Temperature Backward Average is a method to reduce data gaps and measurement noise in the Land Surface Temperature (LST) data. Depending on the requirements, we can choose a lookback period, for example 20 days. The 20-day backward average of LST for day n is the average of LST over the 20 days preceding day n. We compute the backward average using all available measurements within this 20-day period, and therefore, we do have a valid value for every day, except in case of prolonged data unavailability, such as during long frost and snow periods. | ||
|
||
## Why it is useful | ||
The Land Surface Temperature Backward Average is suitable for applications where long-term temperatures are more relevant than daily fluctuations. The moving average operation reduces day-to-day variations and in the resulting time series, seasonal and longer-term changes can be easily detected. It can be used for monitoring drought risk, yield forecasting and analysis of climate change. | ||
|
||
## Useful links | ||
- [Product specifications](https://planet.widen.net/s/tltwk6hnps) | ||
- [Data sheet](https://planet.widen.net/s/ttvp2rvwzd) | ||
- [Sentinel Hub documentation about Land Surface Temperature](https://docs.sentinel-hub.com/api/latest/data/planetary-variables/land-surface-temp/) |
60 changes: 60 additions & 0 deletions
60
...etary-variables/land-surface-temperature/land-surface-temperature-backward-average/raw.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//VERSION=3 | ||
|
||
// LST has two observations per day: 1h30 and 13h30 solar local time | ||
|
||
const date = "2022-12-31"; // The date for which the backward average is calculated | ||
const nDays = 20; // The number of days to load data for | ||
const scaleFactor = 100; // The scale factor for the SWC values | ||
const sensing_time = "0130"; // Observation time: "0130" or "1330" or "" | ||
const variable = "LST"; // Variable of interest: "LST" or "LST_MaskedPixels" | ||
|
||
function setup() { | ||
return { | ||
input: [variable, "dataMask"], | ||
output: { bands: 1, sampleType: "FLOAT32" }, | ||
mosaicking: "TILE", | ||
}; | ||
} | ||
|
||
// Select files based on sensing time (0130 or 1330) and within the last nDays | ||
function preProcessScenes(collections) { | ||
var calculationDate = new Date(date); | ||
collections.scenes.tiles = collections.scenes.tiles.filter(function (tile) { | ||
var tileDate = new Date(tile.date); | ||
return ( | ||
tile.dataPath.includes("T" + sensing_time) && | ||
tileDate.getTime() >= calculationDate.getTime() - nDays * 24 * 3600 * 1000 | ||
); | ||
}); | ||
return collections; | ||
} | ||
|
||
function get_mean_lst_value(samples) { | ||
// Get the sum of all LST values | ||
let n_valid_dates = 0; | ||
let sum = 0; | ||
for (let i = 0; i < samples.length; i++) { | ||
if (samples[i].dataMask) { | ||
sum += samples[i].LST / scaleFactor; | ||
n_valid_dates += 1; | ||
} | ||
} | ||
|
||
// Calculate the mean LST value | ||
let mean_lst_value = NaN; | ||
if (n_valid_dates > 0) { | ||
mean_lst_value = sum / n_valid_dates; | ||
} | ||
|
||
return mean_lst_value; | ||
} | ||
|
||
function evaluatePixel(samples) { | ||
// When there are no dates, return no data | ||
if (samples.length == 0) return [NaN]; | ||
|
||
// Calculate mean LST value | ||
const mean_lst_val = get_mean_lst_value(samples); | ||
|
||
return [mean_lst_val]; | ||
} |
99 changes: 99 additions & 0 deletions
99
...ry-variables/land-surface-temperature/land-surface-temperature-backward-average/script.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
//VERSION=3 | ||
|
||
// Set defaultVis to false to scale and set color_min and color_max values. | ||
// LST has two observations per day: 1h30 and 13h30 solar local time | ||
|
||
const date = "2022-12-31"; // The date for which the backward average is calculated | ||
const nDays = 20; // The number of days to load data for | ||
const scaleFactor = 100; // The scale factor for the SWC values | ||
const color_min = 260; // The minimum value of the colormap. | ||
const color_max = 280; // The maximum value of the colormap. | ||
const sensing_time = "0130"; // Observation time: "0130" or "1330" or "" | ||
const variable = "LST"; // Variable of interest: "LST" or "LST_MaskedPixels" | ||
|
||
function setup() { | ||
return { | ||
input: [variable, "dataMask"], | ||
output: { id: "default", bands: 4 }, | ||
mosaicking: "TILE", | ||
}; | ||
} | ||
|
||
// Select files based on sensing time (0130 or 1330) and within the last nDays | ||
function preProcessScenes(collections) { | ||
var calculationDate = new Date(date); | ||
collections.scenes.tiles = collections.scenes.tiles.filter(function (tile) { | ||
var tileDate = new Date(tile.date); | ||
return ( | ||
tile.dataPath.includes("T" + sensing_time) && | ||
tileDate.getTime() >= calculationDate.getTime() - nDays * 24 * 3600 * 1000 | ||
); | ||
}); | ||
return collections; | ||
} | ||
|
||
function get_mean_lst_value(samples) { | ||
// Get the sum of all LST values | ||
let n_valid_dates = 0; | ||
let sum = 0; | ||
for (let i = 0; i < samples.length; i++) { | ||
if (samples[i].dataMask) { | ||
sum += samples[i].LST / scaleFactor; | ||
n_valid_dates += 1; | ||
} | ||
} | ||
|
||
// Calculate the mean LST value | ||
let mean_lst_value = NaN; | ||
if (n_valid_dates > 0) { | ||
mean_lst_value = sum / n_valid_dates; | ||
} | ||
|
||
return mean_lst_value; | ||
} | ||
|
||
// Create color ramp 250 - 340 (full range) | ||
const cmap = [ | ||
[263, 0x000004], | ||
[266, 0x06051a], | ||
[270, 0x140e36], | ||
[274, 0x251255], | ||
[278, 0x3b0f70], | ||
[282, 0x51127c], | ||
[286, 0x641a80], | ||
[289, 0x782281], | ||
[293, 0x8c2981], | ||
[297, 0xa1307e], | ||
[301, 0xb73779], | ||
[305, 0xca3e72], | ||
[309, 0xde4968], | ||
[313, 0xed5a5f], | ||
[316, 0xf7705c], | ||
[320, 0xfc8961], | ||
[324, 0xfe9f6d], | ||
[328, 0xfeb77e], | ||
[332, 0xfecf92], | ||
[336, 0xfde7a9], | ||
[340, 0xfcfdbf], | ||
]; | ||
|
||
// Initialize the ColorRamp | ||
const visualizer = new ColorRampVisualizer(cmap, color_min, color_max); | ||
|
||
function evaluatePixel(samples) { | ||
// When there are no dates, return no data | ||
if (samples.length == 0) return [NaN, NaN, NaN, 0]; | ||
|
||
// Calculate mean LST value | ||
const mean_lst_val = get_mean_lst_value(samples); | ||
|
||
// Set opacity to 0 if there is no valid data | ||
let opacity = 1; | ||
if (isNaN(mean_lst_val)) { | ||
opacity = 0; | ||
} | ||
|
||
// Apply colormap | ||
imgVals = visualizer.process(mean_lst_val); | ||
return [...imgVals, opacity]; | ||
} |
Binary file added
BIN
+1.54 MB
...face-temperature-quality-flags/fig/qf_lst_100m_water_netherlands_2022-12-31.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions
47
...iables/land-surface-temperature/land-surface-temperature-quality-flags/index.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
title: Land Surface Temperature Quality Flags | ||
grand_parent: Planetary Variables | ||
parent: Land Surface Temperature | ||
layout: script | ||
nav_exclude: false | ||
scripts: | ||
- [Visualization, script.js] | ||
- [Raw Values, raw.js] | ||
examples: | ||
- zoom: '11' | ||
lat: '44.8398' | ||
lng: '-0.5294' | ||
datasetId: '8d977093-cf9e-4351-8159-90f2522c29c1' | ||
fromTime: '2022-04-26T00:00:00.000Z' | ||
toTime: '2022-04-26T23:59:59.999Z' | ||
platform: | ||
- EOB | ||
evalscripturl: https://custom-scripts.sentinel-hub.com/custom-scripts/planetary-variables/land-surface-temperature/land-surface-temperature-quality-flags/script.js | ||
additionalQueryParams: | ||
- - themeId | ||
- PLANET_SANDBOX | ||
--- | ||
## General description | ||
Land Surface Temperature (LST) products include [quality flag assets](https://developers.planet.com/docs/planetary-variables/land-surface-temperature-technical-specification/#quality-flags) that provide quality metadata for each pixel using a bitwise flag system. These flags help identify the reliability of the LST values for each pixel. Here we show how these quality flags can be easily displayed using custom scripts. For a complete list of all possible quality flags and their corresponding bits, please refer to [these tables](https://developers.planet.com/docs/planetary-variables/land-surface-temperature-technical-specification/#quality-flags). | ||
|
||
## Notes on usage | ||
Users can customize the script by adding the bit numbers corresponding to the quality flag(s) of interest to the `bits_to_check` list within the script. By default, the provided scripts are set to check all critical flags (indicating unreliable data, with corresponding LST pixels set to the no data value), but this can be updated to include or exclude specific flags as needed. | ||
|
||
Planet’s LST product provides near real-time measurements twice a day at 1:30 and 13:30 solar local time. The `sensing_time` variable in the scripts can be used to select the sensing time of interest | ||
|
||
The provided Visualization script highlights pixels for which specific quality flags of interest are set. This allows users to visually inspect areas of concern or interest. | ||
|
||
The Raw Values script retrieves a binary raster where: | ||
|
||
- `1` indicates pixels for which the quality flag(s) of interest are set | ||
- `0` indicates pixels where the quality flag(s) of interest are not set | ||
|
||
## Description of representative images | ||
The 'Open water' (bit 15\) quality flag in Flevoland, The Netherlands, on 2022-12-31. | ||
|
||
![The water quality flag](fig/qf_lst_100m_water_netherlands_2022-12-31.png) | ||
|
||
## Useful links | ||
- [Product specifications](https://planet.widen.net/s/tltwk6hnps) | ||
- [Data sheet](https://planet.widen.net/s/ttvp2rvwzd) | ||
- [Sentinel Hub documentation about Land Surface Temperature](https://docs.sentinel-hub.com/api/latest/data/planetary-variables/land-surface-temp/) |
47 changes: 47 additions & 0 deletions
47
planetary-variables/land-surface-temperature/land-surface-temperature-quality-flags/raw.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//VERSION=3 | ||
|
||
const bits_to_check = [8, 9, 11, 13, 14, 15]; // Bits to check if they are set | ||
const sensing_time = "0130"; // "0130" or "1330" or "" | ||
|
||
function setup() { | ||
return { | ||
input: ["QF", "dataMask"], | ||
output: { bands: 1, sampleType: "UINT8" }, | ||
mosaicking: "TILE", | ||
}; | ||
} | ||
|
||
//Select files based on sensing time (0130 or 1330) | ||
function preProcessScenes(collections) { | ||
collections.scenes.tiles = collections.scenes.tiles.filter(function (tile) { | ||
return tile.dataPath.includes("T" + sensing_time); | ||
}); | ||
collections.scenes.tiles.sort((a, b) => new Date(b.date) - new Date(a.date)); | ||
return collections; | ||
} | ||
|
||
function areBitsSet(qf) { | ||
// Check if the bits are set | ||
for (let idx in bits_to_check) { | ||
const bit = 1 << (bits_to_check[idx] - 1); | ||
if ((qf & bit) !== 0) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
function evaluatePixel(sample) { | ||
// When there are no dates, return no data | ||
if (sample.length == 0) return [NaN]; | ||
|
||
// Return NaN for no data pixels | ||
if (sample[0].dataMask == 0) { | ||
return [NaN]; | ||
} | ||
|
||
// Check if the bits are set | ||
const bit_set = areBitsSet(sample[0].QF); | ||
|
||
return [bit_set ? 1 : 0]; | ||
} |
54 changes: 54 additions & 0 deletions
54
...etary-variables/land-surface-temperature/land-surface-temperature-quality-flags/script.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//VERSION=3 | ||
|
||
const bits_to_check = [8, 9, 11, 13, 14, 15]; // Bits to check if they are set | ||
const sensing_time = "0130"; // "0130" or "1330" or "" | ||
|
||
function setup() { | ||
return { | ||
input: ["QF", "dataMask"], | ||
output: { id: "default", bands: 4 }, | ||
mosaicking: "TILE", | ||
}; | ||
} | ||
|
||
//Select files based on sensing time (0130 or 1330) | ||
function preProcessScenes(collections) { | ||
collections.scenes.tiles = collections.scenes.tiles.filter(function (tile) { | ||
return tile.dataPath.includes("T" + sensing_time); | ||
}); | ||
collections.scenes.tiles.sort((a, b) => new Date(b.date) - new Date(a.date)); | ||
return collections; | ||
} | ||
|
||
function areBitsSet(qf) { | ||
// Check if the bits are set | ||
for (let idx in bits_to_check) { | ||
const bit = 1 << (bits_to_check[idx] - 1); | ||
if ((qf & bit) !== 0) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
function evaluatePixel(sample) { | ||
// When there are no dates, return no data | ||
if (sample.length == 0) return [NaN, NaN, NaN, 0]; | ||
|
||
// Return NaN for no data pixels | ||
if (sample[0].dataMask == 0) { | ||
return [NaN, NaN, NaN, 0]; | ||
} | ||
|
||
// Check if the bits are set | ||
const bit_set = areBitsSet(sample[0].QF); | ||
|
||
// Ensure only flagged pixels are displayed | ||
let opacity = 0; | ||
let imgVals = [1, 0, 0]; | ||
if (bit_set) { | ||
opacity = 0.5; | ||
} | ||
|
||
return [...imgVals, opacity]; | ||
} |
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
Binary file added
BIN
+1.48 MB
...quality-flags/fig/qf_swc_100m_frozen_and_possibly_frozen_alberta_2022-12-23.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.9 MB
.../soil-water-content-quality-flags/fig/qf_swc_100m_water_bordeaux_2022-04-26.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.