MCPcopy
hub / github.com/pydata/xarray / _datatree_from_backend_datatree

Function _datatree_from_backend_datatree

xarray/backends/api.py:332–386  ·  view source on GitHub ↗
(
    backend_tree,
    filename_or_obj,
    engine,
    chunks,
    cache,
    overwrite_encoded_chunks,
    inline_array,
    chunked_array_type,
    from_array_kwargs,
    create_default_indexes,
    **extra_tokens,
)

Source from the content-addressed store, hash-verified

330
331
332def _datatree_from_backend_datatree(
333 backend_tree,
334 filename_or_obj,
335 engine,
336 chunks,
337 cache,
338 overwrite_encoded_chunks,
339 inline_array,
340 chunked_array_type,
341 from_array_kwargs,
342 create_default_indexes,
343 **extra_tokens,
344):
345 if not isinstance(chunks, int | dict) and chunks not in {None, "auto"}:
346 raise ValueError(
347 f"chunks must be an int, dict, 'auto', or None. Instead found {chunks}."
348 )
349
350 _protect_datatree_variables_inplace(backend_tree, cache)
351 if create_default_indexes:
352 tree = backend_tree.map_over_datasets(_maybe_create_default_indexes)
353 else:
354 tree = backend_tree
355 if chunks is not None:
356 tree = DataTree.from_dict(
357 {
358 path: _chunk_ds(
359 node.dataset,
360 filename_or_obj,
361 engine,
362 chunks,
363 overwrite_encoded_chunks,
364 inline_array,
365 chunked_array_type,
366 from_array_kwargs,
367 node=path,
368 **extra_tokens,
369 )
370 for path, [node] in group_subtrees(tree)
371 },
372 name=tree.name,
373 )
374
375 if create_default_indexes or chunks is not None:
376 for path, [node] in group_subtrees(backend_tree):
377 tree[path].set_close(node._close)
378
379 # Ensure source filename always stored in dataset object
380 if "source" not in tree.encoding:
381 path = getattr(filename_or_obj, "path", filename_or_obj)
382
383 if isinstance(path, str | os.PathLike):
384 tree.encoding["source"] = _normalize_path(path)
385
386 return tree
387
388
389def open_dataset(

Callers 1

open_datatreeFunction · 0.85

Calls 7

group_subtreesFunction · 0.90
_normalize_pathFunction · 0.90
_chunk_dsFunction · 0.85
map_over_datasetsMethod · 0.80
from_dictMethod · 0.45
set_closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…