Skip to content

Instantly share code, notes, and snippets.

@robbibt
Last active November 10, 2020 00:32
Show Gist options
  • Save robbibt/5e1bf4e63d1f429ca2ee078227801dfc to your computer and use it in GitHub Desktop.
Save robbibt/5e1bf4e63d1f429ca2ee078227801dfc to your computer and use it in GitHub Desktop.
Virtual product for loading cloud masked Landsat
about: Catalog of virtual products loading, normalising and cloud masking Landsat products
products:
# Loads a subset of data from Landsat 8, including spectral bands
# (blue, green, red, nir, swir1, swir2), a cloud masking band (fmask)
# and a contiguity band (contiguity).
ls8_nbart:
recipe:
&ls8_nbart
product: ga_ls8c_ard_3
measurements: [nbart_blue, nbart_green, nbart_red, nbart_nir,
nbart_swir_1, nbart_swir_2, oa_nbart_contiguity,
oa_fmask]
group_by: solar_day
# Loads Landsat 7 data based on bands included in the `ls8_nbart` product
ls7_nbart:
recipe:
&ls7_nbart
<<: *ls8_nbart
product: ga_ls7e_ard_3
# Loads Landsat 5 data based on bands included in the `ls8_nbart` product
ls5_nbart:
recipe:
&ls5_nbart
<<: *ls8_nbart
product: ga_ls5t_ard_3
# Loads data from Landsat 5, 7 and 8, and combines this into a virtual
# product containing spectral bands (blue, green, red, nir, swir1, swir2),
# a cloud masking band (fmask) and a contiguity band (contiguity).
ls_nbart:
recipe:
&ls_nbart
transform: expressions
input:
collate:
- *ls5_nbart
- *ls7_nbart
- *ls8_nbart
output:
blue:
formula: nbart_blue
dtype: float32
green:
formula: nbart_green
dtype: float32
red:
formula: nbart_red
dtype: float32
nir:
formula: nbart_nir
dtype: float32
swir1:
formula: nbart_swir_1
dtype: float32
swir2:
formula: nbart_swir_2
dtype: float32
fmask: oa_fmask
contiguity: oa_nbart_contiguity
# Takes the `ls_nbart` product containing Landsat 5, 7 and 8 data,
# and normnalises spectral band values so they are between 0 and 1.0.
# (compared to the default of 0 to 10,000).
ls_nbart_norm:
recipe:
&ls_nbart_norm
transform: expressions
input: *ls_nbart
output:
blue:
formula: blue * 0.0001
dtype: float32
green:
formula: green * 0.0001
dtype: float32
red:
formula: red * 0.0001
dtype: float32
nir:
formula: nir * 0.0001
dtype: float32
swir1:
formula: swir1 * 0.0001
dtype: float32
swir2:
formula: swir2 * 0.0001
dtype: float32
fmask: fmask
contiguity: contiguity
# Takes the `ls_nbart_norm` product containing normalised Landsat 5,
# 7 and 8 data, and applies a mask to remove cloud, cloud shadow and
# other invalid pixels (using fmask), and any pixels that are missing
# data in any spectral band (using contiguity).
ls_nbart_masked:
recipe:
&ls_nbart_masked
transform: apply_mask
mask_measurement_name: mask
input:
transform: expressions
input: *ls_nbart_norm
output:
red: red
green: green
blue: blue
nir: nir
swir1: swir1
swir2: swir2
mask:
formula: ((fmask == 1) | (fmask == 4) | (fmask == 5)) & (contiguity == 1)
@robbibt
Copy link
Author

robbibt commented Oct 13, 2020

Please fell free to suggest any re-writes! I think the Landsat 5/7/8 is probably likely to be the most used virtual product, so important to get that one as nice and clean and well written as possible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment