opengate.sources.gansources =========================== .. py:module:: opengate.sources.gansources Classes ------- .. autoapisummary:: opengate.sources.gansources.VoxelizedSourcePDFSampler opengate.sources.gansources.VoxelizedSourceConditionGenerator opengate.sources.gansources.GANSource opengate.sources.gansources.GANPairsSource opengate.sources.gansources.GANSourceDefaultGenerator opengate.sources.gansources.GANSourceDefaultPairsGenerator opengate.sources.gansources.GANSourceConditionalGenerator opengate.sources.gansources.GANSourceConditionalPairsGenerator Functions --------- .. autoapisummary:: opengate.sources.gansources.import_gaga_phsp Module Contents --------------- .. py:function:: import_gaga_phsp() .. py:class:: VoxelizedSourcePDFSampler(itk_image, version=1) 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) .. py:attribute:: image .. py:attribute:: version .. py:attribute:: imga .. py:attribute:: pdf .. py:attribute:: linear_indices .. py:method:: init_cdf() .. py:method:: searchsorted2d(a, b) .. py:method:: sample_indices_slower(n, rs=np.random) This version seems slower than the other version with np random choice .. py:method:: samples_g4(n) .. py:method:: sample_indices(n, rs=np.random) .. py:method:: sample_indices_phys(n, rs=np.random) .. py:class:: VoxelizedSourceConditionGenerator(activity_source_filename, rs=np.random, use_activity_origin=False) .. py:attribute:: activity_source_filename .. py:attribute:: compute_directions :value: False .. py:attribute:: use_activity_origin .. py:attribute:: translation :value: [0, 0, 0] .. py:attribute:: rotation .. py:attribute:: image :value: None .. py:attribute:: rs .. py:attribute:: img_info :value: None .. py:attribute:: sampler :value: None .. py:attribute:: points_offset :value: None .. py:attribute:: is_initialized :value: False .. py:method:: initialize_source() .. py:method:: generate_condition(n) .. py:class:: GANSource(user_info) Bases: :py:obj:`opengate.sources.generic.GenericSource` GAN source: the Generator produces particles Input is a neural network Generator trained with a GAN .. py:attribute:: type_name :value: 'GANSource' .. py:method:: set_default_user_info(user_info) :staticmethod: .. py:method:: create_g4_source() .. py:method:: initialize(run_timing_intervals) .. py:method:: set_default_generator() .. py:class:: GANPairsSource(user_info) Bases: :py:obj:`GANSource` GAN source: the Generator produces pairs of particles (for PET) Input is a neural network Generator trained with a GAN .. py:attribute:: type_name :value: 'GANPairsSource' .. py:method:: set_default_user_info(user_info) :staticmethod: .. py:method:: create_g4_source() .. py:method:: set_default_generator() .. py:class:: GANSourceDefaultGenerator(user_info) 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. .. py:attribute:: user_info .. py:attribute:: gaga :value: None .. py:attribute:: indexes_are_build :value: None .. py:attribute:: lock :value: None .. py:attribute:: initialize_is_done :value: False .. py:attribute:: keys_output :value: None .. py:attribute:: gan_info :value: None .. py:attribute:: gpu_mode :value: None .. py:method:: __getstate__() .. py:method:: initialize() .. py:method:: read_gan_and_keys() .. py:method:: get_output_keys() .. py:method:: get_output_keys_with_lock() .. py:method:: check_parameters(g) .. py:method:: fatal(txt) .. py:method:: get_position_index(g, the_keys, n) .. py:method:: get_direction_index(g, the_keys, n) .. py:method:: get_energy_index(g, the_keys, n) .. py:method:: get_time_index(g, the_keys, n) .. py:method:: get_weight_index(g, the_keys, n) .. py:method:: get_gan_key_index(all_keys, user_keys, n) 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. .. py:method:: generator(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) .. py:method:: copy_generated_particle_to_g4(source, g, fake) .. py:method:: move_backward(g, fake) .. py:class:: GANSourceDefaultPairsGenerator(user_info) Bases: :py:obj:`GANSourceDefaultGenerator` Like GANSourceDefaultGenerator but for pairs of particle (PET) .. py:attribute:: is_paired :value: True .. py:method:: __getstate__() .. py:method:: check_parameters(g) .. py:method:: get_energy_index(g, the_keys, n) .. py:method:: get_time_index(g, the_keys, n) .. py:method:: get_weight_index(g, the_keys, n) .. py:method:: generator(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) .. py:method:: copy_generated_particle_to_g4(source, g, fake) .. py:method:: move_backward(g, fake) .. py:class:: GANSourceConditionalGenerator(user_info, generate_condition_function) Bases: :py:obj:`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. .. py:attribute:: generate_condition .. py:method:: generator(source) Generate particles with a GAN, considering conditional vectors. .. py:class:: GANSourceConditionalPairsGenerator(user_info, sphere_radius, generate_condition_function) Bases: :py:obj:`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. .. py:attribute:: sphere_radius .. py:attribute:: generate_condition .. py:method:: __getstate__() .. py:method:: generator(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)