def plot_pins(scatter_axis, size=75, pin_file="pin_array.dat"):
    '''plot the pinning array from ascii file with pin_file:
    --------------------------------------------------
    n     x     y    radius mag
    int float float  float  float
    ---------------------------------------------------
    required args:
    scatter_axis = matplotlib axes object

    optional args:
    size=75, to plot pin radius
    pin_file="pin_array.dat"
    '''
    try:
        pin_data = di.get_data(pin_file, 5, sep=" ")
    except:
        print("No pinning data in expected format")
        return
    pin_x = pin_data[1]
    pin_y = pin_data[2]
    pin_rad = pin_data[3]
    pin_mag = pin_data[4]

    scatter_axis.scatter(pin_x, pin_y, c="gray", alpha=0.4,
                         s=size)  #,rasterized=True)

    return
Exemple #2
0
def enstrophy_field(ax,
                    filename="coarse_grain_field.txt",
                    Sx=[0, 60.0],
                    Sy=[0, 60.0],
                    BW=0,
                    plot_log=0,
                    plot_cbar=1):
    '''Read in a formatted file containing a velocity field
    and make a vector plot
    you could totally combine this with the curl field
    and possibly even the heat map
    as a general subroutine
    '''

    #ax is declared in main function
    ax.set_aspect('equal')

    #get the formatted data from c code calculation
    (x, y, vx, vy, speed, enstrophy) = diDM.get_data(filename,
                                                     6,
                                                     sep='\t',
                                                     path1=os.getcwd())

    ax.set_xlim(*Sx)
    ax.set_ylim(*Sy)

    #create regular x-y grid
    xi = numpy.linspace(min(x), max(x))
    yi = numpy.linspace(min(y), max(y))

    #create a mesh x-y grid from the numpy.linspace
    #these are necessary for the plot
    X, Y = numpy.meshgrid(xi, yi)

    #take the Heat (x,y,z) data and grid it on the xi, yi (not the mesh)
    Z = matplotlib.mlab.griddata(x, y, enstrophy, xi, yi, interp='linear')

    #############################################
    # color map of curl of coarse grain field
    #############################################
    cset = ax.contourf(X, Y, Z, zdir='enstrophy', offset=0, cmap=cm.Purples)
    #cbar = fig.colorbar(cset, ax=ax)
    '''
    if plot_cbar:
        cbar_ax=add_subplot_axes(ax,rect=[-1.0,0.0,2.0,0.05])
        cb = plt.colorbar(cset,ax=ax,cax=cbar_ax,orientation='horizontal')
        cbar_ax.set_title(r"$\varepsilon(\vec{\omega})$",fontsize=18)

        #,ticks=tick_loc )
    '''

    return  #cset
Exemple #3
0
def get_and_parse_data(data_type,
                       starttime,
                       datafile_prefix="velocity_data/XV_data_t=",
                       movie_type="smovie"):
    '''Guide to data types

    0: "smtest"      
    read from smtest, write to XV_data_t=39999800.npy

    1: "ascii"
    read from XV_data_t=39999800,
    write XV_data_t=39999800.npy

    2: "binary"
    read from XV_data_t=39999800.npy, 
    could also be smtest_...npy with recode

    '''

    init_file = datafile_prefix + "%08d" % (starttime)

    if data_type == 0:

        #make a series of binary files in subroutine,
        #only call once
        di.read_smtest(movie_type=movie_type)
        binary_file = "%s%s" % (init_file, ".npy")
        particle_data = np.load(binary_file)

    elif data_type == 1:
        particle_data = di.get_data(init_file, 7, sep=" ")
        np.save(init_file, particle_data)

        #DON'T BOTHER WITH THESE PARAMETERS
        #only in ascii, not smtest
        #vx    = particle_data[4]
        #vy    = particle_data[5]
        #speed = particle_data[6]

    elif data_type == 2:
        binary_file = "%s%s" % (init_file, ".npy")
        particle_data = np.load(binary_file)

    id = particle_data[0]  #NOT USED
    type = particle_data[1]  #1 OR 2, SETS SIZE, FIXED FOR ANIMATION
    xp = particle_data[2]  #DYMAMICALLY UPDATED POSITIONS
    yp = particle_data[3]

    #size = disk_size*np.ones(len(type))

    return id, type, xp, yp
Exemple #4
0
#from matplotlib import cm
import matplotlib.ticker as ticker
import sys
#functions written by D.M. to get and plot specific data files
import data_importerDM as di

plt.rc('font', size=10)

