Data#

class up4.Data(filename)#

Bases: object

Class that holds the particle data for processing.

If you have simulation data, you will probably want to use Data.from_pdata() to instantiate this class as this handles a large number of particles. For experimental data, Data.from_tdata() is recommended. However, as the choice ultimately makes no difference to how you use this library, that choice is down to you!

Methods

from_pdata:

Constructor for up4.Data using data that has large numbers of particles, typically from simulation.

from_tdata:

Constructor for up4.Data using data that has low numbers of particles, typically from experiment.

stats:

Calculate statistics of the dataset such as dimensions, mean velocity and number of particles.

set_time:

Select the dataset between two times.

vectorfield:

Return vector data as a vector field.

velocityfield:

Return the velocity data as a velocity field.

extract:

Return particle information over specified duration.

numberfield:

Return the number density field.

mean_velocity:

Return the mean velocity of all valid particles in the system.

dispersion:

Return the dispersion of all valid particles in the system for a given time

histogram:

Return the histogram of all valid particles in the system for a given time

granular_temperature:

Return the granular temperature of all valid particles in the system for a given time

lacey_mixing_index:

Return the lacey mixing index for the whole system over a given time

circulation_time:

Return the circulation time for the whole system, returns all times as one large array

circulation_time_two_boundary:

Return the circulation time for the whole system determined using two bounaries, returns all times as one large array

concentration_field:

Return the concentration field for the whole system

homogenity_index:

Return the homogenity index for the whole system, defiuned by two particle species

msd_field:

Return the mean square displacement field for the whole system

msd:

Return the mean square displacement for the whole system over time

circulation_time(position, axis=0)#

Calculate the circulation time of a particle in a system. This algorithm works by setting a single boundary, which the particle has to cross 3 times.

Parameters:
positionfloat

The position of the boundary.

axisint

The axis along which the boundary is set. Default 0.

Returns:
circulation_timelist

The circulation time of the particle.

circulation_time_two_boundary(position, axis=0)#

Calculate the circulation time of a particle in a system. This algorithm works by setting two boundaries, which the particle has to cross 5 times in total.

Parameters:
positiontuple[float, float]

The positions of the boundaries.

axisint

The axis along which the boundary is set. Default 0.

Returns:
list[tuple]

The start and end times for each circulation

concentration_field(grid, type_a=1, type_b=2)#

Calculate the concentration field of the system The concentration field is calculated by counting the number of particles of type a and b in a region of the system. The concentration is calculated by n_a / (n_a + n_b).

Parameters:
gridPyGrid

The grid that defines the region of the system.

type_aint

The particle type of the first particle.

type_bint

The particle type of the second particle.

Returns:
concentration_fieldPyGrid

The concentration field of the system.

dimensions()#

Return the dimensions of the system as a dictionary. The dictionary contains the following keys: * xmin: Minimum x coordinate. * xmax: Maximum x coordinate. * ymin: Minimum y coordinate. * ymax: Maximum y coordinate. * zmin: Minimum z coordinate. * zmax: Maximum z coordinate.

dispersion(grid, time_for_dispersion)#

Return the dispersion of the particles in the system.

See [1] for further details.

Parameters:
gridup4.Grid

Grid class containing the grid layout.

time_for_dispersionfloat

Time for which the dispersion is calculated.

Returns:
up4.Grid

Grid class containing the dispersion field.

float

Mixing efficiency

References

[1]

Martin, T. W., J. P. K. Seville, and D. J. Parker. “A general method for quantifying dispersion in multiscale systems using trajectory analysis.”

extract(particle_id, timestep)#

Return particle information over specified duration.

Parameters:
particle_idint

Particle ID.

timesteptuple[int, int]

Start and end timesteps for particle selection.

Returns:
numpy.ndarray

2D numpy array with shape (timestep[1] - timestep[0]) X 7. Where in each row is the current time, particle position and its velocity components.

static from_pdata(filename)#

Create new instance of the up4.Data class. This method assumes a particle oriented hdf5 file.

Parameters:
filenamestr

Filename of hdf5 dataset.

Returns:
up4.Data

Data class

static from_tdata(filename)#

Create new instance of the Data class. This method assumes a time oriented hdf5 file.

Parameters:
filenamestr

Filename of hdf5 dataset.

