Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving em_progenitors.py and ns_sequence data from tmpltbank to new neutron_stars package #3937

Merged
merged 63 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
ee354e1
Remnant mass function moved from em_progenitors to conversions. Relev…
Feb 10, 2022
29a8ddd
no change, pushing to resolve issue with checkout
Feb 11, 2022
97bcb6c
importing pycbc.tmpltbank rather than pycbc in attempt to resolve imp…
Feb 11, 2022
4bfd370
moved neutron stars code and eos data to new package and created __in…
Feb 14, 2022
faaea1a
Renamed em_progenitors as ns_functions and moved to neutron_stars pac…
Feb 15, 2022
a64bcbe
First suite of changes suggested in PR. Removes some cases of double …
Feb 16, 2022
31f0691
Removed the logging and sys calls. Changed the exception to a ValueEr…
SamuelH-97 Feb 18, 2022
e8aa44e
retrigger checks
Feb 25, 2022
42b145b
EM-bright work
Feb 23, 2022
2fdb638
Constraint string substitutions for static args
Mar 15, 2022
2dd6ebc
Speed up remnant mass calculation (1st attempt)
Mar 15, 2022
c1c6eaa
Adding derivatives in ns_functions for root solver
Mar 18, 2022
72f6dd2
Add to comment
Mar 21, 2022
65f35fb
Missing bracket
Mar 21, 2022
d287a84
Fix bugs
Mar 21, 2022
e3c3b6f
Enable spherical or cartesian spins for m_rem calc
Mar 22, 2022
4bdb8a9
Reorganising neutron_stars module
Mar 22, 2022
f7961a7
Some fixes to isso solver
Mar 23, 2022
fad9d12
Adding 2D interpolation for ISSO radii
Mar 23, 2022
2127485
Refined bivariate interpolator for ISSO calc
Mar 24, 2022
1b4c3da
Change in setup.py, needed for tox
May 12, 2022
4e4e499
Fix docstrings
May 17, 2022
8ee3bc0
Fixing doc strings
May 17, 2022
59f8bfd
Remove old pycbc_dark_vs_bright_injections code
May 24, 2022
162fb0c
Merge branch 'master' into EMbright_branch
SamuelH-97 Jul 14, 2022
1902416
Added newline at end of file to conform to codeclimate check
Jul 25, 2022
fec33b7
removed trailing whitespace
Jul 25, 2022
883852e
removed trailing whitespaces
Jul 25, 2022
600c021
Removed imports outside of toplevel
Jul 25, 2022
0696f4c
removed trailing whitespaces
Jul 25, 2022
91efbff
Empty-Commit, retrigger checks
Jul 25, 2022
b4600c3
correctly importing pickle and os.path at top of pg_isso_solver.py
Jul 25, 2022
ec8670f
Creating 3 variables in which previously repeated lines of calculatio…
Jul 28, 2022
3a503ab
fixed issue with unnecessary indents
Jul 28, 2022
d66b23b
changed variables to functions after negecting to realise they relied…
Jul 28, 2022
fe802b1
removed trailing whitespaces
Aug 2, 2022
d769479
Fixing error in trig functions (missing return)
Aug 2, 2022
c4c1d57
removed functions aimed at avoiding repeated code. Deemed unnecessary
Aug 9, 2022
85576b6
rectified mislabeled parameter chi_lims to bounds as required by func…
Aug 9, 2022
391858f
introducing latest version of remnant mass function in coord_utils ge…
Aug 10, 2022
bfaa2f0
added short description of concat_grid function
Aug 10, 2022
36c3f7a
Moved ns_sequence_file initialisation above it's first use to avoid e…
Aug 10, 2022
9d305c7
fixed issue with methods used to call variables in remnant mass function
Aug 11, 2022
ee204af
introduced eos as a variable in the get_random_mass function in order…
Aug 22, 2022
45dc282
adding new lines between function definitions
Aug 22, 2022
eb527c7
re-introduced eta_nsbh in get_random_mass as it is required later in …
Aug 22, 2022
3f26b52
moved module level imports to top of init file
Aug 22, 2022
d44c6da
moved module level imports back to bottom of init file as moving to t…
Aug 22, 2022
058320a
removed trailing whitespace
Aug 22, 2022
ab2ff2a
Initialised input_is_array variable and added functionality to check …
Aug 24, 2022
f9946e0
resolved issue with undefined variable erroneously added in code whic…
Aug 29, 2022
9c17498
addrd r prefix to doctring in an attempt to resolve issues related to…
Sep 2, 2022
169a654
Replace code which checks if input is an array with more reliable method
SamuelH-97 Sep 26, 2022
5ee27ef
Updated docstrings to more accurately represent the forms of inputs a…
Sep 26, 2022
61691d0
Fixed typo in docstring
SamuelH-97 Sep 26, 2022
c3b25fb
Reformatted code to agree with codeclimate
SamuelH-97 Sep 26, 2022
c16af9b
Removed hardcoded output path for generate_isso_bivariate_interp()
Sep 26, 2022
10dd3cc
Fix wrong import name
titodalcanton Sep 26, 2022
636fbda
Updated comments in constraint function
SamuelH-97 Oct 3, 2022
d981400
Remove ISSO interpolant, will bring back a better version later
titodalcanton Oct 6, 2022
f49809c
Forgot a few things
titodalcanton Oct 7, 2022
65bd0d2
Merge pull request #1 from titodalcanton/embright_remove_isso_interp
SamuelH-97 Oct 11, 2022
3d255a0
Update pycbc/tmpltbank/coord_utils.py
pannarale Oct 13, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/pycbc_create_injections
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ dists = distributions.read_distributions_from_config(cp, opts.dist_section)

# construct class that will draw the samples
randomsampler = JointDistribution(variable_params, *dists,
**{"constraints" : constraints})
**{"constraints": constraints})

if opts.ninjections:
draw_size = opts.ninjections
Expand Down
201 changes: 0 additions & 201 deletions bin/pycbc_dark_vs_bright_injections

This file was deleted.

97 changes: 94 additions & 3 deletions pycbc/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# =============================================================================
#
"""
This modules provides a library of functions that calculate waveform parameters
This module provides a library of functions that calculate waveform parameters
from other parameters. All exposed functions in this module's namespace return
one parameter given a set of inputs.
"""
Expand All @@ -33,7 +33,10 @@
import lal
from pycbc.detector import Detector
import pycbc.cosmology
from .coordinates import spherical_to_cartesian as _spherical_to_cartesian
from .coordinates import (
spherical_to_cartesian as _spherical_to_cartesian,
cartesian_to_spherical as _cartesian_to_spherical)
from pycbc import neutron_stars as ns

pykerr = pycbc.libutils.import_optional('pykerr')
lalsim = pycbc.libutils.import_optional('lalsimulation')
Expand Down Expand Up @@ -417,6 +420,92 @@ def lambda_from_mass_tov_file(mass, tov_file, distance=0.):
lambdav = numpy.interp(mass_src, mass_from_file, lambda_from_file)
return lambdav


def remnant_mass_from_mass1_mass2_spherical_spin_eos(
mass1, mass2, spin1a=0.0, spin1pol=0.0, eos='2H'):
"""
Function that determines the remnant disk mass of an NS-BH system
using the fit to numerical-relativity results discussed in
Foucart, Hinderer & Nissanke, PRD 98, 081501(R) (2018).
The BH spin may be misaligned with the orbital angular momentum.
In such cases the ISSO is approximated following the approach of
Stone, Loeb & Berger, PRD 87, 084053 (2013), which was originally
devised for a previous NS-BH remnant mass fit of
Foucart, PRD 86, 124007 (2012).
Note: NS spin is assumed to be 0!
Parameters
-----------
mass1 : float
The mass of the black hole, in solar masses.
mass2 : float
The mass of the neutron star, in solar masses.
spin1a : float, optional
The dimensionless magnitude of the spin of mass1. Default = 0.
spin1pol : float, optional
The tilt angle of the spin of mass1. Default = 0 (aligned w L).
eos : str, optional
Name of the equation of state being adopted. Default is '2H'.
Returns
----------
remnant_mass: float
The remnant mass in solar masses
"""
mass1, mass2, spin1a, spin1pol, input_is_array = ensurearray(
mass1, mass2, spin1a, spin1pol)
# mass1 must be greater than mass2
try:
if any(mass2 > mass1) and input_is_array:
raise ValueError(f'Require mass1 >= mass2')
except TypeError:
if mass2 > mass1 and not input_is_array:
raise ValueError(f'Require mass1 >= mass2. {mass1} < {mass2}')
ns_compactness, ns_b_mass = ns.initialize_eos(mass2, eos)
eta = eta_from_mass1_mass2(mass1, mass2)
remnant_mass = ns.foucart18(
eta, ns_compactness, ns_b_mass, spin1a, spin1pol)
return formatreturn(remnant_mass, input_is_array)


def remnant_mass_from_mass1_mass2_cartesian_spin_eos(
mass1, mass2, spin1x=0.0, spin1y=0.0, spin1z=0.0, eos='2H'):
"""
Function that determines the remnant disk mass of an NS-BH system
using the fit to numerical-relativity results discussed in
Foucart, Hinderer & Nissanke, PRD 98, 081501(R) (2018).
The BH spin may be misaligned with the orbital angular momentum.
In such cases the ISSO is approximated following the approach of
Stone, Loeb & Berger, PRD 87, 084053 (2013), which was originally
devised for a previous NS-BH remnant mass fit of
Foucart, PRD 86, 124007 (2012).
Note: NS spin is assumed to be 0!
Parameters
-----------
mass1 : float
The mass of the black hole, in solar masses.
mass2 : float
The mass of the neutron star, in solar masses.
spin1x : float, optional
The dimensionless x-component of the spin of mass1. Default = 0.
spin1y : float, optional
The dimensionless y-component of the spin of mass1. Default = 0.
spin1z : float, optional
The dimensionless z-component of the spin of mass1. Default = 0.
eos: str, optional
Name of the equation of state being adopted. Default is '2H'.
Returns
----------
remnant_mass: float
The remnant mass in solar masses
"""
spin1a, _, spin1pol = _cartesian_to_spherical(spin1x, spin1y, spin1z)
return remnant_mass_from_mass1_mass2_spherical_spin_eos(
mass1, mass2, spin1a, spin1pol, eos=eos)


#
# =============================================================================
#
Expand Down Expand Up @@ -1537,5 +1626,7 @@ def nltides_gw_phase_diff_isco(f_low, f0, amplitude, n, m1, m2):
'optimal_dec_from_detector', 'optimal_ra_from_detector',
'chi_eff_from_spherical', 'chi_p_from_spherical',
'nltides_gw_phase_diff_isco', 'spin_from_pulsar_freq',
'freqlmn_from_other_lmn', 'taulmn_from_other_lmn'
'freqlmn_from_other_lmn', 'taulmn_from_other_lmn',
'remnant_mass_from_mass1_mass2_spherical_spin_eos',
'remnant_mass_from_mass1_mass2_cartesian_spin_eos'
]
11 changes: 10 additions & 1 deletion pycbc/distributions/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
This modules provides classes for evaluating multi-dimensional constraints.
"""

import re
import scipy.spatial
import numpy
import h5py
Expand All @@ -37,7 +38,15 @@ def __init__(self, constraint_arg, static_args=None, transforms=None,
static_args.items(), key=lambda x: len(x[0]), reverse=True))
)
for arg, val in static_args.items():
constraint_arg = constraint_arg.replace(arg, str(val))
swp = f"'{val}'" if isinstance(val, str) else str(val)
# Substitute static arg name for value if it appears in the
# constraint_arg string at the beginning of a word and is not
# followed by an underscore or equals sign.
# This ensures that static_args that are also kwargs in function calls are
# handled correctly, i.e., the kwarg is not touched while its value is replaced
# with the static_arg value.
constraint_arg = re.sub(
r'\b{}(?!\_|\=)'.format(arg), swp, constraint_arg)
self.constraint_arg = constraint_arg
self.transforms = transforms
for kwarg in kwargs.keys():
Expand Down
10 changes: 9 additions & 1 deletion pycbc/io/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,8 @@ class WaveformArray(_FieldArrayWithDefaults):
parameters.spin_px, parameters.spin_py, parameters.spin_pz,
parameters.spin_sx, parameters.spin_sy, parameters.spin_sz,
parameters.spin1_a, parameters.spin1_azimuthal, parameters.spin1_polar,
parameters.spin2_a, parameters.spin2_azimuthal, parameters.spin2_polar]
parameters.spin2_a, parameters.spin2_azimuthal, parameters.spin2_polar,
parameters.remnant_mass]

@property
def primary_mass(self):
Expand Down Expand Up @@ -1912,5 +1913,12 @@ def spin2_polar(self):
return coordinates.cartesian_to_spherical_polar(
self.spin2x, self.spin2y, self.spin2z)

@property
def remnant_mass(self):
"""Returns the remnant mass for an NS-BH binary."""
return conversions.remnant_mass_from_mass1_mass2_cartesian_spin_eos(
self.mass1, self.mass2, self.spin1x,
self.spin1y, self.spin1z)


__all__ = ['FieldArray', 'WaveformArray']
9 changes: 9 additions & 0 deletions pycbc/neutron_stars/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import os.path
# Setup the directory with the NS equilibrium sequence(s)
NS_DATA_DIRECTORY = os.path.join(
os.path.dirname(__file__), 'ns_data')
NS_SEQUENCES = [
f.replace('equil_', '').replace('.dat', '')
for f in os.listdir(NS_DATA_DIRECTORY) if f.endswith('.dat')]
from pycbc.neutron_stars.eos_utils import *
from pycbc.neutron_stars.pg_isso_solver import *
Loading