Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CTMAMA downloading script #79

Open
zxdawn opened this issue Feb 21, 2024 · 0 comments
Open

Update CTMAMA downloading script #79

zxdawn opened this issue Feb 21, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@zxdawn
Copy link
Owner

zxdawn commented Feb 21, 2024

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>
@zxdawn zxdawn added the bug Something isn't working label Feb 21, 2024
@zxdawn zxdawn self-assigned this Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant