mirror of
https://github.com/noerw/sentinel_fire
synced 2025-03-12 18:00:28 +01:00
creates thumbnails, and writes the visualization template to the input folder
39 lines
1.3 KiB
Python
Executable file
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'
|