openclimatefix / MetOfficeDataHub

Python wrapper around MetOffice Atmospheric Model Data REST API
MIT License
3 stars 0 forks source link

load netcdf #65

Open peterdudfield opened 1 year ago

peterdudfield commented 1 year ago

Still struggling to load netcdf file from s3, could we show an example on how to do this?

I tried

with fsspec.open("simplecache::s3://nowcasting-nwp-development/data/latest.netcdf", mode="rb") as f:
    nwp = xr.load_dataset(f, engine='h5netcdf')
ValueError: b'' is not the signature of a valid netCDF4 file

and

with fsspec.open("simplecache::s3://nowcasting-nwp-development/data/latest.netcdf", mode="r") as f:
    nwp = xr.load_dataset(f, engine='h5netcdf')
TypeError: startswith first arg must be str or a tuple of str, not bytes
peterdudfield commented 1 year ago
with fsspec.open("s3://nowcasting-nwp-development/data/latest.netcdf", mode="rb""") as f:
    nwp = xr.load_dataset(f, engine='h5netcdf')

is the same error

peterdudfield commented 1 year ago

The current save method is

The current save method is

with fsspec.open("simplecache::s3://nowcasting-nwp-development/data/test.netcdf", mode="wb") as f:
    dataset.to_netcdf(f,engine='h5netcdf')
peterdudfield commented 1 year ago

This might work - it did not

with fsspec.open("s3://nowcasting-nwp-development/data/test.netcdf", mode="rb") as f:
    file_bytes = f.read()
with io.BytesIO(file_bytes) as file:
    nwp = xr.load_dataset(file, engine='h5netcdf')