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 coordinates_space.py #4289

Merged
merged 144 commits into from
Oct 31, 2023
Merged
Changes from 1 commit
Commits
Show all changes
144 commits
Select commit Hold shift + click to select a range
06522ce
add coordinates_space.py
WuShichao Mar 13, 2023
a967fbb
add LISA/SSB frame params
WuShichao Mar 15, 2023
d31f211
add LISA_to_GEO and GEO_to_LISA
WuShichao Mar 15, 2023
3bbb0b1
add coordinates_space into FieldArray
WuShichao Mar 18, 2023
b1e3216
add doc and Astropy support
WuShichao Mar 18, 2023
27c26a9
update comments on sympy
WuShichao Mar 18, 2023
bd83c64
use fsolve from scipy instead
WuShichao Mar 19, 2023
bf07a1e
fix cc issues
WuShichao Mar 19, 2023
f1c21fb
fix cc issues
WuShichao Mar 19, 2023
e856f4b
minor fix
WuShichao Mar 19, 2023
e85bc51
update
WuShichao Mar 19, 2023
62fdd9f
Merge branch 'gwastro:master' into multiband_transform
WuShichao Mar 21, 2023
a1c8739
not use iteration
WuShichao Mar 22, 2023
542523d
Merge branch 'gwastro:master' into multiband_transform
WuShichao Mar 24, 2023
668ae7d
decouple LISA orbit and more accurate Earth
WuShichao Mar 27, 2023
cae4757
rename
WuShichao Mar 27, 2023
e3b5f84
remove jplephem
WuShichao Mar 27, 2023
0cddb9c
add the angular displacement of the Earth
WuShichao Mar 27, 2023
ced106d
use radians
WuShichao Mar 27, 2023
d67375f
make func readable in .ini
WuShichao Mar 28, 2023
5d9e72d
reverse back to master
WuShichao Mar 28, 2023
df18e9b
correct psi range
WuShichao Mar 29, 2023
c03d88c
reverse to master
WuShichao Mar 29, 2023
352073e
Merge branch 'multiband_transform' of https://github.com/WuShichao/py…
WuShichao Mar 29, 2023
52ec83b
fix unit issue in earth_position_SSB
WuShichao Apr 3, 2023
79bc677
put LISA to the "right" position
WuShichao Apr 4, 2023
6f1ebca
add LISA specific transform classes here
WuShichao Apr 5, 2023
ac4fc40
change names
WuShichao Apr 5, 2023
0b89641
update
WuShichao Apr 5, 2023
4f01ef2
make a package for coordinates
WuShichao Apr 6, 2023
cd10893
remove coordinates_space import
WuShichao Apr 6, 2023
b8e5625
move __all__ into __init__.py
WuShichao Apr 6, 2023
2615d02
remove all coordinates_space
WuShichao Apr 6, 2023
b432f0e
change TIME_OFFSET to seconds
WuShichao Apr 8, 2023
b434c09
fix SOBHB issue
WuShichao Apr 12, 2023
5f14830
rename
WuShichao Apr 17, 2023
0f85dc3
add SSB or LISA params into fid_params
WuShichao Apr 17, 2023
e00d1b6
rename
WuShichao Apr 17, 2023
7b2e5e4
fix cc issues
WuShichao Apr 17, 2023
ac74625
fix cc issue
WuShichao Apr 17, 2023
ad77581
fix cc issue
WuShichao Apr 17, 2023
b91ac58
update
WuShichao Apr 19, 2023
cf04a2e
update
WuShichao Apr 19, 2023
54073e4
fix
WuShichao Apr 19, 2023
9d859b5
add default names
WuShichao Apr 23, 2023
7910a95
overwrite params with same names
WuShichao Apr 23, 2023
d516d30
remove pre-fixed names
WuShichao Apr 23, 2023
9b57574
remove all pre-fixed names
WuShichao Apr 23, 2023
6c8cef3
not pop
WuShichao Apr 23, 2023
5669f07
fix inverse transform
WuShichao Apr 25, 2023
53b20ce
update tc
WuShichao Apr 26, 2023
3662303
not overwrite
WuShichao Apr 30, 2023
38d95f9
add SNR support for multi-model
WuShichao Apr 30, 2023
7166baa
Update waveform.py
WuShichao May 3, 2023
6c806f3
Merge branch 'gwastro:master' into multiband_transform
WuShichao May 3, 2023
cc0c2d9
t0 issue
WuShichao May 3, 2023
830b5c3
t0 issue
WuShichao May 3, 2023
bc24cd9
Update space.py
WuShichao May 7, 2023
2529d52
add obstime
WuShichao May 19, 2023
3a9322d
np.mod(psi_newframe, 2*np.pi)
WuShichao May 19, 2023
156dfd6
fix obstime
WuShichao May 21, 2023
1a38386
add support for array inputs
WuShichao Jun 4, 2023
e1b4ca4
Update hierarchical.py
WuShichao Jun 4, 2023
b38d47d
Merge branch 'gwastro:master' into multiband_transform
WuShichao Jun 4, 2023
2bfd901
just use Alex's implementation
WuShichao Jun 5, 2023
5372a32
CustomTransformMultiOutputs is in another PR, so remove it
WuShichao Jun 9, 2023
29215db
add LDC and LAL convention correction
WuShichao Jun 9, 2023
e2d389c
use pycbc standard names
WuShichao Jun 11, 2023
ad2e0a3
more meaningful name
WuShichao Jun 11, 2023
2b2e93a
use pycbc standard names
WuShichao Jun 11, 2023
2ce81bc
Update relbin.py
WuShichao Jun 11, 2023
eec4c1c
Merge branch 'gwastro:master' into multiband_transform
WuShichao Jun 11, 2023
cee4738
Update parameters.py
WuShichao Jun 11, 2023
fc04312
remove unnecessary changes
WuShichao Jun 11, 2023
e6f2674
fix cc issue
WuShichao Jun 11, 2023
9cda1f2
fix cc issue
WuShichao Jun 11, 2023
f4f8d32
fix cc issue
WuShichao Jun 11, 2023
1279666
fix cc issue
WuShichao Jun 11, 2023
ff2af5d
Merge branch 'gwastro:master' into multiband_transform
WuShichao Jun 12, 2023
b547483
compactify
WuShichao Jun 13, 2023
7ce1b9d
compactify
WuShichao Jun 13, 2023
c997389
add __all__ back
WuShichao Jun 13, 2023
f34b1d0
Update transforms.py
WuShichao Jun 13, 2023
db90980
Update transforms.py
WuShichao Jun 13, 2023
78b8ec3
Update test_transforms.py
WuShichao Jun 14, 2023
948e3ca
Update transforms.py
WuShichao Jun 14, 2023
7998cd2
update doc
WuShichao Jun 15, 2023
d39bf09
fix time warning
WuShichao Jun 15, 2023
199ce9d
Merge branch 'gwastro:master' into multiband_transform
WuShichao Jun 22, 2023
5acd874
Update space.py
WuShichao Jun 22, 2023
b45fdce
Update test_transforms.py
WuShichao Jun 22, 2023
f513dcc
Create test_coordinates_space.py
WuShichao Jun 22, 2023
9264796
fix cc issues
WuShichao Jun 23, 2023
2c001b6
fix cc issues
WuShichao Jun 23, 2023
6d3c503
fix cc issue
WuShichao Jun 23, 2023
450eebf
Update tox.ini
WuShichao Jun 23, 2023
0af7e89
Update tox.ini
WuShichao Jun 23, 2023
a6347b0
Update tox.ini
WuShichao Jun 23, 2023
44e7e21
Update tox.ini
WuShichao Jun 23, 2023
159b6c9
Update tox.ini
WuShichao Jun 25, 2023
9ee8c86
Update tox.ini
WuShichao Jun 25, 2023
5159f75
Update tox.ini
WuShichao Jun 25, 2023
7ddad33
Update test_coordinates_space.py
WuShichao Jun 26, 2023
cb8cd25
add inline doc
WuShichao Jun 26, 2023
4aaef29
Update tox.ini
WuShichao Jun 26, 2023
5e3aa85
add check of bbhx
WuShichao Jun 27, 2023
8ed9575
Update test_coordinates_space.py
WuShichao Jun 27, 2023
61d61ed
Update tox.ini
WuShichao Jun 27, 2023
d81314e
Merge branch 'gwastro:master' into multiband_transform
WuShichao Jul 4, 2023
fbf8fbd
Update test_coordinates_space.py
WuShichao Jul 4, 2023
d1fe3c8
Merge branch 'gwastro:master' into multiband_transform
WuShichao Jul 5, 2023
9629250
Merge branch 'gwastro:master' into multiband_transform
WuShichao Jul 10, 2023
3de4b35
Merge branch 'gwastro:master' into multiband_transform
WuShichao Aug 2, 2023
3d9dba7
add MultibandRelativeTimeDom into hierarchical.py
WuShichao Aug 2, 2023
b6c27f6
Update __init__.py
WuShichao Aug 3, 2023
37029ca
Update hierarchical.py
WuShichao Aug 3, 2023
6721aff
Merge branch 'gwastro:master' into multiband_transform
WuShichao Aug 7, 2023
635c3ee
Update hierarchical.py
WuShichao Aug 7, 2023
39f4a1d
Merge branch 'gwastro:master' into multiband_transform
WuShichao Aug 17, 2023
b24a047
Update relbin.py
WuShichao Aug 17, 2023
395039d
Update hierarchical.py
WuShichao Aug 17, 2023
e176430
Update hierarchical.py
WuShichao Aug 20, 2023
e3c793e
Update relbin.py
WuShichao Aug 24, 2023
7423058
Update hierarchical.py
WuShichao Aug 24, 2023
fef5a3f
Update hierarchical.py
WuShichao Aug 28, 2023
2e78ba8
Update hierarchical.py
WuShichao Aug 28, 2023
116e5bc
Update hierarchical.py
WuShichao Aug 28, 2023
cb5a9c4
Update hierarchical.py
WuShichao Aug 31, 2023
d13dca2
Update relbin.py
WuShichao Aug 31, 2023
b79d265
Update hierarchical.py
WuShichao Aug 31, 2023
7de0de5
Update hierarchical.py
WuShichao Sep 27, 2023
5418546
Update relbin.py
WuShichao Sep 27, 2023
1f9cf7d
Update __init__.py
WuShichao Sep 27, 2023
b22eb7e
Merge branch 'gwastro:master' into multiband_transform
WuShichao Oct 12, 2023
c673186
Update space.py
WuShichao Oct 12, 2023
2fa62c0
Update space.py
WuShichao Oct 12, 2023
c60008f
Update space.py
WuShichao Oct 12, 2023
5eb784a
fix psi issue
WuShichao Oct 12, 2023
7753d85
Merge branch 'gwastro:master' into multiband_transform
WuShichao Oct 13, 2023
a6718ca
Update test_coordinates_space.py
WuShichao Oct 13, 2023
df1619e
Update test_coordinates_space.py
WuShichao Oct 13, 2023
670f9de
Merge branch 'gwastro:master' into multiband_transform
WuShichao Oct 13, 2023
e39902b
Merge branch 'gwastro:master' into multiband_transform
WuShichao Oct 25, 2023
f8cb244
Merge branch 'gwastro:master' into multiband_transform
WuShichao Oct 30, 2023
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
196 changes: 196 additions & 0 deletions pycbc/coordinates_space.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
# Copyright (C) 2023 Shichao Wu, Alex Nitz
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


