diff --git a/Common/demtools.py b/Common/demtools.py index 83b7312e2422af1a51a75bc51de142fad8200da6..3d51faeb4e6ff5df1578e8a1eeca4b83a46277f5 100644 --- a/Common/demtools.py +++ b/Common/demtools.py @@ -9,7 +9,9 @@ import os from shapely.geometry import Polygon import urllib.request -def fetch(shp, output_fld, product='cop-dem-glo-30'): +def fetch(shp, output_fld, product='cop-dem-glo-30', auth=None): + if auth is not None: + os.environ['PC_SDK_SUBSCRIPTION_KEY'] = auth bbox, i_bbox, shp_srs = get_query_bbox(shp, return_all=True) api = Client.open('https://planetarycomputer.microsoft.com/api/stac/v1', modifier=PC.sign_inplace) res = api.search(collections=product, bbox=bbox) diff --git a/TimeSeries/landsat_planetary.py b/TimeSeries/landsat_planetary.py index 2945be06e678c1ce5b44bf85ceee99115dd86c67..aa2db6a897a9ce51c8313ce629efd461e37b1c44 100644 --- a/TimeSeries/landsat_planetary.py +++ b/TimeSeries/landsat_planetary.py @@ -8,8 +8,10 @@ from shapely.geometry import Polygon import rasterio.mask import os -def fetch(shp, dt, out_fld, band_list=None): - +def fetch(shp, dt, out_fld, auth=None, band_list=None): + + if auth is not None: + os.environ['PC_SDK_SUBSCRIPTION_KEY'] = auth bbox, i_bbox, shp_srs = get_query_bbox(shp, return_all=True) api = Client.open('https://planetarycomputer.microsoft.com/api/stac/v1', modifier=PC.sign_inplace) res = api.search(collections="landsat-c2-l2", bbox=bbox, datetime=dt) diff --git a/TimeSeries/s2planetary.py b/TimeSeries/s2planetary.py index 928ce5399ea04c0120d91aec304639f6924d6e33..efa8dd4d9cfb0e35714358c0ae6d95e5de4bb87d 100644 --- a/TimeSeries/s2planetary.py +++ b/TimeSeries/s2planetary.py @@ -8,10 +8,12 @@ from pyproj import Transformer as T from shapely.geometry import Polygon import tqdm -def fetch(shp, dt, output_fld, band_list=None): +def fetch(shp, dt, output_fld, auth=None, band_list=None): bbox, i_bbox, shp_srs = get_query_bbox(shp, return_all=True) + if auth is not None: + os.environ['PC_SDK_SUBSCRIPTION_KEY'] = auth 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'] diff --git a/Workflows/operations.py b/Workflows/operations.py index 5d7b80557a848ff4a17a6401f11598560b337a52..3619f5f40da921dac5c82706c47afafd491e35f5 100644 --- a/Workflows/operations.py +++ b/Workflows/operations.py @@ -1,7 +1,7 @@ import os.path import OBIA.segmentation import VHR.vhrbase -from TimeSeries import s2theia, s2planetary, s1base, s1planetary, planet_mosaics +from TimeSeries import s2theia, s2planetary, s1base, s1planetary, planet_mosaics, landsat_planetary from Common import demtools def run_segmentation(img, threshold, cw, sw , out_seg, @@ -84,7 +84,7 @@ def preprocess_s1(in_fld, roi, out_fld, dem_fld=None, geoid=None, direction=None return s1.write_outputs(out_fld) def fetch(imagery, shp, out_fld, dt=None, auth=None, only_tiles=None): - assert(imagery in ['s2theia', 's2planetary', 's1grd', 's1rtc', 'planetmosaics', 'cop-dem-glo-30', 'nasadem']) + assert(imagery in ['s2theia', 's2planetary', 's1grd', 's1rtc', 'planetmosaics', 'cop-dem-glo-30', 'nasadem', 'landsatplanetary']) if imagery not in ['s2planetary', 'cop-dem-glo-30', 'nasadem'] and auth is None: raise ValueError("Please provide authentication information.") if imagery not in ['cop-dem-glo-30', 'nasadem'] and dt is None: @@ -93,7 +93,7 @@ def fetch(imagery, shp, out_fld, dt=None, auth=None, only_tiles=None): #temporarily switch to eodag since theia_picker is unusable s2theia.fetch_eodag(shp, dt, out_fld, auth, only_tiles.split(';')) elif imagery == 's2planetary': - s2planetary.fetch(shp, dt, out_fld) + s2planetary.fetch(shp, dt, out_fld, auth) elif imagery == 's1grd': s1base.fetch(shp, dt, out_fld, auth) elif imagery == 's1rtc': @@ -101,5 +101,7 @@ def fetch(imagery, shp, out_fld, dt=None, auth=None, only_tiles=None): elif imagery == 'planetmosaics': planet_mosaics.fetch(shp, dt, out_fld, auth) elif imagery in ['cop-dem-glo-30', 'nasadem']: - demtools.fetch(shp, out_fld, product=imagery) + demtools.fetch(shp, out_fld, product=imagery, auth=auth) + elif imagery == 'landsatplanetary': + landsat_planetary.fetch(shp, dt, out_fld, auth) return