Coverage for python/lsst/analysis/drp/_treecorrConfig.py: 56%
39 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-02-08 11:39 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2023-02-08 11:39 +0000
1# This file is part of analysis_drp.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
23__all__ = ("BinnedCorr2Config",)
25from lsst.pex.config import ChoiceField, Config, Field, FieldValidationError
28class BinnedCorr2Config(Config):
29 """A Config class that holds the various parameters supported by treecorr.
31 The fields in this class correspond to the parameters that can be passed to
32 BinnedCorr2 in `treecorr`, which is the base class for all two-point
33 correlation function calculations. The default values set for the fields
34 are identical to the default values set in v4.2 of `treecorr`. The
35 parameters that are excluded in this class are
36 'verbose', 'log_file', 'output_dots', 'rng' and 'pairwise' (deprecated).
37 For details about these options, see the documentation for `treecorr`:
38 https://rmjarvis.github.io/TreeCorr/_build/html/correlation2.html
40 A separate config class is used instead
41 of constructing a `~lsst.pex.config.DictField` so that mixed types can be
42 supported and the config can be validated at the beginning of the
43 execution.
45 Notes
46 -----
47 This is intended to be used in CalcRhoStatistics class.
48 """
50 nbins = Field( 50 ↛ exitline 50 didn't jump to the function exit
51 doc=(
52 "How many bins to use. "
53 "(Exactly three of nbins, bin_size, min_sep, max_sep "
54 "are required. If nbins is not given, it will be "
55 "calculated from the values of the other three, "
56 "rounding up to the next highest integer. "
57 "In this case, bin_size will be readjusted to account "
58 "for this rounding up."
59 ),
60 dtype=int,
61 optional=True,
62 check=lambda x: x > 0,
63 )
65 bin_size = Field(
66 doc=(
67 "The width of the bins in log(separation). "
68 "Exactly three of nbins, bin_size, min_sep, max_sep are required. "
69 "If bin_size is not given, it will be calculated from the values "
70 "of the other three."
71 ),
72 dtype=float,
73 optional=True,
74 )
76 min_sep = Field(
77 doc=(
78 "The minimum separation in units of sep_units, if relevant. "
79 "Exactly three of nbins, bin_size, min_sep, max_sep are required. "
80 "If min_sep is not given, it will be calculated from the values "
81 "of the other three."
82 ),
83 dtype=float,
84 optional=True,
85 )
87 max_sep = Field(
88 doc=(
89 "The maximum separation in units of sep_units, if relevant. "
90 "Exactly three of nbins, bin_size, min_sep, max_sep are required. "
91 "If max_sep is not given, it will be calculated from the values "
92 "of the other three."
93 ),
94 dtype=float,
95 optional=True,
96 )
98 sep_units = ChoiceField(
99 doc=(
100 "The units to use for the separation values, given as a string. "
101 "This includes both min_sep and max_sep above, as well as the "
102 "units of the output distance values."
103 ),
104 default="radian",
105 dtype=str,
106 optional=True,
107 allowed={
108 units: units
109 for units in ["arcsec", "arcmin", "degree", "hour", "radian"]
110 },
111 )
113 bin_slop = Field(
114 doc=(
115 "How much slop to allow in the placement of pairs in the bins. "
116 "If bin_slop = 1, then the bin into which a particular pair is "
117 "placed may be incorrect by at most 1.0 bin widths. "
118 r"If None, use a bin_slop that gives a maximum error of 10% on "
119 "any bin, which has been found to yield good results for most "
120 "applications."
121 ),
122 default=None,
123 dtype=float,
124 optional=True,
125 )
127 brute = Field(
128 doc=(
129 "Whether to use the 'brute force' algorithm? "
130 "Unlike treecorr, setting this to 1 or 2 is not supported."
131 ),
132 default=False,
133 dtype=bool,
134 optional=True,
135 )
137 split_method = ChoiceField(
138 doc=("How to split the cells in the tree when building the tree " "structure."),
139 default="mean",
140 dtype=str,
141 optional=True,
142 allowed={
143 "mean": "Use the arithmetic mean of the coordinate being split.",
144 "median": "Use the median of the coordinate being split.",
145 "middle": (
146 "Use the middle of the range; i.e. the average of the "
147 "minimum and maximum value."
148 ),
149 "random": (
150 "Use a random point somewhere in the middle two "
151 "quartiles of the range."
152 ),
153 },
154 )
156 min_top = Field(
157 doc=(
158 "The minimum number of top layers to use when setting up the "
159 "field. The top-level cells are where each calculation job "
160 "starts."
161 ),
162 default=3,
163 dtype=int,
164 optional=True,
165 )
167 max_top = Field(
168 doc=(
169 "The maximum number of top layers to use when setting up the "
170 "field. The top-level cells are where each calculation job "
171 "starts. There will typically be of order 2**max_top cells."
172 ),
173 default=10,
174 dtype=int,
175 optional=True,
176 )
178 precision = Field( 178 ↛ exitline 178 didn't jump to the function exit
179 doc=(
180 "The precision to use for the output values. This specifies how "
181 "many digits to write."
182 ),
183 default=4,
184 dtype=int,
185 optional=True,
186 check=lambda x: x > 0,
187 )
189 m2_uform = ChoiceField(
190 doc="The default functional form to use for aperture mass calculations.",
191 default="Crittenden",
192 dtype=str,
193 optional=True,
194 allowed={
195 "Crittenden": "Crittenden et al. (2002); ApJ, 568, 20",
196 "Schneider": "Schneider, et al (2002); A&A, 389, 729",
197 },
198 )
200 metric = ChoiceField(
201 doc=(
202 "Which metric to use for distance measurements. For details, see "
203 "https://rmjarvis.github.io/TreeCorr/_build/html/metric.html"
204 ),
205 default="Euclidean",
206 dtype=str,
207 optional=True,
208 allowed={
209 "Euclidean": "straight-line Euclidean distance between two points",
210 "FisherRperp": (
211 "the perpendicular component of the distance, "
212 "following the definitions in "
213 "Fisher et al, 1994 (MNRAS, 267, 927)"
214 ),
215 "OldRperp": (
216 "the perpendicular component of the distance using the "
217 "definition of Rperp from TreeCorr v3.x."
218 ),
219 "Rlens": (
220 "Distance from the first object (taken to be a lens) to "
221 "the line connecting Earth and the second object "
222 "(taken to be a lensed source)."
223 ),
224 "Arc": "the true great circle distance for spherical coordinates.",
225 "Periodic": "Like ``Euclidean``, but with periodic boundaries.",
226 },
227 )
229 bin_type = ChoiceField(
230 doc="What type of binning should be used?",
231 default="Log",
232 dtype=str,
233 optional=True,
234 allowed={
235 "Log": (
236 "Logarithmic binning in the distance. The bin steps will "
237 "be uniform in log(r) from log(min_sep) .. log(max_sep)."
238 ),
239 "Linear": (
240 "Linear binning in the distance. The bin steps will be "
241 "uniform in r from min_sep .. max_sep."
242 ),
243 "TwoD": (
244 "2-dimensional binning from x = (-max_sep .. max_sep) "
245 "and y = (-max_sep .. max_sep). The bin steps will be "
246 "uniform in both x and y. (i.e. linear in x,y)"
247 ),
248 },
249 )
251 min_rpar = Field(
252 doc=(
253 "The minimum difference in Rparallel to allow for pairs being "
254 "included in the correlation function. "
255 ),
256 default=None,
257 dtype=float,
258 optional=True,
259 )
261 max_rpar = Field(
262 doc=(
263 "The maximum difference in Rparallel to allow for pairs being "
264 "included in the correlation function. "
265 ),
266 default=None,
267 dtype=float,
268 optional=True,
269 )
271 period = Field(
272 doc="For the 'Periodic' metric, the period to use in all directions.",
273 default=None,
274 dtype=float,
275 optional=True,
276 )
278 xperiod = Field(
279 doc="For the 'Periodic' metric, the period to use in the x direction.",
280 default=None,
281 dtype=float,
282 optional=True,
283 )
285 yperiod = Field(
286 doc="For the 'Periodic' metric, the period to use in the y direction.",
287 default=None,
288 dtype=float,
289 optional=True,
290 )
292 zperiod = Field(
293 doc="For the 'Periodic' metric, the period to use in the z direction.",
294 default=None,
295 dtype=float,
296 optional=True,
297 )
299 var_method = ChoiceField(
300 doc="Which method to use for estimating the variance",
301 default="shot",
302 dtype=str,
303 optional=True,
304 allowed={
305 method: method
306 for method in [
307 "shot",
308 "jackknife",
309 "sample",
310 "bootstrap",
311 "marked_bootstrap",
312 ]
313 },
314 )
316 num_bootstrap = Field(
317 doc=(
318 "How many bootstrap samples to use for the 'bootstrap' and "
319 "'marked_bootstrap' var methods."
320 ),
321 default=500,
322 dtype=int,
323 optional=True,
324 )
326 num_threads = Field(
327 doc=(
328 "How many OpenMP threads to use during the calculation. "
329 "If set to None, use all the available CPU cores."
330 ),
331 default=None,
332 dtype=int,
333 optional=True,
334 )
336 def validate(self):
337 # Docs inherited from base class
338 super().validate()
339 req_params = (self.nbins, self.bin_size, self.min_sep, self.max_sep)
340 num_req_params = sum(param is not None for param in req_params)
341 if num_req_params != 3:
342 msg = (
343 "You must specify exactly three of ``nbins``, ``bin_size``, ``min_sep`` and ``max_sep``"
344 f" in treecorr_config. {num_req_params} parameters were set instead."
345 )
346 raise FieldValidationError(self.__class__.bin_size, self, msg)
348 if self.min_sep is not None and self.max_sep is not None:
349 if self.min_sep > self.max_sep:
350 raise FieldValidationError(
351 self.__class__.min_sep, self, "min_sep must be <= max_sep"
352 )
354 if self.min_rpar is not None and self.max_rpar is not None:
355 if self.min_rpar > self.max_rpar:
356 raise FieldValidationError(
357 self.__class__.min_rpar, self, "min_rpar must be <= max_rpar"
358 )