pytomography.utils.simind_mc#

Module Contents#

Functions#

save_attenuation_map(attenuation_map, dx, temp_path)

Save attenuation map as binary file to temporary directory for subsequent use by Monte Carlo scatter simulation.

save_source_map(source_map, temp_path, scaling[, vmax])

Save source map as binary file to temporary directory for subsequent use by Monte Carlo scatter simulation.

get_simind_params_from_metadata(object_meta, proj_meta)

Obtain dictionary of SIMIND parameters from object and projection metadata

get_simind_isotope_detector_params(isotope_name, ...)

Obtain SIMIND parameter dictionary from isotope and detector parameters

get_energy_window_params_dicom(file_NM[, idxs])

Obtain energy window parameters from a DICOM file: this includes a list of strings which, when written to a file, correspond to a typical "scattwin.win" file used by SIMIND.

get_energy_window_params_simind(headerfiles)

Obtain energy window parameters from a list of SIMIND header files: this includes a list of strings which, when written to a file, correspond to a typical "scattwin.win" file used by SIMIND.

create_simind_command(index_dict, parallel_idx)

Creates the terminal command to run SIMIND with the specified parameters

add_together(n_parallel, n_windows, temp_path)

Adds together all the parallel SIMIND simulations to obtain the final scatter and total projections

run_scatter_simulation(source_map, ...[, n_parallel, ...])

Runs a Monte Carlo scatter simulation using SIMIND

Attributes#

pytomography.utils.simind_mc.ENERGY_RESOLUTION_MODELS = ['siemens'][source]#
pytomography.utils.simind_mc.save_attenuation_map(attenuation_map, dx, temp_path)[source]#

Save attenuation map as binary file to temporary directory for subsequent use by Monte Carlo scatter simulation.

Parameters:
  • attenuation_map (torch.Tensor) – Attenuation map to save

  • dx (float) – Spacing of attenuation map in cm

  • temp_path (str) – Temporary folder to save to

pytomography.utils.simind_mc.save_source_map(source_map, temp_path, scaling, vmax=1000000.0)[source]#

Save source map as binary file to temporary directory for subsequent use by Monte Carlo scatter simulation.

Parameters:
  • source_map (torch.Tensor) – Source map to save

  • temp_path (str) – Temporary folder to save to

  • vmax (float, optional) – Maximum value of source map, prevents divergence at early iterations. Defaults to 1e6.

  • scaling (float) –

pytomography.utils.simind_mc.get_simind_params_from_metadata(object_meta, proj_meta)[source]#

Obtain dictionary of SIMIND parameters from object and projection metadata

Parameters:
  • object_meta (ObjectMeta) – SPECT object metadata used in reconstruction

  • proj_meta (SPECTProjMeta) – SPECT projection metadata used in reconstruction

Returns:

Dictionary of SIMIND parameters obtainable from object and projection metadata

Return type:

dict

pytomography.utils.simind_mc.get_simind_isotope_detector_params(isotope_name, collimator_type, cover_thickness, backscatter_thickness, crystal_thickness, energy_resolution_140keV=0, advanced_energy_resolution_model=None, advanced_collimator_modeling=False, random_collimator_movement=False)[source]#

Obtain SIMIND parameter dictionary from isotope and detector parameters

Parameters:
  • isotope_name (str) – Name of isotope used for Monte Carlo scatter simulation

  • collimator_type (str) – Collimator type used for Monte Carlo scatter simulation.

  • cover_thickness (float) – Cover thickness used for simulation. Currently assumes aluminum is used.

  • backscatter_thickness (float) – Equivalent backscatter thickness used for simulation. Currently assumes pyrex is used.

  • energy_resolution_140keV (float) – Energy resolution in percent of the detector at 140keV. Currently uses the relationship that resolution is proportional to sqrt(E) for E in keV.

  • advanced_collimator_modeling (bool, optional) – Whether or not to use advanced collimator modeling that can be used to model septal penetration and scatter. Defaults to False.

  • random_collimator_movement (bool, optional) – Whether or not to include random collimator movement (e.g. holes are not fixed in place). Defaults to False.

  • crystal_thickness (float) –

  • advanced_energy_resolution_model (str | None) –

Returns:

Dictionary of SIMIND parameters obtainable from isotope and detector parameters

Return type:

dict

pytomography.utils.simind_mc.get_energy_window_params_dicom(file_NM, idxs=None)[source]#

Obtain energy window parameters from a DICOM file: this includes a list of strings which, when written to a file, correspond to a typical “scattwin.win” file used by SIMIND.

Parameters:
  • file_NM (str) – DICOM projection file name

  • idxs (Sequence[int]) – Indices corresponding to the energy windows to extract. More than one index is provided in cases where multi-photopeak reconstruction is used and scatter needs to be obtained at all windows.

Returns:

Lines of the “scattwin.win” file corresponding to the energy windows specified by the indices.

Return type:

Sequence[str]

pytomography.utils.simind_mc.get_energy_window_params_simind(headerfiles)[source]#

Obtain energy window parameters from a list of SIMIND header files: this includes a list of strings which, when written to a file, correspond to a typical “scattwin.win” file used by SIMIND.

Parameters:

headerfiles (Sequence[str]) – SIMIND header files

Returns:

Lines of the “scattwin.win” file corresponding to the energy windows specified by the header files.

Return type:

Sequence[str]

pytomography.utils.simind_mc.create_simind_command(index_dict, parallel_idx)[source]#

Creates the terminal command to run SIMIND with the specified parameters

Parameters:
  • index_dict (dict) – Dictionary of SIMIND parameters

  • parallel_idx (int) – Random seed used for simulation, used to differentiate between parallel simulations

Returns:

Terminal command to run SIMIND with the specified parameters

Return type:

str

pytomography.utils.simind_mc.add_together(n_parallel, n_windows, temp_path)[source]#

Adds together all the parallel SIMIND simulations to obtain the final scatter and total projections

Parameters:
  • n_parallel (int) – Number of parallel simulations

  • n_windows (int) – Number of energy windows used in the simulation

  • temp_path (str) – Temporary directory where files were saved

pytomography.utils.simind_mc.run_scatter_simulation(source_map, attenuation_map_140keV, object_meta, proj_meta, energy_window_params, simind_index_dict, n_events, n_parallel=1, return_total=False)[source]#

Runs a Monte Carlo scatter simulation using SIMIND

Parameters:
  • source_map (torch.Tensor) – Source map used in the simulation

  • attenuation_map_140keV (torch.Tensor) – Attenuation map at 140keV used in the simulation

  • object_meta (ObjectMeta) – SPECT ObjectMeta used in reconstruction

  • proj_meta (SPECTProjMeta) – SPECT projection metadata used in reconstruction

  • energy_window_params (list) – List of strings which constitute a typical “scattwin.win” file used by SIMIND

  • primary_window_idxs (Sequence[int]) – Indices from the energy_window_params list corresponding to indices used as photopeak in reconstruction. For single photopeak reconstruction, this will be a list of length 1, while for multi-photopeak reconstruction, this will be a list of length > 1.

  • simind_index_dict (dict) – Dictionary of SIMIND parameters

  • n_events (int) – Number of events to simulate per projection angle

  • n_parallel (int, optional) – Number of simulations to perform in parallel, should not exceed number of CPU cores. Defaults to 1.

  • return_total (bool, optional) – Whether or not to also return the total projections. Defaults to False.

Returns:

Simulated projections

Return type:

torch.Tensor