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.
@@ -1,5 +1,5 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: insituTEM
3
- Version: 0.1.3
3
+ Version: 0.1.5
4
4
  Summary: A package of tools for processing in situ TEM data
5
5
  Author: Meng Li
@@ -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
- def findconnectingpoints(points,startpoint,r,level):
114
- """
115
- FUnction for find all surrounding points within distance r betwwen each other from startpoint
116
- return: index of all connected points
117
- """
118
- from scipy import spatial
119
- tree = spatial.cKDTree(points, leafsize=30)
120
- idx =tree.query_ball_point(startpoint,r)
121
- i=0
122
- while i<level:
123
- for results in idx:
124
- nearby_point = points[results]
125
- idx2=tree.query_ball_point(nearby_point ,r)
126
- idx=list(set(idx)|set(idx2))
127
- idx=list(set(idx)|set(idx2))
128
- i=i+1
129
- print(idx)
130
- return idx
131
-
132
- #Automatic find ROI bg color from
133
- def AutoROIbg(img):
134
- """
135
- Function to find ROI color from BW image:
136
- if ROI is 255, then the bg is 0
137
- """
138
- bg=int(np.mean(img))
139
- if bg<128:
140
- ROI =255
141
- else:
142
- ROI = 0
143
- return ROI
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
 
@@ -1,5 +1,5 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: insituTEM
3
- Version: 0.1.3
3
+ Version: 0.1.5
4
4
  Summary: A package of tools for processing in situ TEM data
5
5
  Author: Meng Li
@@ -4,5 +4,4 @@ tqdm
4
4
  numpy
5
5
  opencv-python
6
6
  scipy
7
- PIL
8
7
  matplotlib
@@ -2,7 +2,7 @@ from setuptools import setup
2
2
 
3
3
  setup(
4
4
  name='insituTEM',
5
- version='0.1.3',
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