-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStackToMaxSum.py
More file actions
131 lines (107 loc) · 3.91 KB
/
Copy pathStackToMaxSum.py
File metadata and controls
131 lines (107 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import warnings
import logging
import skimage.io
import numpy as np
from os import path, getcwd
from joblib import Parallel, delayed, cpu_count
warnings.filterwarnings("ignore")
logger = logging.getLogger('StackToMaxSum.py')
hdlr = logging.FileHandler(path.join(getcwd(), 'StackToMaxSum.log'))
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.INFO)
def project_single_site(base_dir, fname_stub, well_name, timeline_name,
field, l_name,
action_name, input_channel_name,
output_channel_names, z_planes,
input_dir, output_dir):
logger.info('Processing channel %s, well %s, site %d',
input_channel_name, well_name, field)
field_name = 'F' + str(field).zfill(3)
image_names = []
for z in range(1, z_planes + 1):
z_name = 'Z' + str(z).zfill(2)
image_names.append(
(
fname_stub + well_name + '_' + timeline_name + field_name +
l_name + action_name + z_name + input_channel_name + '.tif'
)
)
image_paths = [
path.join(base_dir, input_dir, in_name) for in_name in image_names
]
logger.debug('Well %s, site %d, image paths %s', well_name, field, image_paths)
ic = skimage.io.imread_collection(image_paths)
arr = skimage.io.concatenate_images(ic)
sum_proj = np.sum(arr, axis=0, dtype=np.uint16)
max_proj = np.max(arr, axis=0)
max_name = (
fname_stub + well_name + '_' + timeline_name + field_name +
l_name + action_name + 'Z01' + output_channel_names[0] + '.tif'
)
sum_name = (
fname_stub + well_name + '_' + timeline_name + field_name +
l_name + action_name + 'Z01' + output_channel_names[1] + '.tif'
)
max_path = path.join(base_dir, output_dir, max_name)
sum_path = path.join(base_dir, output_dir, sum_name)
logger.info('Channel %s, well %s, Site %d, saving max projection: %s',
input_channel_name, well_name, field, max_path)
skimage.io.imsave(fname=max_path, arr=max_proj)
logger.info('Channel %s, well %s, Site %d, saving sum projection: %s',
input_channel_name, well_name, field, sum_path)
skimage.io.imsave(fname=sum_path, arr=sum_proj)
return
# Define parameters
# -----------------
base_dir = path.join(
path.expanduser('~'), 'pelkmans-sc-storage',
'20170807-Kim2-NascentRNA-Inhibitors'
)
input_dir = 'ACQ03'
output_dir = 'MAXSUM2'
fname_stub = '20170807-Kim2-NascentRNA-Inhibitors-DAPI-EU-Beads-SE-3_'
well_name_list = (
# ['E' + str(i).zfill(2) for i in range(2, 9)] +
# ['F' + str(i).zfill(2) for i in range(2, 9)] +
['G' + str(i).zfill(2) for i in range(7, 9)]
)
timeline_name = 'T0002'
action_name = 'A02'
l_name = 'L02'
z_planes = 16
n_fields = 48
n_cores = cpu_count() - 1
# Map input channel C03 to C03 (max), C04 (sum)
#input_channel_name = 'C03'
#output_channel_names = ['C03', 'C04']
#
#for well_name in well_name_list:
#
# # Process sites in parallel
# Parallel(n_jobs=n_cores)(
# delayed(project_single_site)
# (
# base_dir, fname_stub,
# well_name, timeline_name,
# i, l_name, action_name, input_channel_name,
# output_channel_names, z_planes,
# input_dir, output_dir
# ) for i in range(1, n_fields + 1)
# )
# Map input channel C04 to C05 (max), C06 (sum)
input_channel_name = 'C04'
output_channel_names = ['C05', 'C06']
for well_name in well_name_list:
# Process sites in parallel
Parallel(n_jobs=n_cores)(
delayed(project_single_site)
(
base_dir, fname_stub,
well_name, timeline_name,
i, l_name, action_name, input_channel_name,
output_channel_names, z_planes,
input_dir, output_dir
) for i in range(1, n_fields + 1)
)