Esempio n. 1
0
 def test_within_limits_and_xm1_and_ym1(self):
     x_min_i = 7
     x_max_i = -1
     y_min_i = 2
     y_max_i = -1
     data, x_axis, y_axis = FU.truncate_data(self.data, self.x_axis, self.y_axis, x_min_i, x_max_i, y_min_i, y_max_i, flag_verbose = self.flag_verbose)
     self.assertEqual(numpy.shape(data), (8,13))
     self.assertTrue(numpy.all(x_axis == range(x_min_i,20)))
     self.assertTrue(numpy.all(y_axis == range(y_min_i,10)))
Esempio n. 2
0
 def test_within_limits_and_xmax_and_ymax(self):
     x_min_i = 7
     x_max_i = 19
     y_min_i = 2
     y_max_i = 9
     data, x_axis, y_axis = FU.truncate_data(self.data, self.x_axis, self.y_axis, x_min_i, x_max_i, y_min_i, y_max_i, flag_verbose = self.flag_verbose)
     self.assertEqual(numpy.shape(data), (7,12))
     self.assertTrue(numpy.all(x_axis == range(x_min_i,x_max_i)))
     self.assertTrue(numpy.all(y_axis == range(y_min_i,y_max_i)))
    def export_2d_data_for_Maxim_helper(self, x_axis, y_axis, data, path_and_filename, **kwargs):
        """
        
    
        INPUT:
        - data:
        - x_range, y_range (optional)
    
        OUTPUT:

    
        CHANGELOG:
        20160502-RB: started function

        """
        
        if "x_range" in kwargs:
            x_range = kwargs["x_range"]
        else:
            x_range = [0,0]

        if "y_range" in kwargs:
            y_range = kwargs["y_range"]
        else:
            y_range = [0,-1]

        # determine the range to be plotted
        x_min, x_max, y_min, y_max = FU.find_axes(x_axis, y_axis, x_range, y_range, self.flag_verbose)
    
        # find the area to be plotted
        x_min_i, x_max_i = FU.find_axes_indices(x_axis, x_min, x_max)
        y_min_i, y_max_i = FU.find_axes_indices(y_axis, y_min, y_max)
          
        # truncate the data
        data, x_axis, y_axis = FU.truncate_data(data, y_axis, x_axis, y_min_i, y_max_i, x_min_i, x_max_i) 
        
        n_x = len(x_axis)
        n_y = len(y_axis)
            
        with open(path_and_filename, 'w') as f:
        
            for x_i in range(n_x):
                for y_i in range(n_y):
                    f.write("{y:4.3f}, {x:4.3f}, {z:.8f}\n".format(y = y_axis[y_i], x = x_axis[x_i], z = data[y_i, x_i]))
            
#                 f.write("\n")
            
        f.close()
Esempio n. 4
0
    def make_Z_table(self, x_range = [0,0], y_range = [0,-1], **kwargs):
        """
        
        INPUT:
        - -
        
        OUTPUT:
        - -
        
        DESCRIPTION:
        - - 
        
        CHANGELOG:
        2016014/RB: started function
        
        """
        
        print("sp sm de sc   min    max    delta")

        # determine the range to be plotted
        x_min, x_max, y_min, y_max = FU.find_axes(self.s_axes[0], self.s_axes[1], x_range = x_range, y_range = y_range, flag_verbose = self.flag_verbose)
        
#         print(x_min, x_max, y_min, y_max)
    
        # find the area to be plotted
        x_min_i, x_max_i = FU.find_axes_indices(self.s_axes[0], x_min, x_max)
        y_min_i, y_max_i = FU.find_axes_indices(self.s_axes[1], y_min, y_max)
    
#         print(x_min_i, x_max_i, y_min_i, y_max_i)
        
        for _sp in range(self.s_n[2]):
            for _sm in range(self.s_n[4]):
                for _de in range(self.s_n[5]):
                    for _sc in range(self.s_n[7]):
                        data, x_axis, y_axis = FU.truncate_data(self.s[:,:,_sp,0,_sm,_de,0,_sc].T, self.s_axes[0], self.s_axes[1], x_min_i, x_max_i, y_min_i, y_max_i)
                        
#                         print(data)
                    
                        a = numpy.amin(data)
                        b = numpy.amax(data)
                        print(" {sp}  {sm}  {de}  {sc}  {min:5.1f} {max:5.1f} {delta:5.1f}".format(sp = _sp, sm = _sm, de = _de, sc = _sc, min = a, max = b, delta = (b - a)))
