Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load_ard changes #512

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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