Beispiel #1
0
if __name__ == "__main__":
    import argparse
    parser = argparse.ArgumentParser(description=
                                     'Fit and plot ellipses from 2d data')
    parser.add_argument('-f', '--file', dest="file",
                        help='csv file', default=None)
    parser.add_argument('-r', '--radius', default=1.0, type=float,
                        help="Radius of the circle")
    parser.add_argument('-x' '--deltaX', dest="x", type=float,
                        default=0.0, help="Center position in x")
    parser.add_argument('-y' '--deltaY', dest="y", type=float,
                        default=0.0, help="Center position in y")
    parser.add_argument('-n', '--noise', dest="noise", type=float,
                        help='Random noise', default=0.3)
    parser.add_argument('-p', '--points', dest="points", type=int,
                        help='Number of data points', default=100)
    args = parser.parse_args()

    if args.file:
        data = np.loadtxt(args.file, delimiter=',')
        x = data[1:, 0] - data[0, 0]
        y = data[1:, 1] - data[0, 1]
    else:
        err = randn(args.points)*args.noise
        phi = np.linspace(0, 2*np.pi, args.points)  # angles of the channels
        x, y = pol2cat(phi, args.radius+err, deg=False)

    fit_circle(x+args.x, y+args.y)
    show()
Beispiel #2
0
    ax.axvline(x=0.0, color='k')
    return fig, ax


if __name__ == '__main__':
    import argparse

    parser = argparse.ArgumentParser(description=
                                     'Fit and plot ellipses from 2d data')
    parser.add_argument('-f', '--file', dest="file",
                        help='csv file', default=None)
    parser.add_argument('-n', '--noise', dest="noise", type=float,
                        help='Random noise', default=0.3)
    parser.add_argument('-p', '--points', dest="points", type=int,
                        help='Number of data points', default=100)
    args = parser.parse_args()

    if args.file:
        data= np.loadtxt(args.file, delimiter=',')
        x = data[1:, 0] - data[0, 0]
        y = data[1:, 1] - data[0, 1]
    else:
        err = randn(args.points)*args.noise
        phi = np.linspace(0, 2*np.pi, args.points)  # angles of the channels
        r0 = ellipse_polar(phi, 4, rand(), rand()*np.pi)
        x, y = pol2cat(phi, r0+err, deg=False)

    fit_ellipse(x, y)
    show()