1
- # -*- coding: utf-8 -*-
2
-
3
1
"""
4
- galaxy group classes
2
+ Module containing the `~halotools.mock_observables.FoFGroups` class used to
3
+ identify friends-of-friends groups of points.
5
4
"""
6
5
7
- from __future__ import (absolute_import , division , print_function ,
8
- unicode_literals )
6
+ from __future__ import absolute_import , division , print_function , unicode_literals
9
7
10
8
import numpy as np
11
9
from scipy .sparse import csgraph , csr_matrix
10
+
11
+ from .pair_counters .pairwise_distance_xy_z import pairwise_distance_xy_z
12
+
12
13
from ..custom_exceptions import HalotoolsError
13
- from .pair_counters .double_tree_pair_matrix import xy_z_pair_matrix
14
14
15
15
igraph_available = True
16
- try : import igraph
16
+ try :
17
+ import igraph
17
18
except ImportError :
18
19
igraph_available = False
19
20
if igraph_available is True : #there is another package called igraph--need to distinguish.
20
21
if not hasattr (igraph ,'Graph' ):
21
22
igraph_available is False
22
23
no_igraph_msg = ("igraph package not installed. Some functions will not be available. \n "
23
- "See http://igraph.org/ and note that there are two packages called \n "
24
- "'igraph'." )
24
+ "See http://igraph.org/ and note that there are two packages called 'igraph'." )
25
25
26
- __all__ = ['FoFGroups' ]
26
+ __all__ = ['FoFGroups' ]
27
27
__author__ = ['Duncan Campbell' ]
28
28
29
29
class FoFGroups (object ):
@@ -37,34 +37,42 @@ def __init__(self, positions, b_perp, b_para, period=None, Lbox=None, num_thread
37
37
38
38
The first two dimensions (x, y) define the plane for perpendicular distances.
39
39
The third dimension (z) is used for line-of-sight distances.
40
+
40
41
See the :ref:`mock_obs_pos_formatting` documentation page for
41
42
instructions on how to transform your coordinate position arrays into the
42
43
format accepted by the ``positions`` argument.
43
- See also :ref:`galaxy_catalog_analysis_tutorial5`.
44
44
45
+ See also :ref:`galaxy_catalog_analysis_tutorial5`.
46
+
45
47
Parameters
46
48
----------
47
49
positions : array_like
48
50
Npts x 3 numpy array containing 3-D positions of galaxies.
49
-
51
+ Length units assumed to be in Mpc/h, here and throughout Halotools.
52
+
50
53
b_perp : float
51
- Normalized maximum linking length in the perpendicular direction.
52
- Normalized to the mean separation between galaxies.
54
+ Maximum linking length in the perpendicular direction,
55
+ normalized to the mean separation between galaxies.
53
56
54
57
b_para : float
55
- Normalized maximum linking length in the parallel direction.
56
- Normalized to the mean separation between galaxies.
58
+ Maximum linking length in the parallel direction,
59
+ normalized to the mean separation between galaxies.
57
60
58
61
period : array_like, optional
59
- length 3 array defining periodic boundary conditions.
60
-
62
+ Length-3 sequence defining the periodic boundary conditions
63
+ in each dimension. If you instead provide a single scalar, Lbox,
64
+ period is assumed to be the same in all Cartesian directions.
65
+ Length units assumed to be in Mpc/h, here and throughout Halotools.
66
+
61
67
Lbox : array_like, optional
62
68
length 3 array defining boundaries of the simulation box.
63
69
64
70
num_threads : int, optional
65
- number of threads to use in calculation. Default is 1. A string 'max' may be
66
- used to indicate that the pair counters should use all available cores on
67
- the machine.
71
+ Number of threads to use in calculation, where parallelization is performed
72
+ using the python ``multiprocessing`` module. Default is 1 for a purely serial
73
+ calculation, in which case a multiprocessing Pool object will
74
+ never be instantiated. A string 'max' may be used to indicate that
75
+ the pair counters should use all available cores on the machine.
68
76
69
77
Examples
70
78
--------
@@ -73,7 +81,7 @@ def __init__(self, positions, b_perp, b_para, period=None, Lbox=None, num_thread
73
81
74
82
>>> Npts = 1000
75
83
>>> Lbox = 1.0
76
- >>> period = np.array([ Lbox,Lbox,Lbox])
84
+ >>> period = Lbox
77
85
78
86
>>> x = np.random.random(Npts)
79
87
>>> y = np.random.random(Npts)
@@ -103,11 +111,11 @@ def __init__(self, positions, b_perp, b_para, period=None, Lbox=None, num_thread
103
111
raise ValueError ("Lbox and Period cannot be both be None." )
104
112
elif (Lbox is None ) & (period is not None ):
105
113
Lbox = period
106
- elif np . shape ( Lbox ) == ():
107
- Lbox = np .array ([ Lbox ] * 3 )
108
- elif np . shape (Lbox )== ( 1 ,) :
109
- Lbox = np .array ([Lbox [ 0 ]] * 3 )
110
- else : Lbox = np . array ( Lbox )
114
+
115
+ Lbox = np .atleast_1d ( Lbox )
116
+ if len (Lbox ) == 1 :
117
+ Lbox = np .array ([period , period , period ] )
118
+
111
119
if np .shape (Lbox ) != (3 ,):
112
120
raise ValueError ("Lbox must be an array of length 3, or number indicating the\
113
121
length of one side of a cube" )
@@ -123,7 +131,7 @@ def __init__(self, positions, b_perp, b_para, period=None, Lbox=None, num_thread
123
131
self .d_perp = self .b_perp / (self .n_gal ** (1.0 / 3.0 ))
124
132
self .d_para = self .b_para / (self .n_gal ** (1.0 / 3.0 ))
125
133
126
- self .m_perp , self .m_para = xy_z_pair_matrix (
134
+ self .m_perp , self .m_para = pairwise_distance_xy_z (
127
135
self .positions , self .positions , self .d_perp , self .d_para ,
128
136
period = self .period ,num_threads = num_threads )
129
137
@@ -171,7 +179,8 @@ def create_graph(self):
171
179
"""
172
180
if igraph_available is True :
173
181
self .g = _scipy_to_igraph (self .m , self .positions , directed = False )
174
- else : raise HalotoolsError (no_igraph_msg )
182
+ else :
183
+ raise HalotoolsError (no_igraph_msg )
175
184
176
185
def get_degree (self ):
177
186
"""
@@ -186,7 +195,8 @@ def get_degree(self):
186
195
if igraph_available is True :
187
196
self .degree = self .g .degree ()
188
197
return self .degree
189
- else : raise HalotoolsError (no_igraph_msg )
198
+ else :
199
+ raise HalotoolsError (no_igraph_msg )
190
200
191
201
def get_betweenness (self ):
192
202
"""
@@ -200,7 +210,8 @@ def get_betweenness(self):
200
210
if igraph_available is True :
201
211
self .betweenness = self .g .betweenness ()
202
212
return self .betweenness
203
- else : raise HalotoolsError (no_igraph_msg )
213
+ else :
214
+ raise HalotoolsError (no_igraph_msg )
204
215
205
216
def get_multiplicity (self ):
206
217
"""
@@ -211,7 +222,8 @@ def get_multiplicity(self):
211
222
mltp = np .array (clusters .sizes ())
212
223
self .multiplicity = mltp [self .group_ids ]
213
224
return self .multiplicity
214
- else : raise HalotoolsError (no_igraph_msg )
225
+ else :
226
+ raise HalotoolsError (no_igraph_msg )
215
227
216
228
def get_edges (self ):
217
229
"""
0 commit comments