pytomography.io.PET.prd#

Submodules#

Package Contents#

Classes#

OutOfRangeEnum

Enum that allows values outside of the its defined values.

DateTime

A basic datetime with nanosecond precision, always in UTC.

Time

A basic time of day with nanosecond precision. It is not timezone-aware and is meant

UnionCase

Helper class that provides a standard way to create an ABC using

CoincidenceEvent

All information about a coincidence event specified as identifiers or indices (i.e. discretized).

Detector

Detector ID and location. Units are in mm

ExamInformation

Items describing the exam (incomplete)

Header

Institution

ScannerInformation

Subject

TimeBlock

TimeFrameInformation

A sequence of time intervals (could be consecutive)

TimeInterval

Time interval in milliseconds since start of acquisition

PrdExperimentReaderBase

Abstract reader for the PrdExperiment protocol.

PrdExperimentWriterBase

Abstract writer for the PrdExperiment protocol.

BinaryPrdExperimentReader

Binary writer for the PrdExperiment protocol.

BinaryPrdExperimentWriter

Binary writer for the PrdExperiment protocol.

NDJsonPrdExperimentReader

NDJson writer for the PrdExperiment protocol.

NDJsonPrdExperimentWriter

NDJson writer for the PrdExperiment protocol.

Functions#

_parse_version(version)

structural_equal(a, b)

Attributes#

_MIN_NUMPY_VERSION

Int8

UInt8

Int16

UInt16

Int32

UInt32

Int64

UInt64

Size

Float32

Float64

ComplexFloat

ComplexDouble

_T

get_dtype

pytomography.io.PET.prd._MIN_NUMPY_VERSION = (1, 22, 0)[source]#
pytomography.io.PET.prd._parse_version(version)[source]#
Parameters:

version (str) –

Return type:

Tuple[int, Ellipsis]

exception pytomography.io.PET.prd.ProtocolError[source]#

Bases: Exception

Raised when the contract of a protocol is not respected.

class pytomography.io.PET.prd.OutOfRangeEnum[source]#

Bases: enum.Enum

Enum that allows values outside of the its defined values.

classmethod _missing_(value)[source]#
Parameters:

value (object) –

__eq__(other)[source]#

Return self==value.

Parameters:

other (object) –

__hash__()[source]#

Return hash(self).

Return type:

int

__str__()[source]#

Return str(self).

Return type:

str

__repr__()[source]#

Return repr(self).

Return type:

str

class pytomography.io.PET.prd.DateTime(nanoseconds_from_epoch=0)[source]#

A basic datetime with nanosecond precision, always in UTC.

Parameters:

nanoseconds_from_epoch (Union[int, numpy.datetime64]) –

property numpy_value: numpy.datetime64#
Return type:

numpy.datetime64

to_datetime()[source]#
Return type:

datetime.datetime

static from_components(year, month, day, hour=0, minute=0, second=0, nanosecond=0)[source]#
Parameters:
  • year (int) –

  • month (int) –

  • day (int) –

  • hour (int) –

  • minute (int) –

  • second (int) –

  • nanosecond (int) –

Return type:

DateTime

static from_datetime(dt)[source]#
Parameters:

dt (datetime.datetime) –

Return type:

DateTime

static parse(s)[source]#
Parameters:

s (str) –

Return type:

DateTime

static now()[source]#
Return type:

DateTime

__str__()[source]#

Return str(self).

Return type:

str

__repr__()[source]#

Return repr(self).

Return type:

str

__eq__(other)[source]#

Return self==value.

Parameters:

other (object) –

Return type:

bool

__hash__()[source]#

Return hash(self).

Return type:

int

class pytomography.io.PET.prd.Time(nanoseconds_since_midnight=0)[source]#

A basic time of day with nanosecond precision. It is not timezone-aware and is meant to represent a wall clock time.

Parameters:

nanoseconds_since_midnight (Union[int, numpy.timedelta64]) –

property numpy_value: numpy.timedelta64#
Return type:

numpy.timedelta64

_NANOSECONDS_PER_DAY#
static from_components(hour, minute, second=0, nanosecond=0)[source]#
Parameters:
  • hour (int) –

  • minute (int) –

  • second (int) –

  • nanosecond (int) –

