diff --git a/sen2chain/__init__.py b/sen2chain/__init__.py index 83cd50323fe9fb2ce950a214f32d892e9bce4028..1651d4b478d76f59aa8505c7b57ed7be14c84e35 100644 --- a/sen2chain/__init__.py +++ b/sen2chain/__init__.py @@ -32,6 +32,7 @@ from .library import Library from .data_request import DataRequest from .indices import IndicesCollection from .download_and_process import DownloadAndProcess +from .download_eodag import S2cEodag from .time_series import TimeSeries from .automatization import Automatization from .utils import ( @@ -56,6 +57,7 @@ from .multi_processing import ( from .tileset import TileSet from .jobs import Jobs, Job + __version__ = "0.7.0" __author__ = ( "Jérémy Commins <jebins@laposte.net> & Impact <pascal.mouquet@ird.fr>" diff --git a/sen2chain/config.py b/sen2chain/config.py index d44d7c6feeb42420d9c13efe2ae0f03ea98c544c..27b47680ad293f22c8b11136a5f3318c99822987 100644 --- a/sen2chain/config.py +++ b/sen2chain/config.py @@ -22,6 +22,7 @@ SHARED_DATA = dict( peps_download=ROOT / "sen2chain" / "peps_download3.py", sen2chain_meta=ROOT / "sen2chain" / "data" / "sen2chain_info.xml", raw_job_cfg=ROOT / "sen2chain" / "data" / "job_ini.cfg", + eodag_centroids_shp=ROOT / "sen2chain" / "data" / "eodag_workspace_locations_tiles" / "sentinel2_tiling_grid_centroids.shp" ) diff --git a/sen2chain/data/eodag_workspace_locations_tiles/custom_locations.yml b/sen2chain/data/eodag_workspace_locations_tiles/custom_locations.yml deleted file mode 100644 index 32a529959bcf8e00afc1b85fc7aad99e798587d1..0000000000000000000000000000000000000000 --- a/sen2chain/data/eodag_workspace_locations_tiles/custom_locations.yml +++ /dev/null @@ -1,4 +0,0 @@ -shapefiles: - - name: s2_tile_centroid - path: /home/operateur/sen2chain/sen2chain/data/sentinel2_tiling_grid_centroids.shp - attr: tile_id \ No newline at end of file diff --git a/sen2chain/download_and_process.py b/sen2chain/download_and_process.py index 99532dcc383ee04526209f409133de912dbf2ba5..fa7aae9f9a1210d43f60f46cb63fc56163e255b4 100644 --- a/sen2chain/download_and_process.py +++ b/sen2chain/download_and_process.py @@ -13,7 +13,7 @@ from datetime import datetime from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor from collections import defaultdict from sentinelsat import SentinelAPI -from sentinelhub import AwsProductRequest +# from sentinelhub import AwsProductRequest from pprint import pprint # type annotations diff --git a/sen2chain/download_eodag.py b/sen2chain/download_eodag.py index b81b490970f9f7ed63b7ce37f9650bc2abe4466b..3f2716d0b693f5675c7f379f5802cd0af04972ff 100644 --- a/sen2chain/download_eodag.py +++ b/sen2chain/download_eodag.py @@ -6,7 +6,68 @@ Module for downloading Sentinel-2 images using EODAG https://www.github.com/CS-SI/EODAG """ +import logging +import shapefile +import os +from pathlib import Path +from eodag import EODataAccessGateway +from .config import SHARED_DATA, Config +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) +ROOT = Path(os.path.realpath(__file__)).parent.parent +class S2cEodag: + + def __init__(self, name: str): + self.name = name + eodag_centroids_shp = SHARED_DATA.get("eodag_centroids_shp") + + with shapefile.Reader(eodag_centroids_shp) as shp: + shaperecs = shp.shapeRecords() + + locations_yaml_content = """ + shapefiles: + - name: s2_tile_centroid + path: {} + attr: tile_id + """.format(os.path.abspath(eodag_centroids_shp)) + + eodag_custom_location_cfg = os.path.abspath(Config()._CONFIG_DIR / "eodag_custom_locations.yml") + + with open(eodag_custom_location_cfg, "w") as f_yml: + f_yml.write(locations_yaml_content.strip()) + + self.dag = EODataAccessGateway(locations_conf_path = eodag_custom_location_cfg) + self.dag.set_preferred_provider("peps") + + targeted_tile = [ + sr + for sr in shaperecs + if sr.record["tile_id"] == name + ][0] + + + def search( + self, + productType = "S2_MSI_L1C", + start: str = "2015-01-01", + end: str = "9999-01-01", + + ): + default_search_criteria = dict( + productType = productType, + start = start, + end = end + ) + + products = self.dag.search_all( + locations=dict(s2_tile_centroid=self.name), + **default_search_criteria + ) + logger.info("{} products were found given the above search criteria".format(len(products))) + logger.info(products) + logger.info([p.properties["storageStatus"] for p in products]) +