if __name__ == "__main__":

    #------------------------------------------------------------------------
    #get data for initial frame,
    #------------------------------------------------------------------------

    plot_file = "AverageEnergies.txt"
    p_data = di.get_data(plot_file, 3, sep=" ")
    #Use index 1 for scaled velocity and index 3 for plain velocity
    for i in range(len(p_data[0, :])):
        p_data[1][i] = p_data[1][i] / (2610 * 50)
        p_data[2][i] = p_data[2][i] / (2610 * 50)

    #Use index 1 for scaled velocity and index 3 for plain velocity
    index = 1
    rows = 1
    columns = 1

    gs = gridspec.GridSpec(rows, columns)
    fig = plt.figure(figsize=(8 * columns, 4 * rows))

    ax1 = fig.add_subplot(gs[:])  #scatter plot of particles
    #-----------------------------------
    ax1.set_xlabel("x")
    ax1.set_ylabel("y")
    ax1.set_ylim(0, Sy[1])
    ax1.set_xlim(0, Sx[1])
    num_ticks = 6
    ax1.xaxis.set_major_locator(ticker.MaxNLocator(num_ticks))
    ax1.yaxis.set_major_locator(ticker.MaxNLocator(num_ticks))

    #------------------------------------------------------------------------
    #get data for initial frame,
    #------------------------------------------------------------------------

    datafile_prefix = "velocity_data/XV_data_t="
    plot_file = datafile_prefix + "%08d" % (plot_time)
    particle_data = di.get_data(plot_file, 7, sep=" ")

    id = particle_data[0]  #NOT USED
    type = particle_data[1]  #1 OR 2, SETS SIZE, FIXED FOR ANIMATION
    xp = particle_data[2]  #DYMAMICALLY UPDATED POSITIONS
    yp = particle_data[3]

    #DON'T BOTHER WITH THESE PARAMETERS
    #vx    = particle_data[4]
    #vy    = particle_data[5]
    #speed = particle_data[6]

    #RESIZE PARTICLES BASED ON TYPE
    #not efficient - python can do this much faster
    #than this c-like array
    #since we only do this once, that is fine.  multiple times?  fix!
    inputfile = "Pa0"

    (Sx, Sy, radius, maxtime, writemovietime) = cpl.get_input_data(inputfile)

    out_file1 = "EnergiesAndNN.txt"
    out_file2 = "../../AverageNNEnergies.txt"

    #---------------------------
    #get and parse data
    #---------------------------

    datafile_prefix = "velocity_data/XV_data_t="
    pin_file = "pin_array.dat"
    time = 49950
    try:
        pin_data = di.get_data(pin_file, 5, sep=" ")
    except:
        print("No pinning data in expected format")
        sys.exit()
    xd = pin_data[1]
    yd = pin_data[2]
    pin_rad = pin_data[3][0]
    pin_mag = pin_data[4][0]
    total_energy = 0
    EnergyArray = []

    id, type, xp, yp = cpl.get_and_parse_data(data_type,
                                              time,
                                              movie_type="cmovie")

    #Calculate nearest neigbors
Exemple #7
0
def particle_velocity_field(ax,
                            filename="velocity_frame22000",
                            Sx=[0, 60.0],
                            Sy=[0, 60.0],
                            BW=0,
                            plot_log=0,
                            scale=1.0,
                            xshift=0.0,
                            yshift=0.0,
                            arrow_color='black',
                            shrink=0,
                            abs_SX=60.0):
    '''Read in a formatted file containing a velocity field
    and make a vector plot
    '''

    size_vectors = 12  #currently hardcoded
    #ax is declared in main function
    ax.set_aspect('equal')

    #get the formatted data from c code calculation
    print("The filename is:", filename)
    print("")
    (i, type, x, y, vx, vy, radius, speed) = diDM.get_data(filename,
                                                           8,
                                                           path1=os.getcwd())

    #############################################################
    #Here we are typically centering the particles in the figure
    #############################################################
    #beware, intentionally hardcoded, meant as an absolute size

    if xshift:
        for j in range(len(x)):
            x[j] = x[j] + xshift
            if x[j] > abs_SX:
                x[j] -= abs_SX
            elif x[j] < 0.0:
                x[j] += abs_SX

    if yshift:
        for j in range(len(y)):
            y[j] = y[j] + yshift

            if y[j] > abs_SX:
                y[j] -= abs_SX
            elif y[j] < 0.0:
                y[j] += abs_SX

    if shrink:
        center = 0.5 * Sx[-1]
        ax.set_xlim(center - 5.0, center + 7.0)
    else:
        ax.set_xlim(*Sx)

    ax.set_ylim(*Sy)

    #use a list to track the arguments we will call with quiver
    quiver_args = [x, y, vx, vy]

    #use a dictionary to track the optional arguments
    quiver_kargs = {
        'pivot': 'middle',
        'headwidth': size_vectors,
        'headlength': size_vectors
    }

    if scale != 1.0:
        scale_vectors = 1
        quiver_kargs['scale'] = scale

    if BW == 0:
        #speend the list to color the arrows
        quiver_args.append(speed)

        #use a logscale to color the arrows by speed
        if plot_log:
            vmin = 1e-7
            vmax = 1e-3
            norm1 = matplotlib.colors.LogNorm(vmin, vmax)
            #append our optional arguments with color map information
            quiver_kargs['cmap'] = cm.jet
            quiver_kargs['norm'] = norm1

    #Black and white arrows
    else:

        if arrow_color != 'black':
            quiver_kargs['color'] = arrow_color

    #now call quiver with the args and optional args we have defined!
    ax.quiver(*quiver_args, **quiver_kargs)

    ax.set_xlim(*Sx)
    ax.set_ylim(*Sy)

    return
