How to use the tweakwcs.linearfit.SingularMatrixError 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
m = np.array([[su, sv, sw], [suu, suv, su], [suv, svv, sv]],
                 dtype=np.longdouble)
    a = np.array([sx, sxu, sxv], dtype=np.longdouble)
    b = np.array([sy, syu, syv], dtype=np.longdouble)

    try:
        inv_m = inv(m)
    except np.linalg.LinAlgError:
        raise SingularMatrixError(
            "Singular matrix: suspected colinear points."
        )

    p = np.dot(inv_m, a)
    q = np.dot(inv_m, b)
    if not (np.all(np.isfinite(p)) and np.all(np.isfinite(q))):
        raise SingularMatrixError(
            "Singular matrix: suspected colinear points."
        )  # pragma: no cover

    # Return the shift, rotation, and scale changes
    fit = _build_fit(p, q, 'general')
    resids = xy - np.dot(uv, fit['matrix_ld'].T) - fit['shift_ld']
    fit['resids'] = resids.astype(np.double)
    _compute_stat(fit, residuals=resids, weights=w)
    return fit
github spacetelescope / tweakwcs / tweakwcs / linearfit.py View on Github external
syu = np.dot(w, y * u)
        sxv = np.dot(w, x * v)
        syv = np.dot(w, y * v)
        suu = np.dot(w, u * u)
        svv = np.dot(w, v * v)
        suv = np.dot(w, u * v)

    m = np.array([[su, sv, sw], [suu, suv, su], [suv, svv, sv]],
                 dtype=np.longdouble)
    a = np.array([sx, sxu, sxv], dtype=np.longdouble)
    b = np.array([sy, syu, syv], dtype=np.longdouble)

    try:
        inv_m = inv(m)
    except np.linalg.LinAlgError:
        raise SingularMatrixError(
            "Singular matrix: suspected colinear points."
        )

    p = np.dot(inv_m, a)
    q = np.dot(inv_m, b)
    if not (np.all(np.isfinite(p)) and np.all(np.isfinite(q))):
        raise SingularMatrixError(
            "Singular matrix: suspected colinear points."
        )  # pragma: no cover

    # Return the shift, rotation, and scale changes
    fit = _build_fit(p, q, 'general')
    resids = xy - np.dot(uv, fit['matrix_ld'].T) - fit['shift_ld']
    fit['resids'] = resids.astype(np.double)
    _compute_stat(fit, residuals=resids, weights=w)
    return fit
github spacetelescope / tweakwcs / tweakwcs / linearfit.py View on Github external
if rot_num == rot_denom:
        theta = 0.0
    else:
        theta = np.rad2deg(np.arctan2(rot_num, rot_denom))
        if theta < 0:
            theta += 360.0

    ctheta = np.cos(np.deg2rad(theta))
    stheta = np.sin(np.deg2rad(theta))
    s_num = rot_denom * ctheta + rot_num * stheta

    if su2v2 > 0.0:
        mag = s_num / su2v2
    else:
        raise SingularMatrixError(
            "Singular matrix: suspected colinear points."
        )

    if det < 0:
        # "flip" y-axis (reflection about x-axis *after* rotation)
        # NOTE: keep in mind that 'matrix' is the transposed rotation matrix.
        sthetax = -mag * stheta
        cthetay = -mag * ctheta
    else:
        sthetax = mag * stheta
        cthetay = mag * ctheta

    cthetax = mag * ctheta
    sthetay = mag * stheta

    sdet = np.sign(det)