Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions Tools/deafrica_tools/datahandling.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def load_ard(

Sentinel-2:
* s2_l2a
* s2_l2a_c1

Sentinel-1:
* s1_rtc
Expand All @@ -140,7 +141,7 @@ def load_ard(
A list of product names to load data from. For example:

* Landsat C2: ``['ls5_sr', 'ls7_sr', 'ls8_sr', 'ls9_sr']``
* Sentinel-2: ``['s2_l2a']``
* Sentinel-2: ``['s2_l2a', 's2_l2a_c1']``
* Sentinel-1: ``['s1_rtc']``

min_gooddata : float, optional
Expand Down Expand Up @@ -256,7 +257,7 @@ def load_ard(
"Please provide a list of product names to load data from. "
"Valid options are: Landsat C2 SR: ['ls5_sr', 'ls7_sr', 'ls8_sr', 'ls9_sr'], or "
"Landsat C2 ST: ['ls5_st', 'ls7_st', 'ls8_st', 'ls9_st'], or "
"Sentinel-2: ['s2_l2a'], or"
"Sentinel-2: ['s2_l2a', 's2_l2a_c1'], or"
"Sentinel-1: ['s1_rtc'], or"
)

Expand Down Expand Up @@ -614,6 +615,28 @@ def load_ard(
# add back attrs that are lost during scaling calcs
for band in ds.data_vars:
ds[band].attrs.update(attrs)

if product == "s2_l2a_c1":
if verbose:
print("Re-scaling Sentinel-2 C1 data")

sr_bands = ["coastal", "red", "green", "blue", "rededge1", "rededge2",
"rededge3", "nir", "nir08", "nir09", "swir16", "swir22"]

if mask_pixel_quality == False:
# set nodata to NaNs before rescaling
# in the case where masking hasn't already done this
for band in ds.data_vars:
if band not in qa:
ds[band] = odc.algo.to_f32(ds[band])

for band in ds.data_vars:
if band in sr_bands:
ds[band] = ds[band] - 1000

# add back attrs that are lost during scaling calcs
for band in ds.data_vars:
ds[band].attrs.update(attrs)

# If user supplied dask_chunks, return data as a dask array without
# actually loading it in
Expand Down
2 changes: 1 addition & 1 deletion Tools/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "deafrica-tools"
# reflect version changes in deafrica_tools/__init__.py
version = "2.5.7"
version = "2.5.8"
description = "Functions and algorithms for analysing Digital Earth Africa data."
authors = [{name = "Digital Earth Africa", email = "systems@digitalearthafrica.org"}]
maintainers = [{name = "Digital Earth Africa", email = "systems@digitalearthafrica.org"}]
Expand Down