Skip to content

Commit f84b8e5

Browse files
committed
ENH: Add parameter to specify maximum phantom length in pctweplfit
1 parent 76e78ff commit f84b8e5

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

applications/pctweplfit/pctweplfit.py

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

1212
epsilon_mm = 1e-5
1313

14-
PROTON_RANGE = 260 # mm
15-
1614

1715
def pv(verbose, *args, **kwargs):
1816
if verbose:
@@ -339,6 +337,7 @@ def pctweplfit(
339337
path_type,
340338
phantom_length_samples,
341339
phantom_width,
340+
max_phantom_length,
342341
detector_distance,
343342
number_of_detectors,
344343
initial_energy,
@@ -350,8 +349,13 @@ def pctweplfit(
350349
seed,
351350
verbose,
352351
):
352+
if detector_distance < max_phantom_length:
353+
print(
354+
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.",
355+
file=sys.stderr,
356+
)
353357
phantom_lengths = np.linspace(
354-
0.0, min(PROTON_RANGE, detector_distance), phantom_length_samples
358+
0.0, min(max_phantom_length, detector_distance), phantom_length_samples
355359
)
356360

357361
seed_seq = np.random.SeedSequence(seed)
@@ -433,6 +437,13 @@ def build_parser():
433437
default=40.0,
434438
type=float,
435439
)
440+
parser.add_argument(
441+
"-l",
442+
"--max-phantom-length",
443+
help="Maximum phantom length to consider (defaults to proton range in water)",
444+
type=float,
445+
default=260.0,
446+
)
436447
parser.add_argument(
437448
"-d",
438449
"--detector-distance",
@@ -498,6 +509,7 @@ def process(args_info: argparse.Namespace):
498509
path_type=args_info.path_type,
499510
phantom_length_samples=args_info.phantom_length_samples,
500511
phantom_width=args_info.phantom_width,
512+
max_phantom_length=args_info.max_phantom_length,
501513
detector_distance=args_info.detector_distance,
502514
number_of_detectors=args_info.number_of_detectors,
503515
initial_energy=args_info.initial_energy,

test/pct_application_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ def test_pairprotons_application(
5050
def test_weplfit_application(tmp_path):
5151
output = tmp_path / "weplfit"
5252
pct.pctweplfit(
53-
f"-o {output} --path-type phantom_length -d 220 -e 200 --seed 1234 -v")
53+
f"-o {output} --path-type phantom_length -d 220 -e 200 -l 220 --seed 1234 -v"
54+
)
5455

5556
with open(output / "tof_to_wepl_fit_deg3.json", encoding="utf-8") as f:
5657
tof_to_wepl_fit = np.array(json.load(f))

0 commit comments

Comments
 (0)