From c536ea9ba141ee19574373bbafe1c98f1cfbc190 Mon Sep 17 00:00:00 2001 From: Michael Wellington Date: Tue, 11 Jun 2024 05:27:11 +0000 Subject: [PATCH] load_ard changes --- Tools/deafrica_tools/datahandling.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/Tools/deafrica_tools/datahandling.py b/Tools/deafrica_tools/datahandling.py index bacb931df..e20dffc46 100644 --- a/Tools/deafrica_tools/datahandling.py +++ b/Tools/deafrica_tools/datahandling.py @@ -125,6 +125,7 @@ def load_ard( Sentinel-2: * s2_l2a + * s2_l2a_c1 Sentinel-1: * s1_rtc @@ -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 @@ -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" ) @@ -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