Skip to content

Commit 6b208c2

Browse files
committed
python overload
1 parent 9f87c51 commit 6b208c2

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

python/petsird/helpers/__init__.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,37 @@ def make_detection_bin(
8383
[expanded_detection_bin])[0]
8484

8585

86+
@typing.overload
8687
def get_detection_efficiency(scanner: petsird.ScannerInformation,
8788
type_of_module_pair: petsird.TypeOfModulePair,
8889
detection_bin_1: petsird.DetectionBin,
8990
detection_bin_2: petsird.DetectionBin) -> float:
9091
"""Compute the detection efficiency for a pair of detectors"""
92+
...
93+
94+
95+
@typing.overload
96+
def get_detection_efficiency(scanner: petsird.ScannerInformation,
97+
type_of_module_pair: petsird.TypeOfModulePair,
98+
event: petsird.CoincidenceEvent) -> float:
99+
"""Compute the detection efficiency for a coincidence event"""
100+
...
101+
102+
103+
def get_detection_efficiency(
104+
scanner: petsird.ScannerInformation,
105+
type_of_module_pair: petsird.TypeOfModulePair,
106+
event_or_detection_bin_1: typing.Union[petsird.CoincidenceEvent,
107+
petsird.DetectionBin],
108+
detection_bin_2: petsird.DetectionBin = None) -> float:
109+
"""Compute the detection efficiency"""
110+
if isinstance(event_or_detection_bin_1, petsird.DetectionBin):
111+
detection_bin_1 = event_or_detection_bin_1
112+
assert detection_bin_2 is not None, "Second detection bin must be provided"
113+
else:
114+
detection_bin_1, detection_bin_2 = event_or_detection_bin_1.detection_bins[:
115+
2]
116+
91117
if scanner.detection_efficiencies is None:
92118
# should never happen really, but this way, we don't crash.
93119
return 1.
@@ -139,13 +165,3 @@ def get_detection_efficiency(scanner: petsird.ScannerInformation,
139165
expanded_det_bin1.energy_index]
140166

141167
return eff
142-
143-
144-
def get_event_detection_efficiency(
145-
scanner: petsird.ScannerInformation,
146-
type_of_module_pair: petsird.TypeOfModulePair,
147-
event: petsird.CoincidenceEvent) -> float:
148-
"""Compute the detection efficiency for a coincidence event"""
149-
return get_detection_efficiency(scanner, type_of_module_pair,
150-
event.detection_bins[0],
151-
event.detection_bins[1])

python/petsird/helpers/analysis.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
import petsird
1010
import petsird.helpers.geometry
11-
from petsird.helpers import (expand_detection_bin,
12-
get_event_detection_efficiency, get_num_det_els)
11+
from petsird.helpers import (expand_detection_bin, get_detection_efficiency,
12+
get_num_det_els)
1313

1414

1515
def parserCreator():
@@ -123,7 +123,7 @@ def parserCreator():
123123
", ",
124124
expanded_det_bin1,
125125
)
126-
eff = get_event_detection_efficiency(
126+
eff = get_detection_efficiency(
127127
scanner, mtype_pair, event)
128128
print(" efficiency:", eff)
129129

python/petsird/helpers/generator.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99

1010
import numpy
1111
import petsird
12-
from petsird.helpers import (get_event_detection_efficiency,
13-
get_num_detection_bins)
12+
from petsird.helpers import get_detection_efficiency, get_num_detection_bins
1413

1514
# these are constants for now
1615
NUMBER_OF_EVENT_ENERGY_BINS = 3
@@ -268,8 +267,8 @@ def get_events(header: petsird.Header,
268267
# short-cut to directly generate a random detection bin
269268
event.detection_bins[1] = get_random_uint(count1)
270269

271-
if get_event_detection_efficiency(header.scanner,
272-
type_of_module_pair, event) > 0:
270+
if get_detection_efficiency(header.scanner, type_of_module_pair,
271+
event) > 0:
273272
# in coincidence, we can get out of the loop
274273
break
275274

0 commit comments

Comments
 (0)