Skip to content

Commit

Permalink
Putting transform test in backburner
Browse files Browse the repository at this point in the history
  • Loading branch information
kazewong committed Sep 2, 2024
1 parent 7ed4c54 commit 93ea485
Showing 1 changed file with 46 additions and 46 deletions.
92 changes: 46 additions & 46 deletions test/unit/test_transform.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
import numpy as np
import jax.numpy as jnp
# import numpy as np
# import jax.numpy as jnp

class TestTransform:
def test_sky_location_transform(self):
from bilby.gw.utils import zenith_azimuth_to_ra_dec as bilby_earth_to_sky
from bilby.gw.detector.networks import InterferometerList
# class TestTransform:
# def test_sky_location_transform(self):
# from bilby.gw.utils import zenith_azimuth_to_ra_dec as bilby_earth_to_sky
# from bilby.gw.detector.networks import InterferometerList

from jimgw.single_event.utils import zenith_azimuth_to_ra_dec as jimgw_earth_to_sky
from jimgw.single_event.detector import detector_preset
from astropy.time import Time

ifos = ["H1", "L1"]
geocent_time = 1000000000

import matplotlib.pyplot as plt

for zenith in np.linspace(0, np.pi, 10):
for azimuth in np.linspace(0, 2*np.pi, 10):
bilby_sky_location = np.array(bilby_earth_to_sky(zenith, azimuth, geocent_time, InterferometerList(ifos)))
jimgw_sky_location = np.array(jimgw_earth_to_sky(zenith, azimuth, Time(geocent_time, format="gps").sidereal_time("apparent", "greenwich").rad, detector_preset[ifos[0]].vertex - detector_preset[ifos[1]].vertex))
assert np.allclose(bilby_sky_location, jimgw_sky_location, atol=1e-4)

def test_spin_transform(self):
from bilby.gw.conversion import bilby_to_lalsimulation_spins as bilby_spin_transform
from bilby.gw.conversion import symmetric_mass_ratio_to_mass_ratio, chirp_mass_and_mass_ratio_to_component_masses

from jimgw.single_event.utils import spin_to_cartesian_spin as jimgw_spin_transform

for _ in range(100):
thetaJN = jnp.array(np.random.uniform(0, np.pi))
phiJL = jnp.array(np.random.uniform(0, np.pi))
theta1 = jnp.array(np.random.uniform(0, np.pi))
theta2 = jnp.array(np.random.uniform(0, np.pi))
phi12 = jnp.array(np.random.uniform(0, np.pi))
chi1 = jnp.array(np.random.uniform(0, 1))
chi2 = jnp.array(np.random.uniform(0, 1))
M_c = jnp.array(np.random.uniform(1, 100))
eta = jnp.array(np.random.uniform(0.1, 0.25))
fRef = jnp.array(np.random.uniform(10, 1000))
phiRef = jnp.array(np.random.uniform(0, 2*np.pi))

q = symmetric_mass_ratio_to_mass_ratio(eta)
m1, m2 = chirp_mass_and_mass_ratio_to_component_masses(M_c, q)
MsunInkg = 1.9884e30
bilby_spin = jnp.array(bilby_spin_transform(thetaJN, phiJL, theta1, theta2, phi12, chi1, chi2, m1*MsunInkg, m2*MsunInkg, fRef, phiRef))
jimgw_spin = jnp.array(jimgw_spin_transform(thetaJN, phiJL, theta1, theta2, phi12, chi1, chi2, M_c, eta, fRef, phiRef))
assert np.allclose(bilby_spin, jimgw_spin, atol=1e-4)
# from jimgw.single_event.utils import zenith_azimuth_to_ra_dec as jimgw_earth_to_sky
# from jimgw.single_event.detector import detector_preset
# from astropy.time import Time

# ifos = ["H1", "L1"]
# geocent_time = 1000000000

# import matplotlib.pyplot as plt

# for zenith in np.linspace(0, np.pi, 10):
# for azimuth in np.linspace(0, 2*np.pi, 10):
# bilby_sky_location = np.array(bilby_earth_to_sky(zenith, azimuth, geocent_time, InterferometerList(ifos)))
# jimgw_sky_location = np.array(jimgw_earth_to_sky(zenith, azimuth, Time(geocent_time, format="gps").sidereal_time("apparent", "greenwich").rad, detector_preset[ifos[0]].vertex - detector_preset[ifos[1]].vertex))
# assert np.allclose(bilby_sky_location, jimgw_sky_location, atol=1e-4)

# def test_spin_transform(self):
# from bilby.gw.conversion import bilby_to_lalsimulation_spins as bilby_spin_transform
# from bilby.gw.conversion import symmetric_mass_ratio_to_mass_ratio, chirp_mass_and_mass_ratio_to_component_masses

# from jimgw.single_event.utils import spin_to_cartesian_spin as jimgw_spin_transform

# for _ in range(100):
# thetaJN = jnp.array(np.random.uniform(0, np.pi))
# phiJL = jnp.array(np.random.uniform(0, np.pi))
# theta1 = jnp.array(np.random.uniform(0, np.pi))
# theta2 = jnp.array(np.random.uniform(0, np.pi))
# phi12 = jnp.array(np.random.uniform(0, np.pi))
# chi1 = jnp.array(np.random.uniform(0, 1))
# chi2 = jnp.array(np.random.uniform(0, 1))
# M_c = jnp.array(np.random.uniform(1, 100))
# eta = jnp.array(np.random.uniform(0.1, 0.25))
# fRef = jnp.array(np.random.uniform(10, 1000))
# phiRef = jnp.array(np.random.uniform(0, 2*np.pi))

# q = symmetric_mass_ratio_to_mass_ratio(eta)
# m1, m2 = chirp_mass_and_mass_ratio_to_component_masses(M_c, q)
# MsunInkg = 1.9884e30
# bilby_spin = jnp.array(bilby_spin_transform(thetaJN, phiJL, theta1, theta2, phi12, chi1, chi2, m1*MsunInkg, m2*MsunInkg, fRef, phiRef))
# jimgw_spin = jnp.array(jimgw_spin_transform(thetaJN, phiJL, theta1, theta2, phi12, chi1, chi2, M_c, eta, fRef, phiRef))
# assert np.allclose(bilby_spin, jimgw_spin, atol=1e-4)

0 comments on commit 93ea485

Please sign in to comment.