Returns:
up4.Data

Data class

granular_temperature(grid, mode='xyz')#

Calculate the granular temperature of the system. The granular temperature is defined as the mean fluctuating velocity of the particles.

Parameters:
gridPyGrid

The grid that defines the region of the system.

modestr

The mode in which the granular temperature is calculated. The following modes are available:

  • ‘xyz’

  • ‘x’

  • ‘y’

  • ‘z’

, by default ‘xyz’

Returns:
PyGrid

The granular temperature of the system.

histogram(grid, property='velocity', bins=100, limit=0.0)#

Calculate a histogram of a specific property in a region of the system.

The histogram is calculated for all particles that are valid according to the particleselector. The histogram is calculated for the region defined by the grid.

Parameters:
gridpygrid

The grid that defines the region of the system.

propertystr

The property that is used to calculate the histogram, the following properties are available: - ‘velocity’

binsint

The number of bins in the histogram.

Returns:
histogramnumpy.ndarray

The histogram.

bin_edgesnumpy.ndarray

The bin edges.

homogenity_index(grid, min_vel=0.0)#

Calculate the homogenity index.

Parameters:
gridPyGrid

The grid that defines the region of the system.

lacey_mixing_index(grid, type_a=0, type_b=1, threshold=10)#

Calculate the Lacey mixing index for two particle types in a region of the system for a time period.

Parameters:
gridPyGrid

The grid that defines the region of the system.

type_aint

The particle type of the first particle.

type_bint

The particle type of the second particle.

Returns:
timenumpy.ndarray

The time of the mixing index.

mixing_indexnumpy.ndarray

The mixing index.

max_position()#

Return the max position of the system as a array The array contains the following values at positions: * 0: Maximum x coordinate. * 1: Maximum y coordinate. * 2: Maximum z coordinate.

mean_velocity()#

Return the mean velocity of all valid particles in the system.

Returns:
float

Mean particle velocity

min_position()#

Return the min position of the system as a array The array contains the following values at positions: * 0: Minimum x coordinate. * 1: Minimum y coordinate. * 2: Minimum z coordinate.

msd(grid, min_time=0.0, max_time=0.0, steps=100)#

Calculate the mean squared displacement of a particle in a system.

Parameters:
gridPyGrid

The grid that defines the region of the system.

min_timefloat

The minimum time to start calculating the MSD.

max_timefloat

The maximum time to stop calculating the MSD.

Returns:
msdndarray

The mean squared displacement of the particle.

timendarray

The time at which the MSD was calculated.

msd_field(grid, time)#

Calculate the mean squared displacement field of the system. The mean squared displacement field is calculated by calculating the mean squared displacement of a particle in a region of the system. Each cell element represents the mean squared displacement of all particles in that cell.

Parameters:
gridPyGrid

The grid that defines the region of the system.

Returns:
msd_fieldPyGrid

The mean squared displacement field of the system.

nparticles()#

Number of particles in the system.

numberfield(grid)#

Return the number density field.

Parameters:
gridup4.Grid

Grid class containing the grid layout.

Returns:
up4.Grid

Grid class containing the number field

occupancyfield(grid, min_vel=0.0)#

Return the occupancy field.

Parameters:
gridup4.Grid

Grid class containing the grid layout.

min_velfloat, optional

Minimum velocity to be considered as occupied.

Returns:
up4.Grid

Grid class containing the number field

set_time(min_time, max_time)#

Select the dataset between two different times.

Parameters:
min_timefloat

Starting time for selection.

max_timefloat

End time for selection.

stats()#

Calculate statistics of the dataset and print to terminal. Currently these are: * System dimensions. * Maximum time. * Number of particles. * Mean velocity. * Minimum and maximum velocity.

time()#

Return the time array of the dataset.

Returns:
Array of time values.
vectorfield(grid)#

Return velocity data as a vector field.

Parameters:
gridup4.Grid

Grid class containing the grid layout.

Returns:
up4.VectorGrid

VectorGrid class containing each vector component for each grid cell.

velocityfield(grid, mode='absolute', min_velocity=..., max_velocity=1000000.0)#

Return the velocity data as a velocity field of their norms.

Parameters:
gridup4.Grid

Grid class containing the grid layout.

Returns:
up4.Grid

Grid class containing the velocity field.