Skip to content

Some useful s-expressions to be used in STACK


icon


In the STACK service s-expressions are defined by the user using logical/arithmetic operators and functions described in the STACK service specification. Below are listed some use cases of s-expressions which can be replicated in multiple situations when it is necessary to derive a single band asset from a co-located stack (e.g. to derive a binary mask from thresholding).

Compute average backscatter

To compute average backscatter from multiple single band assets with STACK (e.g. from 3 single band C-band Sigma nought assets in VV polarization 1.s0_db_c_vv, 2.s0_db_c_vv and 3.s0_db_c_vv) the following s-expression can be used:

sigma_average:(/ (+ 1.s0_db_c_vv 2.s0_db_c_vv 3.s0_db_c_vv) 3)

Input single band assets are:

  1. 1.s0_db_c_vv single band asset representing C-band Sigma Nought in VV polarization from a 1st Radar Calibrated Dataset,

  2. 2.s0_db_c_vv single band asset representing C-band Sigma Nought in VV polarization from a 2nd Radar Calibrated Dataset,

  3. 3.s0_db_c_vv single band asset representing C-band Sigma Nought in VV polarization from a 3rd Radar Calibrated Dataset.

The output sigma_average is a single band asset representing the average Sigma Nought values derived from these input assets with the provided s-expression.

In this s-expression the / and + arithmetic operators are applied to compute the average.

Derive a normalized difference spectral index

To derive the Normalized Difference Snow Index (NDSI) from an Optical Calibrated Dataset with STACK the following s-expression can be used:

ndsi:(norm_diff 1.green 1.swir16)

Input single band assets are:

  1. 1.green single band asset representing green TOA reflectance from an Optical Calibrated Dataset,

  2. 1.swir16 single band asset representing swir16 TOA reflectance from the same Optical Calibrated Dataset.

The output ndsi is a single band asset representing NDSI values derived from these input assets with the provided s-expression.

In this s-expression the norm_diff operator is used to employ the normalized difference between green and swir16 assets included into the same Optical Calibrated Dataset.

Quick estimation of satellite-detected water from optical or SAR data

Below use cases describe possible ways to derive water masks from optical and SAR data.

Derive water mask from optical data

The following s-expression:

opt_water_mask:(where (>= (norm_diff 1.green 1.nir) 0.3) 1 0)

can be used to derive a water mask from the binarization of the NDWI spectral index.

Input single band assets are:

  1. 1.green single band asset representing green TOA reflectance from an Optical Calibrated Dataset,

  2. 1.nir single band asset representing nir TOA reflectance from the same Optical Calibrated Dataset.

The output opt_water_mask is a single band binary mask derived from these input assets with the provided s-expression.

In this s-expression norm_diff operator is used to employ the normalized difference between green and nir assets included into the same Optical Calibrated Dataset. The where operator is then applied to derive a binary mask satisfying this condition: NDWI >= threshold. The value 0.3 represents the threshold as TOA reflectance.

Derive water mask from radar data

The following s-expression:

sar_water_mask:(where (<= 1.s0_db_c_hh -23) 1 0)

can be used to derive a water mask from the binarization of radar backscatter.

The input is the 1.s0_db_c_hh single band asset representing Sigma Nought in dB from systematic Radar Calibration of a C-band intensity image in HH polarization.

The output sar_water_mask is a single band binary mask derived from this input backscatter asset with the provided s-expression.

In this s-expression the where operator is then applied to derive a binary mask satisfying this condition: Sigma0 <= signed threshold in db. The value -23 represents the threshold for Sigma Nought in dB.

Extract flooded areas over a land cover class

STACK can be used also to post-process an asset from a Result of another processor. For instance, this makes it possible to co-locate a binary flood map from the Result of the HASARD on-demand service with the Land Cover Auxiliary Dataset to extract flooded pixels over only a certain LC class. As an example the following s-expression:

flooded_cropland:(where (== 2.worldcover 40) 1.flood-mask 0)

can be used to derive a flood mask over only crop fields.

Input single band assets are:

  1. 1.ndvi single band asset representing NDVI before the landslide from an OPT-Index result,

  2. 2.worldcover single band asset representing land cover classes from the ESA World Cover 2020 Auxiliary Dataset.

The output flooded_cropland is a single band binary mask derived from these 2 input single band assets with the provided s-expression.

In this case the s-expression (where (== 2.worldcover 40) 1.flood-mask 0) is used to generate the flooded_cropland asset from the flood-mask one using the condition (== 2.worldcover 40). The value 40 represents the pixel value of the LC class cropland for the single-band asset worldcover offered in the ESA World Cover Auxiliary Dataset.

Figure

Figure 1 - Extraction of flooded cropland using the STACK service from a co-location of an HASARD`s binary flood map and the ESA world Cover.

Hint

Specifications of the worldcover single band asset can be found here.

Compute NDVI loss after a landslide

S-expressions can be used also to combine assets from 2 Results obtained with the same on-demand processor supported by STACK. As an example, STACK allows to co-locate NDVI indexes from the Results of the OPT-Index on-demand service obtained with two different Calibrated Dataset acquired before and after a landslide. As an example the following s-expression:

ndvi_loss:(where (<= (- 2.ndvi 1.ndvi) -0.55) 1 0)

can be used to derive a binary mask which is mapping NDVI loss due to a landslide over vegetated areas.

Input single band assets are:

  1. 1.ndvi single band asset representing NDVI before the landslide from a 1st OPT-Index result,

  2. 2.ndvi single band asset representing NDVI after the landslide from a 2nd OPT-Index result.

The output ndvi_loss is a single band binary mask derived from these 2 input single band assets with the provided s-expression.

In this case the s-expression (where (<= (- 2.ndvi 1.ndvi) -0.55) 1 0) is used to generate the ndvi_loss asset with a binarization of negative NDVI difference values (NDVI-post - NDVI-pre <= -0.55). The value -0.55 represents the threshold applied to the NDVI difference.

Compute coherence loss after an earthquake

Another useful use case with STACK is the one exploiting a pair of coherence single band assets from 2 SAR-COIN results, obtained from 3 SLC Datasets acquired before and after an earthquake. As an example the following s-expression:

ccd:(where (<= (- 2.coh_c_vv_20230129_20230210 1.coh_c_vv_20230117_20230129) -0.4) 3.wsf2019 0)

can be used to derive a binary mask which is mapping coherence loss due to an earthquake over built-up areas.

Input single band assets are:

  1. 1.coh_c_vv_20230117_20230129 single band asset representing coherence before the earthquake from a 1st SAR-COIN result,

  2. 2.coh_c_vv_20230129_20230210 single band asset representing coherence after the earthquake from a 2nd SAR-COIN result,

  3. 3.wsf2019 single band asset representing a binary mask of built up areas from the DLR`s World Settlement Footprint 2019 Auxiliary Dataset.

The output ccd is a single band binary mask derived from these input single band assets with the provided s-expression.

In this case the s-expression (where (<= (- 2.coh_c_vv_20230129_20230210 1.coh_c_vv_20230117_20230129) -0.4) 3.wsf2019 0) is used to generate the ccd asset with a binarization of negative coherence difference values (coherence-post - coherence-pre <= -0.4). The value -0.4 represents the threshold applied to the coherence difference.

Hint

Specifications of the wsf2019 single band asset can be found here.