Exemple #8
0
def plot_velocity_field(ax,
                        filename="coarse_grain_field.txt",
                        Sx=[0, 60.0],
                        Sy=[0, 60.0],
                        plot_curl=0,
                        plot_coarse_field=0,
                        plot_cbar=0,
                        vmin=None,
                        vmax=None,
                        shift=None):
    '''Read in a formatted file containing a velocity field
    and make a vector plot
    '''

    #ax is declared in main function
    ax.set_aspect('equal')

    #get the formatted data from c code calculation
    (x, y, vx, vy, curl, enstrophy) = diDM.get_data(filename,
                                                    6,
                                                    sep='\t',
                                                    path1=os.getcwd())

    if plot_curl:
        #create regular x-y grid
        xi = numpy.linspace(min(x), max(x))
        yi = numpy.linspace(min(y), max(y))

        #create a mesh x-y grid from the numpy.linspace
        #these are necessary for the plot
        X, Y = numpy.meshgrid(xi, yi)

        #take the Heat (x,y,z) data and grid it on the xi, yi (not the mesh)
        Z = matplotlib.mlab.griddata(x, y, curl, xi, yi, interp='linear')

        #############################################
        # color map of curl of coarse grain field
        #############################################

        orig_cmap = cm.RdBu
        kwargs_cset = {'offset': 0}
        if shift:
            shifted_cmap = shiftedColorMap(orig_cmap,
                                           midpoint=shift,
                                           name='shifted')
            kwargs_cset['cmap'] = shifted_cmap
        else:
            kwargs_cset['cmap'] = orig_cmap

        if vmin:
            kwargs_cset['vmin'] = vmin
        if vmax:
            kwargs_cset['vmax'] = vmax

        cset = ax.contourf(X, Y, Z, zdir='curl', **kwargs_cset)
        #cbar = fig.colorbar(cset, ax=ax)
        '''
        if plot_cbar:
            cbar_ax=add_subplot_axes(ax,rect=[-0.5,0.9,2.0,0.05])
            cb = plt.colorbar(cset,ax=ax,cax=cbar_ax,orientation='horizontal') 
        cbar_ax.set_title(r"$\vec{\omega}=\nabla \times \vec{v}$",fontsize=18)
        '''

    if plot_coarse_field:
        ax.quiver(x, y, vx, vy, pivot='middle', headwidth=20, headlength=20)

    ax.set_xlim(*Sx)
    ax.set_ylim(*Sy)

    return  #cset
    #leave room for subplotting
    ax1 = fig.add_subplot(G[0])
    
    '''
    ax2 = fig.add_subplot(G[1])
    ax3 = fig.add_subplot(G[2])
    ax4 = fig.add_subplot(G[3])
    '''
    
    #hardcode the data filename, could clean this up
    data_file1 = "velocity_data/XV_data_t=04500000"
    number_columns=8
    path1=os.getcwd()
    
    data_list=di.get_data(data_file1,number_columns,sep=" ",path1=path1)

    x_particle = np.array(data_list[2])
    y_particle = np.array(data_list[3])
    #vx         = np.array(data_list[4])
    #vy         = np.array(data_list[5])
    radius     = np.array(data_list[6])
    #speed      = data_list[7]

    data_file2 = "force_chain_data/data_t=04500000"
    number_columns2=14
    data_list2=di.get_data(data_file2,number_columns2,sep=" ",path1=path1)

    x_p1=np.array(data_list2[1])
    y_p1=np.array(data_list2[2])
    x_p2=np.array(data_list2[6])
