Example #1
0
def envelope(A,t):
    """
    Wrapper for rb_gaussian
    
    INPUT:
    t: numpy.array
    A[0]: sigma (sigma^2 = variance)
    A[1]: mu (mean)
    A[2]: offset 
    A[3]: scale, before offset
    
    CHANGELOG:
    20130408/RB: started function
    """
    return EQ.rb_gaussian(A,t)
Example #2
0
    def make_plot(self, ax = False, normalize = False, fit = False):
        """
        Make a plot of scan spectrum data. 
    
        INPUT:
        - ax (plt axis instance, or False): If False, a new figure and axis instance will be made. 
        - normalize (bool, False): If True, the minimum is subtract from the data, then it is divided by the maximum. 
        - fit (Bool, False): If True, a fit will be made and will also be plotted. The fitting parameters are written to the terminal. 
    
        CHANGELOG:
        201604-RB: started function
    
        """
        if ax == False:
            fig = plt.figure()
            ax = fig.add_subplot(111)
        
        if normalize:
            for ds in range(self.r_n[2]):
                self.r[:,0,ds,0,0,0,0,0] -= numpy.nanmin(self.r[:,0,ds,0,0,0,0,0])
                self.r[:,0,ds,0,0,0,0,0] /= numpy.nanmax(self.r[:,0,ds,0,0,0,0,0])

        ax.plot(self.r_axes[0], self.r[:,0,0,0,0,0,0,0], color = "g")
        ax.plot(self.r_axes[0], self.r[:,0,1,0,0,0,0,0], color = "r")
             
             
        
        if fit:
            colors = ["lightgreen", "orange"]
            labels = ["probe", "reference"]
            sigma = (self.r_axes[0][0] - self.r_axes[0][-1]) / 4

                      
            print("           mu       sigma   offset    scale")
            for ds in range(self.r_n[2]):
                A = [sigma, self.r_axes[0][numpy.argmax(self.r[:,0,ds,0,0,0,0,0])], 0, 1] # initial guess
            
                A_final = M.fit(self.r_axes[0], self.r[:,0,ds,0,0,0,0,0], EQ.rb_gaussian, A)
                ax.plot(self.r_axes[0], EQ.rb_gaussian(A_final, self.r_axes[0]), color = colors[ds])
                
                print("{label:10} {mu:.5}   {sigma:.3}   {offset:.3}   {scale:.3}".format(label = labels[ds], mu = A_final[1], sigma = A_final[0], offset = A_final[2], scale = A_final[3]))