From d0f92759041f32e93e74063bbf81f736ec621497 Mon Sep 17 00:00:00 2001 From: luptmoor Date: Wed, 4 Mar 2026 15:53:43 +0100 Subject: [PATCH] single image test --- .env.example | 5 ++--- app/main.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 11 ++++++++- 3 files changed, 68 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index 0e2d31a..394d557 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,2 @@ -GEODB_USER=xxx -GEODB_PW=xxx -GEODB_NAME=xxx \ No newline at end of file +CDSE_S3_ACCESS_KEY=xxxx +CDSE_S3_SECRET_KEY=xxxx \ No newline at end of file diff --git a/app/main.py b/app/main.py index cd13a2c..1431827 100644 --- a/app/main.py +++ b/app/main.py @@ -4,9 +4,65 @@ import time import pystac_client import geogif import stackstac +from matplotlib import pyplot as plt if __name__ == "__main__": print("starting app.") + + URL = "https://stac.dataspace.copernicus.eu/v1" + cat = pystac_client.Client.open(URL) + cat.add_conforms_to("ITEM_SEARCH") + geom = { + "type": "Polygon", + "coordinates": [ + [ + [32.6, -17.3], + [32.6, -17.1], + [33.0, -17.1], + [33.0, -17.3], + [32.6, -17.3], + ] + ], + } + + + params = { + "max_items": 1, + "collections": "sentinel-2-l2a", + "datetime": "2017-02-01/2017-10-01", + "intersects": geom, + "query": {"eo:cloud_cover": {"gte": 0, "lte": 20}}, + "sortby": "properties.eo:cloud_cover", + "fields": {"exclude": ["geometry"]}, + } + + print("Searching items...") + items = list(cat.search(**params).items_as_dicts()) + print("Search successful.") + + + + stack = stackstac.stack( + items=items, + resolution=(60, 60), + bounds_latlon=(33.0, -17.1, 32.6, -17.3), + chunksize=98304, + epsg=32634, + gdal_env=stackstac.DEFAULT_GDAL_ENV.updated( + { + "GDAL_NUM_THREADS": -1, + "GDAL_HTTP_UNSAFESSL": "YES", + "GDAL_HTTP_TCP_KEEPALIVE": "YES", + "AWS_VIRTUAL_HOSTING": "FALSE", + "AWS_HTTPS": "YES", + } + ), + ) + + rgb = stack.sel(band=["B04_60m", "B03_60m", "B02_60m"]) + print(rgb) + rgb.plot() + plt.show() \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index cb02c56..7f0beb0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,16 @@ services: app: build: . container_name: copernicus-app + volumes: + - ./app:/app environment: PYTHONUNBUFFERED: 1 - \ No newline at end of file + GDAL_HTTP_TCP_KEEPALIVE: YES + AWS_S3_ENDPOINT: odata.dataspace.copernicus.eu + AWS_ACCESS_KEY_ID: ${CDSE_S3_ACCESS_KEY} + AWS_SECRET_ACCESS_KEY: ${CDSE_S3_SECRET_KEY} + AWS_HTTPS: YES + AWS_VIRTUAL_HOSTING: FALSE + GDAL_HTTP_UNSAFESSL: YES +