cosmic-popsynth 3.6.2__cp313-cp313-macosx_14_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.
- cosmic/.dylibs/libgcc_s.1.1.dylib +0 -0
- cosmic/.dylibs/libgfortran.5.dylib +0 -0
- cosmic/.dylibs/libquadmath.0.dylib +0 -0
- cosmic/Match.py +191 -0
- cosmic/__init__.py +32 -0
- cosmic/_commit_hash.py +1 -0
- cosmic/_evolvebin.cpython-313-darwin.so +0 -0
- cosmic/_version.py +1 -0
- cosmic/bse_utils/__init__.py +18 -0
- cosmic/bse_utils/zcnsts.py +570 -0
- cosmic/bse_utils/zdata.py +596 -0
- cosmic/checkstate.py +128 -0
- cosmic/data/cosmic-settings.json +1635 -0
- cosmic/evolve.py +607 -0
- cosmic/filter.py +214 -0
- cosmic/get_commit_hash.py +15 -0
- cosmic/output.py +466 -0
- cosmic/plotting.py +680 -0
- cosmic/sample/__init__.py +26 -0
- cosmic/sample/cmc/__init__.py +18 -0
- cosmic/sample/cmc/elson.py +411 -0
- cosmic/sample/cmc/king.py +260 -0
- cosmic/sample/initialbinarytable.py +251 -0
- cosmic/sample/initialcmctable.py +449 -0
- cosmic/sample/sampler/__init__.py +25 -0
- cosmic/sample/sampler/cmc.py +418 -0
- cosmic/sample/sampler/independent.py +1252 -0
- cosmic/sample/sampler/multidim.py +882 -0
- cosmic/sample/sampler/sampler.py +130 -0
- cosmic/test_evolve.py +108 -0
- cosmic/test_match.py +30 -0
- cosmic/test_sample.py +580 -0
- cosmic/test_utils.py +198 -0
- cosmic/utils.py +1574 -0
- cosmic_popsynth-3.6.2.data/scripts/cosmic-pop +544 -0
- cosmic_popsynth-3.6.2.dist-info/METADATA +55 -0
- cosmic_popsynth-3.6.2.dist-info/RECORD +38 -0
- cosmic_popsynth-3.6.2.dist-info/WHEEL +6 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Copyright (C) Duncan Macleod (2013)
|
|
3
|
+
#
|
|
4
|
+
# This file is part of GWpy.
|
|
5
|
+
#
|
|
6
|
+
# GWpy 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
|
+
# GWpy 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 GWpy. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
|
|
19
|
+
"""Fetch registration for database queries
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
import re
|
|
23
|
+
|
|
24
|
+
from six import string_types
|
|
25
|
+
|
|
26
|
+
from astropy.io.registry import IORegistryError
|
|
27
|
+
from astropy.table import Table
|
|
28
|
+
|
|
29
|
+
_SAMPLERS = {}
|
|
30
|
+
|
|
31
|
+
__author__ = "Duncan Macleod <duncan.macleod@ligo.org>"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def register_sampler(data_format, data_class, function, force=False, usage=None):
|
|
35
|
+
"""Register a new method to InitialBinaryTable.sampler() for a given format
|
|
36
|
+
|
|
37
|
+
Parameters
|
|
38
|
+
----------
|
|
39
|
+
data_format : `str`
|
|
40
|
+
name of the format to be registered
|
|
41
|
+
|
|
42
|
+
data_class : `type`
|
|
43
|
+
the class that the sampler returns
|
|
44
|
+
|
|
45
|
+
function : `callable`
|
|
46
|
+
the method to call from :meth:`InitialBinaryTable.sampler`
|
|
47
|
+
|
|
48
|
+
force : `bool`, optional
|
|
49
|
+
overwrite existing registration for ``data_format`` if found,
|
|
50
|
+
default: `False`
|
|
51
|
+
"""
|
|
52
|
+
key = (data_format, data_class)
|
|
53
|
+
if key not in _SAMPLERS or force:
|
|
54
|
+
_SAMPLERS[key] = (function, usage)
|
|
55
|
+
else:
|
|
56
|
+
raise IORegistryError(
|
|
57
|
+
"Fetcher for format '{0}' and class '{1}' "
|
|
58
|
+
"has already been "
|
|
59
|
+
"defined".format(data_format, data_class)
|
|
60
|
+
)
|
|
61
|
+
_update__doc__(data_class)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def get_sampler(data_format, data_class):
|
|
65
|
+
"""Return the :meth:`~InitialBinaryTable.sampler` function for the given format
|
|
66
|
+
|
|
67
|
+
Parameters
|
|
68
|
+
----------
|
|
69
|
+
data_format : `str`
|
|
70
|
+
name of the format
|
|
71
|
+
|
|
72
|
+
data_class : `type`
|
|
73
|
+
the class that the sampler returns
|
|
74
|
+
|
|
75
|
+
Raises
|
|
76
|
+
------
|
|
77
|
+
astropy.io.registry.IORegistryError
|
|
78
|
+
if not registration is found matching ``data_format``
|
|
79
|
+
"""
|
|
80
|
+
try:
|
|
81
|
+
return _SAMPLERS[(data_format, data_class)][0]
|
|
82
|
+
except KeyError:
|
|
83
|
+
formats = "\n".join(_SAMPLERS.keys())
|
|
84
|
+
raise IORegistryError(
|
|
85
|
+
"No sampler definer for format %r. "
|
|
86
|
+
"The available formats are:\n%r" % (data_format, formats)
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _update__doc__(data_class):
|
|
91
|
+
header = "The available named formats are:"
|
|
92
|
+
sampler = data_class.sampler
|
|
93
|
+
|
|
94
|
+
# if __doc__ isn't a string, bail-out now
|
|
95
|
+
if not isinstance(sampler.__doc__, string_types):
|
|
96
|
+
return
|
|
97
|
+
|
|
98
|
+
# remove the old format list
|
|
99
|
+
lines = sampler.__doc__.splitlines()
|
|
100
|
+
try:
|
|
101
|
+
pos = [i for i, line in enumerate(lines) if header in line][0]
|
|
102
|
+
except IndexError:
|
|
103
|
+
pass
|
|
104
|
+
else:
|
|
105
|
+
lines = lines[:pos]
|
|
106
|
+
|
|
107
|
+
# work out the indentation
|
|
108
|
+
matches = [re.search(r"(\S)", line) for line in lines[1:]]
|
|
109
|
+
indent = min(match.start() for match in matches if match)
|
|
110
|
+
|
|
111
|
+
# now re-write the format list
|
|
112
|
+
formats = []
|
|
113
|
+
for fmt, cls in sorted(_SAMPLERS, key=lambda x: x[0]):
|
|
114
|
+
if cls is not data_class:
|
|
115
|
+
continue
|
|
116
|
+
usage = _SAMPLERS[(fmt, cls)][1]
|
|
117
|
+
formats.append((fmt, "``sampler(%r, %s)``" % (fmt, usage)))
|
|
118
|
+
format_str = Table(rows=formats, names=["Format", "Basic usage"]).pformat(
|
|
119
|
+
max_lines=-1, max_width=80, align=(">", "<")
|
|
120
|
+
)
|
|
121
|
+
format_str[1] = format_str[1].replace("-", "=")
|
|
122
|
+
format_str.insert(0, format_str[1])
|
|
123
|
+
format_str.append(format_str[0])
|
|
124
|
+
|
|
125
|
+
lines.extend([" " * indent + line for line in [header, ""] + format_str])
|
|
126
|
+
# and overwrite the docstring
|
|
127
|
+
try:
|
|
128
|
+
sampler.__doc__ = "\n".join(lines)
|
|
129
|
+
except AttributeError:
|
|
130
|
+
sampler.__func__.__doc__ = "\n".join(lines)
|
cosmic/test_evolve.py
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"""Unit test for cosmic
|
|
2
|
+
"""
|
|
3
|
+
|
|
4
|
+
__author__ = 'Katie Breivik <katie.breivik@gmail.com>'
|
|
5
|
+
|
|
6
|
+
import os
|
|
7
|
+
import unittest
|
|
8
|
+
import numpy as np
|
|
9
|
+
import pandas as pd
|
|
10
|
+
|
|
11
|
+
from cosmic.evolve import Evolve
|
|
12
|
+
from cosmic.sample.initialbinarytable import InitialBinaryTable
|
|
13
|
+
from cosmic.sample import initialbinarytable
|
|
14
|
+
from cosmic import evolve
|
|
15
|
+
|
|
16
|
+
import warnings
|
|
17
|
+
warnings.filterwarnings("ignore")
|
|
18
|
+
|
|
19
|
+
TEST_DATA_DIR = os.path.join(os.path.split(__file__)[0], 'data')
|
|
20
|
+
PARAMS_INI = os.path.join(TEST_DATA_DIR,'Params.ini')
|
|
21
|
+
INIT_CONDITIONS = pd.read_hdf(os.path.join(TEST_DATA_DIR, 'initial_conditions_for_testing.hdf5'), key='initC')
|
|
22
|
+
KICK_INITC = pd.read_hdf(os.path.join(TEST_DATA_DIR, 'kick_initial_conditions.h5'), key='initC')
|
|
23
|
+
|
|
24
|
+
init_conds_columns = initialbinarytable.INITIAL_CONDITIONS_COLUMNS_ALL
|
|
25
|
+
|
|
26
|
+
INIT_CONDITIONS_NO_BSE_COLUMNS = INIT_CONDITIONS[init_conds_columns]
|
|
27
|
+
BPP_DF = pd.read_hdf(os.path.join(TEST_DATA_DIR, 'unit_tests_results.hdf5'), key='bpp')
|
|
28
|
+
BCM_DF = pd.read_hdf(os.path.join(TEST_DATA_DIR, 'unit_tests_results.hdf5'), key='bcm')
|
|
29
|
+
BSEFlag_columns = list(set(evolve.INITIAL_BINARY_TABLE_SAVE_COLUMNS) - set(initialbinarytable.INITIAL_CONDITIONS_COLUMNS_ALL))
|
|
30
|
+
BSEDict = INIT_CONDITIONS[BSEFlag_columns].to_dict(orient='index')[0]
|
|
31
|
+
BSEDict['qcrit_array'] = [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]
|
|
32
|
+
BSEDict['natal_kick_array'] = [[-100.0,-100.0,-100.0,-100.0,0.0], [-100.0,-100.0,-100.0,-100.0,0.0]]
|
|
33
|
+
BSEDict['fprimc_array'] = [2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,
|
|
34
|
+
2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,
|
|
35
|
+
2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0]
|
|
36
|
+
BSEDict['grflag'] = 1
|
|
37
|
+
BSEDict['don_lim'] = -1
|
|
38
|
+
BSEDict['acc_lim'] = -1
|
|
39
|
+
BSEDict['wd_mass_lim'] = 0
|
|
40
|
+
BSEDict['kick_flag'] = -1
|
|
41
|
+
|
|
42
|
+
class TestEvolve(unittest.TestCase):
|
|
43
|
+
"""`TestCase` for the cosmic
|
|
44
|
+
"""
|
|
45
|
+
def test_single_evolve_with_table(self):
|
|
46
|
+
|
|
47
|
+
# Check that the sample_primary function samples mass correctly
|
|
48
|
+
EvolvedBinaryBPP, EvolvedBinaryBCM, initCond, kick_info = Evolve.evolve(
|
|
49
|
+
initialbinarytable=INIT_CONDITIONS, randomseed=523574)
|
|
50
|
+
|
|
51
|
+
pd.testing.assert_frame_equal(EvolvedBinaryBPP, BPP_DF, check_dtype=False, check_exact=False)
|
|
52
|
+
pd.testing.assert_frame_equal(EvolvedBinaryBCM, BCM_DF, check_dtype=False, check_exact=False)
|
|
53
|
+
|
|
54
|
+
def test_single_evolve_with_dict(self):
|
|
55
|
+
EvolvedBinaryBPP, EvolvedBinaryBCM, initCond, kick_info = Evolve.evolve(
|
|
56
|
+
initialbinarytable=INIT_CONDITIONS_NO_BSE_COLUMNS, BSEDict=BSEDict, randomseed=523574)
|
|
57
|
+
|
|
58
|
+
pd.testing.assert_frame_equal(EvolvedBinaryBPP, BPP_DF, check_dtype=False, check_exact=False)
|
|
59
|
+
pd.testing.assert_frame_equal(EvolvedBinaryBCM, BCM_DF, check_dtype=False, check_exact=False)
|
|
60
|
+
|
|
61
|
+
def test_single_evolve_with_inifile(self):
|
|
62
|
+
EvolvedBinaryBPP, EvolvedBinaryBCM, initCond, kick_info = Evolve.evolve(
|
|
63
|
+
initialbinarytable=INIT_CONDITIONS_NO_BSE_COLUMNS, params=PARAMS_INI, randomseed=523574)
|
|
64
|
+
|
|
65
|
+
pd.testing.assert_frame_equal(EvolvedBinaryBPP, BPP_DF, check_dtype=False, check_exact=False)
|
|
66
|
+
pd.testing.assert_frame_equal(EvolvedBinaryBCM, BCM_DF, check_dtype=False, check_exact=False)
|
|
67
|
+
|
|
68
|
+
def test_single_evolve_with_dict_and_table(self):
|
|
69
|
+
EvolvedBinaryBPP, EvolvedBinaryBCM, initCond, kick_info = Evolve.evolve(
|
|
70
|
+
initialbinarytable=INIT_CONDITIONS, BSEDict=BSEDict, randomseed=523574)
|
|
71
|
+
|
|
72
|
+
pd.testing.assert_frame_equal(EvolvedBinaryBPP, BPP_DF, check_dtype=False, check_exact=False)
|
|
73
|
+
pd.testing.assert_frame_equal(EvolvedBinaryBCM, BCM_DF, check_dtype=False, check_exact=False)
|
|
74
|
+
|
|
75
|
+
def test_multi_evolve_with_table(self):
|
|
76
|
+
# Check that the sample_primary function samples mass correctly
|
|
77
|
+
EvolvedBinaryBPP, EvolvedBinaryBCM, initCond, kick_info = Evolve.evolve(
|
|
78
|
+
initialbinarytable=INIT_CONDITIONS, n_per_block=100)
|
|
79
|
+
|
|
80
|
+
pd.testing.assert_frame_equal(EvolvedBinaryBPP, BPP_DF, check_dtype=False, check_exact=False)
|
|
81
|
+
pd.testing.assert_frame_equal(EvolvedBinaryBCM, BCM_DF, check_dtype=False, check_exact=False)
|
|
82
|
+
|
|
83
|
+
def test_multi_evolve_with_dict(self):
|
|
84
|
+
EvolvedBinaryBPP, EvolvedBinaryBCM, initCond, kick_info = Evolve.evolve(
|
|
85
|
+
initialbinarytable=INIT_CONDITIONS_NO_BSE_COLUMNS, BSEDict=BSEDict, randomseed=523574, n_per_block=100)
|
|
86
|
+
|
|
87
|
+
pd.testing.assert_frame_equal(EvolvedBinaryBPP, BPP_DF, check_dtype=False, check_exact=False)
|
|
88
|
+
pd.testing.assert_frame_equal(EvolvedBinaryBCM, BCM_DF, check_dtype=False, check_exact=False)
|
|
89
|
+
|
|
90
|
+
def test_multi_evolve_with_inifile(self):
|
|
91
|
+
EvolvedBinaryBPP, EvolvedBinaryBCM, initCond, kick_info = Evolve.evolve(
|
|
92
|
+
initialbinarytable=INIT_CONDITIONS_NO_BSE_COLUMNS, params=PARAMS_INI, randomseed=523574, n_per_block=100)
|
|
93
|
+
|
|
94
|
+
pd.testing.assert_frame_equal(EvolvedBinaryBPP, BPP_DF, check_dtype=False, check_exact=False)
|
|
95
|
+
pd.testing.assert_frame_equal(EvolvedBinaryBCM, BCM_DF, check_dtype=False, check_exact=False)
|
|
96
|
+
|
|
97
|
+
def test_multi_evolve_with_dict_and_table(self):
|
|
98
|
+
EvolvedBinaryBPP, EvolvedBinaryBCM, initCond, kick_info = Evolve.evolve(
|
|
99
|
+
initialbinarytable=INIT_CONDITIONS, BSEDict=BSEDict, randomseed=523574, n_per_block=100)
|
|
100
|
+
|
|
101
|
+
pd.testing.assert_frame_equal(EvolvedBinaryBPP, BPP_DF, check_dtype=False, check_exact=False)
|
|
102
|
+
pd.testing.assert_frame_equal(EvolvedBinaryBCM, BCM_DF, check_dtype=False, check_exact=False)
|
|
103
|
+
|
|
104
|
+
def test_ejection_velocity_pfahl(self):
|
|
105
|
+
EvolvedBinaryBPP, EvolvedBinaryBCM, initCond, kick_info = Evolve.evolve(
|
|
106
|
+
initialbinarytable=KICK_INITC)
|
|
107
|
+
|
|
108
|
+
self.assertAlmostEqual(kick_info['vsys_2_total'].iloc[0], 482.346136, places=5)
|
cosmic/test_match.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Unit test for cosmic
|
|
2
|
+
"""
|
|
3
|
+
|
|
4
|
+
__author__ = 'Katie Breivik <katie.breivik@gmail.com>'
|
|
5
|
+
|
|
6
|
+
import os
|
|
7
|
+
import unittest
|
|
8
|
+
import numpy as np
|
|
9
|
+
import scipy.integrate
|
|
10
|
+
import pandas as pd
|
|
11
|
+
|
|
12
|
+
from cosmic import Match
|
|
13
|
+
|
|
14
|
+
np.random.seed(2)
|
|
15
|
+
sample = np.random.uniform(0,1,500)
|
|
16
|
+
|
|
17
|
+
MATCH_TEST = np.log10(1-0.99636185870762237007)
|
|
18
|
+
|
|
19
|
+
class TestMatch(unittest.TestCase):
|
|
20
|
+
"""`TestCase` for the match method
|
|
21
|
+
"""
|
|
22
|
+
def test_Match(self):
|
|
23
|
+
# test the match by dividing the sample into to sub samples
|
|
24
|
+
# one containing half of the set and one containing the full set
|
|
25
|
+
|
|
26
|
+
dataCm = [sample[:int(len(sample)/2)], sample]
|
|
27
|
+
match, bin_width = Match.match(dataCm)
|
|
28
|
+
self.assertAlmostEqual(match,MATCH_TEST)
|
|
29
|
+
|
|
30
|
+
|