MCPcopy Index your code
hub / github.com/pydata/xarray / _combine_nd

Function _combine_nd

xarray/structure/combine.py:216–273  ·  view source on GitHub ↗

Combines an N-dimensional structure of datasets into one by applying a series of either concat and merge operations along each dimension. No checks are performed on the consistency of the datasets, concat_dims or tile_IDs, because it is assumed that this has already been done.

(
    combined_ids,
    concat_dims,
    data_vars,
    coords,
    compat: CompatOptions | CombineKwargDefault,
    fill_value,
    join: JoinOptions | CombineKwargDefault,
    combine_attrs: CombineAttrsOptions,
)

Source from the content-addressed store, hash-verified

214
215
216def _combine_nd(
217 combined_ids,
218 concat_dims,
219 data_vars,
220 coords,
221 compat: CompatOptions | CombineKwargDefault,
222 fill_value,
223 join: JoinOptions | CombineKwargDefault,
224 combine_attrs: CombineAttrsOptions,
225):
226 """
227 Combines an N-dimensional structure of datasets into one by applying a
228 series of either concat and merge operations along each dimension.
229
230 No checks are performed on the consistency of the datasets, concat_dims or
231 tile_IDs, because it is assumed that this has already been done.
232
233 Parameters
234 ----------
235 combined_ids : Dict[Tuple[int, ...]], xarray.Dataset | xarray.DataTree]
236 Structure containing all datasets to be concatenated with "tile_IDs" as
237 keys, which specify position within the desired final combined result.
238 concat_dims : sequence of str
239 The dimensions along which the datasets should be concatenated. Must be
240 in order, and the length must match the length of the tuples used as
241 keys in combined_ids. If the string is a dimension name then concat
242 along that dimension, if it is None then merge.
243
244 Returns
245 -------
246 combined_ds : xarray.Dataset | xarray.DataTree
247 """
248
249 example_tile_id = next(iter(combined_ids.keys()))
250
251 n_dims = len(example_tile_id)
252 if len(concat_dims) != n_dims:
253 raise ValueError(
254 f"concat_dims has length {len(concat_dims)} but the datasets "
255 f"passed are nested in a {n_dims}-dimensional structure"
256 )
257
258 # Each iteration of this loop reduces the length of the tile_ids tuples
259 # by one. It always combines along the first dimension, removing the first
260 # element of the tuple
261 for concat_dim in concat_dims:
262 combined_ids = _combine_all_along_first_dim(
263 combined_ids,
264 dim=concat_dim,
265 data_vars=data_vars,
266 coords=coords,
267 compat=compat,
268 fill_value=fill_value,
269 join=join,
270 combine_attrs=combine_attrs,
271 )
272 (combined_ds,) = combined_ids.values()
273 return combined_ds

Callers 3

test_concat_twiceMethod · 0.90
_nested_combineFunction · 0.85

Calls 3

keysMethod · 0.80
valuesMethod · 0.45

Tested by 1

test_concat_twiceMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…