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

Function _combine_single_variable_hypercube

xarray/structure/combine.py:739–795  ·  view source on GitHub ↗

Attempt to combine a list of Datasets into a hypercube using their coordinates. All provided Datasets must belong to a single variable, ie. must be assigned the same variable name. This precondition is not checked by this function, so the caller is assumed to know what it's doi

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

Source from the content-addressed store, hash-verified

737
738
739def _combine_single_variable_hypercube(
740 datasets,
741 fill_value,
742 data_vars,
743 coords,
744 compat: CompatOptions | CombineKwargDefault,
745 join: JoinOptions | CombineKwargDefault,
746 combine_attrs: CombineAttrsOptions,
747):
748 """
749 Attempt to combine a list of Datasets into a hypercube using their
750 coordinates.
751
752 All provided Datasets must belong to a single variable, ie. must be
753 assigned the same variable name. This precondition is not checked by this
754 function, so the caller is assumed to know what it's doing.
755
756 This function is NOT part of the public API.
757 """
758 if len(datasets) == 0:
759 raise ValueError(
760 "At least one Dataset is required to resolve variable names "
761 "for combined hypercube."
762 )
763
764 combined_ids, concat_dims = _infer_concat_order_from_coords(list(datasets))
765
766 if fill_value is None:
767 # check that datasets form complete hypercube
768 _check_shape_tile_ids(combined_ids)
769 else:
770 # check only that all datasets have same dimension depth for these
771 # vars
772 _check_dimension_depth_tile_ids(combined_ids)
773
774 # Concatenate along all of concat_dims one by one to create single ds
775 concatenated = _combine_nd(
776 combined_ids,
777 concat_dims=concat_dims,
778 data_vars=data_vars,
779 coords=coords,
780 compat=compat,
781 fill_value=fill_value,
782 join=join,
783 combine_attrs=combine_attrs,
784 )
785
786 # Check the overall coordinates are monotonically increasing
787 for dim in concat_dims:
788 indexes = concatenated.indexes.get(dim)
789 if not (indexes.is_monotonic_increasing or indexes.is_monotonic_decreasing):
790 raise ValueError(
791 "Resulting object does not have monotonic"
792 f" global indexes along dimension {dim}"
793 )
794
795 return concatenated
796

Callers 1

combine_by_coordsFunction · 0.85

Calls 5

_check_shape_tile_idsFunction · 0.85
_combine_ndFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…