Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
gschramm committed Nov 15, 2023
1 parent 8774b46 commit c09e513
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
~$*
*~
*.bak

# user defined things
figs/*
2 changes: 2 additions & 0 deletions data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.npy
*.prd
2 changes: 2 additions & 0 deletions python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.png
*.npy
13 changes: 8 additions & 5 deletions python/demo_read_reconstruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from array_api_compat import to_device
import matplotlib.pyplot as plt
from io_yardl import read_yardl

from pathlib import Path

dev = "cpu"

Expand All @@ -20,13 +20,13 @@
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------

event_det_id_1, event_det_id_2, scanner_lut = read_yardl("write_test.prd")
event_det_id_1, event_det_id_2, scanner_lut = read_yardl("../data/write_test.prd")

xstart = scanner_lut[event_det_id_1, :]
xend = scanner_lut[event_det_id_2, :]

# HACK: load the sensitivity image
sens_img = np.load("sensitivity_image.npy")
sens_img = np.load("../data/sensitivity_image.npy")

# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
Expand Down Expand Up @@ -63,13 +63,16 @@
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------

fig_dir = Path("../figs")
fig_dir.mkdir(exist_ok=True)

vmax = 0.055
fig, ax = plt.subplots(1, recon.shape[2], figsize=(recon.shape[2] * 2, 2))
for i in range(recon.shape[2]):
ax[i].imshow(
np.asarray(to_device(recon[:, :, i], "cpu")), vmin=0, vmax=vmax, cmap="Greys"
)
ax[i].set_title(f"ground truth sl {i+1}", fontsize="small")
ax[i].set_title(f"LM recon sl {i+1}", fontsize="small")

fig.tight_layout()
fig.savefig("lm_reconstruction.png")
fig.savefig(fig_dir / "lm_reconstruction.png")
20 changes: 13 additions & 7 deletions python/demo_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import matplotlib.pyplot as plt
from array_api_compat import to_device
from io_yardl import write_yardl
from pathlib import Path

# device variable (cpu or cuda) that determines whether calculations
# are performed on the cpu or cuda gpu
Expand Down Expand Up @@ -122,22 +123,27 @@
scanner_lut = lor_descriptor.scanner.all_lor_endpoints

# write the data to PETSIRD
write_yardl(event_det_id_1, event_det_id_2, scanner_lut, output_file="write_test.prd")
write_yardl(
event_det_id_1, event_det_id_2, scanner_lut, output_file="../data/write_test.prd"
)

# HACK: write the sensitivity image to file
np.save("sensitivity_image.npy", sens_img)
np.save("../data/sensitivity_image.npy", sens_img)

# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------

fig_dir = Path("../figs")
fig_dir.mkdir(exist_ok=True)

vmax = 1.2 * img.max()
fig2, ax2 = plt.subplots(1, img.shape[2], figsize=(img.shape[2] * 2, 2))
fig, ax = plt.subplots(1, img.shape[2], figsize=(img.shape[2] * 2, 2))
for i in range(img.shape[2]):
ax2[i].imshow(
ax[i].imshow(
np.asarray(to_device(img[:, :, i], "cpu")), vmin=0, vmax=vmax, cmap="Greys"
)
ax2[i].set_title(f"ground truth sl {i+1}", fontsize="small")
ax[i].set_title(f"ground truth sl {i+1}", fontsize="small")

fig2.tight_layout()
fig2.savefig("simulated_phantom.png")
fig.tight_layout()
fig.savefig(fig_dir / "simulated_phantom.png")

0 comments on commit c09e513

Please sign in to comment.