1
0
Fork 0
mirror of https://github.com/noerw/sentinel_fire synced 2025-03-12 18:00:28 +01:00
sentinel2_pipeline/bin/s2_download
Norwin Roosen 75d963b299 add s2_visualize
creates thumbnails, and writes the visualization template to the input folder
2019-01-20 00:34:07 +01:00

39 lines
1.3 KiB
Python
Executable file

#!/usr/bin/env python2
import logging
import os
import argparse
import zipfile
from sentinelsat.sentinel import SentinelAPI
# log to stderr. stdout is used for pipe communications!
logger = logging.getLogger()
logger.setLevel(logging.INFO)
logger.addHandler(logging.StreamHandler())
# argparse
parser = argparse.ArgumentParser()
parser.add_argument('outdir', type = str, help = 'directory to store the results in')
parser.add_argument('productid', type = str, help = 'UUID of the product to download')
parser.add_argument('--rmzip', help = 'Whether to delete the zip source file. If true, already downloaded files will be downloaded again.', default = False)
parser.add_argument('--user', help = 'Copernicus Apihub username', default = 'user')
parser.add_argument('--password', help = 'Copernicus Apihub password', default = 'user')
args = parser.parse_args()
api = SentinelAPI(
os.environ.get('S2_USER') or args.user,
os.environ.get('S2_PASS') or args.password,
)
product = api.download(args.productid, args.outdir)
# print the resulting zip or directory for piping
zip_path = product['path']
zip_ref = zipfile.ZipFile(zip_path, 'r')
zip_ref.extractall(args.outdir)
zip_ref.close()
if args.rmzip:
os.remove(zip_path)
# resulting product directory: replace .zip with .SAFE extension
print zip_path[:-4] + '.SAFE'