Skip to content

Update CTMAMA downloading script #79

Description

@zxdawn

Because the s5pHub moved to dataspace, we need to write a new script to download CTMANA data.

Here is an simple example:

import os
import boto3

session = boto3.Session(profile_name='eodata')
credentials = session.get_credentials()
access_key = credentials.access_key
secret_key = credentials.secret_key

s3 = boto3.resource(
    's3',
    endpoint_url='https://eodata.dataspace.copernicus.eu',
    aws_access_key_id=access_key,
    aws_secret_access_key=secret_key,
)


def download(bucket, product, savedir='./', s3_client=boto3.client('s3')):
    """
    Downloads every file in bucket with provided product as prefix

    Raises FileNotFoundError if the product was not found

    Args:
        bucket: boto3 Resource bucket object
        product: Path to product
        savefir: the directory to save CTMANA data
    """
    files = bucket.objects.filter(Prefix=product)

    if not list(files):
        raise FileNotFoundError(f"Could not find any files for {product}")

    for file in files:
        if file.key.endswith('.nc'):
            savename = os.path.basename(file.key)
            savepath = os.path.join(savedir, savename)
            print(f'Download {savepath} now ...')
            bucket.download_file(file.key, savepath)

product = 'Sentinel-5P/TROPOMI/AUX_CTMANA/2023/04/03/S5P_OPER_AUX_CTMANA_20230403T000000'
download(s3.Bucket('eodata'), product)

The step of generating key is here: https://documentation.dataspace.copernicus.eu/APIs/S3.html

You can modify ~/.aws/credentials like this:

[eodata]
aws_access_key_id=<your_id>
aws_secret_access_key=<your_key>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions