xarray.merge:ValueError:找不到任何维度坐标来用于排序数据集以进行串联
我想将多个 .nc 文件合并为一个。每个 .nc 文件都对应一个时间步长,应将其添加到一起以形成一个包含所有日期的所有数据的 .nc 文件。
当我执行以下行时,我会收到错误消息,尽管有几个维度可用(时间、纬度、经度),但未找到维度。为什么它不起作用?
代码:
ds = xr.open_mfdataset(os.getcwd() + '/test/*.nc')
Traceback:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-40-c0e9d8bf97e7> in <module>
----> 1 ds = xr.open_mfdataset(os.getcwd() + '/test/*.nc')
/opt/conda/lib/python3.7/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)
945 coords=coords,
946 join=join,
--> 947 combine_attrs=combine_attrs,
948 )
949 else:
/opt/conda/lib/python3.7/site-packages/xarray/core/combine.py in combine_by_coords(data_objects, compat, data_vars, coords, fill_value, join, combine_attrs, datasets)
903 compat=compat,
904 join=join,
--> 905 combine_attrs=combine_attrs,
906 )
907 concatenated_grouped_by_data_vars.append(concatenated)
/opt/conda/lib/python3.7/site-packages/xarray/core/combine.py in _combine_single_variable_hypercube(datasets, fill_value, data_vars, coords, compat, join, combine_attrs)
602 )
603
--> 604 combined_ids, concat_dims = _infer_concat_order_from_coords(list(datasets))
605
606 if fill_value is None:
/opt/conda/lib/python3.7/site-packages/xarray/core/combine.py in _infer_concat_order_from_coords(datasets)
128 if len(datasets) > 1 and not concat_dims:
129 raise ValueError(
--> 130 "Could not find any dimension coordinates to use to "
131 "order the datasets for concatenation"
132 )
ValueError: Could not find any dimension coordinates to use to order the datasets for concatenation
我想要合并的 .nc 文件之一的示例(全部相同):
<xarray.Dataset>
Dimensions: (columns: 321, rows: 321, Time: 1)
Coordinates:
longitude (columns, rows) float32 ...
latitude (columns, rows) float32 ...
time (Time) datetime64[ns] 2010-01-02T02:00:00
Dimensions without coordinates: columns, rows, Time
Data variables:
cdr_surface_albedo (Time, columns, rows) float32 ...
cdr_surface_temperature (Time, columns, rows) float32 ...
Attributes:
standard_name: surface_albedo
long_name: NOAA CDR of surface broadband albedo
valid_range: [0. 1.]
units: 1
grid_mapping: crs
coverage_content_type: physicalMeasurement
I want to merge multiple .nc files into one. Each of the .nc files corresponds to a timestep which should be added together to have one .nc file with all data for all dates.
When I execute the following line I'll get the error that no dimensions found although several are available (time, latitude, longitude). Why it doesn't work?
Code:
ds = xr.open_mfdataset(os.getcwd() + '/test/*.nc')
Traceback:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-40-c0e9d8bf97e7> in <module>
----> 1 ds = xr.open_mfdataset(os.getcwd() + '/test/*.nc')
/opt/conda/lib/python3.7/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)
945 coords=coords,
946 join=join,
--> 947 combine_attrs=combine_attrs,
948 )
949 else:
/opt/conda/lib/python3.7/site-packages/xarray/core/combine.py in combine_by_coords(data_objects, compat, data_vars, coords, fill_value, join, combine_attrs, datasets)
903 compat=compat,
904 join=join,
--> 905 combine_attrs=combine_attrs,
906 )
907 concatenated_grouped_by_data_vars.append(concatenated)
/opt/conda/lib/python3.7/site-packages/xarray/core/combine.py in _combine_single_variable_hypercube(datasets, fill_value, data_vars, coords, compat, join, combine_attrs)
602 )
603
--> 604 combined_ids, concat_dims = _infer_concat_order_from_coords(list(datasets))
605
606 if fill_value is None:
/opt/conda/lib/python3.7/site-packages/xarray/core/combine.py in _infer_concat_order_from_coords(datasets)
128 if len(datasets) > 1 and not concat_dims:
129 raise ValueError(
--> 130 "Could not find any dimension coordinates to use to "
131 "order the datasets for concatenation"
132 )
ValueError: Could not find any dimension coordinates to use to order the datasets for concatenation
Examples for one of the .nc files I want to merge (all are same):
<xarray.Dataset>
Dimensions: (columns: 321, rows: 321, Time: 1)
Coordinates:
longitude (columns, rows) float32 ...
latitude (columns, rows) float32 ...
time (Time) datetime64[ns] 2010-01-02T02:00:00
Dimensions without coordinates: columns, rows, Time
Data variables:
cdr_surface_albedo (Time, columns, rows) float32 ...
cdr_surface_temperature (Time, columns, rows) float32 ...
Attributes:
standard_name: surface_albedo
long_name: NOAA CDR of surface broadband albedo
valid_range: [0. 1.]
units: 1
grid_mapping: crs
coverage_content_type: physicalMeasurement
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试 NCO 的 ncrcat:
You could try NCO's ncrcat: