nanopyx.core.generate.simulate_particle_field

def simulate_particle_field_based_on_2D_PDF( image_pdf, min_particles: int = 10, max_particles: int = 1000, min_distance: float = 0.1, mean_distance_threshold: float = 0.0, normalize: 'bint' = 1, max_tries=3):

Simulate a particle field based on a 2D probability density function (PDF)

Parameters
  • image_pdf: 2D array of floats, the PDF
  • min_particles: int, the minimum number of particles to simulate
  • max_particles: int, the maximum number of particles to simulate
  • min_distance: float, ensure that paricle distances are above minimum distance given
  • mean_distance_threshold: float, the mean distance between closest particles, if the mean distance is below this threshold, the simulation will stop
  • normalize: bint, whether or not the image requires normalization
  • max_tries: int, the maximum number of tries to place particles before giving up
Returns

(2D array of floats, mean closest distance), for the first tupple element the shape is (n_particles, 2) where the last dimension is the x and y coordinates of the simulated particle

The code does the following:

  1. It samples the image PDF and places a particle at a point with a probability that is proportional to the PDF at that point.
  2. It places the particles such that no two particles are closer than min_distance pixels.
  3. It stops placing particles once the mean distance between all particles is less than mean_distance_threshold pixels.

Example:

>>> import numpy as np
>>> image_pdf = np.random.random((100, 200)).astype(np.float32)
>>> particles = simulate_particle_field_based_on_2D_PDF(image_pdf, min_particles=100, mean_distance_threshold=0.1)
def get_closest_distance(particle_field):

Get the closest distance between all particles

Parameters
  • particle_field: 2D array of floats, the particle field
Returns

double, the closest distance between all particles

def render_particle_histogram(particle_field, h, w, amplitude, sigma_x, sigma_y):

Render a particle field as an image

Parameters
  • particle_field: 2D array of floats, the particle field with shape (n_particles, 2) where the last dimension is the x and y coordinates of the particle
  • w: int, the width of the image
  • h: int, the height of the image
Returns

2D array of floats, the rendered particle field

def render_particle_histogram_with_tracks(particle_field, states, h, w):

Render a particle field as an image stack

Parameters
  • particle_field: 2D array of floats, the particle field
  • states: 2D array of ints, the states of the particles
  • w: int, the width of the stack (in pixels)
  • h: int, the height of the stack (in pixels)
Returns

3D array of floats, the rendered particle field

def render_particle_gaussians_with_tracks(particle_field, states, h, w, amplitude, sigma_x, sigma_y):