Exemple #10
0
def animate(i, scatter1, fileprefix, force_template, force_text, data_type):
    '''
    subroutine driven by the matplotlib animation library

    i:  integer
        clock time of simulation, 
        used in naming scheme for velocity files

    scatter1: matplotlib plot object
              plot containing positions of particles to be updated

    fileprefix: string 
                used to name all data files, needs i to specify file

    force_template: string with integer argument
                    is used to update the frame-by-frame label

    force_text: matplotlib text object
                the text itself is updated with every frame call
                but the object's position and settings 
                are given in the main function 

    data_type: 0/1/2

              0: read formatted data from smtest AND writes binary files
              for subsequent movie making from the same data sets

              1: reads ascii files (slow) AND writes binary files
              for subsequent movie making from the same data sets

              2: directly reads the ".npy" binary files
              which contain numpy arrays of the data that 
              also sits in the ascii file

    fp: file pointer
    nV: number vorticles
    '''

    ############################################################
    #get new particle positions from new integer time i
    ############################################################
    init_file = fileprefix + "%08d" % (i)

    if data_type == 0 or data_type == 2:
        binary_file = "%s%s" % (init_file, ".npy")
        particle_data = np.load(binary_file)

    elif data_type == 1:
        particle_data = di.get_data(init_file, 7, sep=" ")

        #if we haven't save the data in binary format, do it now
        np.save(init_file, particle_data)

    #either way, the relevant data the particle positions
    #we already know the particle id and its size
    xp = particle_data[2]
    yp = particle_data[3]
    '''
    #if you need to change the particle sizes with time
    #for instance if your system is under compression
    #this is the format of the array and the manner
    #to update a size array
    if i>1000000:
        new_sizes = np.array([50 - i/1000000.0]*len(xp))
        scatter1.set_sizes(new_sizes)
    '''

    #specially formatted array to update scatter plot
    data = np.hstack((xp[:i, np.newaxis], yp[:i, np.newaxis]))

    #update the scatter plot created in the main function with the new data
    scatter1.set_offsets(data)

    #if you're changing the color
    #color_array = np.array(something)
    #scatter1.set_array(color_array)

    #update the text label for the new time
    force_text.set_text(force_template % (i))

    #print current time to user
    print(i)

    return scatter1,
Exemple #11
0
    j = 0

    for f_i in force:
        for phi_i in phi:

            ax = fig.add_subplot(G[i])

            #hardcode the data filename, could clean this up
            data_file = "FD_%1.1f/phi_%1.1f_FD_%1.1f_ptrap_0.4/velocity_data/XV_data_t=04500000" % (
                f_i, phi_i, f_i)
            number_columns = 8
            path1 = os.getcwd()

            try:
                data_list = di.get_data(data_file,
                                        number_columns,
                                        sep=" ",
                                        path1=path1)

            except:
                print "didn't work"
                i += 1
                j += 1
                if j == columns:
                    j = 0
                continue

            x_particle = np.array(data_list[2])
            y_particle = np.array(data_list[3])
            vx = np.array(data_list[4])
            vy = np.array(data_list[5])
            radius = np.array(data_list[6])
    for cell in cells:
        n_sides = len(cell["adjacency"])
        index1 = n_sides - 4
        
        if index1 < 4:            
            pN[index1] += 1

    norm_factor = float(sum(pN))
    
    return pN/norm_factor
#--------------------------------------------------------------------
#--------------------------------------------------------------------
#--------------------------------------------------------------------
if __name__ == "__main__":

    all_data = di.get_data("test_data.txt",7,sep=" ")

    id1 = all_data[0]
    type1 = all_data[1]
    x = all_data[2]
    y = all_data[3]

    radii1 = np.zeros(len(type1))
    
    for (i,value1) in zip(range(len(type1)),type1):
        if value1 == 1:
            radii1[i] = 0.7
        else:
            radii1[i] = 0.5

    cells = pyvoro.compute_2d_voronoi(
Exemple #13
0
    ax1.set_xlabel("x")
    ax1.set_ylabel("y")
    ax1.set_ylim(0, Sy[1])
    ax1.set_xlim(0, Sx[1])
    num_ticks = 6
    ax1.xaxis.set_major_locator(ticker.MaxNLocator(num_ticks))
    ax1.yaxis.set_major_locator(ticker.MaxNLocator(num_ticks))

    starttime = 50

    time_inc = 50  #increment to count by
    maxtime = starttime + 49900  #maximum frame to read
    init_file = datafile_prefix + "%08d" % (starttime)

    if get_data:
        particle_data = di.get_data(init_file, 7, sep=" ")
    else:
        binary_file = "%s%s" % (init_file, ".npy")
        particle_data = np.load(binary_file)

    id = particle_data[0]  #NOT USED
    type = particle_data[1]  #1 OR 2, SETS SIZE, FIXED FOR ANIMATION
    xp = particle_data[2]  #DYMAMICALLY UPDATED POSITIONS
    yp = particle_data[3]

    #DON'T BOTHER WITH THESE PARAMETERS
    #vx    = particle_data[4]
    #vy    = particle_data[5]
    #speed = particle_data[6]

    if get_data: