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

Add ability to set frame for returned waveform #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 23 additions & 8 deletions gwsurrogate/new/precessing_surrogate.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,12 @@ def coorb_spins_from_copr_spins(chiA_copr, chiB_copr, orbphase):
chiB_coorb = rotate_spin(chiB_copr, orbphase)
return chiA_coorb, chiB_coorb

def coprecessing_waveform_modes(orbphase, h_coorb):
"""Rotates waveform in co-orbital frame to co-precessing."""
q_rot = np.array([np.cos(orbphase / 2.), 0. * orbphase,
0. * orbphase, np.sin(orbphase / 2.)])
return rotateWaveform(q_rot, h_coorb)

def inertial_waveform_modes(t, orbphase, quat, h_coorb):
q_rot = np.array([np.cos(orbphase / 2.), 0. * orbphase,
0. * orbphase, np.sin(orbphase / 2.)])
Expand Down Expand Up @@ -877,7 +883,8 @@ def get_dynamics(self, q, chiA0, chiB0, init_quat=None, \

def __call__(self, x, fM_low=None, fM_ref=None, dtM=None,
timesM=None, dfM=None, freqsM=None, mode_list=None, ellMax=None,
precessing_opts=None, tidal_opts=None, par_dict=None):
precessing_opts=None, tidal_opts=None, par_dict=None,
frame='inertial'):
"""
Evaluates a precessing surrogate model.

Expand Down Expand Up @@ -940,7 +947,8 @@ def __call__(self, x, fM_low=None, fM_ref=None, dtM=None,
}
tidal_opts: Should be None for this model.
par_dict: Should be None for this model.

frame: The frame of the returned waveform. Options are "inertial",
"co-precessing", or "co-orbital"; default is "inertial".

Returns:
domain, h, dynamics.
Expand Down Expand Up @@ -1019,8 +1027,15 @@ def __call__(self, x, fM_low=None, fM_ref=None, dtM=None,
ellMax=ellMax)

# Transform the sparsely sampled waveform
h_inertial = inertial_waveform_modes(self.t_coorb, orbphase, quat,
h_coorb)
if frame == 'inertial':
h_array = inertial_waveform_modes(self.t_coorb, orbphase, quat,
h_coorb)
elif frame == 'co-precessing':
h_array = coprecessing_waveform_modes(orbphase, h_coorb)
elif frame == 'co-orbital':
h_array = h_coorb
else:
raise ValueError("unrecognized frame option {}".format(frame))

if timesM is not None:
if timesM[-1] > self.t_coorb[-1] + 0.01:
Expand Down Expand Up @@ -1053,16 +1068,16 @@ def __call__(self, x, fM_low=None, fM_ref=None, dtM=None,


if do_interp:
hre = splinterp_many(timesM, self.t_coorb, np.real(h_inertial))
him = splinterp_many(timesM, self.t_coorb, np.imag(h_inertial))
h_inertial = hre + 1.j*him
hre = splinterp_many(timesM, self.t_coorb, np.real(h_array))
him = splinterp_many(timesM, self.t_coorb, np.imag(h_array))
h_array = hre + 1.j*him

# Make mode dict
h = {}
i=0
for ell in range(2, ellMax+1):
for m in range(-ell, ell+1):
h[(ell, m)] = h_inertial[i]
h[(ell, m)] = h_array[i]
i += 1

# Transform and interpolate spins if needed
Expand Down
7 changes: 5 additions & 2 deletions gwsurrogate/surrogate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1719,7 +1719,7 @@ def _mode_sum(self, h_modes, theta, phi, fake_neg_modes=False):
def __call__(self, q, chiA0, chiB0, M=None, dist_mpc=None, f_low=None,
f_ref=None, dt=None, df=None, times=None, freqs=None,
mode_list=None, ellMax=None, inclination=None, phi_ref=0,
precessing_opts=None, tidal_opts=None, par_dict=None,
precessing_opts=None, tidal_opts=None, par_dict=None, frame='inertial',
units='dimensionless', skip_param_checks=False,
taper_end_duration=None):
"""
Expand Down Expand Up @@ -1879,6 +1879,9 @@ def __call__(self, q, chiA0, chiB0, M=None, dist_mpc=None, f_low=None,
par_dict: A dictionary containing any additional parameters needed for a
particular surrogate model. Default: None.

frame: The frame of the returned waveform. Options are "inertial",
"co-precessing", or "co-orbital"; default is "inertial".

units: 'dimensionless' or 'mks'. Default: 'dimensionless'.
If 'dimensionless': Any of f_low, f_ref, dt, df, times and
freqs, if specified, must be in dimensionless units. That
Expand Down Expand Up @@ -2057,7 +2060,7 @@ def __call__(self, q, chiA0, chiB0, M=None, dist_mpc=None, f_low=None,
fM_ref=fM_ref, dtM=dtM, timesM=timesM, dfM=dfM,
freqsM=freqsM, mode_list=mode_list, ellMax=ellMax,
precessing_opts=precessing_opts, tidal_opts=tidal_opts,
par_dict=par_dict)
par_dict=par_dict, frame=frame)

# taper the last portion of the waveform, regardless of whether or not
# this corresponds to inspiral, merger, or ringdown.
Expand Down