How to use the tweakwcs.linearfit.NotEnoughPointsError function in tweakwcs

To help you get started, we’ve selected a few tweakwcs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github spacetelescope / tweakwcs / tweakwcs / linearfit.py View on Github external
def fit_rscale(xy, uv, wxy=None, wuv=None):
    """ Fits (non-iteratively and without sigma-clipping) a displacement,
    rotation and scale transformations between input lists of positions
    ``xy`` and ``uv``. When weights are provided, a weighted fit is performed.
    Parameter descriptions and return values are identical to those
    in `iter_linear_fit`, except returned ``fit`` dictionary does not contain
    the following keys irrelevant to this function: ``'center'``,
    ``'fitmask'``, and ``'eff_nclip'``.

    """
    if len(xy) < 2:
        raise NotEnoughPointsError(
            "At least two points are required to find shifts, rotation, and "
            "scale."
        )

    x = np.array(xy[:, 0], dtype=np.longdouble)
    y = np.array(xy[:, 1], dtype=np.longdouble)
    u = np.array(uv[:, 0], dtype=np.longdouble)
    v = np.array(uv[:, 1], dtype=np.longdouble)

    if wxy is None and wuv is None:
        # no weighting
        w = None

        xm = np.mean(x)
        ym = np.mean(y)
        um = np.mean(u)
github spacetelescope / tweakwcs / tweakwcs / linearfit.py View on Github external
def fit_general(xy, uv, wxy=None, wuv=None):
    """ Fits (non-iteratively and without sigma-clipping) a displacement,
    rotation, scale, and skew transformations (i.e., the full ``2x2``
    transformation matrix) between input lists of positions
    ``xy`` and ``uv``. When weights are provided, a weighted fit is performed.
    Parameter descriptions and return values are identical to those
    in `iter_linear_fit`, except returned ``fit`` dictionary does not contain
    the following keys irrelevant to this function: ``'center'``,
    ``'fitmask'``, and ``'eff_nclip'``.

    """
    if len(xy) < 3:
        raise NotEnoughPointsError(
            "At least three points are required to find 6-parameter linear "
            "affine transformations."
        )

    x = np.array(xy[:, 0], dtype=np.longdouble)
    y = np.array(xy[:, 1], dtype=np.longdouble)
    u = np.array(uv[:, 0], dtype=np.longdouble)
    v = np.array(uv[:, 1], dtype=np.longdouble)

    if wxy is None and wuv is None:
        # no weighting
        w = None

        # Set up products used for computing the fit
        sw = float(x.size)
        sx = x.sum()
github spacetelescope / tweakwcs / tweakwcs / linearfit.py View on Github external
def fit_shifts(xy, uv, wxy=None, wuv=None):
    """ Fits (non-iteratively and without sigma-clipping) a displacement
    transformation only between input lists of positions ``xy`` and ``uv``.
    When weights are provided, a weighted fit is performed. Parameter
    descriptions and return values are identical to those in `iter_linear_fit`,
    except returned ``fit`` dictionary does not contain the following
    keys irrelevant to this function: ``'center'``, ``'fitmask'``, and
    ``'eff_nclip'``.

    """
    if xy.size == 0:
        raise NotEnoughPointsError(
            "At least one point is required to find shifts."
        )

    diff_pts = np.subtract(xy, uv, dtype=np.longdouble)

    if wxy is None and wuv is None:
        # no weighting
        w = None

        meanx = diff_pts[:, 0].mean(dtype=np.longdouble)
        meany = diff_pts[:, 1].mean(dtype=np.longdouble)

    else:
        if wxy is None:
            w = np.array(wuv, dtype=np.longdouble)
        elif wuv is None: