jaxtfwaves 0.2.0__py3-none-any.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.
- jaxtfwaves-0.2.0.dist-info/METADATA +144 -0
- jaxtfwaves-0.2.0.dist-info/RECORD +14 -0
- jaxtfwaves-0.2.0.dist-info/WHEEL +4 -0
- jaxtfwaves-0.2.0.dist-info/entry_points.txt +2 -0
- tfplugins/__init__.py +0 -0
- tfplugins/sobhbwaveform/__init__.py +0 -0
- tfplugins/sobhbwaveform/sobhbparams.py +758 -0
- tfplugins/sobhbwaveform/sobhbwaveform_ripple.py +474 -0
- tfwaves/__init__.py +9 -0
- tfwaves/interpolation.py +265 -0
- tfwaves/response.py +633 -0
- tfwaves/stft.py +902 -0
- tfwaves/utils.py +705 -0
- tfwaves/waveform.py +369 -0
tfwaves/response.py
ADDED
|
@@ -0,0 +1,633 @@
|
|
|
1
|
+
#! /usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Response module
|
|
6
|
+
|
|
7
|
+
This module provides functions for the response of LISA in time domain.
|
|
8
|
+
It is based on the LISA GW Response and lisaring implementations.
|
|
9
|
+
|
|
10
|
+
Authors:
|
|
11
|
+
Jean-Baptiste Bayle <j2b.bayle@gmail.com>
|
|
12
|
+
Chantal Pitte
|
|
13
|
+
Quentin Baghi <quentin.baghi@protonmail.com>
|
|
14
|
+
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import abc
|
|
18
|
+
import logging
|
|
19
|
+
from collections.abc import Iterable
|
|
20
|
+
|
|
21
|
+
import h5py
|
|
22
|
+
import jax
|
|
23
|
+
import jax.numpy as jnp
|
|
24
|
+
import lisaconstants as const
|
|
25
|
+
import numpy as np
|
|
26
|
+
from packaging.version import Version
|
|
27
|
+
|
|
28
|
+
from .utils import (
|
|
29
|
+
dot_custom,
|
|
30
|
+
emitter,
|
|
31
|
+
norm,
|
|
32
|
+
receiver,
|
|
33
|
+
spline_1d,
|
|
34
|
+
spline_2d,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
c_light = const.c # Speed of light
|
|
38
|
+
# AET matrix
|
|
39
|
+
aet_mat = np.array(
|
|
40
|
+
[
|
|
41
|
+
[-1 / jnp.sqrt(2), 0, 1 / jnp.sqrt(2)],
|
|
42
|
+
[1 / jnp.sqrt(6), -2 / jnp.sqrt(6), 1 / jnp.sqrt(6)],
|
|
43
|
+
[1 / jnp.sqrt(3), 1 / jnp.sqrt(3), 1 / jnp.sqrt(3)],
|
|
44
|
+
]
|
|
45
|
+
)
|
|
46
|
+
# Conversion from old MOSA ordering to LISA GW Response ordering
|
|
47
|
+
convert = jnp.array([0, 1, 2, 3, 5, 4])
|
|
48
|
+
|
|
49
|
+
link_sequence_X = jnp.array([0, 5, 3, 2, 3, 2, 0], dtype=jnp.int32) # [12, 21, 13, 31, 13, 31, 12])
|
|
50
|
+
link_sequence_X_p = jnp.array(
|
|
51
|
+
[3, 2, 0, 5, 0, 5, 3], dtype=jnp.int32
|
|
52
|
+
) # [13, 31, 12, 21, 12, 21, 13])
|
|
53
|
+
link_sequence_Y = jnp.array([1, 4, 5, 0, 5, 0, 1], dtype=jnp.int32) # [23, 32, 21, 12, 21, 12, 23])
|
|
54
|
+
link_sequence_Y_p = jnp.array(
|
|
55
|
+
[5, 0, 1, 4, 1, 4, 5], dtype=jnp.int32
|
|
56
|
+
) # [21, 12, 23, 32, 23, 32, 21])
|
|
57
|
+
link_sequence_Z = jnp.array([2, 3, 4, 1, 4, 1, 2], dtype=jnp.int32) # [31, 13, 32, 23, 32, 23, 31])
|
|
58
|
+
link_sequence_Z_p = jnp.array(
|
|
59
|
+
[4, 1, 2, 3, 2, 3, 4], dtype=jnp.int32
|
|
60
|
+
) # [32, 23, 31, 13, 31, 13, 32])
|
|
61
|
+
|
|
62
|
+
# Prepare logger
|
|
63
|
+
logger = logging.getLogger(__name__)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class Response(abc.ABC):
|
|
67
|
+
"""Abstract base class representing a GW source.
|
|
68
|
+
|
|
69
|
+
Sampling parameters (``dt``, ``size``, ``t0``, and ``t``) are used to generate when creating a
|
|
70
|
+
GW file. Note that they are ignored when writing to an existing GW file.
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
orbits (str): path to orbit file
|
|
74
|
+
orbit_interp_order (int): orbits spline-interpolation order [one of 1, 2, 3, 4, 5]
|
|
75
|
+
t (array-like or None): time array [s], optional
|
|
76
|
+
dt (float): simulation sampling period [s]
|
|
77
|
+
size (int): simulation size [samples]
|
|
78
|
+
t0 (int): simulation initial time [s]
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
SC = [1, 2, 3] #: List of spacecraft indices.
|
|
82
|
+
LINKS = [12, 23, 31, 13, 32, 21] #: List of link indices.
|
|
83
|
+
|
|
84
|
+
def __init__(self, orbits, orbit_interp_order=2, t=None, dt=0.5, size=259200, t0=0):
|
|
85
|
+
|
|
86
|
+
self.classname = self.__class__.__name__
|
|
87
|
+
|
|
88
|
+
self.orbits_path = str(orbits) #: str: Path to orbit file.
|
|
89
|
+
self.orbit_interp_order = int(
|
|
90
|
+
orbit_interp_order
|
|
91
|
+
) #: int: Orbits spline-interpolation order.
|
|
92
|
+
|
|
93
|
+
self.dt = float(dt) #: float: Sampling period [s].
|
|
94
|
+
self.t0 = float(t0) #: float: Initial time [s].
|
|
95
|
+
self.size = int(size) #: int: Simulation size [samples].
|
|
96
|
+
self.fs = 1 / self.dt #: float: Sampling frequency [Hz].
|
|
97
|
+
self.duration = self.size * self.dt #: float: Simulation duration [s].
|
|
98
|
+
if t is not None:
|
|
99
|
+
self.t = t
|
|
100
|
+
else:
|
|
101
|
+
self.t = self.t0 + jnp.arange(self.size) * self.dt #: array: Time array [s].
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class ResponseFromStrain(Response, abc.ABC):
|
|
105
|
+
"""Abstract base that computes link responses from GW strain time series.
|
|
106
|
+
|
|
107
|
+
Args:
|
|
108
|
+
dec (float): declination [rad]
|
|
109
|
+
ra (float): right ascension [rad]
|
|
110
|
+
x (callable): spacecraft x-position interpolating functions, overrides orbits [m]
|
|
111
|
+
y (callable): spacecraft y-position interpolating functions, overrides orbits [m]
|
|
112
|
+
z (callable): spacecraft z-position interpolating functions, overrides orbits [m]
|
|
113
|
+
ltt (callable): light travel time interpolating functions, overrides orbits [s]
|
|
114
|
+
t0 (float or str): initial time [s], or ``'orbits'`` to match orbit file's initial time
|
|
115
|
+
**kwargs: all other args from :class:`lisagwresponse.Response`
|
|
116
|
+
"""
|
|
117
|
+
|
|
118
|
+
LINKS = [12, 23, 31, 13, 32, 21]
|
|
119
|
+
|
|
120
|
+
def __init__(
|
|
121
|
+
self,
|
|
122
|
+
x=None,
|
|
123
|
+
y=None,
|
|
124
|
+
z=None,
|
|
125
|
+
ltt=None,
|
|
126
|
+
t0="orbits",
|
|
127
|
+
**kwargs,
|
|
128
|
+
):
|
|
129
|
+
|
|
130
|
+
# Forward numerical values of t0 to superclass
|
|
131
|
+
if t0 != "orbits":
|
|
132
|
+
kwargs["t0"] = t0
|
|
133
|
+
|
|
134
|
+
super().__init__(**kwargs)
|
|
135
|
+
self.dec = None
|
|
136
|
+
self.ra = None
|
|
137
|
+
self.k = None #: Wave propagation unit vector.
|
|
138
|
+
self.u = None #: Wave polarization unit vector.
|
|
139
|
+
self.v = None #: Wave polarization unit vector.
|
|
140
|
+
self.n = None #: Link unit vector.
|
|
141
|
+
|
|
142
|
+
self.trec_sun = None # spacecraft time at reception
|
|
143
|
+
self.temi_sun = None # spacecraft time at emission
|
|
144
|
+
|
|
145
|
+
self.drec = None # delay such that trec_sun = trec + drec
|
|
146
|
+
self.demi = None # delay such that temi_sun = temi + demi
|
|
147
|
+
|
|
148
|
+
# self.hplus = None
|
|
149
|
+
# self.hcross = None
|
|
150
|
+
|
|
151
|
+
self.xiplus = None
|
|
152
|
+
self.xicross = None
|
|
153
|
+
|
|
154
|
+
# Handle orbits
|
|
155
|
+
if x is not None or y is not None or z is not None or ltt is not None:
|
|
156
|
+
logger.info("Using provided functions for orbits")
|
|
157
|
+
assert x is not None
|
|
158
|
+
assert y is not None
|
|
159
|
+
assert z is not None
|
|
160
|
+
self._set_orbits(x, y, z, ltt)
|
|
161
|
+
else:
|
|
162
|
+
logger.info("Reading orbits from file '%s'", self.orbits_path)
|
|
163
|
+
self._interpolate_orbits()
|
|
164
|
+
|
|
165
|
+
self._compute_emission_reception(t=self.t)
|
|
166
|
+
|
|
167
|
+
def set_position(self, dec: float, ra: float, **kwargs):
|
|
168
|
+
"""Set the source position in the sky, with the source-localization basis vectors.
|
|
169
|
+
|
|
170
|
+
Args:
|
|
171
|
+
- dec (array (n_sources)): declination [rad]
|
|
172
|
+
- ra (array (n_sources)): right ascension [rad]
|
|
173
|
+
- shift_sun (bool): Move t0 to the moment when the gw crosses the SSB,
|
|
174
|
+
not the constellation (Default=True).
|
|
175
|
+
"""
|
|
176
|
+
if isinstance(dec, jax.Array):
|
|
177
|
+
self.dec = jnp.atleast_1d(dec)
|
|
178
|
+
else:
|
|
179
|
+
self.dec = jnp.array([dec]) # (n_sources = K)
|
|
180
|
+
if isinstance(ra, jax.Array):
|
|
181
|
+
self.ra = jnp.atleast_1d(ra)
|
|
182
|
+
else:
|
|
183
|
+
self.ra = jnp.array([ra])
|
|
184
|
+
if self.dec.shape[0] != self.ra.shape[0]:
|
|
185
|
+
raise ValueError("dec and ra should have equal length")
|
|
186
|
+
|
|
187
|
+
# Compute source-localization vector basis -->(n_sources, 3)
|
|
188
|
+
self.k = jnp.array(
|
|
189
|
+
[
|
|
190
|
+
-jnp.cos(self.dec) * jnp.cos(self.ra),
|
|
191
|
+
-jnp.cos(self.dec) * jnp.sin(self.ra),
|
|
192
|
+
-jnp.sin(self.dec),
|
|
193
|
+
]
|
|
194
|
+
) #: Wave propagation unit vector
|
|
195
|
+
self.u = jnp.array(
|
|
196
|
+
[
|
|
197
|
+
jnp.sin(self.ra),
|
|
198
|
+
-jnp.cos(self.ra),
|
|
199
|
+
jnp.zeros_like(self.dec),
|
|
200
|
+
]
|
|
201
|
+
)
|
|
202
|
+
self.v = jnp.array(
|
|
203
|
+
[
|
|
204
|
+
-jnp.sin(self.dec) * jnp.cos(self.ra),
|
|
205
|
+
-jnp.sin(self.dec) * jnp.sin(self.ra),
|
|
206
|
+
jnp.cos(self.dec),
|
|
207
|
+
]
|
|
208
|
+
)
|
|
209
|
+
shift_sun = kwargs.get("shift_sun", True)
|
|
210
|
+
if shift_sun == "no":
|
|
211
|
+
shift_sun = False
|
|
212
|
+
elif shift_sun == "constant":
|
|
213
|
+
shift_sun = True
|
|
214
|
+
temi = self.temi[:, :, jnp.newaxis]
|
|
215
|
+
trec = self.trec[:, :, jnp.newaxis]
|
|
216
|
+
# here self.trec == t_bins (not delayed), hence used to initialize delays at emission.
|
|
217
|
+
demi = jnp.array(
|
|
218
|
+
[
|
|
219
|
+
-jnp.array(self.ltt[link_index](trec[:, link_index]))
|
|
220
|
+
for link_index in range(len(self.LINKS))
|
|
221
|
+
]
|
|
222
|
+
).transpose((1, 0, 2))
|
|
223
|
+
drec = jnp.zeros_like(trec)
|
|
224
|
+
temi_sun, trec_sun, self.xiplus, self.xicross, self.demi, self.drec = (
|
|
225
|
+
_set_antenna_pattern_jit(
|
|
226
|
+
temi,
|
|
227
|
+
trec,
|
|
228
|
+
self.xemi,
|
|
229
|
+
self.xrec,
|
|
230
|
+
demi,
|
|
231
|
+
drec,
|
|
232
|
+
self.u,
|
|
233
|
+
self.v,
|
|
234
|
+
self.k,
|
|
235
|
+
self.n,
|
|
236
|
+
shift_sun=shift_sun,
|
|
237
|
+
)
|
|
238
|
+
)
|
|
239
|
+
self.temi_sun = temi_sun.transpose((0, 2, 1))
|
|
240
|
+
self.trec_sun = trec_sun.transpose((0, 2, 1))
|
|
241
|
+
|
|
242
|
+
def get_fplus_fcross(self, complex_output=False):
|
|
243
|
+
"""Get the elements of the antenna pattern function that multiply h_plus and h_cross"""
|
|
244
|
+
|
|
245
|
+
denominator = 2 * (1 - dot_custom(self.n, self.k))
|
|
246
|
+
|
|
247
|
+
fplus = jnp.squeeze(self.xiplus / denominator)
|
|
248
|
+
fcross = jnp.squeeze(self.xicross / denominator)
|
|
249
|
+
|
|
250
|
+
if not complex_output:
|
|
251
|
+
return fplus, fcross
|
|
252
|
+
# Return complex representation
|
|
253
|
+
return fplus + 1j * fcross
|
|
254
|
+
|
|
255
|
+
def _compute_xyz_times(self, t):
|
|
256
|
+
"""Compute the retarded time at each S/C, following the XYZ path to compute TDI variables"""
|
|
257
|
+
|
|
258
|
+
ltt = tuple(self.ltt)
|
|
259
|
+
t_x, t_xp, t_y, t_yp, t_z, t_zp = (
|
|
260
|
+
t.copy(),
|
|
261
|
+
t.copy(),
|
|
262
|
+
t.copy(),
|
|
263
|
+
t.copy(),
|
|
264
|
+
t.copy(),
|
|
265
|
+
t.copy(),
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
def retarded_times(t0, sequence):
|
|
269
|
+
# step function for jax.lax.scan
|
|
270
|
+
def step(value, key):
|
|
271
|
+
key = key.astype(int)
|
|
272
|
+
delta = jax.lax.switch(key, ltt, value)
|
|
273
|
+
new_value = value - delta
|
|
274
|
+
return new_value, new_value[None, :]
|
|
275
|
+
|
|
276
|
+
_, history = jax.lax.scan(step, t0, sequence)
|
|
277
|
+
return history
|
|
278
|
+
|
|
279
|
+
tx1 = retarded_times(t_x, link_sequence_X)
|
|
280
|
+
tx2 = retarded_times(t_xp, link_sequence_X_p)
|
|
281
|
+
ty1 = retarded_times(t_y, link_sequence_Y)
|
|
282
|
+
ty2 = retarded_times(t_yp, link_sequence_Y_p)
|
|
283
|
+
tz1 = retarded_times(t_z, link_sequence_Z)
|
|
284
|
+
tz2 = retarded_times(t_zp, link_sequence_Z_p)
|
|
285
|
+
|
|
286
|
+
tx = jnp.concatenate([tx1, tx2], axis=1)
|
|
287
|
+
ty = jnp.concatenate([ty1, ty2], axis=1)
|
|
288
|
+
tz = jnp.concatenate([tz1, tz2], axis=1)
|
|
289
|
+
|
|
290
|
+
return tx, ty, tz
|
|
291
|
+
|
|
292
|
+
def _interpolate_orbits(self):
|
|
293
|
+
"""Interpolate orbit data (spacecraft positions and light travel times).
|
|
294
|
+
|
|
295
|
+
Also check that orbit file is valid and supported.
|
|
296
|
+
|
|
297
|
+
Raises:
|
|
298
|
+
ValueError if orbit file is not supported.
|
|
299
|
+
"""
|
|
300
|
+
logger.info("Computing spline interpolation for orbits")
|
|
301
|
+
|
|
302
|
+
with h5py.File(self.orbits_path, "r") as orbitf:
|
|
303
|
+
# Warn for orbit file development version
|
|
304
|
+
version = Version(orbitf.attrs["version"])
|
|
305
|
+
logger.debug("Using orbit file version %s", version)
|
|
306
|
+
if version.is_devrelease or version.local is not None:
|
|
307
|
+
logger.warning("You are using an orbit file in a development version")
|
|
308
|
+
if version > Version("2.0"):
|
|
309
|
+
logger.warning(
|
|
310
|
+
"You are using an orbit file in a version that might not be fully supported"
|
|
311
|
+
)
|
|
312
|
+
|
|
313
|
+
if version >= Version("2.0.dev"):
|
|
314
|
+
# Time vector
|
|
315
|
+
t_max = orbitf.attrs["size"] * orbitf.attrs["dt"] + orbitf.attrs["t0"]
|
|
316
|
+
times = jnp.linspace(
|
|
317
|
+
orbitf.attrs["t0"], t_max, num=orbitf.attrs["size"], endpoint=False
|
|
318
|
+
)
|
|
319
|
+
xyz = orbitf["tcb/x"][:] # -->(time, SC, coord)
|
|
320
|
+
|
|
321
|
+
self.x = lambda t: spline_2d(times, xyz[:, :, 0], t)
|
|
322
|
+
self.y = lambda t: spline_2d(times, xyz[:, :, 1], t)
|
|
323
|
+
self.z = lambda t: spline_2d(times, xyz[:, :, 2], t)
|
|
324
|
+
ltt_data = [orbitf["tcb/ltt"][:, i] for i in range(len(self.LINKS))]
|
|
325
|
+
self.ltt = [lambda t, arr=arr: spline_1d(times, arr, t) for arr in ltt_data]
|
|
326
|
+
|
|
327
|
+
else:
|
|
328
|
+
raise ValueError("Please use a recent version of lisaorbits.")
|
|
329
|
+
|
|
330
|
+
def _compute_emission_reception(self, t):
|
|
331
|
+
"""Computes the emision and reception time and position for each SC for a given time array.
|
|
332
|
+
|
|
333
|
+
Raises:
|
|
334
|
+
ValueError if time is outside the orbit file.
|
|
335
|
+
"""
|
|
336
|
+
|
|
337
|
+
if t.ndim == 1:
|
|
338
|
+
t = jnp.tile(t[:, jnp.newaxis], len(self.LINKS)) # (time, links)
|
|
339
|
+
# Compute emission and reception time at spacecraft
|
|
340
|
+
logger.debug("Computing emission time at spacecraft")
|
|
341
|
+
trec = jnp.array(t) # (time, links)
|
|
342
|
+
temi = jnp.array(t) # (time, links)
|
|
343
|
+
|
|
344
|
+
for link_index in range(len(self.LINKS)):
|
|
345
|
+
temi = temi.at[:, link_index].add(
|
|
346
|
+
-jnp.array(self.ltt[link_index](t[:, link_index]))
|
|
347
|
+
) # (N, L)
|
|
348
|
+
# Compute spacecraft positions at emission and reception
|
|
349
|
+
try:
|
|
350
|
+
logger.debug("Computing receiver position at reception time")
|
|
351
|
+
xrec = jnp.zeros((*t.shape, 3)) # (N, L, 3)
|
|
352
|
+
for i, a_receiver in enumerate(receiver(self.LINKS)):
|
|
353
|
+
a_receiver -= 1
|
|
354
|
+
xrec = xrec.at[:, i, 0].add(self.x(trec[:, i])[:, a_receiver])
|
|
355
|
+
xrec = xrec.at[:, i, 1].add(self.y(trec[:, i])[:, a_receiver])
|
|
356
|
+
xrec = xrec.at[:, i, 2].add(self.z(trec[:, i])[:, a_receiver])
|
|
357
|
+
logger.debug("Computing emitter position at emission time")
|
|
358
|
+
xemi = jnp.zeros((*t.shape, 3)) # (N, L, coord)
|
|
359
|
+
for i, an_emitter in enumerate(emitter(self.LINKS)):
|
|
360
|
+
an_emitter -= 1
|
|
361
|
+
xemi = xemi.at[:, i, 0].add(self.x(temi[:, i])[:, an_emitter])
|
|
362
|
+
xemi = xemi.at[:, i, 1].add(self.y(temi[:, i])[:, an_emitter])
|
|
363
|
+
xemi = xemi.at[:, i, 2].add(self.z(temi[:, i])[:, an_emitter])
|
|
364
|
+
except ValueError as error:
|
|
365
|
+
logger.error("Missing orbit information")
|
|
366
|
+
raise ValueError(
|
|
367
|
+
"missing orbit information, use longer orbit file or adjust sampling"
|
|
368
|
+
) from error
|
|
369
|
+
|
|
370
|
+
n = xrec - xemi # (times, links, coord)
|
|
371
|
+
n /= norm(n)[..., jnp.newaxis] # (times, links, coord)
|
|
372
|
+
self.n = jnp.array(n)
|
|
373
|
+
|
|
374
|
+
# pos are (times, links, coords) and never change as they depend on the SCs,
|
|
375
|
+
# if frozen (1,1,3) for xemi/xrec.
|
|
376
|
+
# times are (times, links) and never change as they depend on the SCs, if frozen N=1.
|
|
377
|
+
self.xemi = jnp.array(xemi)
|
|
378
|
+
self.xrec = jnp.array(xrec)
|
|
379
|
+
self.temi = jnp.array(temi)
|
|
380
|
+
self.trec = jnp.array(trec)
|
|
381
|
+
|
|
382
|
+
def _set_orbits(self, x, y, z, ltt):
|
|
383
|
+
"""Set orbit data from dictionaries (spacecraft positions and light travel times).
|
|
384
|
+
|
|
385
|
+
Args:
|
|
386
|
+
x (callable): spacecraft x-position interpolating functions, overrides orbits [m]
|
|
387
|
+
y (callable): spacecraft y-position interpolating functions, overrides orbits [m]
|
|
388
|
+
z (callable): spacecraft z-position interpolating functions, overrides orbits [m]
|
|
389
|
+
ltt (callable): light travel time interpolating functions, overrides orbits [s]
|
|
390
|
+
"""
|
|
391
|
+
# We use default values for `val` in lambdas to capture the values
|
|
392
|
+
self.x = {
|
|
393
|
+
sc: x[sc] if callable(x[sc]) else lambda t, val=x[sc]: float(val) for sc in self.SC
|
|
394
|
+
}
|
|
395
|
+
self.y = {
|
|
396
|
+
sc: y[sc] if callable(y[sc]) else lambda t, val=y[sc]: float(val) for sc in self.SC
|
|
397
|
+
}
|
|
398
|
+
self.z = {
|
|
399
|
+
sc: z[sc] if callable(z[sc]) else lambda t, val=z[sc]: float(val) for sc in self.SC
|
|
400
|
+
}
|
|
401
|
+
self.ltt = {
|
|
402
|
+
link: (ltt[link] if callable(ltt[link]) else lambda t, val=ltt[link]: float(val))
|
|
403
|
+
for link in self.LINKS
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
def _set_antenna_pattern(
|
|
408
|
+
temi: jax.Array,
|
|
409
|
+
trec: jax.Array,
|
|
410
|
+
xemi: jax.Array,
|
|
411
|
+
xrec: jax.Array,
|
|
412
|
+
demi: jax.Array,
|
|
413
|
+
drec: jax.Array,
|
|
414
|
+
u: jax.Array,
|
|
415
|
+
v: jax.Array,
|
|
416
|
+
k: jax.Array,
|
|
417
|
+
n: jax.Array,
|
|
418
|
+
shift_sun: bool = True,
|
|
419
|
+
):
|
|
420
|
+
"""Set the antenna patterns to project the waveforms onto the links.
|
|
421
|
+
|
|
422
|
+
Args:
|
|
423
|
+
- temi (array (n_points, links)): emission time of each link
|
|
424
|
+
- trec (array (n_points, links)): reception time of each link
|
|
425
|
+
- xemi (array (n_points, links, coord)): emission position of each link
|
|
426
|
+
- xrec (array (n_points, links, coord)): reception position of each link
|
|
427
|
+
- demi (array (n_points, links)): delays for emitting spacecraft for each link
|
|
428
|
+
- drec (array (n_points, links)): delays for receiving spacecraft for each link
|
|
429
|
+
- u (array (coord, n_sources)) : Source position
|
|
430
|
+
- v (array (coord, n_sources)) : Source position
|
|
431
|
+
- k (array (coord, n_sources)) : Source propagation
|
|
432
|
+
- n (array (n_points, links, coord)) : normal vector between links
|
|
433
|
+
- shift_sun (bool) : Move t0 to the moment when the GW crosses the SSB,
|
|
434
|
+
not the constellation (Default=True).
|
|
435
|
+
Returns:
|
|
436
|
+
Time of reception and emission in the SSB frame for each link, delays,
|
|
437
|
+
and the antenna pattern Fx, F+
|
|
438
|
+
|
|
439
|
+
"""
|
|
440
|
+
|
|
441
|
+
if not shift_sun:
|
|
442
|
+
# Compute equivalent emission and reception time at the Sun
|
|
443
|
+
logger.debug("Computing equivalent reception time at the Sun")
|
|
444
|
+
xrec_dot_k = dot_custom(xrec, k) / c_light
|
|
445
|
+
trec_sun = trec - xrec_dot_k # (N, K)
|
|
446
|
+
drec -= xrec_dot_k
|
|
447
|
+
logger.debug("Computing equivalent emission time at the Sun")
|
|
448
|
+
xemi_dot_k = dot_custom(xemi, k) / c_light
|
|
449
|
+
temi_sun = temi - xemi_dot_k # (N, K)
|
|
450
|
+
demi -= xemi_dot_k
|
|
451
|
+
else:
|
|
452
|
+
# Compute constant shift from constellation barycenter at t[0]
|
|
453
|
+
logger.debug("Computing constant shift from constellation barycenter")
|
|
454
|
+
xbary = jnp.mean(xrec[0, :, :], axis=0) # (3,)
|
|
455
|
+
shift = jnp.einsum("i, ij -> j", xbary, k) / c_light # dot_custom(xbary, k) / c # ()
|
|
456
|
+
logger.debug("Computing equivalent reception time at the Sun")
|
|
457
|
+
xrec_dot_k = dot_custom(xrec, k) / c_light
|
|
458
|
+
trec_sun = trec + shift - xrec_dot_k # (N, K)
|
|
459
|
+
drec -= xrec_dot_k
|
|
460
|
+
logger.debug("Computing equivalent emission time at the Sun")
|
|
461
|
+
xemi_dot_k = dot_custom(xemi, k) / c_light
|
|
462
|
+
temi_sun = temi + shift - xemi_dot_k # (N, K)
|
|
463
|
+
demi -= xemi_dot_k
|
|
464
|
+
demi = jnp.squeeze(demi)
|
|
465
|
+
drec = jnp.squeeze(drec)
|
|
466
|
+
# Compute antenna pattern functions
|
|
467
|
+
logger.debug("Computing antenna pattern functions")
|
|
468
|
+
xiplus = dot_custom(n, u) ** 2 - dot_custom(n, v) ** 2 # (N, K)
|
|
469
|
+
xicross = 2 * dot_custom(n, u) * dot_custom(n, v) # (N, K)
|
|
470
|
+
return temi_sun, trec_sun, xiplus, xicross, demi, drec
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
_set_antenna_pattern_jit = jax.jit(_set_antenna_pattern, static_argnames=("shift_sun",))
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
def delay_operator(fr, delta_t):
|
|
477
|
+
"""Simple delay operator in the frequency domain, assuming
|
|
478
|
+
infinite continuous observation time.
|
|
479
|
+
|
|
480
|
+
Parameters
|
|
481
|
+
----------
|
|
482
|
+
fr : ndarray
|
|
483
|
+
frequency array (Hz)
|
|
484
|
+
delta_t : float
|
|
485
|
+
time delay (s)
|
|
486
|
+
|
|
487
|
+
Returns
|
|
488
|
+
-------
|
|
489
|
+
exponential phase
|
|
490
|
+
Frequency-domain delay operator
|
|
491
|
+
"""
|
|
492
|
+
return jnp.exp(-2j * jnp.pi * fr * delta_t)
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
def compute_tdi_tf(
|
|
496
|
+
fr,
|
|
497
|
+
tt,
|
|
498
|
+
t_vect,
|
|
499
|
+
gen="2.0",
|
|
500
|
+
use_lisagwresponse_convention=False,
|
|
501
|
+
):
|
|
502
|
+
"""Compute the TDI transfer function matrix from eta variables to
|
|
503
|
+
TDI. It's valid for readout (OMS) noises.
|
|
504
|
+
|
|
505
|
+
Parameters
|
|
506
|
+
----------
|
|
507
|
+
fr : ndarray
|
|
508
|
+
frequency array [Hz], size nf
|
|
509
|
+
tt : dict
|
|
510
|
+
dictionary of arm light travel times [s], size nt
|
|
511
|
+
t_vect : ndarray
|
|
512
|
+
time vector where to compute the light travel time.
|
|
513
|
+
gen : str, optional
|
|
514
|
+
TDI generation, by default '2.0'.
|
|
515
|
+
use_lisagwresponse_convention : bool, optional
|
|
516
|
+
If True, use the LISA GW Response convention for the TDI transfer function, by default
|
|
517
|
+
False. If False, it assumes the following MOSA order: 12, 23, 31, 13, 21, 32.
|
|
518
|
+
If True, it uses the LISA GW Response convention: 12, 23, 31, 13, 32, 21.
|
|
519
|
+
|
|
520
|
+
Returns
|
|
521
|
+
-------
|
|
522
|
+
tdi_mat_eval
|
|
523
|
+
TDI transfer function matrix for XYZ, array of size nf x nt x 3 x 6
|
|
524
|
+
|
|
525
|
+
Raises
|
|
526
|
+
------
|
|
527
|
+
ValueError
|
|
528
|
+
TDI generation can only be 1.5 or 2.0.
|
|
529
|
+
"""
|
|
530
|
+
|
|
531
|
+
if isinstance(t_vect, Iterable):
|
|
532
|
+
fr_arr = np.asarray(fr)[:, np.newaxis]
|
|
533
|
+
else:
|
|
534
|
+
fr_arr = fr
|
|
535
|
+
|
|
536
|
+
# Make sure that we have dimensions nf x nt
|
|
537
|
+
d1 = delay_operator(fr_arr, np.nan_to_num(tt[1](t_vect))).T
|
|
538
|
+
d2 = delay_operator(fr_arr, np.nan_to_num(tt[2](t_vect))).T
|
|
539
|
+
d3 = delay_operator(fr_arr, np.nan_to_num(tt[0](t_vect))).T
|
|
540
|
+
d1p = delay_operator(fr_arr, np.nan_to_num(tt[5](t_vect))).T
|
|
541
|
+
d2p = delay_operator(fr_arr, np.nan_to_num(tt[3](t_vect))).T
|
|
542
|
+
d3p = delay_operator(fr_arr, np.nan_to_num(tt[4](t_vect))).T
|
|
543
|
+
# Build TDI transformation matrix
|
|
544
|
+
zer = np.zeros(np.shape(d1))
|
|
545
|
+
# TDI 1.5
|
|
546
|
+
if gen == "1.5":
|
|
547
|
+
tdi_mat = np.array(
|
|
548
|
+
[
|
|
549
|
+
[
|
|
550
|
+
d2 * d2p - 1,
|
|
551
|
+
zer,
|
|
552
|
+
-(d3 * d3p - 1) * d2p,
|
|
553
|
+
-(d3 * d3p - 1),
|
|
554
|
+
(d2 * d2p - 1) * d3,
|
|
555
|
+
zer,
|
|
556
|
+
],
|
|
557
|
+
[
|
|
558
|
+
-(d1 * d1p - 1) * d3p,
|
|
559
|
+
d3 * d3p - 1,
|
|
560
|
+
zer,
|
|
561
|
+
zer,
|
|
562
|
+
-(d1 * d1p - 1),
|
|
563
|
+
(d3 * d3p - 1) * d1,
|
|
564
|
+
],
|
|
565
|
+
[
|
|
566
|
+
zer,
|
|
567
|
+
-d1p * (d2 * d2p - 1),
|
|
568
|
+
d1 * d1p - 1,
|
|
569
|
+
(d1 * d1p - 1) * d2,
|
|
570
|
+
zer,
|
|
571
|
+
-(d2 * d2p - 1),
|
|
572
|
+
],
|
|
573
|
+
]
|
|
574
|
+
)
|
|
575
|
+
# TDI 2.0
|
|
576
|
+
elif gen == "2.0":
|
|
577
|
+
tdi_mat = np.array(
|
|
578
|
+
[
|
|
579
|
+
[
|
|
580
|
+
d2p * d2 + d2p * d2 * d3 * d3p - 1 - d3 * d3p * d2p * d2 * d2p * d2, # 12
|
|
581
|
+
zer, # 23
|
|
582
|
+
d2p
|
|
583
|
+
+ d2p * d2 * d3 * d3p * d3 * d3p * d2p
|
|
584
|
+
- d3 * d3p * d2p
|
|
585
|
+
- d3 * d3p * d2p * d2 * d2p, # 31
|
|
586
|
+
1 + d2p * d2 * d3 * d3p * d3 * d3p - d3 * d3p - d3 * d3p * d2p * d2, # 13
|
|
587
|
+
d2p * d2 * d3
|
|
588
|
+
+ d2p * d2 * d3 * d3p * d3
|
|
589
|
+
- d3
|
|
590
|
+
- d3 * d3p * d2p * d2 * d2p * d2 * d3, # 21
|
|
591
|
+
zer, # 32
|
|
592
|
+
],
|
|
593
|
+
[
|
|
594
|
+
d3p
|
|
595
|
+
+ d3p * d3 * d1 * d1p * d1 * d1p * d3p
|
|
596
|
+
- d1 * d1p * d3p
|
|
597
|
+
- d1 * d1p * d3p * d3 * d3p,
|
|
598
|
+
d3p * d3 + d3p * d3 * d1 * d1p - 1 - d1 * d1p * d3p * d3 * d3p * d3,
|
|
599
|
+
zer,
|
|
600
|
+
zer,
|
|
601
|
+
1 + d3p * d3 * d1 * d1p * d1 * d1p - d1 * d1p - d1 * d1p * d3 * d3p,
|
|
602
|
+
d3p * d3 * d1
|
|
603
|
+
+ d3p * d3 * d1 * d1p * d1
|
|
604
|
+
- d1
|
|
605
|
+
- d1 * d1p * d3p * d3 * d3p * d3 * d1,
|
|
606
|
+
],
|
|
607
|
+
[
|
|
608
|
+
zer,
|
|
609
|
+
d1p
|
|
610
|
+
+ d1p * d1 * d2 * d2p * d2 * d2p * d1p
|
|
611
|
+
- d2 * d2p * d1p
|
|
612
|
+
- d2 * d2p * d1p * d1 * d1p,
|
|
613
|
+
d1p * d1 + d1p * d1 * d2 * d2p - 1 - d2 * d2p * d1p * d1 * d1p * d1,
|
|
614
|
+
d1p * d1 * d2
|
|
615
|
+
+ d1p * d1 * d2 * d2p * d2
|
|
616
|
+
- d2
|
|
617
|
+
- d2 * d2p * d1p * d1 * d1p * d1 * d2,
|
|
618
|
+
zer,
|
|
619
|
+
1 + d1p * d1 * d2 * d2p * d2 * d2p - d2 * d2p - d2 * d2p * d1 * d1p,
|
|
620
|
+
],
|
|
621
|
+
]
|
|
622
|
+
)
|
|
623
|
+
else:
|
|
624
|
+
raise ValueError("Unknown TDI generation.")
|
|
625
|
+
|
|
626
|
+
# Reshape the matrix to nf x nt x 3 x 6
|
|
627
|
+
tdi_mat_eval = np.swapaxes(tdi_mat.T, tdi_mat.ndim - 2, tdi_mat.ndim - 1)
|
|
628
|
+
|
|
629
|
+
if use_lisagwresponse_convention:
|
|
630
|
+
# If requested, re-order the matrix columns to match the LISA GW Response convention
|
|
631
|
+
tdi_mat_eval = tdi_mat_eval[..., convert]
|
|
632
|
+
|
|
633
|
+
return tdi_mat_eval
|