Beispiel #1
0
def PLOTTING1():
    """
    croc.Tests.Tests.PLOTTING1
    
    Tests if the contour lines are correctly placed.

    CHANGELOG:
    - 20110912 RB: init
    
    """
    
    print("=== TEST ===\nTest of plotting\n")
    
    print("PLOT 1:\n" + 
        "Ranges from -1 to 1. The white band should be in the middle.\n"+
        "PLOT 2:\n" + 
        "Ranges from -1 to 0.9. The white band should be rotated a bit clockwise."
    )
    
    # plot 1
    X, Y = numpy.meshgrid(numpy.linspace(-1, 0, num=11), numpy.linspace(0, 1, num=11))  
    x_axis = numpy.linspace(0, 1, num=11)
    y_axis = numpy.linspace(0, 1, num=11)
    S = X + Y
    title = "range:-1, 1, zlimit:-1"
    P.contourplot(S, x_axis, y_axis, zlimit = -1, title = title)

    # plot 2
    X, Y = numpy.meshgrid(numpy.linspace(-1, 0, num=11), numpy.linspace(0, 0.9, num=11))
    x_axis = numpy.linspace(0, 1, num=11)
    y_axis = numpy.linspace(0, 1, num=11)
    S = X + Y
    title = "range:-1, 0.9, zlimit:-1"
    P.contourplot(S, x_axis, y_axis, zlimit = -1)
Beispiel #2
0
    def plot(self, x_range = [0, 0], y_range = [0, 0], x_label = "", y_label = "", title = "", scale = "OD", legend = "", new_figure = True):
        
        """
        Plot the linear spectrum.
        
        CHANGELOG:
        2011/xx/xx/RB: started
        2012/08/03/RB: changes
        
        INPUT:
        - x_range (list with 2 elements): range for the frequency axis. Set to [0,0] for the full range
        - y_range  (list with 2 elements): range for the optical density. Set to [0,0] for the full range
        - x_label (string): set the x_label. 
        - y_label (string): set the label for the y-axis. Default is OD.
        - title (string): set the title
        - scale (string): default is 'OD', alternatively: 'EC' for extinction coefficient. You should have set self.concentration and self.pathlength.
        - new_figure (BOOL): If set to True, it will call plt.figure(), plt.plot() and plt.show(). If set to False, it will only call plt.plot() and you need to call plt.figure() and plt.show() yourself. Usefull if you want to have sub-plots
        """
        # data = (self.s[0])[::-1]
        # y_label = "Absorption (OD)"
        
        print("plot...")
        
        if type(scale) == float:
            print("float")
            data = self.s[0] * scale
            if y_label == "":
                y_label = "Absorption (AU)"
            
        elif scale == "OD":
            data = self.s[0]
            if y_label == "":
                y_label = "Absorption (OD)"
            print("OD")
        elif scale == "EC":
            data = self.s[0] / (100 * self.concentration * self.pathlength)
            if y_label == "":
                y_label = "Extinction Coefficient (M-1cm-1)"
            print("EC")
        
        axis = self.s_axis[0]

        if title == "": 
            title = self.objectname
                    
        if x_label == "":
            x_label = self.s_units[0]

                
        
        P.linear(data, axis, x_range = x_range, y_range = y_range, x_label = x_label, y_label = y_label, title = title, legend = legend, new_figure = new_figure)
Beispiel #3
0
def find_z(s, s_axis, x_range = [0,0], y_range = [0, -1]):
    
    # determine the range to be plotted
    x_min, x_max, y_min, y_max = P.find_axes(s_axis[2], s_axis[0], x_range, y_range)
    
    # make the contours
    # first find the area to be plotted
    # not the most elegant way I guess
    try:
        y_min_i = numpy.where(s_axis[0] < y_min)[0][-1]
    except: 
        y_min_i = 0
    
    try:
        y_max_i = numpy.where(s_axis[0] > y_max)[0][0]
    except: 
        y_max_i = len(s_axis[0])

    try:
        x_min_i = numpy.where(s_axis[2] < x_min)[0][-1]
    except: 
        x_min_i = 0
    
    try:
        x_max_i = numpy.where(s_axis[2] > x_max)[0][0]
    except: 
        x_max_i = len(s_axis[2])
        
    ma = numpy.amax(s[y_min_i:y_max_i, x_min_i:x_max_i])
    mi = numpy.amin(s[y_min_i:y_max_i, x_min_i:x_max_i])
    
    return ma, mi