#
# =============================================================================
#
# Preamble
#
# =============================================================================
#
"""
This module provides coordinate transform between space-borne detectors and
ground-based detectors.
"""

import numpy as np
from scipy.spatial.transform import Rotation
from sympy import symbols, nsolve, sin, cos
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to the actions items you've already posted, I think we should avoid the sympy dependence here. This may be somewhat covered by switching to astropy for some parts here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this function is fast, but I will check if this can be done with Astropy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.



YRSID_SI = 31558149.763545603
OMEGA_0 = 1.99098659277e-7

def localization_to_propagation_vector(lamda, beta):
x = -np.cos(beta) * np.cos(lamda)
y = -np.cos(beta) * np.sin(lamda)
z = -np.sin(beta)

return np.array([[x], [y], [z]])

def rotation_matrix_SSBtoLISA(alpha):
r = Rotation.from_rotvec([
[0, 0, alpha],
[0, -np.pi/3, 0],
[0, 0, -alpha]
]).as_matrix()
r_total = np.array(r[0]) @ np.array(r[1]) @ np.array(r[2])

return r_total

def propagation_vector_to_localization(k):
# beta already within [-pi/2, pi/2]
beta = np.float64(np.arcsin(-k[2]))
lamda = np.float64(np.arctan2(-k[1]/np.cos(beta), -k[0]/np.cos(beta)))
print("lamda before mod: ", lamda)
# lamda should within [0, 2*pi]
lamda = np.mod(lamda, 2*np.pi)

return np.array([lamda, beta])

def polarization_angle_newframe(psi, k, rotation_matrix):
lamda, beta = propagation_vector_to_localization(k)
u = np.array([[np.sin(lamda)], [-np.cos(lamda)], [0]])
rotation_vector = psi * k
rotation_psi = Rotation.from_rotvec(rotation_vector.T[0])
p = rotation_psi.apply(u.T[0]).reshape(3, 1)
p_newframe = rotation_matrix.T @ p
k_newframe = rotation_matrix.T @ k
lamda_newframe, beta_newframe = propagation_vector_to_localization(k_newframe)
u_newframe = np.array([[np.sin(lamda_newframe)], [-np.cos(lamda_newframe)], [0]])
v_newframe = np.array([[-np.sin(beta_newframe) * np.cos(lamda_newframe)],
[-np.sin(beta_newframe) * np.sin(lamda_newframe)],
[np.cos(beta_newframe)]])
p_dot_u_newframe = np.vdot(p_newframe, u_newframe)
p_dot_v_newframe = np.vdot(p_newframe, v_newframe)
psi_newframe = np.arctan2(p_dot_v_newframe, p_dot_u_newframe)
psi_newframe = np.mod(psi_newframe, np.pi)

return psi_newframe

def tL_from_SSB(tSSB, lamdaSSB, betaSSB, t0=0.0):
R_ORBIT = au.value
OMEGA_L = 2*np.pi / YRSID_SI
t0 *= YRSID_SI
alpha = (tSSB + t0) * OMEGA_L
k = localization_to_propagation_vector(lamdaSSB, betaSSB)
v_LISA = np.array([[R_ORBIT*np.cos(alpha)],
[R_ORBIT*np.sin(alpha)], [0]])
tL = tSSB + np.vdot(k, v_LISA) / c.value

return tL

def tSSB_from_tL(tL, lamdaSSB, betaSSB, t0=0.0):
tSSB = symbols('tSSB')
t0 *= YRSID_SI
R_ORBIT = au.value
OMEGA_L = 2*np.pi / YRSID_SI

equation = tL - tSSB + R_ORBIT * cos(betaSSB) * (
cos(lamdaSSB) * cos(OMEGA_L * (tSSB + t0)) +
sin(lamdaSSB) * sin(OMEGA_L * (tSSB + t0))
) / c.value

return np.float64(nsolve(equation, tL))

def SSB_to_LISA(tSSB, lamdaSSB, betaSSB, psiSSB, t0):
tL = tL_from_SSB(tSSB, lamdaSSB, betaSSB, t0)
kSSB = localization_to_propagation_vector(lamdaSSB, betaSSB)
alpha = OMEGA_0 * (tSSB + t0*YRSID_SI)
rotation_matrix_L = rotation_matrix_SSBtoLISA(alpha)
kL = rotation_matrix_L.T @ kSSB
lamdaL, betaL = propagation_vector_to_localization(kL)
psiL = polarization_angle_newframe(psiSSB, kSSB, rotation_matrix_L)

return (tL, lamdaL, betaL, psiL)

def LISA_to_SSB(tL, lamdaL, betaL, psiL, t0):
lamdaSSB_approx = 0.0
betaSSB_approx = 0.0
tSSB_approx = tL
kL = localization_to_propagation_vector(lamdaL, betaL)
for i in range(3):
alpha = OMEGA_0 * (tSSB_approx + t0*YRSID_SI)
rotation_matrix_L = rotation_matrix_SSBtoLISA(alpha)
kSSB_approx = rotation_matrix_L @ kL
lamdaSSB_approx, betaSSB_approx = propagation_vector_to_localization(kSSB_approx)
tSSB_approx = tSSB_from_tL(tL, lamdaSSB_approx, betaSSB_approx, t0)
psiSSB = polarization_angle_newframe(psiL, kL, rotation_matrix_L.T)

return (tSSB_approx, lamdaSSB_approx, betaSSB_approx, psiSSB)

def rotation_matrix_SSBtoGEO(epsilon=np.deg2rad(23.44)):
r = Rotation.from_rotvec([
[-epsilon, 0, 0]
]).as_matrix()

return np.array(r[0])

def tG_from_SSB(tSSB, lamdaSSB, betaSSB, t0=0.0):
R_ORBIT = au.value
OMEGA_G = 2*np.pi / YRSID_SI
t0 *= YRSID_SI
alpha = (tSSB + t0) * OMEGA_G
k = localization_to_propagation_vector(lamdaSSB, betaSSB)
v_GEO = np.array([[R_ORBIT*np.cos(alpha)],
[R_ORBIT*np.sin(alpha)], [0]])
tG = tSSB + np.vdot(k, v_GEO) / c.value

return tG

def tSSB_from_tG(tG, lamdaSSB, betaSSB, t0=0.0):
tSSB = symbols('tSSB')
t0 *= YRSID_SI
R_ORBIT = au.value
OMEGA_G = 2*np.pi / YRSID_SI

equation = tG - tSSB + R_ORBIT * cos(betaSSB) * (
cos(lamdaSSB) * cos(OMEGA_G * (tSSB + t0)) +
sin(lamdaSSB) * sin(OMEGA_G * (tSSB + t0))
) / c.value

return np.float64(nsolve(equation, tG))

def SSB_to_GEO(tSSB, lamdaSSB, betaSSB, psiSSB, t0):
tG = tG_from_SSB(tSSB, lamdaSSB, betaSSB, t0)
kSSB = localization_to_propagation_vector(lamdaSSB, betaSSB)
rotation_matrix_G = rotation_matrix_SSBtoGEO()
kG = rotation_matrix_G.T @ kSSB
lamdaG, betaG = propagation_vector_to_localization(kG)
psiG = polarization_angle_newframe(psiSSB, kSSB, rotation_matrix_G)

return (tG, lamdaG, betaG, psiG)

def GEO_to_SSB(tG, lamdaG, betaG, psiG, t0):
lamdaSSB_approx = 0.0
betaSSB_approx = 0.0
tSSB_approx = tG
kG = localization_to_propagation_vector(lamdaG, betaG)
for i in range(3):
rotation_matrix_G = rotation_matrix_SSBtoGEO()
kSSB_approx = rotation_matrix_G @ kG
lamdaSSB_approx, betaSSB_approx = propagation_vector_to_localization(kSSB_approx)
tSSB_approx = tSSB_from_tG(tG, lamdaSSB_approx, betaSSB_approx, t0)
psiSSB = polarization_angle_newframe(psiG, kG, rotation_matrix_G.T)

return (tSSB_approx, lamdaSSB_approx, betaSSB_approx, psiSSB)

__all__ = ['localization_to_propagation_vector', 'rotation_matrix_SSBtoLISA',
'propagation_vector_to_localization', 'polarization_angle_newframe',
'tL_from_SSB', 'tSSB_from_tL', 'SSB_to_LISA', 'LISA_to_SSB',
'rotation_matrix_SSBtoGEO', 'tG_from_SSB', 'tSSB_from_tG',
'SSB_to_GEO', 'GEO_to_SSB',
]