def displacement_grid(box_size, centre, Ncases, time, dt, w_traj, u_traj): """ Calculates displcament grid from square uniform coarse-graining. Parameters ---------- box_size : float Length of the considered system's square box. centre : float array Centre of the box. Ncases : int Number of boxes in each direction to compute the displacements. time : int Frame at which displacements will be calculated. dt : int Length of the interval of time for which the displacements are calculated. w_traj : active_particles.dat.Gsd Wrapped trajectory object. u_traj : active_particles.dat.Dat Unwrapped trajectory object. Returns ------- ugrid : 2D array like Displacement grid. """ return w_traj.to_grid( time + dt*get_env('ENDPOINT', default=False, vartype=bool), u_traj.displacement(time, time + dt), Ncases=Ncases, box_size=box_size, centre=centre)
def __init__(self, u_traj, w_traj, frame, box_size, centre, arrow_width, arrow_head_width, arrow_head_length, dt=0, **kwargs): """ Initialises and plots figure. Parameters ---------- u_traj : active_particles.dat.Dat Unwrapped trajectory object. w_traj : active_particles.dat.Gsd Wrapped trajectory object. frame : int Frame to render. box_size : float Length of the square box to render. centre : 2-uple like Centre of the box to render. arrow_width : float Width of the arrows. arrow_head_width : float Width of the arrows' head. arrow_head_length : float Length of the arrows' head. dt : int Lag time for displacement. (default: 0) """ super().__init__(w_traj, frame, box_size, centre, arrow_width, arrow_head_width, arrow_head_length) # initialise superclass global trajectory_tracer_particle # index of tracer particle try: if not(trajectory_tracer_particle in self.particles): # tracer particle not in frame raise NameError # do as if tracer particle were not defined except NameError: # tracer particle not defined if get_env('TRACER_PARTICLE', default=True, vartype=bool): # TRACER_PARTICLE mode trajectory_tracer_particle = np.argmin( np.sum(self.positions**2, axis=-1)) # tracer particle at centre of frame else: trajectory_tracer_particle = -1 # there is no particle with index -1 self.displacements = u_traj.displacement(frame, frame + dt, *self.particles) # particles' displacements between time and time + dt self.draw()
def endpoint(): """ Consider a variable A which depends on space, time and a lag time (e.g., displacement). It is possible to measure (i) A between times t and t + dt for a particle which is at position r at time t: A(r, t ; t, t + dt) (ii) A between times t and t + dt for a particle which is at position r at time t + dt: A(r, t + dt ; t, t + dt) and calculate correlations over space and time in both cases. We will add a 'b' following the name of the correlation for files which have produced considering case (i). e.g., for displacement correlations, filenames will begin with 'Cuub' if correlations were calculated for displacements between times t and t + dt between particles at position r at time t. Case (i) corresponds to environment variable 'ENDPOINT' set as False or not set, while case (ii) corresponds to environment variable 'ENDPOINT' set as True. """ if get_env('ENDPOINT', default=False, vartype=bool): return '' return 'b'
_slope0 = 0 # default initial slope for fitting line slider _slope_min = -2 # minimum slope for fitting line slider _slope_max = 2 # maximum slope for fitting line slider _font_size = 10 # default font size _marker_size = 20 # default marker size _colormap = 'jet' # default plot colormap # SCRIPT if __name__ == '__main__': # executing as script # VARIABLE DEFINITIONS data_dir = get_env('DATA_DIRECTORY', default=getcwd()) # data directory int_max = get_env( 'INTERVAL_MAXIMUM', default=1, vartype=int ) # maximum number of time snapshots taken for the calculation of the mean square displacement at each time int_period = get_env( 'INTERVAL_PERIOD', default=1, vartype=int ) # period of time at which mean square displacement was calculated parameters_file = get_env( 'PARAMETERS_FILE', default=joinpath(data_dir, naming.parameters_file)) # simulation parameters file with open(parameters_file, 'rb') as param_file: parameters = pickle.load(param_file) # parameters hash table
_, self.philocmax[dir], _ = max(histogram3D_dir, key=lambda el: el[2]) self.histogram3D = np.transpose(self.histogram3D) self.time_step_list = sorted( OrderedDict.fromkeys( self.time_step.values())) # list of time steps # SCRIPT if __name__ == '__main__': # executing as script # VARIABLES DEFINITIONS mode = get_env('VARIABLE', default='dr') # plotting variable peclet = get_env( 'PECLET', default=True, vartype=bool) # display Péclet number rather than mode variable if mode == 'dr': vzero = get_env('VZERO', default=_vzero, vartype=float) # self-propulsion velocity attributes = {'vzero': vzero} # attributes displayed in filenames var = 'dr' # plot variable var_min = get_env('DR_MIN', default=_dr_min, vartype=float) # minimum rotation diffusion constant var_max = get_env('DR_MAX', default=_dr_max, vartype=float) # maximum rotation diffusion constant
box_size=box_size, multiply_with_dr=multiply_with_dr) self.init_frame_list = sorted( OrderedDict.fromkeys([ init_frame for dir, init_frame in self.msd ])) # list of mean square displacements initial frames # SCRIPT if __name__ == '__main__': # executing as script # VARIABLES DEFINITIONS mode = get_env('VARIABLE', default='dr') # plotting variable peclet = get_env( 'PECLET', default=True, vartype=bool) # display Péclet number rather than mode variable if mode == 'dr': vzero = get_env('VZERO', default=_vzero, vartype=float) # self-propelling velocity attributes = {'vzero': vzero} # attributes displayed in filenames var = 'dr' # plot variable var_min = get_env('DR_MIN', default=_dr_min, vartype=float) # minimum rotation diffusion constant var_max = get_env('DR_MAX', default=_dr_max, vartype=float) # maximum rotation diffusion constant
def plot_correlation(C, C2D, C1D, C1Dcor, C_min, C_max, naming_standard, **directional_correlations): """ Plot correlations. Parameters ---------- C : string Correlation name. C2D : 2D array Correlation 2D grid. C1D : 1D array Correlation 1D average. NOTE: This has to be of the form (r, C1D(r)) with C1D(r) the averaged 2D grid at radius r. C1Dcor : 1D array Correlation 1D average, correction with density correlation. NOTE: This has to be of the form (r, C1D(r)) with C1D(r) the averaged 2D grid at radius r. C_min : float Correlation minimum for plot. C_max : float Correlation maximum for plot. naming_standard : active_particles.naming standard Standard naming object. Optional keyword arguments -------------------------- CL : float Longitudinal correlation. CT : float Transversal correlation. NOTE: These two variables have to be provided together. Returns ------- fig : matplotlib figure Main figure. axs : array of matplotlib axis Main figure's axis. gc [GRID_CIRCLE mode] : active_particles.plot.mpl_tools.GridCircle object Grid circle object. """ cmap = plt.cm.jet fig, axs = plt.subplots(2, 2) fig.set_size_inches(16, 16) fig.subplots_adjust(wspace=0.3) fig.subplots_adjust(hspace=0.3) suptitle = str(r'$N=%.2e, \phi=%1.2f, \tilde{v}=%.2e, \tilde{\nu}_r=%.2e$' % (parameters['N'], parameters['density'], parameters['vzero'], parameters['dr']) + '\n' + r'$S_{init}=%.2e, \Delta t=%.2e$' % (init_frame, dt*parameters['period_dump']*parameters['time_step']) + r'$, S_{max}=%.2e, N_{cases}=%.2e$' % (int_max, Ncases)) fig.suptitle(suptitle) # C2D cgrid = CorGrid(C2D, box_size, display_size=2*r_max) Cmin = np.min(C2D) Cmax = np.max(C2D) CvNorm = colors.Normalize(vmin=Cmin, vmax=Cmax) CscalarMap = cmx.ScalarMappable(norm=CvNorm, cmap=cmap) axs[0, 0].imshow(cgrid.display_grid.grid, cmap=cmap, norm=CvNorm, extent=[-r_max, r_max, -r_max, r_max]) axs[0, 0].set_xlabel(r'$x$') axs[0, 0].set_ylabel(r'$y$') axs[0, 0].set_title('2D ' + r'$%s$' % C + ' ' + (r'$(%s^T/%s^L(\frac{r}{a} = %.3e) = %.3e)$' % (C, C, (box_size/Ncases)/parameters['a'], directional_correlations['CT']/directional_correlations['CL']) if 'CL' in directional_correlations and 'CT' in directional_correlations else '')) divider = make_axes_locatable(axs[0, 0]) cax = divider.append_axes("right", size="5%", pad=0.05) cb = mpl.colorbar.ColorbarBase(cax, cmap=cmap, norm=CvNorm, orientation='vertical') cb.set_label(r'$%s$' % C, labelpad=20, rotation=270) # C1D shifted fplot(axs[1, 0])(C1D[1:, 0], C1D[1:, 1]/Cnn1D[-1, 1]) axs[1, 0].set_xlabel(r'$r$') axs[1, 0].set_ylabel(r'$%s$' % C + r'$/C_{\rho\rho}(r=r_{max})$') axs[1, 0].set_title('radial ' + r'$%s$' % C + r'$/C_{\rho\rho}(r=r_{max})$' + ' ' + r'$(C_{\rho\rho}(r=r_{max}) = %.3e)$' % Cnn1D[-1, 1]) axs[1, 0].set_xlim(r_min, r_max) axs[1, 0].set_ylim(C_min, C_max) # Cnn1D and C1D axs[0, 1].set_title('radial ' + r'$C_{\rho\rho}$' + ' and ' + r'$%s$' % C) axs[0, 1].set_xlabel(r'$r$') axs[0, 1].set_xlim(r_min, r_max) axs[0, 1].plot(Cnn1D[1:, 0], Cnn1D[1:, 1], color='#1f77b4') axs[0, 1].set_ylabel(r'$C_{\rho\rho}$', color='#1f77b4') axs[0, 1].tick_params('y', colors='#1f77b4') ax_right = axs[0, 1].twinx() ax_right.semilogy(C1D[1:, 0], C1D[1:, 1], color='#ff7f0e') ax_right.set_ylabel(r'$%s$' % C, color='#ff7f0e', rotation=270, labelpad=10) ax_right.tick_params('y', colors='#ff7f0e') ax_right.set_ylim(C_min*Cnn1D[-1, 1], C_max*Cnn1D[-1, 1]) # C1D/Cnn fplot(axs[1, 1])(C1Dcor[1:, 0], C1Dcor[1:, 1]) axs[1, 1].set_xlabel(r'$r$') axs[1, 1].set_ylabel(r'$%s$' % C + r'$/C_{\rho\rho}$') axs[1, 1].set_title('radial ' + r'$%s$' % C + r'$/C_{\rho\rho}$') axs[1, 1].set_xlim(r_min, r_max) axs[1, 1].set_ylim(C_min, C_max) # SAVING if get_env('SAVE', default=False, vartype=bool): # SAVE mode image_name, = naming_standard.image().filename(**attributes) fig.savefig(joinpath(data_dir, image_name)) # GRID CIRCLE if get_env('GRID_CIRCLE', default=False, vartype=bool): # GRID_CIRCLE mode ccorgrid = CorGrid(C2D/Cnn2D, box_size, display_size=2*r_max) # correlation corrected with density correlation gc = GridCircle(ccorgrid.display_grid.grid, extent=(-r_max, r_max, -r_max, r_max)) gc.fig.set_size_inches(fig.get_size_inches()) gc.fig.suptitle(suptitle) gc.fig.subplots_adjust(wspace=0.4) # width space gc.fig.subplots_adjust(hspace=0.3) # height space gc.ax_grid.set_xlabel(r'$x$') gc.ax_grid.set_ylabel(r'$y$') gc.ax_grid.set_title('2D ' + r'$%s$' % C + ' ' + (r'$(%s^T/%s^L(\frac{r}{a} = %.3e) = %.3e)$' % (C, C, (box_size/Ncases)/parameters['a'], directional_correlations['CT']/directional_correlations['CL']) if 'CL' in directional_correlations and 'CT' in directional_correlations else '')) gc.colormap.set_label(r'$%s$' % C, labelpad=20, rotation=270) gc.ax_plot.set_xlabel(r'$\theta$') gc.ax_plot.set_ylabel(r'$%s(\theta)$' % C) try: return fig, axs, gc except NameError: return fig, axs
from os.path import join as joinpath from math import ceil import numpy as np import pickle from operator import itemgetter from collections import OrderedDict from datetime import datetime import matplotlib as mpl if not(get_env('SHOW', default=False, vartype=bool)): mpl.use('Agg') # avoids crash if launching without display import matplotlib.pyplot as plt import matplotlib.colors as colors import matplotlib.cm as cmx from mpl_toolkits.axes_grid1 import make_axes_locatable from active_particles.plot.mpl_tools import GridCircle # DEFAULT VARIABLES _r_min = 1 # default minimum radius for correlations plots _r_max = 20 # default maximum radius for correlations plots _Cuu_min = 1e-3 # default minimum displacement correlation for correlation plots _Cuu_max = 1 # default maximum displacement correlation for correlation plots
from active_particles.exponents import float_to_letters, letters_to_float,\ significant_figures from active_particles.init import get_env from collections import OrderedDict from itertools import chain from copy import deepcopy from os import getcwd from os import environ as envvar from os import listdir as ls from os.path import join as joinpath # DEFAULT NAMES sim_directory = joinpath(get_env('HOME'), 'active_particles_data') # simulation data directory out_directory = joinpath(sim_directory, 'out') # launch output directory parameters_file = 'param.p' # simulation parameters file log_file = 'log-output.log' # simulation log output file wrapped_trajectory_file = 'trajectory.gsd' # wrapped trajectory file (with periodic boundary conditions) unwrapped_trajectory_file = 'trajectory.dat' # unwrapped trajectory file (without periodic boundary conditions) # GLOSSARY class Glossary: """ This class references VarInfo objects. """
if dir in self.corT: self.corT_max[dir] = self.corT[dir][ 1, np.argmin(np.abs(self.corT[dir][0] - dtmax[dir]))] if dir in self.ratioTL: self.ratioTL_max[dir] = self.ratioTL[dir][ 1, np.argmin(np.abs(self.ratioTL[dir][0] - dtmax[dir]))] # SCRIPT if __name__ == '__main__': # executing as script # VARIABLES DEFINITIONS mode = get_env('VARIABLE', default='dr') # plotting variable peclet = get_env( 'PECLET', default=True, vartype=bool) # display Péclet number rather than mode variable if mode == 'dr': vzero = get_env('VZERO', default=_vzero, vartype=float) # self-propelling velocity attributes = {'vzero': vzero} # attributes displayed in filenames var = 'dr' # plot variable var_min = get_env('DR_MIN', default=_dr_min, vartype=float) # minimum rotation diffusion constant var_max = get_env('DR_MAX', default=_dr_max, vartype=float) # maximum rotation diffusion constant
_wspace = 0.4 # default plots width space _hspace = 0.05 # default plots height space _colormap = 'jet' # default plot colormap _slope0 = 0 # default initial slope for fitting line slider _slope_min = -2 # default minimum slope for fitting line slider _slope_max = 2 # maximum slope for fitting line slider # SCRIPT if __name__ == '__main__': # executing as script # VARIABLE DEFINITIONS data_dir = get_env('DATA_DIRECTORY', default=getcwd()) # data directory init_frame = get_env('INITIAL_FRAME', default=-1, vartype=int) # frame to consider as initial int_max = get_env( 'INTERVAL_MAXIMUM', default=1, vartype=int ) # maximum number of intervals of length dt considered in correlations calculations parameters_file = get_env( 'PARAMETERS_FILE', default=joinpath(data_dir, naming.parameters_file)) # simulation parameters file with open(parameters_file, 'rb') as param_file: parameters = pickle.load(param_file) # parameters hash table av_p_sep = parameters['box_size'] / np.sqrt(
from os import getcwd from os import environ as envvar from os.path import join as joinpath import numpy as np from math import ceil import pickle from collections import OrderedDict from datetime import datetime import matplotlib as mpl if not (get_env('SHOW', default=False, vartype=bool)): mpl.use('Agg') # avoids crash if launching without display import matplotlib.pyplot as plt import matplotlib.colors as colors import matplotlib.cm as cmx from mpl_toolkits.axes_grid1 import make_axes_locatable # DEFAULT VARIABLES _init_frame = -1 # default frame to consider as initial _int_max = 1 # default maximum number of frames on which to calculate densities _box_size = 10 # default length of the square box in which particles are counted _Nbins = 10 # default number of bins for the histogram _phimax = 1 # default maximum local density for histogram
from active_particles.maths import wo_mean, mean_sterr, Histogram from os import getcwd from os import environ as envvar from os.path import join as joinpath import numpy as np import pickle from datetime import datetime from collections import OrderedDict import matplotlib as mpl if not (get_env('SHOW', default=False, vartype=bool)): mpl.use('Agg') # avoids crash if launching without display import matplotlib.pyplot as plt import matplotlib.colors as colors import matplotlib.cm as cmx import matplotlib as mpl from mpl_toolkits.axes_grid1 import make_axes_locatable import matplotlib.pyplot as plt from active_particles.plot.mpl_tools import FittingLine # DEFAULT VARIABLES _sq_disp_min = 1e-5 # default minimum included value of square displacement for histogram bins _sq_disp_max = 1e5 # default maximum excluded value of square displacement for histogram bins _Nbins = 100 # default number of histogram bins
_wspace = 0.2 # default plots width space _hspace = 0.05 # default plots height space _colormap = 'jet' # default plot colormap _width_inset = 30 # default maximum C44 inset width in percentage of graph width _height_inset = 30 # default maximum C44 inset height in percentage of graph height # SCRIPT if __name__ == '__main__': # executing as script # VARIABLES DEFINITIONS mode = get_env('MODE', default='real') # strain correlations computation mode if mode in ('real', 'fourier'): naming_Css = naming.Css(mode=mode) # Css naming object elif mode == 'cmsd': naming_Ctt = naming.Ctt() # Ctt naming object naming_Cll = naming.Cll() # Cll naming object else: raise ValueError('Mode %s is not known.' % mode) # mode is not known data_dir = get_env('DATA_DIRECTORY', default=getcwd()) # data directory init_frame = get_env('INITIAL_FRAME', default=-1, vartype=int) # frame to consider as initial int_max = get_env('INTERVAL_MAXIMUM', default=1, vartype=int) # maximum number of intervals of length dt considered in correlations calculations parameters_file = get_env('PARAMETERS_FILE', default=joinpath(data_dir, naming.parameters_file)) # simulation parameters file with open(parameters_file, 'rb') as param_file:
from os import getcwd from os import environ as envvar from os.path import join as joinpath import sys from math import ceil import pickle import numpy as np np.seterr(divide='ignore') import matplotlib as mpl if not(get_env('SHOW', default=False, vartype=bool)): mpl.use('Agg') # avoids crash if launching without display import matplotlib.pyplot as plt from matplotlib.colors import Normalize as ColorsNormalise from matplotlib.cm import ScalarMappable from mpl_toolkits.axes_grid1 import make_axes_locatable from datetime import datetime from collections import OrderedDict import subprocess # DEFAULT VARIABLES _frame_per = 1 # default frame rendering period
_pd2minmin = 1e-4 # default minimum D2min probability _pd2minmax = 1e-1 # default maximum D2min probability _contours = 20 # default contour level value _font_size = 15 # default font size for the plot _colormap = 'inferno' # default plot colormap _colormap_label_pad = 20 # separation between label and colormap # SCRIPT if __name__ == '__main__': # executing as script # VARIABLES DEFINITIONS data_dir = get_env('DATA_DIRECTORY', default=getcwd()) # data directory wrap_file_name = get_env( 'WRAPPED_FILE', default=joinpath( data_dir, naming.wrapped_trajectory_file)) # wrapped trajectory file (.gsd) init_frame = get_env('INITIAL_FRAME', default=-1, vartype=int) # reference frame in D2min calculations dt_min = get_env('DT_MIN', default=1, vartype=int) # minimum lag time dt_max = get_env('DT_MAX', default=-1, vartype=int) # maximum lag time int_max = get_env( 'INTERVAL_MAXIMUM', default=_int_max,