Beispiel #4
0
    def find_ellipticity(self, color_index = 0, new_figure = False, verbose = False):

        if verbose:
            print("Find ellipticity")
            print("  x_min", self.e_x_i[0], self.mess.s_axis[2][self.e_x_i[0]])
            print("  x_max", self.e_x_i[1], self.mess.s_axis[2][self.e_x_i[1]])
            print("  y_min", self.e_y_i[0], self.mess.s_axis[0][self.e_y_i[0]])
            print("  y_max", self.e_y_i[1], self.mess.s_axis[0][self.e_y_i[1]])

        data = self.mess.s[self.dl_y_i[0]:self.dl_y_i[1], self.dl_x_i[0]:self.dl_x_i[1]]
        x_axis = self.mess.s_axis[2][self.dl_x_i[0]:self.dl_x_i[1]]
        y_axis = self.mess.s_axis[0][self.dl_y_i[0]:self.dl_y_i[1]]

        ma, mi = self.mess.find_z(x_range = [x_axis[0], x_axis[-1]], y_range = [y_axis[0], y_axis[-1]])
        
        V = PL.make_contours_2d(data, zlimit = -1, contours = 14)
        
        if new_figure:
            fig = plt.figure()
            ax1 = fig.add_subplot(111, aspect = "equal")
            cntr = ax1.contour(x_axis, y_axis, data, V, colors = "b")  
            ax1.set_title(self.objectname)
        else:
            fig = plt.figure(1000)
            ax1 = fig.add_subplot(111, aspect = "equal")
            cntr = ax1.contour(x_axis, y_axis, data, V, colors = self.color_array[color_index % len(self.color_array)])  

        self.cf_ble = self.find_peak_center_helper(cntr, mi, ax1)
        X, Y = self.find_ellipticity_helper(cntr, mi, ax1)
        self.e_dia_ble = numpy.max(X) - numpy.min(X)
        self.e_adia_ble = numpy.max(Y) - numpy.min(Y)
        self.e_ellipticity_ble = (self.e_dia_ble**2 - self.e_adia_ble**2) / (self.e_dia_ble**2 + self.e_adia_ble**2) 

        self.cf_esa = self.find_peak_center_helper(cntr, ma, ax1)
        X, Y = self.find_ellipticity_helper(cntr, ma, ax1)
        self.e_dia_esa = numpy.max(X) - numpy.min(X)
        self.e_adia_esa = numpy.max(Y) - numpy.min(Y)
        self.e_ellipticity_esa = (self.e_dia_esa**2 - self.e_adia_esa**2) / (self.e_dia_esa**2 + self.e_adia_esa**2) 
        
        plt.show()
Beispiel #5
0
def plot_lineshape_overlap(c_array, ax, index = 1, flag_CLS = False, flag_median = False):
    """
    Specialized method to plot the results from the calculation of the tilt.
    
    c_array has two Lineshape objects.
    
    """
    
    
    ax.plot([1500, 2500], [1500, 2500], c = "k")
    
    for i in range(2):
        data = c_array[i].mess.s[c_array[i].plot_y_i[0]:c_array[i].plot_y_i[1], c_array[i].plot_x_i[0]:c_array[i].plot_x_i[1]]
        x_axis = c_array[i].mess.s_axis[2][c_array[i].plot_x_i[0]:c_array[i].plot_x_i[1]]
        y_axis = c_array[i].mess.s_axis[0][c_array[i].plot_y_i[0]:c_array[i].plot_y_i[1]]
        
        V = PL.make_contours_2d(data, zlimit = -1, contours = 14)
        
        ax.contour(x_axis, y_axis, data, V, colors = c_array[i].color_overlap_array[i])
        
    markersize = 8
    linewidth = 3
    
    if flag_CLS:
        
        # plot the minima and maxima of the double lorentzian fits
#        for i in range(2):
#            
           # y = c_array[i].mess.s_axis[0][c_array[i].dl_y_i[0]:c_array[i].dl_y_i[1]]
#            
#            x = c_array[i].dl_ble
#            ax.plot(x, y, ".", c = c_array[i].color_overlap_array[i], markersize = markersize)

#            x = c_array[i].dl_esa
#            ax.plot(x, y, ".", c = c_array[i].color_overlap_array[i], markersize = markersize)
            

        # plot the linear fits of the minima and maxima
        for i in range(2):

            y = [c_array[i].mess.s_axis[0][c_array[i].dl_y_i[0] + c_array[i].l_i[0]], c_array[i].mess.s_axis[0][c_array[i].dl_y_i[0] + c_array[i].l_i[1]]] 

            x = [(y[0] - c_array[i].l_A_ble[0])/c_array[i].l_A_ble[1], (y[1] - c_array[i].l_A_ble[0])/c_array[i].l_A_ble[1]]
            ax.plot(x, y, "-", c = c_array[i].color_overlap_array[i], linewidth = linewidth)
            
#            x = [(y[0] - c_array[i].l_A_esa[0])/c_array[i].l_A_esa[1], (y[1] - c_array[i].l_A_esa[0])/c_array[i].l_A_esa[1]]
#            ax.plot(x, y, "-", c = c_array[i].color_overlap_array[i], linewidth = linewidth)

         
#    if flag_median:
#        
#        for i in range(2): 
#        
#            x_min_i, x_max_i, y_min_i, y_max_i = find_indices(c_array[i].mess.s_axis[2], c_array[i].mess.s_axis[0], c_array[i].sl_x, c_array[i].sl_y)
#            
#            x = c_array[i].mess.s_axis[2][x_min_i:x_max_i]                       
#            y = c_array[i].sl_A[:,1]
#            ax1.plot(x, y, ":", c = c_array[i].color_overlap_array[i])
#

    # plot properties
    ax.set_title("blue:" + c_array[0].objectname + "\nred: " + c_array[1].objectname)