Esempio n. 5
0
def contourplot(data, x_axis, y_axis,
#     ax = False,
#     x_range = [0,0],
#     y_range = [0,-1],
#     zlimit = -1,
#     contours = 12,
#     filled = True,
#     black_contour = True, 
#     x_label = "", 
#     y_label = "", 
#     title = "", 
#     diagonal_line = True, 
#     invert_colors = False, 
#     linewidth = 1,
#     flag_verbose = False,
    **kwargs):
    
    """
    Make a contourplot.
    
    The defaults are for a plot with w3 as the x-axis. 
    
    - data, x_axis, y_axis: data and axes
    - ax (bool (False) or matplotlib axes instance): if False, it will make a new figure, otherwise it will use the axes instance, allowing subplots etc.
    - x_label, y_label, title (string, default=''): the labels for the axes. If no label is set, it will use the default. Use 'no_label' or 'no_title' to show no label.
    - x_range, y_range (array with 2 elements, [0,0], [0,-1]): the range to be plotted. Possible cases:
        - [min, max]: plot range min to max
        - [0, 0]: plot the whole range
        - [0, -1]: use the range from the other axis. If both have this, it will plot both axes complete. (ie. it is identical to both having [0,0])
    - zlimit (number or list, -1): the z-range that will be used
        Possible cases:
        zlimit = 0, show all, not don't care about centering around zero
        zlimit = -1, show all, centered around zero
        zlimit = all else, use that, centered around zero
        zlimit = [a,b], plot from a to b
    - contours (int, 16): number of contours to be used
    - invert_colors (BOOL, False): data = -data   
    
    CHANGELOG:
    201108xx/RB: started function
    20130213/RB: moved some things out as separate functions
    20160418/RB: replaced arguments with kwargs
    
    """
    if "flag_verbose" in kwargs:
        flag_verbose = kwargs["flag_verbose"]
    else:
        flag_verbose = False
        
    DEBUG.verbose("contour plot", flag_verbose)

    y, x = numpy.shape(data)
    if len(x_axis) != x and len(y_axis) != y:
        DEBUG.printError("The data should have the same shape as the axes, wrong for both axes", inspect.stack())
        return False
    elif len(x_axis) != x:
        DEBUG.printError("The data should have the same shape as the axes, wrong for the x-axis", inspect.stack())
        return False
    elif len(y_axis) != y:
        DEBUG.printError("The data should have the same shape as the axes, wrong for the y-axis", inspect.stack())  
        return False          

    if "invert_colors" in kwargs and kwargs["invert_colors"]:
        data = -data
    
    if "x_range" in kwargs:
        x_range = kwargs["x_range"]
    else:
        x_range = [0,0]

    if "y_range" in kwargs:
        y_range = kwargs["y_range"]
    else:
        y_range = [0,-1]

    # determine the range to be plotted
    x_min, x_max, y_min, y_max = FU.find_axes(x_axis, y_axis, x_range, y_range, flag_verbose)
    
    # find the area to be plotted
    x_min_i, x_max_i = FU.find_axes_indices(x_axis, x_min, x_max)
    y_min_i, y_max_i = FU.find_axes_indices(y_axis, y_min, y_max)
    
    # truncate the data, this speeds up the plotting
    data, x_axis, y_axis = FU.truncate_data(data, x_axis, y_axis, x_min_i, x_max_i, y_min_i, y_max_i)

    if "zlimit" in kwargs:
        zlimit = kwargs["zlimit"]
    else:
        zlimit = -1
        
    if "contours" in kwargs:
        contours = kwargs["contours"]
    else:
        contours = 16

    # now make the actual contours   
    V = FU.make_contours_2d(data, zlimit, contours, flag_verbose)        

    # make sure there is an axis-object
    if "ax" in kwargs:
        ax = kwargs["ax"]
        flag_show = False
    else:
        fig = plt.figure()
        ax = fig.add_subplot(111)
        flag_show = True
#     else:
#         flag_show = False

    if "linewidth" in kwargs:
        linewidth = kwargs["linewidth"]
    else:
        linewidth = 1

    # actually plot the thing
    if "filled" in kwargs and kwargs["filled"] == False:
        pass
    else:
        ax.contourf(x_axis, y_axis, data, V, cmap = FU.rwb_cmap)
        
    if "black_contour" in kwargs and kwargs["black_contour"] == False:
        pass
    else:
        if "filled" in kwargs and kwargs["filled"] == False:
            ax.contour(x_axis, y_axis, data, V, linewidths = linewidth, colors = "k")
        else:
            ax.contour(x_axis, y_axis, data, V, linewidths = linewidth, linestyles = "solid", colors = "k")      
    
    # the diagonal line
    if "diagonal_line" in kwargs and kwargs["diagonal_line"] == False:
        pass
    else:
        ax.plot([x_axis[0]-100,x_axis[-1]+100], [x_axis[0]-100,x_axis[-1]+100], "k", linewidth = linewidth)

    # we only want to see a certain part of the spectrum   
    ax.set_xlim(x_min, x_max)
    ax.set_ylim(y_min, y_max)
    
    # add some text
    if "x_label" in kwargs and kwargs["x_label"] != "" and kwargs["x_label"]  != "no_label":
        ax.set_xlabel(kwargs["x_label"] )
    
    if "y_label" in kwargs and kwargs["y_label"] != "" and kwargs["y_label"] != "no_label":
        ax.set_ylabel(kwargs["y_label"])
    
    if "title" in kwargs and kwargs["title"] != "":
        ax.set_title(kwargs["title"])    

    if flag_show:
        plt.show()

    return True