0

我正在尝试通过运行 docker 容器来下载哨兵 2 数据。我只想下载一个图像进行测试,所以我将文件名作为环境变量传递,但是当我执行时docker run,它会找到所有相关的图像并开始下载所有这些不是我想要的。

这是执行docker run语句的命令

sudo docker run --rm -v $(pwd):/out_data \
> -e scihub_username=test \
> -e scihub_password=test \
> -e producttype=S2MSI2A \
> -e platformname=Sentinel-2 \
> -e files=S2A_MSIL2A_20190612T104031_N0212_R008_T31UGT_20190612T133140 \
> -e days_back=7 \
> -e footprint="POLYGON((5.8664000 50.3276000,9.4623000 50.3276000,9.4623000 52.5325000,5.8664000 52.5325000,5.8664000 50.3276000))" \
> -e max_cloud_cover_percentage=10 \
> -e start_date=2018-01-01T00:00:00.000Z \
> -e end_date=2019-01-01T00:00:00.000Z \
> -e BASE_URL=localohost:8081/swagger-ui.html \
> -e JOB_ID=8c04ee18-92e3-4739-b460-a78b0822a497 \
> ingestion

我还在一个ingestion.py正在执行的文件中定义了变量docker build。它看起来像这样:

import os
import shutil
import logging

logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(name)s - %(message)s')
logger = logging.getLogger("ingestion")

import requests

import datahub

scihub_username = os.environ["scihub_username"]
scihub_password = os.environ["scihub_password"]
result_url = "http://" + os.environ["BASE_URL"] + "/jobs/" + os.environ["JOB_ID"] + "/results"

logger.info("Searching the Copernicus Open Access Hub")
scenes = datahub.search(username=scihub_username,
                        password=scihub_password,
                        producttype=os.getenv("producttype"),
                        platformname=os.getenv("platformname"),
            files=os.getenv("filename")
                        days_back=os.getenv("days_back", 2),
                        footprint=os.getenv("footprint"),
                        max_cloud_cover_percentage=os.getenv("max_cloud_cover_percentage"),
                        start_date = os.getenv("start_date"),
                        end_date = os.getenv("end_date"))

logger.info("Found {} relevant scenes".format(len(scenes)))

job_results = []
for scene in scenes:
    # do not donwload a scene that has already been ingested
    if os.path.exists(os.path.join("/out_data", scene["title"]+".SAFE")):
        logger.info("The scene {} already exists in /out_data and will not be downloaded again.".format(scene["title"]))
        filename = scene["title"]+".SAFE"
    else:
        logger.info("Starting the download of scene {}".format(scene["title"]))
        filename = datahub.download(scene, "/tmp", scihub_username, scihub_password, unpack=True)
        logger.info("The download was successful.")
        shutil.move(filename, "/out_data")
    result_message = {"description": "test",
                      "type": "Raster",
                      "format": "SAFE",
                      "filename": os.path.basename(filename)}
    job_results.append(result_message)

res = requests.put(result_url, json=job_results, timeout=60)
res.raise_for_status()

这就是搜索在下面的 datahub 中的样子:

def search(username, password, producttype=None, platformname=None, days_back=2, footprint=None, max_cloud_cover_percentage=None, start_date=None, end_date=None):
4

0 回答 0