insituTEM 0.1.3__tar.gz → 0.1.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {insituTEM-0.1.3 → insituTEM-0.1.5}/PKG-INFO +1 -1
- {insituTEM-0.1.3 → insituTEM-0.1.5}/insituTEM/insitu_DP.py +160 -143
- {insituTEM-0.1.3 → insituTEM-0.1.5}/insituTEM.egg-info/PKG-INFO +1 -1
- {insituTEM-0.1.3 → insituTEM-0.1.5}/insituTEM.egg-info/requires.txt +0 -1
- {insituTEM-0.1.3 → insituTEM-0.1.5}/setup.py +1 -2
- {insituTEM-0.1.3 → insituTEM-0.1.5}/insituTEM/__ init __.py +0 -0
- {insituTEM-0.1.3 → insituTEM-0.1.5}/insituTEM/insitu_IO.py +0 -0
- {insituTEM-0.1.3 → insituTEM-0.1.5}/insituTEM/insitu_Preprocess.py +0 -0
- {insituTEM-0.1.3 → insituTEM-0.1.5}/insituTEM/insitu_alignment.py +0 -0
- {insituTEM-0.1.3 → insituTEM-0.1.5}/insituTEM.egg-info/SOURCES.txt +0 -0
- {insituTEM-0.1.3 → insituTEM-0.1.5}/insituTEM.egg-info/dependency_links.txt +0 -0
- {insituTEM-0.1.3 → insituTEM-0.1.5}/insituTEM.egg-info/top_level.txt +0 -0
- {insituTEM-0.1.3 → insituTEM-0.1.5}/setup.cfg +0 -0
|
@@ -1,144 +1,161 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""
|
|
3
|
-
in-situ TEM Toolbox - Data process
|
|
4
|
-
|
|
5
|
-
Assembles of functions related to movie input output
|
|
6
|
-
|
|
7
|
-
Example:
|
|
8
|
-
|
|
9
|
-
import insitu_DP as DP
|
|
10
|
-
IO.f2tif(path,1)
|
|
11
|
-
|
|
12
|
-
Created on Tue Jun 11 10:25:25 2019
|
|
13
|
-
@author: Mona
|
|
14
|
-
"""
|
|
15
|
-
import numpy as np
|
|
16
|
-
|
|
17
|
-
def readcsvCol(path,col):
|
|
18
|
-
"""
|
|
19
|
-
Function to read csv rol into array
|
|
20
|
-
Inputs: file path; col number
|
|
21
|
-
Output: 1D np array
|
|
22
|
-
|
|
23
|
-
Example:
|
|
24
|
-
x = readcsvCol(path,1)
|
|
25
|
-
"""
|
|
26
|
-
import csv
|
|
27
|
-
x=[]
|
|
28
|
-
with open(path,'r') as csvfile:
|
|
29
|
-
plots = csv.reader(csvfile, delimiter=',')
|
|
30
|
-
for row in plots:
|
|
31
|
-
if row[col]=='':
|
|
32
|
-
x.append(np.nan)
|
|
33
|
-
else:
|
|
34
|
-
x.append(float(row[col]))
|
|
35
|
-
# plt.plot(x,y) #to check if the read result is correct
|
|
36
|
-
return x
|
|
37
|
-
def readcsv(path,col_list):
|
|
38
|
-
"""
|
|
39
|
-
Function to read csv rol into array
|
|
40
|
-
Inputs: file path; col number list
|
|
41
|
-
Output: 1D np array
|
|
42
|
-
|
|
43
|
-
Example:
|
|
44
|
-
x = readcsv(path,[0:3])
|
|
45
|
-
"""
|
|
46
|
-
# w= len(col_list)
|
|
47
|
-
x=readcsvCol(path,col_list[0])
|
|
48
|
-
# l = len(x)
|
|
49
|
-
D=np.zeros((len(x),len(col_list)))
|
|
50
|
-
i=0
|
|
51
|
-
for col in col_list:
|
|
52
|
-
|
|
53
|
-
x=readcsvCol(path,col)
|
|
54
|
-
D[:,i]=x
|
|
55
|
-
i=i+1
|
|
56
|
-
# D = [D, x]
|
|
57
|
-
return D
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
def writeCSV(pathout,data):
|
|
61
|
-
# import csv
|
|
62
|
-
import numpy as np
|
|
63
|
-
# (length,width)=np.shape(data)
|
|
64
|
-
# np.savetxt(pathout, data, fmt='%1.4d', delimiter=",")
|
|
65
|
-
np.savetxt(pathout, data, fmt='%.4f', delimiter=",")
|
|
66
|
-
|
|
67
|
-
def plot2ani(x,y,outpath,label,w=800,h=600,fps=10,dpi=72,tl_size=20,c='r'):
|
|
68
|
-
"""
|
|
69
|
-
Function to make plot into animation
|
|
70
|
-
Inputs:
|
|
71
|
-
data: x y;
|
|
72
|
-
Movie setting: size: w,h ;
|
|
73
|
-
fps; savepath
|
|
74
|
-
label: ['xlabel','ylabel'] str array
|
|
75
|
-
tl_size: title font size
|
|
76
|
-
c: color of the plot line
|
|
77
|
-
dpi: dpi for screen : 72 for 4k screen, 96 for 1080p screen
|
|
78
|
-
Output: mp4 movie
|
|
79
|
-
|
|
80
|
-
Example:
|
|
81
|
-
plot2ani(x,y,w,h,fps,outpath,dpi,tl_size,'r')
|
|
82
|
-
|
|
83
|
-
"""
|
|
84
|
-
|
|
85
|
-
import matplotlib.pyplot as plt
|
|
86
|
-
import matplotlib.animation as animation
|
|
87
|
-
interV=1000/fps #time interval for each frame: ms
|
|
88
|
-
# w_in=w/dpi
|
|
89
|
-
# h_in=h/dpi
|
|
90
|
-
fig, ax = plt.subplots(figsize=(w/dpi, h/dpi))#figsize unit: inch
|
|
91
|
-
plt.rcParams.update({'font.size': tl_size})
|
|
92
|
-
plt.xlabel(label[0])#Change xy label if needed
|
|
93
|
-
plt.ylabel(label[1])
|
|
94
|
-
l=plt.plot(x,y,'grey') #For inital plot
|
|
95
|
-
redLine, = plt.plot(x[:0],y[:0],color=c, lw=3)
|
|
96
|
-
time_text = ax.text(5,7,str(y[0])+'°',fontsize=20)
|
|
97
|
-
# plt.text(5, 7, str(y[0],fontsize=20))
|
|
98
|
-
def animate(i):
|
|
99
|
-
redLine.set_data(x[:i], y[:i])
|
|
100
|
-
# plt.text(5, 7, str(y[i])+'°',fontsize=20) # Text is overlapping with previous frames
|
|
101
|
-
time_text.set_text(str(round(y[i],1))+'°')
|
|
102
|
-
# print(str(i)/len(x))
|
|
103
|
-
return tuple([redLine,]) + tuple([time_text])
|
|
104
|
-
|
|
105
|
-
plt.tight_layout() #To avoid boarder
|
|
106
|
-
# create animation using the animate() function
|
|
107
|
-
ani = animation.FuncAnimation(fig, animate, frames=len(x), \
|
|
108
|
-
interval=interV, blit=True, repeat=True)
|
|
109
|
-
ani.save(outpath)
|
|
110
|
-
plt.show()
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
in-situ TEM Toolbox - Data process
|
|
4
|
+
|
|
5
|
+
Assembles of functions related to movie input output
|
|
6
|
+
|
|
7
|
+
Example:
|
|
8
|
+
|
|
9
|
+
import insitu_DP as DP
|
|
10
|
+
IO.f2tif(path,1)
|
|
11
|
+
|
|
12
|
+
Created on Tue Jun 11 10:25:25 2019
|
|
13
|
+
@author: Mona
|
|
14
|
+
"""
|
|
15
|
+
import numpy as np
|
|
16
|
+
|
|
17
|
+
def readcsvCol(path,col):
|
|
18
|
+
"""
|
|
19
|
+
Function to read csv rol into array
|
|
20
|
+
Inputs: file path; col number
|
|
21
|
+
Output: 1D np array
|
|
22
|
+
|
|
23
|
+
Example:
|
|
24
|
+
x = readcsvCol(path,1)
|
|
25
|
+
"""
|
|
26
|
+
import csv
|
|
27
|
+
x=[]
|
|
28
|
+
with open(path,'r') as csvfile:
|
|
29
|
+
plots = csv.reader(csvfile, delimiter=',')
|
|
30
|
+
for row in plots:
|
|
31
|
+
if row[col]=='':
|
|
32
|
+
x.append(np.nan)
|
|
33
|
+
else:
|
|
34
|
+
x.append(float(row[col]))
|
|
35
|
+
# plt.plot(x,y) #to check if the read result is correct
|
|
36
|
+
return x
|
|
37
|
+
def readcsv(path,col_list):
|
|
38
|
+
"""
|
|
39
|
+
Function to read csv rol into array
|
|
40
|
+
Inputs: file path; col number list
|
|
41
|
+
Output: 1D np array
|
|
42
|
+
|
|
43
|
+
Example:
|
|
44
|
+
x = readcsv(path,[0:3])
|
|
45
|
+
"""
|
|
46
|
+
# w= len(col_list)
|
|
47
|
+
x=readcsvCol(path,col_list[0])
|
|
48
|
+
# l = len(x)
|
|
49
|
+
D=np.zeros((len(x),len(col_list)))
|
|
50
|
+
i=0
|
|
51
|
+
for col in col_list:
|
|
52
|
+
|
|
53
|
+
x=readcsvCol(path,col)
|
|
54
|
+
D[:,i]=x
|
|
55
|
+
i=i+1
|
|
56
|
+
# D = [D, x]
|
|
57
|
+
return D
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def writeCSV(pathout,data):
|
|
61
|
+
# import csv
|
|
62
|
+
import numpy as np
|
|
63
|
+
# (length,width)=np.shape(data)
|
|
64
|
+
# np.savetxt(pathout, data, fmt='%1.4d', delimiter=",")
|
|
65
|
+
np.savetxt(pathout, data, fmt='%.4f', delimiter=",")
|
|
66
|
+
|
|
67
|
+
def plot2ani(x,y,outpath,label,w=800,h=600,fps=10,dpi=72,tl_size=20,c='r'):
|
|
68
|
+
"""
|
|
69
|
+
Function to make plot into animation
|
|
70
|
+
Inputs:
|
|
71
|
+
data: x y;
|
|
72
|
+
Movie setting: size: w,h ;
|
|
73
|
+
fps; savepath
|
|
74
|
+
label: ['xlabel','ylabel'] str array
|
|
75
|
+
tl_size: title font size
|
|
76
|
+
c: color of the plot line
|
|
77
|
+
dpi: dpi for screen : 72 for 4k screen, 96 for 1080p screen
|
|
78
|
+
Output: mp4 movie
|
|
79
|
+
|
|
80
|
+
Example:
|
|
81
|
+
plot2ani(x,y,w,h,fps,outpath,dpi,tl_size,'r')
|
|
82
|
+
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
import matplotlib.pyplot as plt
|
|
86
|
+
import matplotlib.animation as animation
|
|
87
|
+
interV=1000/fps #time interval for each frame: ms
|
|
88
|
+
# w_in=w/dpi
|
|
89
|
+
# h_in=h/dpi
|
|
90
|
+
fig, ax = plt.subplots(figsize=(w/dpi, h/dpi))#figsize unit: inch
|
|
91
|
+
plt.rcParams.update({'font.size': tl_size})
|
|
92
|
+
plt.xlabel(label[0])#Change xy label if needed
|
|
93
|
+
plt.ylabel(label[1])
|
|
94
|
+
l=plt.plot(x,y,'grey') #For inital plot
|
|
95
|
+
redLine, = plt.plot(x[:0],y[:0],color=c, lw=3)
|
|
96
|
+
time_text = ax.text(5,7,str(y[0])+'°',fontsize=20)
|
|
97
|
+
# plt.text(5, 7, str(y[0],fontsize=20))
|
|
98
|
+
def animate(i):
|
|
99
|
+
redLine.set_data(x[:i], y[:i])
|
|
100
|
+
# plt.text(5, 7, str(y[i])+'°',fontsize=20) # Text is overlapping with previous frames
|
|
101
|
+
time_text.set_text(str(round(y[i],1))+'°')
|
|
102
|
+
# print(str(i)/len(x))
|
|
103
|
+
return tuple([redLine,]) + tuple([time_text])
|
|
104
|
+
|
|
105
|
+
plt.tight_layout() #To avoid boarder
|
|
106
|
+
# create animation using the animate() function
|
|
107
|
+
ani = animation.FuncAnimation(fig, animate, frames=len(x), \
|
|
108
|
+
interval=interV, blit=True, repeat=True)
|
|
109
|
+
ani.save(outpath)
|
|
110
|
+
plt.show()
|
|
111
|
+
|
|
112
|
+
def getintensity(x,y,disk,img):
|
|
113
|
+
"""
|
|
114
|
+
Function to get intensity of a disk region at point (x,y)
|
|
115
|
+
Inputs:
|
|
116
|
+
x,y: coordinates of the detection point
|
|
117
|
+
disk: size of pixels for detection region
|
|
118
|
+
img: 2D grayscale image
|
|
119
|
+
"""
|
|
120
|
+
x_l=int(x-disk)
|
|
121
|
+
x_r=int(x+disk)
|
|
122
|
+
y_l=int(y-disk)
|
|
123
|
+
y_r=int(y+disk)
|
|
124
|
+
intensity=int(np.mean(img[y_l:y_r,x_l:x_r]))
|
|
125
|
+
return intensity
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def findconnectingpoints(points,startpoint,r,level):
|
|
129
|
+
"""
|
|
130
|
+
FUnction for find all surrounding points within distance r betwwen each other from startpoint
|
|
131
|
+
return: index of all connected points
|
|
132
|
+
"""
|
|
133
|
+
from scipy import spatial
|
|
134
|
+
tree = spatial.cKDTree(points, leafsize=30)
|
|
135
|
+
idx =tree.query_ball_point(startpoint,r)
|
|
136
|
+
i=0
|
|
137
|
+
while i<level:
|
|
138
|
+
for results in idx:
|
|
139
|
+
nearby_point = points[results]
|
|
140
|
+
idx2=tree.query_ball_point(nearby_point ,r)
|
|
141
|
+
idx=list(set(idx)|set(idx2))
|
|
142
|
+
idx=list(set(idx)|set(idx2))
|
|
143
|
+
i=i+1
|
|
144
|
+
print(idx)
|
|
145
|
+
return idx
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
#Automatic find ROI bg color from
|
|
150
|
+
def AutoROIbg(img):
|
|
151
|
+
"""
|
|
152
|
+
Function to find ROI color from BW image:
|
|
153
|
+
if ROI is 255, then the bg is 0
|
|
154
|
+
"""
|
|
155
|
+
bg=int(np.mean(img))
|
|
156
|
+
if bg<128:
|
|
157
|
+
ROI =255
|
|
158
|
+
else:
|
|
159
|
+
ROI = 0
|
|
160
|
+
return ROI
|
|
144
161
|
|
|
@@ -2,7 +2,7 @@ from setuptools import setup
|
|
|
2
2
|
|
|
3
3
|
setup(
|
|
4
4
|
name='insituTEM',
|
|
5
|
-
version='0.1.
|
|
5
|
+
version='0.1.5',
|
|
6
6
|
author='Meng Li',
|
|
7
7
|
description='A package of tools for processing in situ TEM data',
|
|
8
8
|
packages=['insituTEM'],
|
|
@@ -13,7 +13,6 @@ setup(
|
|
|
13
13
|
'numpy',
|
|
14
14
|
'opencv-python',
|
|
15
15
|
'scipy',
|
|
16
|
-
'PIL',
|
|
17
16
|
'matplotlib'
|
|
18
17
|
],
|
|
19
18
|
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|