99from ParticleSpy .particle_save import save_plist
1010
1111class Particle (object ):
12- """A segmented particle object."""
12+ """A segmented particle object.
13+
14+ Attributes
15+ ----------
16+ properties : dict
17+ Dictionary of particle properties created by the ParticleAnalysis() function.
18+ origin : str
19+ Origin of particle data, e.g. filename or acquisition number.
20+ zone : str
21+ Zone axis of particle.
22+ mask : array
23+ Boolean array corresponding to the particle pixels on the original image.
24+ image : Hyperspy signal object
25+ Image of particle.
26+ maps : dict
27+ Dictionary containing elemental maps of the particle.
28+ spectrum : Hyperspy signal object
29+ Spectrum obtained from the particle.
30+ composition : dict
31+ Dictionary of composition values for the particle.
32+
33+ """
34+
35+ def __init__ (self ):
36+ self .properties = {}
1337
1438 def set_origin (self , origin ):
1539 """A container for the origin of data (filename, acquisition number etc.)"""
1640 self .origin = origin
1741
1842 def set_area (self , area , units ):
19- self .area = area
20- self .area_units = units
43+ self .properties ['area' ] = {'value' :area ,'units' :units }
44+
45+ def set_circdiam (self , circdiam , units ):
46+ self .properties ['equivalent circular diameter' ] = {'value' :circdiam ,'units' :units }
47+
48+ def set_axes_lengths (self ,axeslengths ,units ):
49+ self .properties ['major axis length' ] = {'value' :axeslengths [0 ],'units' :units }
50+ self .properties ['minor axis length' ] = {'value' :axeslengths [1 ],'units' :units }
2151
2252 def set_circularity (self , circularity ):
23- self .circularity = circularity
53+ self .properties ['circularity' ] = {'value' :circularity ,'units' :None }
54+
55+ def set_eccentricity (self ,eccentricity ):
56+ self .properties ['eccentricity' ] = {'value' :eccentricity ,'units' :None }
57+
58+ def set_intensity (self ,intensity ):
59+ self .properties ['intensity' ] = {'value' :intensity ,'units' :None }
2460
2561 def set_zone (self , zone ):
2662 self .zone = zone
@@ -64,10 +100,10 @@ def plot_area(self,bins=20):
64100 areas = []
65101
66102 for p in self .list :
67- areas .append (p .area )
103+ areas .append (p .properties [ ' area' ][ 'value' ] )
68104
69105 plt .hist (areas ,bins = bins )
70- plt .xlabel ("Area (" + self .list [0 ].area_units + ")" )
106+ plt .xlabel ("Area (" + self .list [0 ].properties [ 'area' ][ 'units' ] + ")" )
71107 plt .ylabel ("No. of particles" )
72108
73109 def plot_circularity (self ,bins = 20 ):
@@ -78,8 +114,33 @@ def plot_circularity(self,bins=20):
78114 circularities = []
79115
80116 for p in self .list :
81- circularities .append (p .circularity )
117+ circularities .append (p .properties [ ' circularity' ][ 'value' ] )
82118
83119 plt .hist (circularities ,bins = bins )
84120 plt .xlabel ("Circularity" )
121+ plt .ylabel ("No. of particles" )
122+
123+ def plot (self ,prop = 'area' ,bins = 20 ):
124+ """
125+ Displays a histogram of the chosen particle property.
126+
127+ Parameters
128+ ----------
129+ prop : str
130+ The name of the property to plot as a histogram.
131+ bins : int
132+ The number of bins in the histogram.
133+
134+ """
135+
136+ property_list = []
137+
138+ for p in self .list :
139+ property_list .append (p .properties [prop ]['value' ])
140+
141+ plt .hist (property_list ,bins = bins )
142+ if self .list [0 ].properties [prop ]['units' ] == None :
143+ plt .xlabel (prop .capitalize ())
144+ else :
145+ plt .xlabel (prop .capitalize ()+ " (" + self .list [0 ].properties [prop ]['units' ]+ ")" )
85146 plt .ylabel ("No. of particles" )
0 commit comments