简体   繁体   English

在 Python 中加载.nc 文件

[英]Loading .nc file in Python

I have a problem with opening.nc files.我在打开 .nc 文件时遇到问题。 I tried with several files (named L3 and L5) and it works for L3 but not for L5.我尝试了几个文件(名为 L3 和 L5),它适用于 L3,但不适用于 L5。

The code works for L3该代码适用于 L3

The code does not work for L5该代码不适用于 L5

The error message is as follows for L5: ''' --------------------------------------------------------------------------- ValueError Traceback (most recent call last) /tmp/ipykernel_442/1488629900.py in 1 # select one site (Howard Springs) ----> 2 ds = xr.open_mfdataset(eddy_files[0]) 3 ds_orig = ds.copy() 4 # Filtering out data gaps marked as -9999 5 ds = ds_orig.where(ds_orig.= -9999.) L5的错误信息如下:''' -------------------------------------- ------------------------------------- ValueError Traceback (最近一次调用最后) /tmp/ipykernel_442/ 1488629900.py in 1 # select 一个站点(霍华德斯普林斯)----> 2 ds = xr.open_mfdataset(eddy_files[0]) 3 ds_orig = ds.copy() 4 # 过滤掉标记为-9999 5 ds的数据间隙= ds_orig.where(ds_orig.= -9999.)

/opt/conda/lib/python3.9/site-packages/xarray/backends/api.py in open_mfdataset(paths, chunks, concat_dim, compat, preprocess, engine, data_vars, coords, combine, parallel, join, attrs_file, combine_attrs, **kwargs) 906 getattr_ = getattr 907 --> 908 datasets = [open_(p, **open_kwargs) for p in paths] 909 closers = [getattr_(ds, "_close") for ds in datasets] 910 if preprocess is not None: /opt/conda/lib/python3.9/site-packages/xarray/backends/api.py 在 open_mfdataset(路径、块、concat_dim、compat、预处理、引擎、data_vars、coords、combine、parallel、join、attrs_file、combine_attrs , **kwargs) 906 getattr_ = getattr 907 --> 908 datasets = [open_(p, **open_kwargs) for p in paths] 909 closes = [getattr_(ds, "_close") for ds in datasets] 910 如果预处理不是无:

/opt/conda/lib/python3.9/site-packages/xarray/backends/api.py in (.0) 906 getattr_ = getattr 907 --> 908 datasets = [open_(p, **open_kwargs) for p in paths] 909 closers = [getattr_(ds, "_close") for ds in datasets] 910 if preprocess is not None: /opt/conda/lib/python3.9/site-packages/xarray/backends/api.py in (.0) 906 getattr_ = getattr 907 --> 908 个数据集 = [open_(p, **open_kwargs) for p in路径] 909 closes = [getattr_(ds, "_close") for ds in datasets] 910 如果预处理不是无:

/opt/conda/lib/python3.9/site-packages/xarray/backends/api.py in open_dataset(filename_or_obj, engine, chunks, cache, decode_cf, mask_and_scale, decode_times, decode_timedelta, use_cftime, concat_characters, decode_coords, drop_variables, backend_kwargs, *args, **kwargs) 477 478 if engine is None: --> 479 engine = plugins.guess_engine(filename_or_obj) 480 481 backend = plugins.get_backend(engine) /opt/conda/lib/python3.9/site-packages/xarray/backends/api.py 在 open_dataset(filename_or_obj,引擎,块,缓存,decode_cf,mask_and_scale,decode_times,decode_timedelta,use_cftime,concat_characters,decode_coords,drop_variables,backend_kwargs , *args, **kwargs) 477 478 如果引擎是 None: --> 479 engine = plugins.guess_engine(filename_or_obj) 480 481 backend = plugins.get_backend(engine)

/opt/conda/lib/python3.9/site-packages/xarray/backends/plugins.py in guess_engine(store_spec) 153 ) 154 --> 155 raise ValueError(error_msg) 156 157 /opt/conda/lib/python3.9/site-packages/xarray/backends/plugins.py 在 guess_engine(store_spec) 153 ) 154 --> 155 raise ValueError(error_msg) 156 157

ValueError: did not find a match in any of xarray's currently installed IO backends ['netcdf4', 'scipy']. ValueError: 在 xarray 当前安装的 IO 后端 ['netcdf4', 'scipy'] 中找不到匹配项。 Consider explicitly selecting one of the installed engines via the engine parameter, or installing additional IO dependencies, see: http://xarray.pydata.org/en/stable/getting-started-guide/installing.html http://xarray.pydata.org/en/stable/user-guide/io.html ''' Consider explicitly selecting one of the installed engines via the engine parameter, or installing additional IO dependencies, see: http://xarray.pydata.org/en/stable/getting-started-guide/installing.html http://xarray. pydata.org/en/stable/user-guide/io.html '''

In the end, the problem was due to incorrect loading of files - Problem solved最后,问题是由于文件加载不正确 - 问题已解决

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM