linopy.align

Contents

linopy.align#

linopy.align(*objects, join='inner', copy=True, indexes=None, exclude=frozenset({}), fill_value=<NA>)#

Given any number of Variables, Expressions, Dataset and/or DataArray objects, returns new objects with aligned indexes and dimension sizes.

Array from the aligned objects are suitable as input to mathematical operators, because along each dimension they have the same index and size.

Missing values (if join != 'inner') are filled with fill_value. The default fill value is NaN.

This functions essentially wraps the xarray function xarray.align().

Parameters:
  • *objects (Variable, LinearExpression, Dataset or DataArray) – Objects to align.

  • join ({"outer", "inner", "left", "right", "exact", "override"}, optional) – Method for joining the indexes of the passed objects along each dimension:

    • “outer”: use the union of object indexes

    • “inner”: use the intersection of object indexes

    • “left”: use indexes from the first object with each dimension

    • “right”: use indexes from the last object with each dimension

    • “exact”: instead of aligning, raise ValueError when indexes to be

    aligned are not equal - “override”: if indexes are of same size, rewrite indexes to be those of the first object with that dimension. Indexes for the same dimension must have the same size in all objects.

  • copy (bool, default: True) – If copy=True, data in the return values is always copied. If copy=False and reindexing is unnecessary, or can be performed with only slice operations, then the output may share memory with the input. In either case, new xarray objects are always returned.

  • indexes (dict-like, optional) – Any indexes explicitly provided with the indexes argument should be used in preference to the aligned indexes.

  • exclude (str, iterable of hashable or None, optional) – Dimensions that must be excluded from alignment

  • fill_value (scalar or dict-like, optional) – Value to use for newly missing values. If a dict-like, maps variable names to fill values. Use a data array’s name to refer to its values.

Returns:

aligned (tuple of DataArray or Dataset) – Tuple of objects with the same type as *objects with aligned coordinates.