Return type:

Time

static from_time(t)[source]#
Parameters:

t (datetime.time) –

Return type:

Time

static parse(s)[source]#
Parameters:

s (str) –

Return type:

Time

__str__()[source]#

Return str(self).

Return type:

str

__repr__()[source]#

Return repr(self).

Return type:

str

__eq__(other)[source]#

Return self==value.

Parameters:

other (object) –

Return type:

bool

pytomography.io.PET.prd.Int8[source]#
pytomography.io.PET.prd.UInt8[source]#
pytomography.io.PET.prd.Int16[source]#
pytomography.io.PET.prd.UInt16[source]#
pytomography.io.PET.prd.Int32[source]#
pytomography.io.PET.prd.UInt32[source]#
pytomography.io.PET.prd.Int64[source]#
pytomography.io.PET.prd.UInt64[source]#
pytomography.io.PET.prd.Size[source]#
pytomography.io.PET.prd.Float32[source]#
pytomography.io.PET.prd.Float64[source]#
pytomography.io.PET.prd.ComplexFloat[source]#
pytomography.io.PET.prd.ComplexDouble[source]#
pytomography.io.PET.prd.structural_equal(a, b)[source]#
Parameters:
  • a (object) –

  • b (object) –

Return type:

bool

pytomography.io.PET.prd._T[source]#
class pytomography.io.PET.prd.UnionCase(value)[source]#

Bases: abc.ABC, Generic[_T]

Helper class that provides a standard way to create an ABC using inheritance.

Parameters:

value (_T) –

index: int#
tag: str#
__str__()[source]#

Return str(self).

Return type:

str

__repr__()[source]#

Return repr(self).

Return type:

str

__eq__(other)[source]#

Return self==value.

Parameters:

other (object) –

Return type:

bool

class pytomography.io.PET.prd.CoincidenceEvent(*, detector_1_id=0, detector_2_id=0, tof_idx=0, energy_1_idx=0, energy_2_idx=0)[source]#

All information about a coincidence event specified as identifiers or indices (i.e. discretized). TODO: this might take up too much space, so some/all of these could be combined in a single index if necessary.

Parameters:
  • detector_1_id (pytomography.io.PET.prd.yardl_types.UInt32) –

  • detector_2_id (pytomography.io.PET.prd.yardl_types.UInt32) –

  • tof_idx (pytomography.io.PET.prd.yardl_types.UInt32) –

  • energy_1_idx (pytomography.io.PET.prd.yardl_types.UInt32) –

  • energy_2_idx (pytomography.io.PET.prd.yardl_types.UInt32) –

detector_1_id: pytomography.io.PET.prd.yardl_types.UInt32#
detector_2_id: pytomography.io.PET.prd.yardl_types.UInt32#
tof_idx: pytomography.io.PET.prd.yardl_types.UInt32#
energy_1_idx: pytomography.io.PET.prd.yardl_types.UInt32#
energy_2_idx: pytomography.io.PET.prd.yardl_types.UInt32#
__eq__(other)[source]#

Return self==value.

Parameters:

other (object) –

Return type:

bool

__str__()[source]#

Return str(self).

Return type:

str

__repr__()[source]#

Return repr(self).

Return type:

str

class pytomography.io.PET.prd.Detector(*, id=0, x=0.0, y=0.0, z=0.0)[source]#

Detector ID and location. Units are in mm TODO: this is currently just a sample implementation with “point” detectors. We plan to have full shape information here.

Parameters:
  • id (pytomography.io.PET.prd.yardl_types.UInt32) –

  • x (pytomography.io.PET.prd.yardl_types.Float32) –

  • y (pytomography.io.PET.prd.yardl_types.Float32) –

  • z (pytomography.io.PET.prd.yardl_types.Float32) –

id: pytomography.io.PET.prd.yardl_types.UInt32#
x: pytomography.io.PET.prd.yardl_types.Float32#
y: pytomography.io.PET.prd.yardl_types.Float32#
z: pytomography.io.PET.prd.yardl_types.Float32#
__eq__(other)[source]#

Return self==value.

Parameters:

other (object) –

Return type:

bool

__str__()[source]#

Return str(self).

Return type:

str

__repr__()[source]#

Return repr(self).

Return type:

str

class pytomography.io.PET.prd.ExamInformation(*, subject=None, institution=None, protocol=None, start_of_acquisition=None)[source]#

Items describing the exam (incomplete)

Parameters:
subject: Subject#
institution: Institution#
protocol: str | None#
start_of_acquisition: pytomography.io.PET.prd.yardl_types.DateTime | None#
__eq__(other)[source]#

Return self==value.

Parameters:

other (object) –

Return type:

bool

__str__()[source]#

Return str(self).

Return type:

str

__repr__()[source]#

Return repr(self).

Return type:

str

class pytomography.io.PET.prd.Header(*, scanner=None, exam=None)[source]#
Parameters:
scanner: ScannerInformation#
exam: ExamInformation | None#
__eq__(other)[source]#

Return self==value.

Parameters:

other (object) –

Return type:

bool

__str__()[source]#

Return str(self).

Return type:

str

__repr__()[source]#

Return repr(self).

Return type:

str

class pytomography.io.PET.prd.Institution(*, name='', address='')[source]#
Parameters:
  • name (str) –

  • address (str) –

name: str#
address: str#
__eq__(other)[source]#

Return self==value.

Parameters:

other (object) –

Return type:

bool

__str__()[source]#

Return str(self).

Return type:

str

__repr__()[source]#

Return repr(self).

Return type:

str

class pytomography.io.PET.prd.ScannerInformation(*, model_name=None, detectors=None, tof_bin_edges=None, tof_resolution=0.0, energy_bin_edges=None, energy_resolution_at_511=0.0, listmode_time_block_duration=0)[source]#
Parameters:
  • model_name (Optional[str]) –

  • detectors (Optional[list[Detector]]) –

  • tof_bin_edges (Optional[numpy.typing.NDArray[numpy.float32]]) –

  • tof_resolution (pytomography.io.PET.prd.yardl_types.Float32) –

  • energy_bin_edges (Optional[numpy.typing.NDArray[numpy.float32]]) –

  • energy_resolution_at_511 (pytomography.io.PET.prd.yardl_types.Float32) –

  • listmode_time_block_duration (pytomography.io.PET.prd.yardl_types.UInt32) –

model_name: str | None#
detectors: list[Detector]#
tof_bin_edges: numpy.typing.NDArray[numpy.float32]#

edge information for TOF bins in mm (given as from first to last edge, so there is one more edge than the number of bins) TODO: this currently assumes equal size for each TOF bin, but some scanners “stretch” TOF bins depending on length of LOR

tof_resolution: pytomography.io.PET.prd.yardl_types.Float32#

TOF resolution in mm

energy_bin_edges: numpy.typing.NDArray[numpy.float32]#

edge information for energy windows in keV (given as from first to last edge, so there is one more edge than the number of bins)

energy_resolution_at_511: pytomography.io.PET.prd.yardl_types.Float32#

FWHM of photopeak for incoming gamma of 511 keV, expressed as a ratio w.r.t. 511

listmode_time_block_duration: pytomography.io.PET.prd.yardl_types.UInt32#

duration of each time block in ms

number_of_detectors()[source]#
Return type:

pytomography.io.PET.prd.yardl_types.Size

number_of_tof_bins()[source]#
Return type:

pytomography.io.PET.prd.yardl_types.Size

number_of_energy_bins()[source]#
Return type:

pytomography.io.PET.prd.yardl_types.Size

__eq__(other)[source]#

Return self==value.

Parameters:

other (object) –

Return type:

bool

__str__()[source]#

Return str(self).

Return type:

str

__repr__()[source]#

Return repr(self).

Return type:

str

class pytomography.io.PET.prd.Subject(*, name=None, id='')[source]#
Parameters:
  • name (Optional[str]) –

  • id (str) –

name: str | None#
id: str#
__eq__(other)[source]#

Return self==value.

Parameters:

other (object) –

Return type:

bool

__str__()[source]#

Return str(self).

Return type:

str

__repr__()[source]#

Return repr(self).

Return type:

str

class pytomography.io.PET.prd.TimeBlock(*, id=0, prompt_events=None, delayed_events=None)[source]#
Parameters:
  • id (pytomography.io.PET.prd.yardl_types.UInt32) –

  • prompt_events (Optional[list[CoincidenceEvent]]) –

  • delayed_events (Optional[list[CoincidenceEvent]]) –

id: pytomography.io.PET.prd.yardl_types.UInt32#

number of the block. Multiply with listmodeTimeBlockDuration to get time since startOfAcquisition

prompt_events: list[CoincidenceEvent]#

list of prompts in this time block TODO might be better to use !array

delayed_events: list[CoincidenceEvent] | None#

list of delayed coincidences in this time block

__eq__(other)[source]#

Return self==value.

Parameters:

other (object) –

Return type:

bool

__str__()[source]#

Return str(self).

Return type:

str

__repr__()[source]#

Return repr(self).

Return type:

str

class pytomography.io.PET.prd.TimeFrameInformation(*, time_frames=None)[source]#

A sequence of time intervals (could be consecutive)

Parameters:

time_frames (Optional[list[TimeInterval]]) –

time_frames: list[TimeInterval]#
number_of_time_frames()[source]#
Return type:

pytomography.io.PET.prd.yardl_types.Size

__eq__(other)[source]#

Return self==value.

Parameters:

other (object) –

Return type:

bool

__str__()[source]#

Return str(self).

Return type:

str

__repr__()[source]#

Return repr(self).

Return type:

str

class pytomography.io.PET.prd.TimeInterval(*, start=0, stop=0)[source]#

Time interval in milliseconds since start of acquisition

Parameters:
  • start (pytomography.io.PET.prd.yardl_types.UInt32) –

  • stop (pytomography.io.PET.prd.yardl_types.UInt32) –

start: pytomography.io.PET.prd.yardl_types.UInt32#
stop: pytomography.io.PET.prd.yardl_types.UInt32#
__eq__(other)[source]#

Return self==value.

Parameters:

other (object) –

Return type:

bool

__str__()[source]#

Return str(self).

Return type:

str

__repr__()[source]#

Return repr(self).

Return type:

str

pytomography.io.PET.prd.get_dtype[source]#
class pytomography.io.PET.prd.PrdExperimentReaderBase[source]#

Bases: abc.ABC

Abstract reader for the PrdExperiment protocol.

schema#
T#
__enter__()[source]#
__exit__(exc_type, exc, traceback)[source]#
Parameters:
  • exc_type (pytomography.io.PET.prd.types.typing.Optional[type[BaseException]]) –

  • exc (pytomography.io.PET.prd.types.typing.Optional[BaseException]) –

  • traceback (object) –

Return type:

None

abstract close()[source]#
Return type:

None

read_header()[source]#

Ordinal 0

Return type:

pytomography.io.PET.prd.types.Header

read_time_blocks()[source]#

Ordinal 1

Return type:

collections.abc.Iterable[pytomography.io.PET.prd.types.TimeBlock]

copy_to(writer)[source]#
Parameters:

writer (PrdExperimentWriterBase) –

Return type:

None

abstract _read_header()[source]#
Return type:

pytomography.io.PET.prd.types.Header

abstract _read_time_blocks()[source]#
Return type:

collections.abc.Iterable[pytomography.io.PET.prd.types.TimeBlock]

_wrap_iterable(iterable, final_state)[source]#
Parameters:
  • iterable (collections.abc.Iterable[T]) –

  • final_state (int) –

Return type:

collections.abc.Iterable[T]

_raise_unexpected_state(actual)[source]#
Parameters:

actual (int) –

Return type:

None

_state_to_method_name(state)[source]#
Parameters:

state (int) –

Return type:

str

class pytomography.io.PET.prd.PrdExperimentWriterBase[source]#

Bases: abc.ABC

Abstract writer for the PrdExperiment protocol.

schema = '{"protocol":{"name":"PrdExperiment","sequence":[{"name":"header","type":"Prd.Header"},{"name":"ti...'#
__enter__()[source]#
__exit__(exc_type, exc, traceback)[source]#
Parameters:
  • exc_type (pytomography.io.PET.prd.types.typing.Optional[type[BaseException]]) –

  • exc (pytomography.io.PET.prd.types.typing.Optional[BaseException]) –

  • traceback (object) –

