Pickling xarray gives cannot pickle '_thread.lock' object

Viewed 126

I am running into some problem with pickling an xarray and totally fail to understand what the problem is.

import xarray as xr
import pickle
ds = xr.open_dataset('62030_prec_1995.nc')
pkl = pickle.dumps(ds, protocol=-1)

This results in the error message:

Traceback (most recent call last):
  File "C:\Users\xxx\Miniconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3441, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-14-08c3b812c30c>", line 1, in <module>
    pkl = pickle.dumps(ds, protocol=-1)
TypeError: cannot pickle '_thread.lock' object

If I run ds.info() it gives me the following info on the file:

    ds.info()
xarray.Dataset {
dimensions:
    time = 365 ;
    bnds = 2 ;
    rlon = 848 ;
    rlat = 824 ;
variables:
    datetime64[ns] time(time) ;
        time:standard_name = time ;
        time:bounds = time_bnds ;
        time:axis = T ;
    datetime64[ns] time_bnds(time, bnds) ;
    float64 rlon(rlon) ;
        rlon:standard_name = projection_x_coordinate ;
        rlon:long_name = longitude in rotated pole grid ;
        rlon:units = degrees ;
        rlon:axis = X ;
    float64 rlat(rlat) ;
        rlat:standard_name = projection_y_coordinate ;
        rlat:long_name = latitude in rotated pole grid ;
        rlat:units = degrees ;
        rlat:axis = Y ;
    int32 rotated_pole() ;
        rotated_pole:grid_mapping_name = rotated_latitude_longitude ;
        rotated_pole:grid_north_pole_longitude = -162.0 ;
        rotated_pole:grid_north_pole_latitude = 39.25 ;
    float32 prec(time, rlat, rlon) ;
        prec:code = 260 ;
        prec:table = 2 ;
        prec:grid_mapping = rotated_pole ;
        prec:cell_methods = time: mean ;
// global attributes:
    :CDI = Climate Data Interface version 1.9.10 (https://mpimet.mpg.de/cdi) ;
    :Conventions = CF-1.6 ;
}
0 Answers
Related