Skip to content

Commit b28f04b

Browse files
committed
ENH: Add parameter to specify maximum phantom length in pctweplfit
1 parent d59b188 commit b28f04b

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

applications/pctweplfit/pctweplfit.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
epsilon_mm = 1e-5
1212

13-
PROTON_RANGE = 260 # mm
14-
1513

1614
def pv(verbose, *args, **kwargs):
1715
if verbose:
@@ -338,6 +336,7 @@ def pctweplfit(
338336
path_type,
339337
phantom_length_samples,
340338
phantom_width,
339+
max_phantom_length,
341340
detector_distance,
342341
number_of_detectors,
343342
initial_energy,
@@ -349,8 +348,13 @@ def pctweplfit(
349348
seed,
350349
verbose,
351350
):
351+
if detector_distance < max_phantom_length:
352+
print(
353+
f"Warning, detector distance of {detector_distance} mm is smaller than the maximum phantom length of {max_phantom_length} mm. A maximum phantom length of {max_phantom_length} will be used.",
354+
file=sys.stderr,
355+
)
352356
phantom_lengths = np.linspace(
353-
0.0, min(PROTON_RANGE, detector_distance), phantom_length_samples
357+
0.0, min(max_phantom_length, detector_distance), phantom_length_samples
354358
)
355359

356360
seed_seq = np.random.SeedSequence(seed)
@@ -426,6 +430,13 @@ def build_parser():
426430
default=40.0,
427431
type=float,
428432
)
433+
parser.add_argument(
434+
"-l",
435+
"--max-phantom-length",
436+
help="Maximum phantom length to consider (defaults to proton range in water)",
437+
type=float,
438+
default=260.0,
439+
)
429440
parser.add_argument(
430441
"-d",
431442
"--detector-distance",
@@ -491,6 +502,7 @@ def process(args_info: argparse.Namespace):
491502
path_type=args_info.path_type,
492503
phantom_length_samples=args_info.phantom_length_samples,
493504
phantom_width=args_info.phantom_width,
505+
max_phantom_length=args_info.max_phantom_length,
494506
detector_distance=args_info.detector_distance,
495507
number_of_detectors=args_info.number_of_detectors,
496508
initial_energy=args_info.initial_energy,

test/pct_application_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_pairprotons_application(
4949
def test_weplfit_application(tmp_path):
5050
output = tmp_path / "weplfit"
5151
pct.pctweplfit(
52-
f"-o {output} --path-type phantom_length -d 220 -e 200 --seed 1234 -v"
52+
f"-o {output} --path-type phantom_length -d 220 -e 200 -l 220 --seed 1234 -v"
5353
)
5454

5555
with open(output / "tof_to_wepl_fit_deg3.json", encoding="utf-8") as f:

0 commit comments

Comments
 (0)