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

Use SkyGrid functions to write the HDF5 file and fix error in angular convention #5000

Merged
merged 9 commits into from
Jan 9, 2025
33 changes: 13 additions & 20 deletions bin/pycbc_make_sky_grid
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import pycbc
from pycbc.detector import Detector
from pycbc.io.hdf import HFile
from pycbc.types import angle_as_radians

from pycbc.tmpltbank import sky_grid
Thomas-JACQUOT marked this conversation as resolved.
Show resolved Hide resolved

def spher_to_cart(sky_points):
"""Convert spherical coordinates to cartesian coordinates."""
Expand Down Expand Up @@ -62,7 +62,7 @@ parser.add_argument(
nargs="+",
type=str,
required=True,
help="List of instruments to analyze.",
help="List of instuments to analyze.",
Thomas-JACQUOT marked this conversation as resolved.
Show resolved Hide resolved
)
parser.add_argument(
'--sky-error',
Expand Down Expand Up @@ -165,23 +165,16 @@ spher = cart_to_spher(rota)

# Calculate the time delays between the Earth center
# and each detector for each sky point
time_delays = [
[
detectors[i].time_delay_from_earth_center(
spher[j][0], spher[j][1], args.trigger_time
sky_grid = sky_grid.SkyGrid(
spher[:, 0], spher[:, 1], args.instruments, args.trigger_time
)
for j in range(len(spher))
]
for i in range(len(detectors))
]
time_delays = sky_grid.calculate_time_delays()
Thomas-JACQUOT marked this conversation as resolved.
Show resolved Hide resolved

extra_attributes = {
'trigger_ra': args.ra,
'trigger_dec': args.dec,
'sky_error': args.sky_error,
'timing_uncertainty': args.timing_uncertainty
}

with HFile(args.output, 'w') as hf:
hf['ra'] = spher[:, 0]
hf['dec'] = spher[:, 1]
hf['trigger_ra'] = [args.ra]
hf['trigger_dec'] = [args.dec]
hf['sky_error'] = [args.sky_error]
hf['trigger_time'] = [args.trigger_time]
hf['timing_uncertainty'] = [args.timing_uncertainty]
hf['instruments'] = [d for d in args.instruments]
hf['time_delays'] = time_delays
sky_grid.write_to_file(args.output, extra_attributes)
6 changes: 5 additions & 1 deletion pycbc/tmpltbank/sky_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,17 @@ def read_from_file(cls, path):
ref_gps_time = hf.attrs['ref_gps_time']
return cls(ra, dec, detectors, ref_gps_time)

def write_to_file(self, path):
def write_to_file(self, path, extra_attrs=None, extra_datasets=None):
"""Writes a sky grid to an HDF5 file."""
with h5py.File(path, 'w') as hf:
hf['ra'] = self.ras
hf['dec'] = self.decs
hf.attrs['detectors'] = self.detectors
hf.attrs['ref_gps_time'] = self.ref_gps_time
for attribute in (extra_attrs or {}):
hf.attrs[attribute] = extra_attrs[attribute]
for datasets in (extra_datasets or {}):
hf[datasets] = extra_datasets[datasets]
Thomas-JACQUOT marked this conversation as resolved.
Show resolved Hide resolved

def calculate_antenna_patterns(self):
"""Calculate the antenna pattern functions at each point in the grid
Expand Down
Loading