cosmic-popsynth 3.4.15__cp310-cp310-macosx_11_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
Binary file
Binary file
cosmic/Match.py ADDED
@@ -0,0 +1,191 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) Katelyn Breivik (2017 - 2021)
3
+ #
4
+ # This file is part of cosmic.
5
+ #
6
+ # cosmic is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # cosmic is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with cosmic. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ """`Match`
20
+ """
21
+
22
+ import numpy as np
23
+ import astropy.stats as astroStats
24
+ import warnings
25
+ from cosmic.utils import dat_transform
26
+
27
+
28
+ __author__ = "Katelyn Breivik <katie.breivik@gmail.com>"
29
+ __credits__ = "Scott Coughlin <scott.coughlin@ligo.org>"
30
+ __all__ = ["match", "perform_convergence"]
31
+
32
+
33
+ def match(dataCm):
34
+ """Performs the Match calculation in Eq. 1 of Breivik & Larson (2018)
35
+
36
+ Parameters
37
+ ----------
38
+ dataCm : list
39
+ List of two cumulative data sets for a single paramter
40
+
41
+ Returns
42
+ -------
43
+ match : list
44
+ List of matches for each cumulative data set
45
+
46
+ binwidth : float
47
+ Binwidth of histograms used for match computation
48
+ """
49
+
50
+ # DEFINE A LIST TO HOLD THE BINNED DATA:
51
+ histo = [[], []]
52
+ histoBinEdges = [[], []]
53
+ # COMPUTE THE BINWIDTH FOR THE MOST COMPLETE DATA SET:
54
+ # NOTE: THIS WILL BE THE BINWIDTH FOR ALL THE HISTOGRAMS IN THE HISTO LIST
55
+ with warnings.catch_warnings():
56
+ warnings.filterwarnings(
57
+ "ignore", message="divide by zero encountered in double_scalars"
58
+ )
59
+ try:
60
+ bw, binEdges = astroStats.knuth_bin_width(
61
+ np.array(dataCm[0]), return_bins=True
62
+ )
63
+ except Exception:
64
+ bw, binEdges = astroStats.scott_bin_width(
65
+ np.array(dataCm[0]), return_bins=True
66
+ )
67
+ if bw < 1e-4:
68
+ bw = 1e-4
69
+ binEdges = np.arange(binEdges[0], binEdges[-1], bw)
70
+
71
+ # BIN THE DATA:
72
+ for i in range(2):
73
+ histo[i], histoBinEdges[i] = astroStats.histogram(
74
+ dataCm[i], bins=binEdges, density=True
75
+ )
76
+ # COMPUTE THE MATCH:
77
+ nominator = []
78
+ denominator1 = []
79
+ denominator2 = []
80
+ nominatorSum = []
81
+ denominator1Sum = []
82
+ denominator2Sum = []
83
+
84
+ histo2 = histo[1]
85
+ histo1 = histo[0]
86
+
87
+ for j in range(len(histo1)):
88
+ nominator.append(histo1[j] * histo2[j])
89
+ denominator1.append((histo1[j] * histo1[j]))
90
+ denominator2.append((histo2[j] * histo2[j]))
91
+ nominatorSum.append(np.sum(nominator))
92
+ denominator1Sum.append(np.sum(denominator1))
93
+ denominator2Sum.append(np.sum(denominator2))
94
+
95
+ nominatorSum = np.array(nominatorSum)
96
+ denominator1Sum = np.array(denominator1Sum)
97
+ denominator2Sum = np.array(denominator2Sum)
98
+
99
+ binwidth = binEdges[1] - binEdges[0]
100
+ if binwidth < 1e-7:
101
+ match = 1e-9
102
+ else:
103
+ match = np.log10(1 - nominatorSum / np.sqrt(denominator1Sum * denominator2Sum))
104
+
105
+ return match[0], binwidth
106
+
107
+
108
+ def perform_convergence(conv_params, conv_1, conv_2, log_file):
109
+ """Performs the convergence calculations for each convergence parameter
110
+ and binary state
111
+
112
+ Parameters
113
+ ----------
114
+ conv_params : dict
115
+ List of user supplied convergence parameters
116
+ conv_1 : DataFrame
117
+ Cumulative data set of conv arrays
118
+ conv_2 : DataFrame
119
+ Most recent data set of conv array from most recent BSE run
120
+ log_file : file write
121
+ File to log matches or if the convergence params are not appropriate
122
+ e.g. eccentricity for a disrupted system
123
+
124
+ Returns
125
+ -------
126
+ match : array
127
+ Matches for each cumulative data set
128
+ """
129
+ match_all = []
130
+ for conv_param in conv_params:
131
+ if (conv_param == "ecc") and (np.all(conv_1[conv_param] < 1e-7)):
132
+ log_file.write(
133
+ "{0} is circular or disrupted for all conv binaries\n".format(
134
+ conv_param
135
+ )
136
+ )
137
+ match_all.append(-9)
138
+ elif (conv_param == "ecc") and (np.all(conv_1[conv_param] == -1.0)):
139
+ log_file.write(
140
+ "{0} is the same for all disrupted binaries\n".format(conv_param)
141
+ )
142
+ match_all.append(-9)
143
+ elif conv_param == "ecc":
144
+ conv_1_ecc = conv_1.loc[conv_1.ecc > 0]
145
+ if len(conv_1_ecc) < 10:
146
+ log_file.write("not enough eccentric binaries to compute match")
147
+ match_all.append(-9)
148
+ else:
149
+ conv_2_ecc = conv_2.loc[conv_2.ecc > 0]
150
+ if len(conv_2_ecc) == len(conv_1_ecc):
151
+ conv_2_ecc = conv_2_ecc[: int(len(conv_2_ecc) / 2)]
152
+ match_compute, bw = match(
153
+ [
154
+ dat_transform(conv_1_ecc, [conv_param])[0].tolist(),
155
+ dat_transform(conv_2_ecc, [conv_param])[0].tolist(),
156
+ ]
157
+ )
158
+ match_all.append(match_compute)
159
+
160
+ elif (conv_param == "porb") and (
161
+ (np.all(conv_1[conv_param] == 0.0)) or (np.all(conv_1[conv_param] == -1.0))
162
+ ):
163
+ log_file.write(
164
+ "{0} is the same for all converging binaries\n".format(conv_param)
165
+ )
166
+ match_all.append(-9)
167
+ elif (conv_param == "sep") and (
168
+ (np.all(conv_1[conv_param] == 0.0)) or (np.all(conv_1[conv_param] == -1.0))
169
+ ):
170
+ log_file.write(
171
+ "{0} is the same for all converging binaries\n".format(conv_param)
172
+ )
173
+ match_all.append(-9)
174
+ else:
175
+ if len(conv_2) == len(conv_1):
176
+ conv_2 = conv_2[: int(len(conv_2) / 2)]
177
+ match_compute, bw = match(
178
+ [
179
+ dat_transform(conv_1, [conv_param])[0].tolist(),
180
+ dat_transform(conv_2, [conv_param])[0].tolist(),
181
+ ]
182
+ )
183
+ match_all.append(match_compute)
184
+
185
+ log_file.write("matches for converging population are are: {0}\n".format(match_all))
186
+ log_file.write(
187
+ "Number of binaries in converging population is: {0}\n".format(len(conv_1))
188
+ )
189
+ log_file.write("Binwidth is: {0}\n".format(bw))
190
+
191
+ return match_all
cosmic/__init__.py ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # Copyright (C) Katie Breivik (2017 - 2020)
4
+ #
5
+ # This file is part of COSMIC
6
+ #
7
+ # COSMIC is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # COSMIC is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with COSMIC. If not, see <http://www.gnu.org/licenses/>
19
+
20
+ """COSMIC (Compact Object Synthesis and Monte Carlo Investigation Code)
21
+ """
22
+
23
+ from ._version import __version__
24
+ from ._commit_hash import COMMIT_HASH
25
+
26
+ __version__ = __version__
27
+ __commithash__ = COMMIT_HASH
28
+ __author__ = "Katie Breivik <katie.breivik@gmail.com>"
29
+ __credits__ = [
30
+ "Scott Coughlin <scott.coughlin@ligo.org>",
31
+ "Michael Zevin <zevin@northwestern.edu>",
32
+ ]
cosmic/_commit_hash.py ADDED
@@ -0,0 +1 @@
1
+ COMMIT_HASH = "45efdfbda534f8f86ff03c3d0d4e6d7236411b3a"
Binary file
cosmic/_version.py ADDED
@@ -0,0 +1 @@
1
+ __version__ = "3.4.15"
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # Copyright (C) Scott Coughlin (2017 - 2021)
4
+ #
5
+ # This file is part of COSMIC
6
+ #
7
+ # COSMIC is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # COSMIC is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with COSMIC. If not, see <http://www.gnu.org/licenses/>