diff --git a/TimeSeries/s2planetary.py b/TimeSeries/s2planetary.py index ad8e1313375fb692ec06de15dc7f389e1218246d..d07cf715c8fe3f915dfeecdaed0c3111cc661ff0 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'