Remote writing NETCDF4 files to Amazon S3
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
Hi all,
I am trying to use xarray's .to_netcdf() function to write an array remotely to a file in an Amazon S3 bucket in NETCDF4 format, but I have absolutely no idea how to do it. So far I have been able to write locally, but it all completely falls apart when I try and provide something that isn't a local path to the .to_netcdf() function. Example code is provided below.
import boto3
import json
import numpy as np
import xarray as xr
with open('<MY_PATH>/boto_test_credentials', 'r') as f:
secrets = json.load(f)
sn = secrets['service_name']
aaki = secrets['aws_access_key_id']
asak = secrets['aws_secret_access_key']
eu = secrets['endpoint_url']
session = boto3.session.Session()
s3 = session.client(
service_name = sn,
aws_access_key_id = aaki,
aws_secret_access_key = asak,
endpoint_url = eu,
)
x = xr.DataArray(np.random.randn(450, 450))
Then finally something like this?
x.to_netcdf(<URL_TO_MY_AMAZON_S3_BUCKET>)
I've thought about trying to trick the .to_netcdf() function by using the urllib module to convert a URL into a file-like object, but I don't understand thing like the authentication process etc well enough, and I don't even know if I'm heading down a blind alley here. Any advice would be most appreciated!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with xarray's DataArray.to_netcdf() entry point and the provided boto3 S3 client example, then determine how NETCDF4 output and S3 authentication are expected to interact. Done would be a documented or implemented, verified way to write a DataArray to an Amazon S3 bucket in NETCDF4 format.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, numpy, python
- Domain
- cloud, data
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100