Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion applications/pctdoublelut/pctdoublelut.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python
import argparse
import json
import sys
from multiprocessing import Pool, Manager
import os
Expand Down
4 changes: 1 addition & 3 deletions applications/pctpairprotons/pctpairprotons.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python
import argparse
import json
import itk
from itk import PCT as pct
import numpy as np
Expand Down Expand Up @@ -311,8 +310,7 @@ def load_tree_as_df(root_file, tree_name):

if args_info.fit is not None: # Single LUT
verbose("Converting energy loss or TOF to WEPL using single LUT technique…")
with open(args_info.fit, encoding="utf-8") as f:
p = json.load(f)
p = np.loadtxt(f)
if args_info.fit_kind == "tof":
xs = pairs["PreGlobalTime_out"] - pairs["PreGlobalTime_in"]
elif args_info.fit_kind == "energy":
Expand Down
6 changes: 1 addition & 5 deletions applications/pctweplfit/pctweplfit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python
import argparse
import json
import sys
from multiprocessing import Pool, Manager
import warnings
Expand Down Expand Up @@ -323,10 +322,7 @@ def fit(xs, ys, xlabel, ylabel):
plt.show()

for d, p in ps.items():
with open(
f"{output}/{xlabel}_to_{ylabel}_fit_deg{d}.json", "w", encoding="utf-8"
) as f:
json.dump(p, f)
np.savetxt(f"{output}/{xlabel}_to_{ylabel}_fit_deg{d}.txt", p)

fit(tofs, wepls, "tof", "wepl")
fit(elosses, wepls, "eloss", "wepl")
Expand Down
10 changes: 5 additions & 5 deletions documentation/docs/wepl_calibration.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pctweplfit \
-v
```

In the resulting `output` folder, along with all intermediate results (ROOT files from the GATE simulations) will be two files `eloss_to_wepl_fit_deg3.json` and `tof_to_wepl_fit_deg3.json` that contain the coefficients of the polynomials. These files can then be passed to `pctpairprotons` with the corresponding `--fit-kind` parameters.
In the resulting `output` folder, along with all intermediate results (ROOT files from the GATE simulations) will be two files `eloss_to_wepl_fit_deg3.txt` and `tof_to_wepl_fit_deg3.txt` that contain the coefficients of the polynomials. These files can then be passed to `pctpairprotons` with the corresponding `--fit-kind` parameters.

Here is an example of a `pctpairprotons` invocations with energy-loss fit:
```bash
Expand All @@ -26,7 +26,7 @@ pctpairprotons \
-o pairs.mhd \
--plane-in -110 \
--plane-out 110 \
--fit output/eloss_to_wepl_fit_deg3.json \
--fit output/eloss_to_wepl_fit_deg3.txt \
--fit-kind energy
```

Expand All @@ -42,7 +42,7 @@ pctdoublelut \
-v
```

In the resulting `output` folder, along with all intermediate results (ROOT files from the GATE simulations) will be files named `tof_coeffs_X.json` and `vel_coeffs_X.json` that contain the coefficients of the polynomials, where `X` is the polynomial degree. These files can then be passed to `pctpairprotons` with the appropriate parameters.
In the resulting `output` folder, along with all intermediate results (ROOT files from the GATE simulations) will be files named `tof_coeffs_X.txt` and `vel_coeffs_X.txt` that contain the coefficients of the polynomials, where `X` is the polynomial degree. These files can then be passed to `pctpairprotons` with the appropriate parameters.

Here is an example of a `pctpairprotons` invocations that uses the double LUT fits with polynomials of degree 9:
```bash
Expand All @@ -52,8 +52,8 @@ pctpairprotons \
-o pairs.mhd \
--plane-in -110 \
--plane-out 110 \
--lut-tof output/tof_coeffs_9.json \
--lut-vel output/vel_coeffs_9.json \
--lut-tof output/tof_coeffs_9.txt \
--lut-vel output/vel_coeffs_9.txt \
--quadric 1 0 1 0 0 0 0 0 0 -10000 \
--angle 0
```
Expand Down
43 changes: 20 additions & 23 deletions test/pct_application_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import pytest
import itk
import urllib.request
Expand Down Expand Up @@ -53,28 +52,26 @@ def test_weplfit_application(tmp_path):
f"-o {output} --path-type phantom_length -d 220 -e 200 -l 220 --seed 1234 -v"
)

with open(output / "tof_to_wepl_fit_deg3.json", encoding="utf-8") as f:
tof_to_wepl_fit = np.array(json.load(f))
reference = np.array(
[
8507.18830081492,
-38342.09213481464,
58268.25904916112,
-29633.875319259325,
]
)
assert np.allclose(tof_to_wepl_fit, reference)
with open(output / "eloss_to_wepl_fit_deg3.json", encoding="utf-8") as f:
eloss_to_wepl_fit = np.array(json.load(f))
reference = np.array(
[
-5.4569381663242e-06,
-0.003455118013641362,
2.236667157315751,
-0.1768424416075149,
]
)
assert np.allclose(eloss_to_wepl_fit, reference)
tof_to_wepl_fit = np.loadtxt(output / "tof_to_wepl_fit_deg3.txt")
reference = np.array(
[
8507.18830081492,
-38342.09213481464,
58268.25904916112,
-29633.875319259325,
]
)
assert np.allclose(tof_to_wepl_fit, reference)
eloss_to_wepl_fit = np.loadtxt(output / "eloss_to_wepl_fit_deg3.txt")
reference = np.array(
[
-5.4569381663242e-06,
-0.003455118013641362,
2.236667157315751,
-0.1768424416075149,
]
)
assert np.allclose(eloss_to_wepl_fit, reference)


def test_doublelut_application(tmp_path):
Expand Down
Loading