Skip to content

Commit 657571c

Browse files
Merge from upstream (#29)
* Update particle_analysis.rst * Add 3D plotting of properties * Add tests for 3D plotting * Update test_plotting.py * Update test_plotting.py * Update ptcl_class.py * Update 3D plot label setting * Fix plotting bug * Update ptcl_class.py * Update test_plotting.py * Add 3D plotting to docs * Update 3D plotting * Add additional 3d plotting functionality * Bugfix for area unit calculation * added Niblack and Sauvola segmentation Added two additional local segmentation methods: Niblack and Sauvola. Also converted local threshold method to odd integers only, as specified by skimage.filters.threshold_local * Bugfix for Invert check in SegUI Fixed invert toggle not applying to SegUI image after 'Update'. Fixed typo in ParticleAnalysis A typo in docs Changes to segmentation.rst to add Niblack and Sauvola. changed parameter files back. * Revert "Bugfix for Invert check in SegUI" This reverts commit 3e65293. * no altered parameters files commit back to 3e65293 without broken parameters files * Assitional clustering tests added new clustering test capable of sets of parameters for each thresholding method * changed test-clustering * fixed test particle clustering * more Parameter testing test particle clustering extended to all thresholding methods apart from sauvola. * Local Filter kernel Fixes disables option to change local filter kernel until a local segmentation method is selected. For Niblack, Sauvola and Local thresholding methods local kernel filter is locked to odd numbers updated parameters file to account for new local filter kernel values * test for scikit image update * remove parameters in regionprops * Update test_parameters.dat * updated test_parameters * updated watershed function used * Updated watershed in SegUI * Update test_params.dat again * corrected clean_borders corrected clean borders to take place after watershed separation to exclude less complete particles * improved compatibility for scikits reverted scikit-learn earliest to 0.21 and scikit-image to 0.17.1 * updated test parameters updated test parameters in test_parameters.dat. updated the default parameters as these were overriding the user-created parameters if they were set at zero * Update setup.py * adds new clustering methods added new clustering methods for individual hyperspy objects and series of hyperspy objects * Update ParticleAnalysis.py * Update test_parameters.dat * Update test_particle_clustering.py * more filter parameters * Update ParticleAnalysis.py * New SegUI tab added new SegUI tab to develop improved labelling methods * added Radion buttons for different tools * added line tool * Update SegUI.py * fixed tool alignment * Fixed Tool selection * added polygon tool * Updated coordinates of SegUI to use QPoints * Tidied Tools and line drawings * Fixed flood Fill flood fill no longer darkens touside of image and correctly fills enclosed shapes * arr flipped to ARGB * updated colour selection of flood fill * moved flood fill to separate function * added test for learn clustering * added documentation and test fix * updated tests * New SegUI tab added new SegUI tab to develop improved labelling methods * added Radion buttons for different tools * added line tool * Update SegUI.py * fixed tool alignment * Fixed Tool selection * added polygon tool * Updated coordinates of SegUI to use QPoints * Tidied Tools and line drawings * Fixed flood Fill flood fill no longer darkens touside of image and correctly fills enclosed shapes * arr flipped to ARGB * updated colour selection of flood fill * moved flood fill to separate function * fixed color flood filling and added color tool buttons * flood fill colour is pen dependent * fixed flooding * added clear button * updated saving labels * added trainable segmentation * updated SegUI layout * corrected trainables * updated classifier * tidied SegUI * commented ClusterTrained * Working trainable segmentation * Update ParticleAnalysis.py * Update labels to v0.5.0 * added difference of gaussians * added membrane projection kernel * added documentation * added training to SegUI * fixed labels displaying on canvas * Update SegUI.py * fixed clustering methods * Adds docs and moves functions Moved all functions related to clustering and classifying to a new file 'segimgs.py' * rewrites clustering algorithms * moves segimgs.py to correct folder * improves docs & fixes bugs * adds partial test and bugfixes * adds test for trainSeg * Update test_particle_clustering.py * removes saving mask to png * fixes tests * updates docs updates docs with example of classifying multiple images * Update segmentation.rst * Update test_particle_clustering.py * Add Figure and axes nomeclature to 1D plotting to fix bug when using notebook backend * Update ptcl_class.py * Added kwargs for plotting * Update ptcl_class.py * Update ptcl_class.py * Update api.py * Removed plot_area and plot_circularity functions * Update test_plotting.py * Update api.py Co-authored-by: CameronGBell <cameronbell2236@gmail.com> Co-authored-by: CameronGBell <70440659+CameronGBell@users.noreply.github.com>
1 parent ccafb01 commit 657571c

3 files changed

Lines changed: 28 additions & 48 deletions

File tree

ParticleSpy/api.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def load(filename):
2020
p_list = load_plist(filename)
2121
return(p_list)
2222

23-
def plot(particle_lists,prop_list=['area'],bins=20):
23+
def plot(particle_lists,prop_list=['area'],**kwargs):
2424
"""
2525
Plots properties of all particles in the Particle_lists.
2626
@@ -43,8 +43,10 @@ def plot(particle_lists,prop_list=['area'],bins=20):
4343
plot([particles],['area'])
4444
4545
"""
46-
47-
if len(prop_list) == 2:
46+
if isinstance(prop_list,str):
47+
fig = plt.figure()
48+
ax = fig.add_subplot(111)
49+
elif len(prop_list) == 1 or len(prop_list) == 2:
4850
fig = plt.figure()
4951
ax = fig.add_subplot(111)
5052
elif len(prop_list) == 3:
@@ -53,14 +55,14 @@ def plot(particle_lists,prop_list=['area'],bins=20):
5355

5456
for p in particle_lists:
5557
if isinstance(prop_list,str):
56-
p._plot_one_property(prop_list,bins)
58+
p._plot_one_property(prop_list,ax,**kwargs)
5759
else:
5860
if len(prop_list) == 1:
59-
p._plot_one_property(prop_list[0],bins)
61+
p._plot_one_property(prop_list[0],ax,**kwargs)
6062
elif len(prop_list) == 2:
61-
p._plot_two_properties(prop_list,ax)
63+
p._plot_two_properties(prop_list,ax,**kwargs)
6264
elif len(prop_list) == 3:
63-
p._plot_three_properties(prop_list,ax)
65+
p._plot_three_properties(prop_list,ax,**kwargs)
6466
else:
6567
print("Can only plot one or two properties, please change the length of the property list.")
6668
break

ParticleSpy/ptcl_class.py

Lines changed: 17 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -115,35 +115,7 @@ def append(self,particle):
115115
def save(self,filename):
116116
save_plist(self,filename)
117117

118-
def plot_area(self,bins=20):
119-
"""
120-
Displays a plot of particle areas for analysed particles.
121-
"""
122-
123-
areas = []
124-
125-
for p in self.list:
126-
areas.append(p.properties['area']['value'])
127-
128-
plt.hist(areas,bins=bins)
129-
plt.xlabel("Area ("+self.list[0].properties['area']['units']+")")
130-
plt.ylabel("No. of particles")
131-
132-
def plot_circularity(self,bins=20):
133-
"""
134-
Displays a plot of particle circularity for analysed particles.
135-
"""
136-
137-
circularities = []
138-
139-
for p in self.list:
140-
circularities.append(p.properties['circularity']['value'])
141-
142-
plt.hist(circularities,bins=bins)
143-
plt.xlabel("Circularity")
144-
plt.ylabel("No. of particles")
145-
146-
def plot(self,prop_list=['area'],bins=20):
118+
def plot(self,prop_list=['area'],bins=20,**kwargs):
147119
"""
148120
Plots properties of all particles in the Particle_list.
149121
@@ -168,38 +140,42 @@ def plot(self,prop_list=['area'],bins=20):
168140
"""
169141

170142
if isinstance(prop_list,str):
171-
self._plot_one_property(prop_list,bins)
143+
fig = plt.figure()
144+
ax = fig.add_subplot(111)
145+
self._plot_one_property(prop_list,ax,**kwargs)
172146
else:
173147
if len(prop_list) == 1:
174-
self._plot_one_property(prop_list[0],bins)
148+
fig = plt.figure()
149+
ax = fig.add_subplot(111)
150+
self._plot_one_property(prop_list[0],ax,**kwargs)
175151
elif len(prop_list) == 2:
176152
fig = plt.figure()
177153
ax = fig.add_subplot(111)
178-
self._plot_two_properties(prop_list,ax)
154+
self._plot_two_properties(prop_list,ax,**kwargs)
179155
elif len(prop_list) == 3:
180156
fig3d = plt.figure()
181157
ax = fig3d.add_subplot(111, projection='3d')
182-
self._plot_three_properties(prop_list,ax)
158+
self._plot_three_properties(prop_list,ax,**kwargs)
183159
else:
184160
print("Can only plot a maximum of three properties, please change the length of the property list.")
185161

186162
plt.show()
187163

188-
def _plot_one_property(self,prop,bins):
164+
def _plot_one_property(self,prop,ax,**kwargs):
189165
property_list = []
190166

191167
for p in self.list:
192168
property_list.append(p.properties[prop]['value'])
193169

194-
plt.hist(property_list,bins=bins,alpha=0.5)
170+
ax.hist(property_list,**kwargs)
195171

196172
if self.list[0].properties[prop]['units'] == None:
197-
plt.xlabel(prop.capitalize())
173+
ax.set_xlabel(prop.capitalize())
198174
else:
199-
plt.xlabel(prop.capitalize()+" ("+self.list[0].properties[prop]['units']+")")
175+
ax.set_xlabel(prop.capitalize()+" ("+self.list[0].properties[prop]['units']+")")
200176
plt.ylabel("No. of particles")
201177

202-
def _plot_two_properties(self,prop_list,ax):
178+
def _plot_two_properties(self,prop_list,ax,**kwargs):
203179

204180
property_list_one = []
205181
property_list_two = []
@@ -208,7 +184,7 @@ def _plot_two_properties(self,prop_list,ax):
208184
property_list_one.append(p.properties[prop_list[0]]['value'])
209185
property_list_two.append(p.properties[prop_list[1]]['value'])
210186

211-
ax.scatter(property_list_one,property_list_two,alpha=0.5)
187+
ax.scatter(property_list_one,property_list_two,**kwargs)
212188

213189
if self.list[0].properties[prop_list[0]]['units'] == None:
214190
ax.set_xlabel(prop_list[0].capitalize())
@@ -220,7 +196,7 @@ def _plot_two_properties(self,prop_list,ax):
220196
else:
221197
ax.set_ylabel(prop_list[1].capitalize()+" ("+self.list[0].properties[prop_list[1]]['units']+")")
222198

223-
def _plot_three_properties(self, prop_list,ax):
199+
def _plot_three_properties(self, prop_list,ax,**kwargs):
224200

225201
property_list_one = []
226202
property_list_two = []
@@ -231,7 +207,7 @@ def _plot_three_properties(self, prop_list,ax):
231207
property_list_two.append(p.properties[prop_list[1]]['value'])
232208
property_list_three.append(p.properties[prop_list[2]]['value'])
233209

234-
ax.scatter(property_list_one, property_list_two, property_list_three)
210+
ax.scatter(property_list_one, property_list_two, property_list_three,**kwargs)
235211

236212
if self.list[0].properties[prop_list[0]]['units'] == None:
237213
ax.set_xlabel(prop_list[0].capitalize())

ParticleSpy/tests/test_plotting.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ def test_plotting():
77
p_list = ps.load(os.path.join(my_path, 'Test_particle.hdf5'))
88

99
p_list.plot('area')
10+
p_list.plot(['area'])
1011
p_list.plot(['area','circularity'])
1112
p_list.plot(['area','circularity','area'])
1213
p_list.plot(['area','circularity','area','area'])
1314

1415
ps.plot([p_list],'area')
16+
ps.plot([p_list],['area'])
1517
ps.plot([p_list],['area','circularity'])
1618
ps.plot([p_list],['area','circularity','area','area'])

0 commit comments

Comments
 (0)