Ejemplo n.º 1
0
def draw_trajectory(mass):
    """
    Create a graph for expected flighttimes
    
    Args:
        mass: The mass to be calculated
    
    Returns:
    
    Raises:
    """
    t,res =  tm.flight_time(mass,0)
    t,res_slow =  tm.flight_time(mass,tm.SLOW_POS)
    t,res_fast =  tm.flight_time(mass,tm.FAST_POS)

    fig = plt.figure()
    fig.subplots_adjust(bottom=0.15) # Make room for x-label
    ratio = 0.6
    fig_width = 8.5
    fig_width = fig_width /2.54     # width in cm converted to inches
    fig_height = fig_width*ratio
    fig.set_size_inches(fig_width,fig_height)    
    
    ax11 = fig.add_subplot(111)
    ax11.plot(res['time'],res['pos'],'r-', linewidth=0.7)
    ax11.plot(res_slow['time'],res_slow['pos'],'g-', linewidth=0.7)
    ax11.plot(res_fast['time'],res_fast['pos'],'b-', linewidth=0.7)
    ax11.set_xlabel('Time / $\mu$s', fontsize=8)
    ax11.set_ylabel('Position / cm', fontsize=8)
    ax11.set_xlim(0,22)
    ax11.set_ylim(-2,120) 
    ax11.tick_params(direction='in', length=2, width=1, colors='k',labelsize=8,axis='both',pad=3)
    
    ins_plt = plt.axes([0.4,0.23,0.4,0.175])
    #plt.setp(ins_plt)

    slow_interp = interpolate.interp1d(res_slow['time'],res_slow['pos'], bounds_error=False)
    fast_interp = interpolate.interp1d(res_fast['time'],res_fast['pos'], bounds_error=False)
    zero = [0]*len(res['time'])
    
    ins_plt.plot(res['time'],slow_interp(res['time'])-res['pos'],'g-', linewidth=0.7)
    ins_plt.plot(res['time'],fast_interp(res['time'])-res['pos'],'b-', linewidth=0.7)
    ins_plt.plot(res['time'],zero,'r-', linewidth=0.5)
    ins_plt.set_ylabel('$\Delta$pos / cm', fontsize=7)
    ins_plt.set_yticks([])
    ins_plt.tick_params(direction='in', length=2, width=1, colors='k',labelsize=7,axis='both',pad=3)
    ins_plt.set_xlim(0,22)

    plt.savefig('Trajectory.png',dpi=300)
Ejemplo n.º 2
0
def extrapolate(start=1,end=100,step=10,plot=False):
    """
    Uses the physical model on a few (currently 10) masses
    to create a fitting-expression for the flight-time as
    a function of mass.
    Args:
        start: First mass in the fit. Default=5
        end:   Last mass in the fit. Default = 100
        step:  Stepsize. Default = 10
        plot:  If true, a plot showing the fit will be produces. Default=False
    Returns:
        The two coefficients for the extrapolation
    Raises:
        ValueError: Raised on non-legal input parameters
    """
    
    if (start<1) or (end<start):
        raise ValueError

    times = []
    masses = []
    for mass in range(start,end,step):
        ft = tm.flight_time(mass)
        times.append(ft[0]*1e6)
        masses.append(mass)

    times = sp.array(times)
    masses = sp.array(masses)

    # Fit the first set
    fitfunc = lambda p, x: p[0]*x**p[1] # Target function
    errfunc = lambda p, x, y: fitfunc(p, x) - y # Distance to the target function
    p0 = [1, 0.5] # Initial guess for the parameters
    p1, success = optimize.leastsq(errfunc, p0[:], args=(masses, times))

    if plot:
        fig = plt.figure()
        #Plot the fit and the data-points
        axis = fig.add_subplot(2,1,1)

        mass_axis = sp.linspace(0, end, 1000)
        # Plot of the data and the fit
        axis.plot(masses, times, 'ro')
        axis.plot(mass_axis, fitfunc(p1, mass_axis), 'r-')
        axis.set_xlabel("Mass [amu]")
        axis.set_ylabel("Expected flighttime (microseconds)")

        #Plot the error-function
        axis = fig.add_subplot(2,1,2)
        axis.plot(masses, (fitfunc(p1, masses)-times)*1000, 'ro')
        axis.set_xlabel("Mass [amu]")
        axis.set_ylabel("Fitting-error / ns")    
        plt.show()
    
    return p1
Ejemplo n.º 3
0
def draw_trajectory(mass):
    """
    Create a graph for expected flighttimes
    
    Args:
        mass: The mass to be calculated
    
    Returns:
    
    Raises:
    """
    res =  tm.flight_time(mass,0)
    res_slow =  tm.flight_time(mass,SLOW_POS)
    res_fast =  tm.flight_time(mass,FAST_POS)
    fig = plt.figure()
    ax11 = fig.add_subplot(111)
    #ax11.plot(res[3],res[2],res_slow[3],res_slow[2],res_fast[3],res_fast[2],'r-','b-','g-')
    ax11.plot(res[3],res[2],'r-')
    ax11.set_xlabel('Position / cm')
    ax11.set_ylabel('Time / micro seconds')
    plt.savefig('Trajectory.png')
Ejemplo n.º 4
0
def draw_trajectory(mass):
    """
    Create a graph for expected flighttimes
    
    Args:
        mass: The mass to be calculated
    
    Returns:
    
    Raises:
    """
    res = tm.flight_time(mass, 0)
    res_slow = tm.flight_time(mass, SLOW_POS)
    res_fast = tm.flight_time(mass, FAST_POS)
    fig = plt.figure()
    ax11 = fig.add_subplot(111)
    #ax11.plot(res[3],res[2],res_slow[3],res_slow[2],res_fast[3],res_fast[2],'r-','b-','g-')
    ax11.plot(res[3], res[2], 'r-')
    ax11.set_xlabel('Position / cm')
    ax11.set_ylabel('Time / micro seconds')
    plt.savefig('Trajectory.png')
Ejemplo n.º 5
0
def extrapolate():
    """
    Uses the physical model on a few (currently 10) masses
    to create a fitting-expression for the flight-time as
    a function of mass.
    Currently the function takes no arguments, but obviously
    it will be nice to be able to set the range and number
    of masses used in the fit
    Args:
        None
    Returns:
        The two coefficients for the extrapolation
    Raises:
    """

    times = []
    masses = []
    for mass in range(1, 50, 5):
        ft = tm.flight_time(mass)
        times.append(ft[0] * 1e6)
        masses.append(mass)

    times = sp.array(times)
    masses = sp.array(masses)

    # Fit the first set
    fitfunc = lambda p, x: p[0] * x**p[1]  # Target function
    errfunc = lambda p, x, y: fitfunc(p, x
                                      ) - y  # Distance to the target function
    p0 = [1, 0.5]  # Initial guess for the parameters
    p1, success = optimize.leastsq(errfunc, p0[:], args=(masses, times))

    time = sp.linspace(0, 100, 500)
    #plt.plot(masses, times, "ro", time, fitfunc(p1, time), "r-") # Plot of the data and the fit

    # Legend the plot
    #plt.title("Calculated Flighttime")
    #plt.xlabel("Mass [amu]")
    #plt.ylabel("Expected flighttime (microseconds)")
    #ax = axes()
    #text(0.8, 0.07,
    #     'x freq :  %.3f kHz' % (1/p1[1]),
    #     fontsize=16,
    #     horizontalalignment='center',
    #     verticalalignment='center',
    #     transform=ax.transAxes)

    #plt.show()

    print "Fitting function: time = {0} * mass^{1}".format(p1[0], p1[1])
    return p1
Ejemplo n.º 6
0
def extrapolate():
    """
    Uses the physical model on a few (currently 10) masses
    to create a fitting-expression for the flight-time as
    a function of mass.
    Currently the function takes no arguments, but obviously
    it will be nice to be able to set the range and number
    of masses used in the fit
    Args:
        None
    Returns:
        The two coefficients for the extrapolation
    Raises:
    """

    times = []
    masses = []
    for mass in range(1,50,5):
        ft = tm.flight_time(mass)
        times.append(ft[0]*1e6)
        masses.append(mass)

    times = sp.array(times)
    masses = sp.array(masses)

    # Fit the first set
    fitfunc = lambda p, x: p[0]*x**p[1] # Target function
    errfunc = lambda p, x, y: fitfunc(p, x) - y # Distance to the target function
    p0 = [1, 0.5] # Initial guess for the parameters
    p1, success = optimize.leastsq(errfunc, p0[:], args=(masses, times))

    time = sp.linspace(0, 100, 500)
    #plt.plot(masses, times, "ro", time, fitfunc(p1, time), "r-") # Plot of the data and the fit

    # Legend the plot
    #plt.title("Calculated Flighttime")
    #plt.xlabel("Mass [amu]")
    #plt.ylabel("Expected flighttime (microseconds)")
    #ax = axes()
    #text(0.8, 0.07,
    #     'x freq :  %.3f kHz' % (1/p1[1]),
    #     fontsize=16,
    #     horizontalalignment='center',
    #     verticalalignment='center',
    #     transform=ax.transAxes)

    #plt.show()

    print "Fitting function: time = {0} * mass^{1}".format(p1[0],p1[1])
    return p1