简体   繁体   English

酸洗 xarray 给出不能酸洗 '_thread.lock' object

[英]Pickling xarray gives cannot pickle '_thread.lock' object

I am running into some problem with pickling an xarray and totally fail to understand what the problem is.我在对 xarray 进行酸洗时遇到了一些问题,完全不明白问题是什么。

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() 它会为我提供有关文件的以下信息:

    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 ;
}

I had the same problem, and I solved it by installing the dask package (with pip install dask ).我遇到了同样的问题,我通过安装dask package (使用pip install dask )解决了这个问题。 Unfortunately I do not have a detailed explanation about why, but since xarray uses dask under the hood I guess it is also needed for correctly pickling objects.不幸的是,我没有关于原因的详细解释,但由于xarray在引擎盖下使用了dask ,我猜它也是正确酸洗对象所必需的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError: cannot pickle '_thread.lock' object Dask 计算 - TypeError: cannot pickle '_thread.lock' object Dask compute Python 进程类型错误:无法腌制'_thread.lock' object - Python process TypeError: cannot pickle '_thread.lock' object 类型错误:无法使用 RQ 腌制“_thread.lock”对象 - TypeError: cannot pickle '_thread.lock' object with RQ Tensorflow - TypeError: cannot pickle '_thread.lock' object - Tensorflow - TypeError: cannot pickle '_thread.lock' object pydantic 设置:类型错误:无法腌制 '_thread.lock' object - pydantic Settings: TypeError: cannot pickle '_thread.lock' object TypeError:在方法上使用 pool.map 时无法 pickle '_thread.lock' object - TypeError: cannot pickle '_thread.lock' object while using pool.map over a method 多处理池apply_async函数在应用于对象时抛出无法腌制 <type 'thread.lock'> 对象 - Multiprocessing pool apply_async function when applied to an Object throws Cannot pickle <type 'thread.lock'> objects 使用多处理的脚本在 Python &gt; 3 上使用部分和映射失败,在 2.7 上工作正常,无法pickle &#39;_thread.lock&#39; - Script using multiprocessing with partial and map failing on Python > 3, working fine on 2.7, cannot pickle '_thread.lock' Joblib错误:TypeError:无法腌制_thread.lock对象 - Joblib error: TypeError: can't pickle _thread.lock objects Keras:TypeError:无法使用KerasClassifier来pickle _thread.lock对象 - Keras: TypeError: can't pickle _thread.lock objects with KerasClassifier
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM