Skip to content

Commit

Permalink
changes to python code recommended by Codacy
Browse files Browse the repository at this point in the history
  • Loading branch information
KrisThielemans committed Nov 16, 2023
1 parent e97b0f0 commit 9559bc1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions examples/python/listmode_loop_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

#%% Initial imports
import stir
import os

#%% read file
filename = '20170809_NEMA_60min_UCL.l.hdr'
# example using the hroot file in recon_test_pack, which needs some env variables to be set
#import os
#os.environ["INPUT_ROOT_FILE"]="test_PET_GATE.root"
#os.environ["EXCLUDE_SCATTERED"] = "1"
#os.environ["EXCLUDE_RANDOM"] = "0"
Expand All @@ -29,15 +29,15 @@
#%% loop over first few events and print some information
# create some variables for re-use in the loop
record = lm.get_empty_record()
bin = stir.Bin()
b = stir.Bin()
for i in range(50):
lm.get_next_record(record)
if (record.is_time()):
print(f"Time: {record.time().get_time_in_millisecs()}")
if (record.is_event()):
event = record.event()
lor = event.get_LOR()
event.get_bin(bin, proj_data_info);
event.get_bin(b, proj_data_info);
# TODO We can will be able to simply print bin once STIR_TOF is on
print(f"Event: p/d: {event.is_prompt()} LOR: {[lor.p1(), lor.p2()]}, ",
f"bin: s:{bin.segment_num}, a: {bin.axial_pos_num}, v: {bin.view_num}, t:{bin.tangential_pos_num}")
f"bin: s:{b.segment_num}, a: {b.axial_pos_num}, v: {b.view_num}, t:{b.tangential_pos_num}")
18 changes: 9 additions & 9 deletions src/swig/test/python/test_listmode.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

#%% read file
# location of script
dir = os.path.dirname(__file__)
loc = os.path.dirname(__file__)
# location of ROOT file
dir = os.path.join(dir, "..", "..", "..", "..", "recon_test_pack")
loc = os.path.join(loc, "..", "..", "..", "..", "recon_test_pack")
filename = "root_header.hroot"

os.environ["INPUT_ROOT_FILE"]="test_PET_GATE.root"
Expand All @@ -29,35 +29,35 @@

def test_get_record():
try:
lm=stir.ListModeData.read_from_file(os.path.join(dir, filename))
lm=stir.ListModeData.read_from_file(os.path.join(loc, filename))
proj_data_info = lm.get_proj_data_info()
except:
except RuntimeError:
print(f"Could not open {filename}")
print("ROOT support not enabled?")
return

record = lm.get_empty_record()
bin = stir.Bin()
b = stir.Bin()
# first event
lm.get_next_record(record)
assert record.is_time()
assert record.time().get_time_in_millisecs() == 2
assert record.is_event()
event = record.event()
lor = event.get_LOR()
event.get_bin(bin, proj_data_info);
event.get_bin(b, proj_data_info);
diff = stir.FloatCartesianCoordinate3D(lor.p1() - stir.Float3BasicCoordinate((2.03125, -149.102, -299.989)))
assert abs(diff.x()) < .1 and abs(diff.y()) < .1 and abs(diff.z()) < .1
assert bin.segment_num == 1 and bin.axial_pos_num == 1 and bin.view_num == 112 and bin.tangential_pos_num == -102
assert b.segment_num == 1 and b.axial_pos_num == 1 and b.view_num == 112 and b.tangential_pos_num == -102
# second event
lm.get_next_record(record)
assert record.is_time()
assert record.time().get_time_in_millisecs() == 3
assert record.is_event()
event = record.event()
lor = event.get_LOR()
event.get_bin(bin, proj_data_info);
event.get_bin(b, proj_data_info);
diff = stir.FloatCartesianCoordinate3D(lor.p1() - stir.Float3BasicCoordinate((-2.03125, 325.646, -78.6102)))
assert abs(diff.x()) < .1 and abs(diff.y()) < .1 and abs(diff.z()) < .1
assert bin.segment_num == -1 and bin.axial_pos_num == 1 and bin.view_num == 12 and bin.tangential_pos_num == -14
assert b.segment_num == -1 and b.axial_pos_num == 1 and b.view_num == 12 and b.tangential_pos_num == -14

0 comments on commit 9559bc1

Please sign in to comment.