Skip to content

Commit

Permalink
Using SkyGrid functions to write the HDF5 file and calculate time
Browse files Browse the repository at this point in the history
delays
  • Loading branch information
jacquot committed Jan 6, 2025
1 parent 0470733 commit 4074e7b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
33 changes: 15 additions & 18 deletions bin/pycbc_make_sky_grid
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,20 @@ 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 = 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()

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

extra_datasets = {
'time_delays': time_delays
}

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, extra_datasets)
8 changes: 7 additions & 1 deletion pycbc/tmpltbank/sky_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,19 @@ 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, extra_datasets):
"""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
if extra_attrs is not None:
for attribute in extra_attrs:
hf.attrs[attribute] = extra_attrs[attribute]
if extra_datasets is not None:
for datasets in extra_datasets:
hf[datasets] = extra_datasets[datasets]

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

0 comments on commit 4074e7b

Please sign in to comment.