Skip to content

Instantly share code, notes, and snippets.

@mdsumner
Last active February 12, 2025 03:38
Show Gist options
  • Save mdsumner/cdc33f28708ea0af1008dea54d05ebfa to your computer and use it in GitHub Desktop.
Save mdsumner/cdc33f28708ea0af1008dea54d05ebfa to your computer and use it in GitHub Desktop.
import s3fs
bucket = 'podaac-ops-cumulus-protected'

creds = "<the literal json available at https://archive.podaac.earthdata.nasa.gov/s3credentials>"

s3 = s3fs.S3FileSystem(key=creds['accessKeyId'], 
                       secret=creds['secretAccessKey'],
                       token=creds['sessionToken'],
                       client_kwargs={'region_name':'us-west-2'})
s3.ls(bucket)
@mdsumner
Copy link
Author

mdsumner commented Feb 12, 2025

so next challenge, open this

's3://podaac-ops-cumulus-protected/MUR-JPL-L4-GLOB-v4.1/20020601090000-JPL-L4_GHRSST-SSTfnd-MUR-GLOB-v02.0-fv04.1.nc'

somehow bend these creds into the zarr open virtual parquet that mursst has (in us-west-2)

## we can't do this because netcdf can't read it, that's why kerchunk
src = "s3://podaac-ops-cumulus-protected/MUR-JPL-L4-GLOB-v4.1/20020601090000-JPL-L4_GHRSST-SSTfnd-MUR-GLOB-v02.0-fv04.1.nc"

import s3fs
import fsspec
import xarray
s_opts = {"requester_pays": True, "skip_instance_cache": True}
r_opts = {
    "key": creds["accessKeyId"],
    "secret": creds["secretAccessKey"],
    "token": creds["sessionToken"],
    "client_kwargs": {"region_name": "us-west-2"},
}

fs = fsspec.filesystem(
    "reference",
    fo=src,
    ref_storage_args=s_opts,
    remote_protocol="s3",
    remote_options=r_opts,
    simple_templates=True,
)
m = fs.get_mapper("")
##ds = xarray.open_dataset(m, decode_times=False, engine="h5netcdf")

this does work however (in us-west-2)


export AWS_REGION="us-west-2"
export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
export AWS_SESSION_TOKEN=
export AWS_VIRTUAL_HOSTING=FALSE
gdalinfo /vsis3/podaac-ops-cumulus-protected/MUR-JPL-L4-GLOB-v4.1/20020601090000-JPL-L4_GHRSST-SSTfnd-MUR-GLOB-v02.0-fv04.1.nc

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