Skip to content

darts_acquisition.utils.copernicus

Copernicus STAC utilities.

logger module-attribute

logger = logging.getLogger(
    __name__.replace("darts_", "darts.")
)

init_copernicus

init_copernicus(profile_name: str = 'default')

Configure odc.stac and rio to authenticate with Copernicus cloud.

This functions expects that credentials are present in the .aws/credentials file. Credentials can be obtained from https://eodata-s3keysmanager.dataspace.copernicus.eu/

Example credentials file:

[default]
AWS_ACCESS_KEY_ID=...
AWS_SECRET_ACCESS_KEY=...

Parameters:

  • profile_name (str, default: 'default' ) –

    The boto3 profile name. This must match with the name in the credentials file!. Defaults to "default".

References
  • S3 access: https://documentation.dataspace.copernicus.eu/APIs/S3.html
Source code in darts-acquisition/src/darts_acquisition/utils/copernicus.py
def init_copernicus(profile_name: str = "default"):
    """Configure odc.stac and rio to authenticate with Copernicus cloud.

    This functions expects that credentials are present in the .aws/credentials file.
    Credentials can be obtained from https://eodata-s3keysmanager.dataspace.copernicus.eu/

    Example credentials file:

    ```
    [default]
    AWS_ACCESS_KEY_ID=...
    AWS_SECRET_ACCESS_KEY=...
    ```

    Args:
        profile_name (str, optional): The boto3 profile name. This must match with the name in the credentials file!.
            Defaults to "default".

    References:
        - S3 access: https://documentation.dataspace.copernicus.eu/APIs/S3.html

    """
    import boto3
    import odc.stac

    session = boto3.Session(profile_name=profile_name)
    credentials = session.get_credentials()

    odc.stac.configure_rio(
        cloud_defaults=True,
        verbose=False,
        aws={
            "profile_name": profile_name,
            "aws_access_key_id": credentials.access_key,
            "aws_secret_access_key": credentials.secret_key,
            "region_name": "default",
            "endpoint_url": "eodata.dataspace.copernicus.eu",
        },
        AWS_VIRTUAL_HOSTING=False,
    )
    logger.debug("Copernicus STAC initialized")

init_copernicus_from_keys

init_copernicus_from_keys(access_key: str, secret_key: str)

Set up the environment for accessing the Copernicus Data Space Ecosystem S3 storage.

This will configure the necessary environment variables for accessing the S3 storage and calls configure_rio to set up the rasterio environment.

Keys can be obtained from the Copernicus S3 Credentials manager: https://eodata-s3keysmanager.dataspace.copernicus.eu/panel/s3-credentials

Parameters:

  • access_key (str) –

    The AWS access key ID.

  • secret_key (str) –

    The AWS secret access key.

References
  • S3 access: https://documentation.dataspace.copernicus.eu/APIs/S3.html
Source code in darts-acquisition/src/darts_acquisition/utils/copernicus.py
def init_copernicus_from_keys(access_key: str, secret_key: str):
    """Set up the environment for accessing the Copernicus Data Space Ecosystem S3 storage.

    This will configure the necessary environment variables for accessing the S3 storage
    and calls configure_rio to set up the rasterio environment.

    Keys can be obtained from the Copernicus S3 Credentials manager:
    https://eodata-s3keysmanager.dataspace.copernicus.eu/panel/s3-credentials

    Args:
        access_key (str): The AWS access key ID.
        secret_key (str): The AWS secret access key.

    References:
        - S3 access: https://documentation.dataspace.copernicus.eu/APIs/S3.html

    """
    import boto3
    import odc.stac

    os.environ["GDAL_HTTP_TCP_KEEPALIVE"] = "YES"
    os.environ["AWS_S3_ENDPOINT"] = "eodata.dataspace.copernicus.eu"
    os.environ["AWS_ACCESS_KEY_ID"] = access_key
    os.environ["AWS_SECRET_ACCESS_KEY"] = secret_key
    os.environ["AWS_HTTPS"] = "YES"
    os.environ["AWS_VIRTUAL_HOSTING"] = "FALSE"
    os.environ["GDAL_HTTP_UNSAFESSL"] = "YES"

    session = boto3.session.Session(
        aws_access_key_id=access_key, aws_secret_access_key=secret_key, region_name="default"
    )
    odc.stac.configure_rio(cloud_defaults=False, aws={"session": session, "aws_unsigned": False})
    logger.debug("Copernicus STAC initialized")