44from warnings import warn
55
66
7-
87def pairCorrelationKDTree2D (feat , cutoff , fraction = 1. , dr = .5 , p_indices = None , ndensity = None , boundary = None ,
98 handle_edge = True ):
109 """
@@ -172,12 +171,8 @@ def pairCorrelationKDTree3D(feat, cutoff, fraction = 1., dr = .5, p_indices = No
172171 for idx in p_indices :
173172 dist , idxs = ckdtree .query (points [idx ], k = max_p_count , distance_upper_bound = cutoff )
174173 dist = dist [dist > 0 ] # We don't want to count the same particle
175- #print dist.shape
176- #print dist[dist.shape[0] - 10:]
177-
174+
178175 area = (4. / 3. ) * np .pi * (np .arange (dr , cutoff + 2 * dr , dr )** 3 - np .arange (0 , cutoff + dr , dr )** 3 )
179-
180- #print area
181176
182177 if handle_edge :
183178 # Find the number of edge collisions at each radii
@@ -188,58 +183,40 @@ def pairCorrelationKDTree3D(feat, cutoff, fraction = 1., dr = .5, p_indices = No
188183
189184 # Use analyitcal solution to find area of disks cut off by one wall.
190185 # Grab the distance to the closest wall
191- #d = _distances_to_wall3D(points[idx], xmin, xmax, ymin, ymax, zmin, zmax).min()
192-
193- #inx = np.where(collisions == 1)[0]
194-
195- #theta = np.arccos(d / (r_edges[inx] + dr/2))
196- #area[inx] *= 1 - 2*np.pi*(1 - np.cos(theta)) / (4*np.pi)
186+ d = _distances_to_wall3D (points [idx ], xmin , xmax , ymin , ymax , zmin , zmax ).min ()
187+ inx = np .where (collisions == 1 )[0 ]
188+ theta = np .arccos (d / (r_edges [inx ] + dr / 2 ))
189+ area [inx ] *= 1 - 2 * np .pi * (1 - np .cos (theta )) / (4 * np .pi )
197190
198191 # If shell is cutoff by 2 or more walls, generate a bunch of points and use a mask to
199192 # estimate the area within the boundaries
200- inx = np .where (collisions >= 1 )[0 ]
193+ inx = np .where (collisions >= 2 )[0 ]
201194 x = refx [inx ] + points [idx ,0 ]
202195 y = refy [inx ] + points [idx ,1 ]
203196 z = refz [inx ] + points [idx ,2 ]
204197 mask = (x >= xmin ) & (x <= xmax ) & (y >= ymin ) & (y <= ymax ) & (z >= zmin ) & (z <= zmax )
205198 area [inx ] *= mask .sum (axis = 1 , dtype = 'float' ) / len (refx [0 ])
206199
207- print points [idx ]
208- print mask .sum (axis = 1 , dtype = 'float' ) / len (refx [0 ])
209-
210200 g_r += np .histogram (dist , bins = r_edges )[0 ] / area [:- 1 ]
211201
212202 g_r /= (ndensity * len (p_indices ))
213203 return r_edges , g_r
214204
215205def _num_wall_collisions2D (point , radius , xmin , xmax , ymin , ymax ):
206+ """Returns the number of walls a shell of a certain radius and position collides with.
207+ Wall boundaries specified by min, max parameters"""
216208 collisions = (point [0 ] + radius >= xmax ).astype (int ) + (point [0 ] - radius <= xmin ).astype (int ) + \
217209 (point [1 ] + radius >= ymax ).astype (int ) + (point [1 ] - radius <= ymin ).astype (int )
218210
219211 return collisions
220212
221213def _distances_to_wall2D (point , xmin , xmax , ymin , ymax ):
214+ """Returns the distance of a paritlce a position 'point' to the nearest wall"""
222215 return np .array ([point [0 ]- xmin , xmax - point [0 ], point [1 ]- ymin , ymax - point [1 ]])
223216
224217def _points_ring2D (r_edges , dr , n ):
225218 """Returns x, y array of points comprising shells extending from r to r_dr.
226-
227- layers determines how many concentric layers are in each shell,
228- and n determines the number of points in each layer"""
229-
230- """
231- refx=np.empty((len(r_edges), n*layers))
232- refy=refx.copy()
233- for index, r in enumerate(r_edges):
234- theta = np.linspace(0, 2*np.pi, n)
235- theta = theta.repeat(layers).reshape((len(theta), layers))
236- x = np.cos(theta) * np.linspace(r, r+dr, layers)
237- y = np.sin(theta) * np.linspace(r, r+dr, layers)
238- refx[index] = x.reshape(n*layers)
239- refy[index] = y.reshape(n*layers)
240-
241- return refx, refy
242- """
219+ n determines the number of points in each ring"""
243220
244221 refx_all , refy_all = [],[]
245222 for r in r_edges :
@@ -255,17 +232,21 @@ def _points_ring2D(r_edges, dr, n):
255232
256233
257234def _num_wall_collisions3D (point , radius , xmin , xmax , ymin , ymax , zmin , zmax ):
235+ """Returns the number of walls a shell of a certain radius and position collides with.
236+ Wall boundaries specified by min, max parameters"""
258237 collisions = (point [0 ] + radius >= xmax ).astype (int ) + (point [0 ] - radius <= xmin ).astype (int ) + \
259238 (point [1 ] + radius >= ymax ).astype (int ) + (point [1 ] - radius <= ymin ).astype (int ) + \
260239 (point [2 ] + radius >= zmax ).astype (int ) + (point [2 ] - radius <= zmin ).astype (int )
261240
262241 return collisions
263242
264243def _distances_to_wall3D (point , xmin , xmax , ymin , ymax , zmin , zmax ):
244+ """Returns the distance of a paritlce a position 'point' to the nearest wall"""
265245 return np .array ([point [0 ]- xmin , xmax - point [0 ], point [1 ]- ymin , ymax - point [1 ], point [2 ]- zmin , zmax - point [2 ]])
266246
267247def _points_ring3D (r_edges , dr , n ):
268- """Returns x, y, z arrays of points comprising shells extending from r to r_dr. n determines the density of the shells"""
248+ """Returns x, y, z arrays of points comprising shells extending from r to r_dr.
249+ n determines the number of particles in each of the shells"""
269250
270251 refx_all , refy_all , refz_all = [],[],[]
271252 for r in r_edges :
0 commit comments