-
Notifications
You must be signed in to change notification settings - Fork 0
/
sfig2_nanosims.py
73 lines (55 loc) · 2.47 KB
/
sfig2_nanosims.py
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
import pandas as pd
from pathlib import Path
import logging
from matplotlib import cm, colors
from nanosims.contours import *
from matplotlib import pyplot as plt
from nanosims.utils import read_nrrd, extract, calculate_delta, save_image, save_colormap
logging.basicConfig(level=logging.INFO)
font = {'family': 'sans-serif',
'sans-serif': 'Helvetica',
'weight': 'normal',
'size': 6}
plt.rc('font', **font)
plt.rc('pdf', fonttype=42)
plt.rc('lines', linewidth=1)
color_max = 3000
smooth = True
k_size = 3
def main():
map = pd.read_csv('nanosims_max_enrich.txt',
sep='\t', index_col='path_to_im')
path_project = Path('/Users/leoburgy/Dropbox/buergy_ncomms/data/sfig2')
nrrd_list = [path for path in path_project.rglob('*/*.nrrd') if not path.name.startswith('.')]
for i, file in enumerate(nrrd_list):
color_max = map.loc[file.stem, 'd13c_max']
header, data = read_nrrd(file)
logging.info(f"{file.name} ({header['Mims_raster']} nm)")
cyanide = extract(data, header, mass_name='14N12C', cumulative=True)
carbide13 = extract(data, header, mass_name='13C12C', cumulative=True)
carbide12 = extract(data, header, mass_name='12C12C', cumulative=True)
if smooth:
carbide13 = cv2.GaussianBlur(carbide13, ksize=(k_size, k_size), sigmaX=0)
carbide12 = cv2.GaussianBlur(carbide12, ksize=(k_size, k_size), sigmaX=0)
delta = calculate_delta(numerator=carbide13, denominator=carbide12)
delta = np.nan_to_num(delta)
save_image(data=np.fliplr(delta), cm='cividis',
cbar_max=color_max,
dst=str(file.parent / f'{file.stem}_delta.png'))
save_image(data=np.fliplr(cyanide), cm='gray',
cbar_max=None,
dst=str(file.parent / f'{file.stem}_cyanide.png'))
save_colormap(cbar_max=color_max,
dst=str(file.parent / f'{file.stem}_cmap.pdf'))
# fig, ax = plt.subplots(figsize=(1, 3))
# fig.subplots_adjust(left=0, bottom=0.05, right=.5, top=.95)
# ax.tick_params(labelsize=8)
# cmap = cm.get_cmap('cividis')
# norm = colors.Normalize(vmin=0, vmax=color_max)
#
# fig.colorbar(cm.ScalarMappable(norm=norm, cmap=cmap),
# cax=ax, orientation='vertical')
# fig.tight_layout()
# fig.savefig(str(path_project / f'{file.stem}_cmap.pdf'))
if __name__ == '__main__':
main()