Commit 6e1b44ca authored by Gaetano Raffaele's avatar Gaetano Raffaele
Browse files

ENH: fetch specific band list from planetary.

parent c7eef4ff
No related merge requests found
Showing with 11 additions and 3 deletions
+11 -3
import warnings
from TimeSeries.s2sen2cor import * from TimeSeries.s2sen2cor import *
import planetary_computer as PC import planetary_computer as PC
from pystac_client import Client from pystac_client import Client
...@@ -8,7 +10,7 @@ from pyproj import Transformer as T ...@@ -8,7 +10,7 @@ from pyproj import Transformer as T
from shapely import Polygon from shapely import Polygon
import tqdm import tqdm
def fetch(shp, dt, output_fld): def fetch(shp, dt, output_fld, band_list=None):
ds = ogr.Open(shp) ds = ogr.Open(shp)
ly = ds.GetLayer(0) ly = ds.GetLayer(0)
...@@ -28,8 +30,10 @@ def fetch(shp, dt, output_fld): ...@@ -28,8 +30,10 @@ def fetch(shp, dt, output_fld):
api = Client.open('https://planetarycomputer.microsoft.com/api/stac/v1', modifier=PC.sign_inplace) 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) res = api.search(collections="sentinel-2-l2a", bbox=bbox, datetime=dt)
lst = ['B02','B03','B04','B05','B06','B07','B08','B8A','B11','B12','SCL'] 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(): for item in res.items():
with rasterio.open(item.assets['B02'].href) as ds: with rasterio.open(item.assets['B02'].href) as ds:
img_srs = ds.crs.to_epsg() img_srs = ds.crs.to_epsg()
...@@ -59,7 +63,11 @@ def fetch(shp, dt, output_fld): ...@@ -59,7 +63,11 @@ def fetch(shp, dt, output_fld):
prg.update() prg.update()
prg.close() 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): class S2PlanetaryTilePipeline(S2Sen2CorTilePipeline):
NAME = 'S2-L2A-SEN2COR-PLANETARY' NAME = 'S2-L2A-SEN2COR-PLANETARY'
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment