Skip to content

Commit 00d351c

Browse files
committed
ENH: Add parameter to specify maximum phantom length in pctweplfit
1 parent ddc545f commit 00d351c

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:
@@ -340,6 +338,7 @@ def pctweplfit(
340338
path_type,
341339
phantom_length_samples,
342340
phantom_width,
341+
max_phantom_length,
343342
detector_distance,
344343
number_of_detectors,
345344
initial_energy,
@@ -351,8 +350,13 @@ def pctweplfit(
351350
seed,
352351
verbose,
353352
):
353+
if detector_distance < max_phantom_length:
354+
print(
355+
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.",
356+
file=sys.stderr,
357+
)
354358
phantom_lengths = np.linspace(
355-
0.0, min(PROTON_RANGE, detector_distance), phantom_length_samples
359+
0.0, min(max_phantom_length, detector_distance), phantom_length_samples
356360
)
357361

358362
seed_seq = np.random.SeedSequence(seed)
@@ -434,6 +438,13 @@ def build_parser():
434438
default=40.0,
435439
type=float,
436440
)
441+
parser.add_argument(
442+
"-l",
443+
"--max-phantom-length",
444+
help="Maximum phantom length to consider (defaults to proton range in water)",
445+
type=float,
446+
default=260.0,
447+
)
437448
parser.add_argument(
438449
"-d",
439450
"--detector-distance",
@@ -499,6 +510,7 @@ def process(args_info: argparse.Namespace):
499510
path_type=args_info.path_type,
500511
phantom_length_samples=args_info.phantom_length_samples,
501512
phantom_width=args_info.phantom_width,
513+
max_phantom_length=args_info.max_phantom_length,
502514
detector_distance=args_info.detector_distance,
503515
number_of_detectors=args_info.number_of_detectors,
504516
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
@@ -49,7 +49,8 @@ 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"
53+
)
5354

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

0 commit comments

Comments
 (0)