From 6e1b44ca72084d2ffcc48c6a887f7901abf05238 Mon Sep 17 00:00:00 2001
From: Raffaele Gaetano <raffaele.gaetano@cirad.fr>
Date: Mon, 15 May 2023 09:42:09 +0200
Subject: [PATCH] ENH: fetch specific band list from planetary.

---
 TimeSeries/s2planetary.py | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/TimeSeries/s2planetary.py b/TimeSeries/s2planetary.py
index ad8e131..d07cf71 100644
--- a/TimeSeries/s2planetary.py
+++ b/TimeSeries/s2planetary.py
@@ -1,3 +1,5 @@
+import warnings
+
 from TimeSeries.s2sen2cor import *
 import planetary_computer as PC
 from pystac_client import Client
@@ -8,7 +10,7 @@ from pyproj import Transformer as T
 from shapely import Polygon
 import tqdm
 
-def fetch(shp, dt, output_fld):
+def fetch(shp, dt, output_fld, band_list=None):
 
     ds = ogr.Open(shp)
     ly = ds.GetLayer(0)
@@ -28,8 +30,10 @@ def fetch(shp, dt, output_fld):
     api = Client.open('https://planetarycomputer.microsoft.com/api/stac/v1', modifier=PC.sign_inplace)
     res = api.search(collections="sentinel-2-l2a", bbox=bbox, datetime=dt)
     lst = ['B02','B03','B04','B05','B06','B07','B08','B8A','B11','B12','SCL']
+    if band_list is not None:
+        lst = band_list
 
-    prg = tqdm.tqdm(total=len(res.item_collection()) * 11, desc="Fetching from Planetary")
+    prg = tqdm.tqdm(total=len(res.item_collection()) * len(lst), desc="Fetching from Planetary")
     for item in res.items():
         with rasterio.open(item.assets['B02'].href) as ds:
             img_srs = ds.crs.to_epsg()
@@ -59,7 +63,11 @@ def fetch(shp, dt, output_fld):
             prg.update()
     prg.close()
 
-    return S2PlaneteryPipeline(output_fld)
+    if band_list is None:
+        return S2PlaneteryPipeline(output_fld)
+    else:
+        warnings.warn("Queried for a non-default band list. Skipping pipeline setup.")
+        return
 
 class S2PlanetaryTilePipeline(S2Sen2CorTilePipeline):
     NAME = 'S2-L2A-SEN2COR-PLANETARY'
-- 
GitLab