Return type:

None

write_header(value)[source]#

Ordinal 0

Parameters:

value (pytomography.io.PET.prd.types.Header) –

Return type:

None

write_time_blocks(value)[source]#

Ordinal 1

Parameters:

value (collections.abc.Iterable[pytomography.io.PET.prd.types.TimeBlock]) –

Return type:

None

abstract _write_header(value)[source]#
Parameters:

value (pytomography.io.PET.prd.types.Header) –

Return type:

None

abstract _write_time_blocks(value)[source]#
Parameters:

value (collections.abc.Iterable[pytomography.io.PET.prd.types.TimeBlock]) –

Return type:

None

abstract close()[source]#
Return type:

None

abstract _end_stream()[source]#
Return type:

None

_raise_unexpected_state(actual)[source]#
Parameters:

actual (int) –

Return type:

None

_state_to_method_name(state)[source]#
Parameters:

state (int) –

Return type:

str

class pytomography.io.PET.prd.BinaryPrdExperimentReader(stream)[source]#

Bases: pytomography.io.PET.prd._binary.BinaryProtocolReader, pytomography.io.PET.prd.protocols.PrdExperimentReaderBase

Binary writer for the PrdExperiment protocol.

Parameters:

stream (pytomography.io.PET.prd.protocols.typing.Union[io.BufferedReader, io.BytesIO, pytomography.io.PET.prd.protocols.typing.BinaryIO, str]) –

_read_header()[source]#
Return type:

pytomography.io.PET.prd.protocols.Header

_read_time_blocks()[source]#
Return type:

pytomography.io.PET.prd.protocols.collections.abc.Iterable[pytomography.io.PET.prd.protocols.TimeBlock]

class pytomography.io.PET.prd.BinaryPrdExperimentWriter(stream)[source]#

Bases: pytomography.io.PET.prd._binary.BinaryProtocolWriter, pytomography.io.PET.prd.protocols.PrdExperimentWriterBase

Binary writer for the PrdExperiment protocol.

Parameters:

stream (pytomography.io.PET.prd.protocols.typing.Union[pytomography.io.PET.prd.protocols.typing.BinaryIO, str]) –

_write_header(value)[source]#
Parameters:

value (pytomography.io.PET.prd.protocols.Header) –

Return type:

None

_write_time_blocks(value)[source]#
Parameters:

value (pytomography.io.PET.prd.protocols.collections.abc.Iterable[pytomography.io.PET.prd.protocols.TimeBlock]) –

Return type:

None

class pytomography.io.PET.prd.NDJsonPrdExperimentReader(stream)[source]#

Bases: pytomography.io.PET.prd._ndjson.NDJsonProtocolReader, pytomography.io.PET.prd.protocols.PrdExperimentReaderBase

NDJson writer for the PrdExperiment protocol.

Parameters:

stream (pytomography.io.PET.prd.protocols.typing.Union[io.BufferedReader, pytomography.io.PET.prd.protocols.typing.TextIO, str]) –

_read_header()[source]#
Return type:

pytomography.io.PET.prd.protocols.Header

_read_time_blocks()[source]#
Return type:

pytomography.io.PET.prd.protocols.collections.abc.Iterable[pytomography.io.PET.prd.protocols.TimeBlock]

class pytomography.io.PET.prd.NDJsonPrdExperimentWriter(stream)[source]#

Bases: pytomography.io.PET.prd._ndjson.NDJsonProtocolWriter, pytomography.io.PET.prd.protocols.PrdExperimentWriterBase

NDJson writer for the PrdExperiment protocol.

Parameters:

stream (pytomography.io.PET.prd.protocols.typing.Union[pytomography.io.PET.prd.protocols.typing.TextIO, str]) –

_write_header(value)[source]#
Parameters:

value (pytomography.io.PET.prd.protocols.Header) –

Return type:

None

_write_time_blocks(value)[source]#
Parameters:

value (pytomography.io.PET.prd.protocols.collections.abc.Iterable[pytomography.io.PET.prd.protocols.TimeBlock]) –

Return type:

None