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

Cannot save to netcdf where dataset contains a structured numpy array #2564

Closed
qAp opened this issue Nov 23, 2018 · 1 comment
Closed

Cannot save to netcdf where dataset contains a structured numpy array #2564

qAp opened this issue Nov 23, 2018 · 1 comment

Comments

@qAp
Copy link

qAp commented Nov 23, 2018

I have this netcdf file which I can load into a xarray.Dataset containing a single data variable. This data variable consists of a structured numpy array. Loading it with:

import xarray as xr
import pandas as pd
import numpy as np

ds = xr.open_dataset('puftrac_2018103100ChinShan_Cs.nc')

returns

<xarray.Dataset>
Dimensions:  (serial: 2657664)
Dimensions without coordinates: serial
Data variables:
    trajec   (serial) {'names':['ReleaseTime','CurrentTime','Longitude','Latitude','RelativeHeight','SigX','SigY','SigZ','AirConcentrationR','GroundConcentrationR'], 'formats':['<i8','<i8','<f4','<f4','<f4','<f4','<f4','<f4','<f4','<f4'], 'offsets':[0,8,16,20,24,28,32,36,40,44], 'itemsize':48, 'aligned':True} ...
Attributes:
    Start Time:      1540944000
    End Time:        1541635200
    Release Period:  300
    Dump Period:     300

I can't save it back to netcdf with

ds.to_netcdf('tmp.nc')

getting

~/anaconda3/lib/python3.6/site-packages/xarray/backends/netCDF4_.py in _get_datatype(var, nc_format, raise_on_invalid_encoding)
    105 def _get_datatype(var, nc_format='NETCDF4', raise_on_invalid_encoding=False):
    106     if nc_format == 'NETCDF4':
--> 107         datatype = _nc4_dtype(var)
    108     else:
    109         if 'dtype' in var.encoding:

~/anaconda3/lib/python3.6/site-packages/xarray/backends/netCDF4_.py in _nc4_dtype(var)
    128     else:
    129         raise ValueError('unsupported dtype for netCDF4 variable: {}'
--> 130                          .format(var.dtype))
    131     return dtype
    132 

ValueError: unsupported dtype for netCDF4 variable: {'names':['ReleaseTime','CurrentTime','Longitude','Latitude','RelativeHeight','SigX','SigY','SigZ','AirConcentrationR','GroundConcentrationR'], 'formats':['<i8','<i8','<f4','<f4','<f4','<f4','<f4','<f4','<f4','<f4'], 'offsets':[0,8,16,20,24,28,32,36,40,44], 'itemsize':48, 'aligned':True}

Any thing I could do here? (I actually intend to change some values before writing back to disk.) The netcdf file can be found here: https://drive.google.com/open?id=1H5M3N_lv471JyOalcA3Bw_Y2ed0EX6xt

@shoyer
Copy link
Member

shoyer commented Nov 24, 2018

We don't currently support this in xarray but would be welcome this feature. See #1626 for existing discussion.

@shoyer shoyer closed this as completed Nov 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants