def rotation(xobj, angle, pivot=None):
    """Rotates an xarray object created using rioxarray around a pivot

    Parameters
    ----------
    angle: float
        angle in degrees to rotate the object
    pivot: tuple
        coordinates around which to pivot. Use array coordinates, not
        the CRS coordinates. If not given, pivots around the center.

    Returns
    -------
    xarray.DataArray or xarray.Dataset
        the rotated xarray object
    """

    width = xobj.sizes["x"]
    height = xobj.sizes["y"]

    # If pivot isn't given, rotate around center
    if pivot is None:
        pivot = [d // 2 for d in (width, height)]

    # Use the maximum dimension of the current object to calculate a shape
    # that will accomodate any rotation. If the orientation of the data is
    # not the same as the array (for example, if the array has already been
    # rotated), this will overestimate the size of the canvas required. Rows
    # and columns consisting of all NaNs are trimmed later to account for this.
    diag = int((width ** 2 + height ** 2) ** 0.5)

    # Rotate object based on the existing transform, then translate the
    # rotated object to the center of the new, larger canvas
    transform = xobj.rio.transform()
    transform *= transform.rotation(angle, pivot)
    transform *= transform.translation((width - diag) // 2,
                                       (height - diag) // 2)

    # Rotate the object according to the transform
    rotated = xobj.rio.reproject(
        xobj.rio.crs, shape=(diag, diag), transform=transform
    )

    # Trim all-Nan rows and columns before returning
    return rotated.dropna("x", "all").dropna("y", "all")