Example #1
0
def _get_axes(*arrays):
    """ find list of axes from a list of axis-aligned DimArray objects
    """
    dims = get_dims(*arrays) # all dimensions present in objects
    axes = Axes()

    for dim in dims:

        common_axis = None

        for o in arrays:

            # skip missing dimensions
            if dim not in o.dims: continue

            axis = o.axes[dim]

            # update values
            if common_axis is None or (common_axis.size==1 and axis.size > 1):
                common_axis = axis

            # Test alignment for non-singleton axes
            if not (axis.size == 1 or np.all(axis.values==common_axis.values)):
                raise ValueError("axes are not aligned")

        # append new axis
        axes.append(common_axis)

    return axes
Example #2
0
def _get_aligned_axes(arrays, join='outer', axis=None , sort=False, strict=False):
    """From a list of arrays, or any object with `axes` attributes, 
    a new list of axes.
    """
    # find the dimensions
    if axis is None:
        dims = get_dims(*arrays)
    elif isinstance(axis, basestring):
        dims = [axis]
    else:
        if not isinstance(axis, basestring):
            raise ValueError("align: axis must be provided as a string")

    axes = Axes()

    for jj, d in enumerate(dims):

        # arrays which have that dimension
        ii = filter(lambda i: d in arrays[i].dims, range(len(arrays)))

        if strict and len(ii) != len(arrays):
            raise ValueError("align (strict=True): some arrays lack dimension {}".format(d))

        # common axis to reindex on
        ax = _common_axis([arrays[i].axes[d] for i in ii], join)

        if sort:
            ax.sort()

        axes.append(ax)

    # assert len(axes) > 0

    return axes