diff --git a/bin/pycbc_make_sky_grid b/bin/pycbc_make_sky_grid index ef2971f9399..3fba8808344 100644 --- a/bin/pycbc_make_sky_grid +++ b/bin/pycbc_make_sky_grid @@ -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) diff --git a/pycbc/tmpltbank/sky_grid.py b/pycbc/tmpltbank/sky_grid.py index 9da627c7689..94ac9668073 100644 --- a/pycbc/tmpltbank/sky_grid.py +++ b/pycbc/tmpltbank/sky_grid.py @@ -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