Helper functions¶
Various functions¶
- class pigreads.helper.ModelParameters(models, imodel)¶
Bases:
MutableMapping[str,float]A view into the core implementation of the models allowing reading and modifying the parameters of a model.
- Parameters:
- Variables:
models (pigreads.models.Models) – Instance of the models class to link to the core.
imodel (int) – Index of the model.
- __delitem__(key)¶
Delete the parameter with the given key.
Note: This operation is not supported in this class.
- __getitem__(key)¶
Get the parameter with the given key.
- __iter__()¶
Get an iterator of the keys of the parameters.
- __repr__()¶
Get the string representation of the parameters.
- Return type:
- Returns:
String representation of the parameters.
- __setitem__(key, value)¶
Set the parameter with the given key.
- __str__()¶
Get the string representation of the parameters.
- Return type:
- Returns:
String representation of the parameters.
- _key_to_index(key)¶
Get the index of the parameter with the given key.
- pigreads.helper.delta(x, ax=-1)¶
Extract grid spacing from a 3D array.
- Parameters:
- Return type:
- Returns:
The distance between the first two points.
For example, consider this code:
z, y, x = np.mgrid[0, 0:4:0.2, 0:1:5j] dx = pig.delta(z, ax=-1) dy = pig.delta(z, ax=-2) dz = pig.delta(z, ax=-3)
- pigreads.helper.deltas(*x)¶
Extract grid spacing from a 3D meshgrid.
For example, consider this code:
z, y, x = np.mgrid[0, 0:4:0.2, 0:1:5j] dz, dy, dx = pig.deltas(z, y, x)
- pigreads.helper.get_upper_triangle(matrix)¶
Convert a 3x3 matrix to a 6D vector, with the diagonal and upper triangle of the matrix as elements in the order xx, yy, zz, yz, xz, xy. Additional dimensions are supported, but the last two dimensions must each have size 3.
- pigreads.helper.normalise_vector(f, dtype=<class 'numpy.float32'>)¶
Normalise a 3D vector to unit length.
- Parameters:
- Return type:
- Returns:
A 5D vector with shape (Nz, Ny, Nx, 3, 1).
- pigreads.helper.prepare_array(shape, path=None, dtype=<class 'numpy.float32'>)¶
Prepare an array in a given shape.
Either create a new array or load an existing array from the file with the given path as a memory map.
The shape and dtype of the array are given as arguments. If the path is
None, a new array is created. If the path is a file, the array is loaded from the file. If the array is not of the correct shape or dtype or the file does not exist, a new array is created.The array is returned as a memory map if a path is given, otherwise as a normal numpy array.
- Parameters:
- Return type:
- Returns:
Resulting array.
- See:
- pigreads.helper.to_ithildin(framedur, dt, dz, dy, dx, models, states, inhom=None)¶
Convert the output of a Pigreads simulation to an Ithildin SimData object.
While originally designed for a different reaction-diffusion solver, the Python module for Ithildin is useful to analyse Pigreads simulations.
- Parameters:
framedur (
float) – The duration between subsequent frames, usually in milliseconds.dt (
float) – The time step size used inpigreads.models.Models.run(), usually in milliseconds.dz (
float) – The distance between points in the z-dimension, seepigreads.helper.deltas().dy (
float) – The distance between points in the y-dimension.dx (
float) – The distance between points in the x-dimension.models (
Models) – The models used in the simulation, seepigreads.models.Models.states (
ndarray[Any,Any]) – The states of the simulation, a 5D array of shape (Nt, Nz, Ny, Nx, Nv), seepigreads.models.Models.resting_states()andpigreads.models.Models.run().inhom (
ndarray[Any,Any] |None) – A 3D array with integer values, encoding which model to use at each point. Its value is zero for points outside the medium and one or more for points inside. IfNone, all points are considered inside the medium. (default:None)
- Return type:
- Returns:
Tuple of an Ithildin log file as a string and a dictionary of the variables by variable name.
Usage:
import ithildin as ith log, variables = pig.to_ithildin(Nt * dt, dt, dz, dy, dx, models, states, inhom) sd = ith.SimData(log=ith.Log(data=log)) sd.vars = variables