Voxelized source#

Description#

A voxelized source can be created as follows:

source = sim.add_source('VoxelSource', 'vox')
source.particle = 'e-'
source.activity = 4000 * Bq
source.image = 'an_activity_image.mhd'
source.direction.type = 'iso'
source.energy.mono = 100 * keV
source.attached_to = 'my_volume_name'

This code create a voxelized source. The 3D activity distribution is read from the given image. This image is internally normalized such that the sum of all pixels values is 1, leading to a 3D probability distribution. Particles will be randomly located somewhere in the image according to this probability distribution. Note that once an activity voxel is chosen from this distribution, the location of the particle inside the voxel is performed uniformly. In the given example, 4 kBq of electrons of 140 keV will be generated.

The voxel image is therefore used as a relative spatial activity distribution for position sampling. Scaling all voxel values by the same constant does not change the total emitted activity; it leaves the same normalized spatial distribution. The total source strength is controlled separately by activity, half_life, or n.

How the voxel is sampled#

The voxel of each particle is drawn with an alias table (Walker’s method, built with Vose’s algorithm). The table is built once, at initialisation, from the normalized image, and contains only the voxels with a non-zero value. Each entry is a voxel, a probability q and a second voxel (its “alias”). To sample, one random number selects an entry uniformly; its fractional part is compared to q to keep the voxel of the entry or take its alias. The cost per particle is one random number and one memory access, whatever the size of the image.

It gives exactly the same distribution as sampling the voxels one after the other along z, y and x, which needs three binary searches in large cumulative tables. The difference is only in speed, about 0.06 µs per particle instead of 0.4 to 0.9 µs for a CT-sized image. It matters when the transport of a particle is cheap compared to its emission, or when the images are large, for example:

  • large activity images (fine voxels, whole body), or many voxel sources in the same simulation (one per organ, per region or per time point), that do not fit in the processor caches;

  • particles that are tracked for only a few steps: low-energy electrons or beta particles that deposit their energy close to the emission point, simulations without a phantom, or a coarse geometry;

  • variance reduction that makes the transport faster, such as the free flight of photons (GammaFreeFlightActor) or a faster navigation in the image volumes (see Details: Volumes).

When most of the time is spent tracking particles in a detailed geometry, the gain is only a few percent.

The table needs 12 bytes per non-zero voxel. It is small for a sparse image (a few spheres, lesions or organs); when all the voxels are non-zero it is three times the size of the image in floats. An image with 2^32 voxels or more is refused. A dynamic image rebuilds the table at each change.

The image and its table are in memory only once: they are shared by the threads, and by all the voxel sources that read the same image file (for example the copies of a source made with sim.source_manager.add_source_copy, one per detector head or per energy line). The cumulative tables used to build the alias table are not kept.

The activity image can also be made dynamic from one run to the next with source.add_dynamic_parametrisation(image=[...]). See Dynamic parametrisations.

Like all objects, by default, the source is located according to the coordinate system of its attached_to volume. For example, if the attached_to volume is a box, it will be the center of the box. If it is a voxelized volume (typically a CT image), it will the center of this image: the image own coordinate system (ITK’s origin) is not considered here. If you want to align a voxelized activity with a CT image that have the same coordinate system you should compute the correct translation. This is done by the function opengate.image.get_translation_between_images_center(). See the contrib example dose_rate.py.

../_images/image_coord_system.png

The direction matrix of the activity image (the rotation or flip stored in its header) is not taken into account. To avoid silently mirroring or rotating the activity, the simulation stops with an error if the image direction is not the identity. The same rule applies to the image volume the source is attached to (see Details: Volumes), so that the CT and the activity image are always interpreted in the same way.

Reference#

get_translation_between_images_center(img_name1, img_name2)[source]#

The two images are considered in the same physical space (coordinate system). This function computes the translation between their centers. Warning, the ITK image origin consider the center of the first voxel, we thus consider half a pixel shift for the center.

class VoxelSource(*args, **kwargs)[source]#

VoxelSource = 3D activity distribution. Sampled with an alias table built from the cumulative distribution functions (CDFs) of the image. The image and the table are shared by the sources (and the thread-local sources) that read the same image file.

