# Path: concert/quantities.py



import logging
import numpy as np
from concert.quantities import q
        raise ValueError("At least 5 coordinate pairs are needed")

    y_ind, x_ind = list(zip(*tips))
    if max(x_ind) - min(x_ind) < 10:
        raise ValueError("Sample off-centering too small, enlarge rotation radius.")

    a_matrix = np.empty((len(x_ind), 6), dtype=np.float)
    for i in range(len(x_ind)):
        a_matrix[i] = np.array([x_ind[i] ** 2, x_ind[i] * y_ind[i],
                                y_ind[i] ** 2, x_ind[i], y_ind[i], 1])

    v_mat = np.linalg.svd(a_matrix)[2]
    params = v_mat.T[:, -1]
    a_33 = np.array([[params[0], params[1] / 2], [params[1] / 2, params[2]]])
    x_ind = np.array(x_ind)
    y_ind = np.array(y_ind)
    d_x = x_ind.max() - x_ind.min()
    usv = np.linalg.svd(a_33)
    s_vec = usv[1]
    v_mat = usv[2]
    det = np.linalg.det(a_33)
    LOG.debug('Conic determinant: %g', det)

    if det <= 0:
        # Not an ellipse
        d_y = float(y_ind.max() - y_ind.min())
        angle = np.arctan(d_y / d_x) * q.rad
        if x_ind[y_ind.argmax()] <= x_ind[y_ind.argmin()]:
            # More than pi/4.
            angle = -angle

# Path: concert/quantities.py



# Path: concert/measures.py
import logging
import numpy as np
from concert.quantities import q

        raise ValueError("At least 5 coordinate pairs are needed")

    y_ind, x_ind = list(zip(*tips))
    if max(x_ind) - min(x_ind) < 10:
        raise ValueError("Sample off-centering too small, enlarge rotation radius.")

    a_matrix = np.empty((len(x_ind), 6), dtype=np.float)
    for i in range(len(x_ind)):
        a_matrix[i] = np.array([x_ind[i] ** 2, x_ind[i] * y_ind[i],
                                y_ind[i] ** 2, x_ind[i], y_ind[i], 1])

    v_mat = np.linalg.svd(a_matrix)[2]
    params = v_mat.T[:, -1]
    a_33 = np.array([[params[0], params[1] / 2], [params[1] / 2, params[2]]])
    x_ind = np.array(x_ind)
    y_ind = np.array(y_ind)
    d_x = x_ind.max() - x_ind.min()
    usv = np.linalg.svd(a_33)
    s_vec = usv[1]
    v_mat = usv[2]
    det = np.linalg.det(a_33)
    LOG.debug('Conic determinant: %g', det)

    if det <= 0:
        # Not an ellipse
        d_y = float(y_ind.max() - y_ind.min())
        angle = np.arctan(d_y / d_x) * q.rad
        if x_ind[y_ind.argmax()] <= x_ind[y_ind.argmin()]:
            # More than pi/4.
            angle = -angle

        phi, psi = (angle, 0.0 * q.rad)