Skip to content

Commit 6e0879c

Browse files
committed
Fix code style issues flagged by Codacy (whitespace, line length, etc.)
1 parent af01353 commit 6e0879c

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

examples/python/Vision_files_preprocess.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
## execute
1515
## set cmd= %cmd% -d ./Debug
1616
## set cmd= %cmd% --os scatter_520_2D.mhdr
17-
##
17+
##
1818
## This way, it will write smoothed randoms, a mu-map and a sinogram for
1919
## normalization to file.
2020
##
@@ -29,7 +29,7 @@
2929
## - prompts-sino_uncompr_00.s.hdr & .s
3030
## - smoothed_randoms_00.h33 & .s (in the "Debug" folder)
3131
## - umap_00.h33 & .i (in the "Debug" folder)
32-
## note: we highly recommend using this mu-map, as it is "cut to the FOV"
32+
## note: we highly recommend using this mu-map, as it is "cut to the FOV"
3333
## and is positioned at scanner center.
3434
## - norm3d_00.h33 & .a (in the "Debug" folder)
3535
## - scatter_520_2D.s.hdr & .s (wherever you set the path to in the batch file)
@@ -56,7 +56,7 @@
5656
#
5757

5858
#%%
59-
import os, sys, re, argparse
59+
import os, re, argparse
6060
import numpy as np
6161
import matplotlib.pyplot as plt
6262
import stir
@@ -79,10 +79,14 @@ def process_files(prompts_header_filename,
7979
Args:
8080
prompts_header_filename (str): filename of the prompts sinogram header file, including path
8181
mu_map_header (str, optional): filename of mu-map header file, must be in the same folder as prompts file. Defaults to 'umap_00.h33'.
82-
randoms_data_filename (str, optional): filename of randoms sinogram header file, must be in the same folder as prompts file. Defaults to 'smoothed_rand_00.s'.
83-
scatter_2D_header_filename (str, optional): filename of 2D scatter header file, must be in the same folder as prompts file. Defaults to 'scat_00_00.s.hdr'.
84-
norm_sino_data_filename (str, optional): filename of norm sinogram header file, must be in the same folder as prompts file. Defaults to 'norm3d_00.a'.
85-
attenuation_corr_factor_data_filename (str, optional): filename of attenuation correction factor header file, must be in the same folder as prompts file. Defaults to 'acf_00.a'.
82+
randoms_data_filename (str, optional): filename of randoms sinogram header file, must be in the same
83+
folder as prompts file. Defaults to 'smoothed_rand_00.s'.
84+
scatter_2D_header_filename (str, optional): filename of 2D scatter header file, must be in the same
85+
folder as prompts file. Defaults to 'scat_00_00.s.hdr'.
86+
norm_sino_data_filename (str, optional): filename of norm sinogram header file, must be in the same
87+
folder as prompts file. Defaults to 'norm3d_00.a'.
88+
attenuation_corr_factor_data_filename (str, optional): filename of attenuation correction factor header
89+
file, must be in the same folder as prompts file. Defaults to 'acf_00.a'.
8690
STIR_output_folder (str, optional): folder where files are written to. Defaults to 'processing', within prompts folder.
8791
"""
8892
data_folder_PATH = os.path.dirname(prompts_header_filename)
@@ -125,7 +129,7 @@ def process_files(prompts_header_filename,
125129
os.mkdir(STIR_output_folder)
126130
except FileExistsError:
127131
print("STIR output folder exists, files are overwritten")
128-
132+
129133
#%%
130134
###################### PROMPTS FILE ############################
131135
##### first, we check if the prompts file is compressed
@@ -159,7 +163,6 @@ def process_files(prompts_header_filename,
159163
######## select display variables
160164
central_slice = proj_info.get_num_axial_poss(0)//2
161165
TOF_bin = proj_info.get_num_tof_poss()//2
162-
view = proj_info.get_num_views()//2
163166
# to draw line-profiles, we'll average over a few slices, specify how many:
164167
thickness_half = 5
165168

@@ -204,7 +207,7 @@ def process_files(prompts_header_filename,
204207
if apply_DOI_adaption: DOI_adaption(norm_sino, 10)
205208
norm_sino_arr = stirextra.to_numpy(norm_sino)
206209

207-
##### in case there were bad miniblocks during your measurement, the norm-file
210+
##### in case there were bad miniblocks during your measurement, the norm-file
208211
##### might contain negative values. We'll set them to a very high value here, such
209212
##### that the detection efficiencies (1/norm-value) will be 0 (numerically)
210213
norm_sino_arr[norm_sino_arr<=0.] = 10^37
@@ -412,8 +415,11 @@ def process_files(prompts_header_filename,
412415

413416
fig, ax = plt.subplots(figsize = (8,6))
414417

415-
ax.plot(np.mean(prompts_precorr_arr[TOF_bin, central_slice-thickness_half:central_slice+thickness_half, 0, :], axis=(0)), label='Prompts, pre-corrected f. multi. factors')
416-
ax.plot(np.mean(additive_term_arr[TOF_bin, central_slice-thickness_half:central_slice+thickness_half, 0, :], axis=(0)), label='additive term')
418+
prompts_mean = np.mean(prompts_precorr_arr[TOF_bin, central_slice-thickness_half:central_slice+thickness_half, 0, :], axis=(0))
419+
ax.plot(prompts_mean, label="Prompts, pre-corrected f. multi. factors")
420+
421+
add_term_mean = np.mean(additive_term_arr[TOF_bin, central_slice-thickness_half:central_slice+thickness_half, 0, :], axis=(0))
422+
ax.plot(add_term_mean, label="additive term")
417423

418424
ax.set_xlabel('Radial distance (bin)')
419425
ax.set_ylabel('total counts')
@@ -482,7 +488,7 @@ def plot_2d_image(idx,vol,title,clims=None,cmap="viridis"):
482488
"""Customized version of subplot to plot 2D image"""
483489
plt.subplot(*idx)
484490
plt.imshow(vol,cmap=cmap)
485-
if not clims is None:
491+
if clims is not None:
486492
plt.clim(clims)
487493
plt.colorbar(shrink=.5, aspect=.9)
488494
plt.title(title)
@@ -571,7 +577,7 @@ def change_max_ring_distance(header_name_new, header_name, max_ring_diff):
571577
f2.write(data)
572578

573579
def remove_tof_dimension(header_name_new, header_name):
574-
580+
575581
with open(header_name) as f:
576582
data = f.read()
577583

@@ -611,7 +617,7 @@ def remove_tof_dimension(header_name_new, header_name):
611617
parser.add_argument('--STIR_output_folder', default='processing', help="The folder where the output files are written to")
612618

613619
args = parser.parse_args()
614-
620+
615621
process_files(args.prompts_filename_inclPath,
616622
mu_map_header=args.mu_map_header,
617623
randoms_data_filename=args.randoms_data_filename,

0 commit comments

Comments
 (0)