User input parameters and default values:

  • activity:

    • Default value: 0

    • Description: Activity of the source in Bq (exclusive with ‘number_of_primaries’)

  • attached_to:

    • Default value: world

    • Description: Name of the volume to which the source is attached.

  • direction:

    • Default value: {‘type’: ‘iso’, ‘theta’: [0, 3.141592653589793], ‘phi’: [0, 6.283185307179586], ‘momentum’: [0, 0, 1], ‘focus_point’: [0, 0, 0], ‘sigma’: [0, 0], ‘angular_acceptance’: {‘policy’: None, ‘skip_policy’: ‘SkipEvents’, ‘max_rejection’: 10000, ‘target_volumes’: [], ‘enable_intersection_check’: False, ‘enable_angle_check’: False, ‘angle_check_reference_vector’: [0, 0, 1], ‘angle_check_proximity_distance’: 0.0, ‘angle_tolerance_proximal’: 1.5707963267948966, ‘angle_tolerance_min’: 0.0, ‘angle_tolerance_max’: 0.10471975511965978, ‘angle_sampling’: ‘uniform’, ‘angle_sampling_scale’: 0.08726646259971647}, ‘accolinearity_flag’: False, ‘accolinearity_fwhm’: 0.008726646259971648, ‘histogram_theta_weights’: [], ‘histogram_theta_angles’: [], ‘histogram_phi_weights’: [], ‘histogram_phi_angles’: []}

    • Description: Define the direction of the primary particles

  • direction_relative_to_attached_volume:

    • Default value: False

    • Description: Should we update the direction of the particle when the volume is moved (with dynamic parametrisation)?

  • dynamic_params (set internally, i.e. read-only):

    • Default value: None

    • Description: Dictionary of dictionaries, where each dictionary specifies how the parameters of this object should evolve over time during the simulation. You cannot set this parameter directly. Instead, use the ‘add_dynamic_parametrisation()’ method of your object.If None, the object is static (default).

  • end_time:

    • Default value: None

    • Description: End time of the source

  • energy:

    • Default value: {‘type’: ‘mono’, ‘mono’: 0, ‘sigma_gauss’: 0, ‘is_cdf’: False, ‘min_energy’: None, ‘max_energy’: None, ‘spectrum_type’: None, ‘spectrum_weights’: [], ‘spectrum_energies’: [], ‘histogram_weight’: [], ‘histogram_energy’: [], ‘spectrum_energy_bin_edges’: [], ‘spectrum_histogram_interpolation’: None}

    • Description: Define the energy of the primary particles

  • half_life:

    • Default value: -1

    • Description: Half-life decay (-1 if no decay). Only when used with ‘activity’

  • image:

    • Default value: None

    • Description: Filename of the image of the 3D activity distribution (will be automatically normalized to sum=1)

  • ion:

    • Default value: {‘Z’: 0, ‘A’: 0, ‘E’: 0}

    • Description: If the particle is an ion, you must set Z: Atomic Number, A: Atomic Mass (nn + np +nlambda), E: Excitation energy (i.e. for metastable)

  • mother:

    • Deprecated: The user input parameter ‘mother’ is deprecated. Use ‘attached_to’ instead.

  • n:

    • Deprecated: The user input parameter ‘n’ is deprecated. Use ‘number_of_primaries’ instead.

  • name (must be provided):

    • Default value: None

  • number_of_primaries:

    • Default value: 0

    • Description: Number of primaries to generate (exclusive with ‘activity’)

  • particle:

    • Default value: gamma

    • Description: Name of the particle generated by the source (gamma, e+ … or an ion such as ‘ion 9 18’)

  • polarization:

    • Default value: []

    • Description: Polarization of the particle (3 Stokes parameters).

  • position:

    • Default value: {‘type’: ‘point’, ‘radius’: 0, ‘sigma_x’: 0, ‘sigma_y’: 0, ‘size’: [0, 0, 0], ‘translation’: [0, 0, 0], ‘rotation’: array([[1., 0., 0.],, [0., 1., 0.],, [0., 0., 1.]]), ‘confine’: None, ‘dz’: None}

    • Description: Define the position of the primary particles

  • start_time:

    • Default value: None

    • Description: Starting time of the source

  • tac_activities:

    • Default value: None

    • Description: TAC: Time Activity Curve, this set the vector for the activities. Must be used with tac_times.

  • tac_times:

    • Default value: None

    • Description: TAC: Time Activity Curve, this set the vector for the times. Must be used with tac_activities. The activity is linearly interpolated between the times, and zero outside.

  • user_particle_life_time:

    • Default value: -1

    • Description: FIXME

  • visualization:

    • Default value: {‘count’: 2000, ‘color’: ‘yellow’, ‘size’: 2}

    • Description: count is the number of particles to visualize, color is the color of the visualized particles and size is their size (in mm).

  • weight:

    • Default value: -1

    • Description: Particle initial weight (for variance reduction technique)

  • weight_sigma:

    • Default value: -1

    • Description: if not negative, the weights of the particle are a Gaussian distribution with this sigma