3.10.1.20.1.3. opengate.sources.gansources

3.10.1.20.1.3.1. Classes

VoxelizedSourcePDFSampler

This is an alternative to GateSPSVoxelsPosDistribution (c++)

VoxelizedSourceConditionGenerator

GANSource

GAN source: the Generator produces particles

GANPairsSource

GAN source: the Generator produces pairs of particles (for PET)

GANSourceDefaultGenerator

This class manage the base components of a particle generator.

GANSourceDefaultPairsGenerator

Like GANSourceDefaultGenerator but for pairs of particle (PET)

GANSourceConditionalGenerator

This class manage the base components of a particle generator.

GANSourceConditionalPairsGenerator

Generate pairs of particles with a GAN, considering conditional vectors.

3.10.1.20.1.3.2. Functions

import_gaga_phsp()

3.10.1.20.1.3.3. Module Contents

opengate.sources.gansources.import_gaga_phsp()[source]
class opengate.sources.gansources.VoxelizedSourcePDFSampler(itk_image, version=1)[source]

This is an alternative to GateSPSVoxelsPosDistribution (c++) It is needed because the cond voxel source is used on python side.

There are two versions, version 2 is much slower (do not use)

image[source]
version[source]
imga[source]
pdf[source]
linear_indices[source]
init_cdf()[source]
searchsorted2d(a, b)[source]
sample_indices_slower(n, rs=np.random)[source]

This version seems slower than the other version with np random choice

samples_g4(n)[source]
sample_indices(n, rs=np.random)[source]
sample_indices_phys(n, rs=np.random)[source]
class opengate.sources.gansources.VoxelizedSourceConditionGenerator(activity_source_filename, rs=np.random, use_activity_origin=False)[source]
activity_source_filename[source]
compute_directions = False[source]
use_activity_origin[source]
translation = [0, 0, 0][source]
rotation[source]
image = None[source]
rs[source]
img_info = None[source]
sampler = None[source]
points_offset = None[source]
is_initialized = False[source]
initialize_source()[source]
generate_condition(n)[source]
class opengate.sources.gansources.GANSource(user_info)[source]

Bases: opengate.sources.generic.GenericSource

GAN source: the Generator produces particles Input is a neural network Generator trained with a GAN

type_name = 'GANSource'[source]
static set_default_user_info(user_info)[source]
create_g4_source()[source]
initialize(run_timing_intervals)[source]
set_default_generator()[source]
class opengate.sources.gansources.GANPairsSource(user_info)[source]

Bases: GANSource

GAN source: the Generator produces pairs of particles (for PET) Input is a neural network Generator trained with a GAN

type_name = 'GANPairsSource'[source]
static set_default_user_info(user_info)[source]
create_g4_source()[source]
set_default_generator()[source]
class opengate.sources.gansources.GANSourceDefaultGenerator(user_info)[source]

This class manage the base components of a particle generator.

  • In the constructor, the module ‘gaga’ is imported. It is only imported in the constructor to only required

this module if it is used

  • ‘initialize’ function: the GAN is loaded and the list of keys is initialized

  • ‘generator’ function: default generator

  • ‘get_output_keys’ function: map the user defined keys to the ones of the generator. There are two usages, either

with on single primary (3 values for position, direction), or paired primary (6 values).

  • ‘move_backward’ function: consider all particles positions and move their backward according to their direction,

using the factor provided by the user in ‘user_info.backward_distance’. This is useful to allow generating particles that do not intersect with the detector.

  • ‘copy_generated_particle_to_g4’ function: copy all the particles (pos, dir, time, energy) to the cpp part.

user_info[source]
gaga = None[source]
indexes_are_build = None[source]
lock = None[source]
initialize_is_done = False[source]
keys_output = None[source]
gan_info = None[source]
gpu_mode = None[source]
__getstate__()[source]
initialize()[source]
read_gan_and_keys()[source]
get_output_keys()[source]
get_output_keys_with_lock()[source]
check_parameters(g)[source]
fatal(txt)[source]
get_position_index(g, the_keys, n)[source]
get_direction_index(g, the_keys, n)[source]
get_energy_index(g, the_keys, n)[source]
get_time_index(g, the_keys, n)[source]
get_weight_index(g, the_keys, n)[source]
get_gan_key_index(all_keys, user_keys, n)[source]

Consider ‘user_keys’ in the list of all keys and return the indexes Special case: if the key name is a float value, we consider the value instead of the index.

generator(source)[source]

Main function that will be called from the cpp side every time a batch of particles should be created. Once created here, the particles are copied to cpp. (Yes maybe the copy could be avoided, but I did not manage to do it)

copy_generated_particle_to_g4(source, g, fake)[source]
move_backward(g, fake)[source]
class opengate.sources.gansources.GANSourceDefaultPairsGenerator(user_info)[source]

Bases: GANSourceDefaultGenerator

Like GANSourceDefaultGenerator but for pairs of particle (PET)

is_paired = True[source]
__getstate__()[source]
check_parameters(g)[source]
get_energy_index(g, the_keys, n)[source]
get_time_index(g, the_keys, n)[source]
get_weight_index(g, the_keys, n)[source]
generator(source)[source]

Main function that will be called from the cpp side every time a batch of particles should be created. Once created here, the particles are copied to cpp. (Yes maybe the copy could be avoided, but I did not manage to do it)

copy_generated_particle_to_g4(source, g, fake)[source]
move_backward(g, fake)[source]
class opengate.sources.gansources.GANSourceConditionalGenerator(user_info, generate_condition_function)[source]

Bases: GANSourceDefaultGenerator

This class manage the base components of a particle generator.

  • In the constructor, the module ‘gaga’ is imported. It is only imported in the constructor to only required

this module if it is used

  • ‘initialize’ function: the GAN is loaded and the list of keys is initialized

  • ‘generator’ function: default generator

  • ‘get_output_keys’ function: map the user defined keys to the ones of the generator. There are two usages, either

with on single primary (3 values for position, direction), or paired primary (6 values).

  • ‘move_backward’ function: consider all particles positions and move their backward according to their direction,

using the factor provided by the user in ‘user_info.backward_distance’. This is useful to allow generating particles that do not intersect with the detector.

  • ‘copy_generated_particle_to_g4’ function: copy all the particles (pos, dir, time, energy) to the cpp part.

generate_condition[source]
generator(source)[source]

Generate particles with a GAN, considering conditional vectors.

class opengate.sources.gansources.GANSourceConditionalPairsGenerator(user_info, sphere_radius, generate_condition_function)[source]

Bases: GANSourceDefaultPairsGenerator

Generate pairs of particles with a GAN, considering conditional vectors.

The parameter sphere_radius is required : it is the radius of the sphere that surround the source during the training.

sphere_radius[source]
generate_condition[source]
__getstate__()[source]
generator(source)[source]

Main function that will be called from the cpp side every time a batch of particles should be created. Once created here, the particles are copied to cpp. (Yes maybe the copy could be avoided, but I did not manage to do it)