swh:1:snp:3a699297f000109a1bc833f294a54171df990207
Tip revision: 3f8c4b8adbfe4f9e9a243f8ba3eb2a1da1b677a3 authored by Tito Dal Canton on 02 March 2023, 13:19:16 UTC
Change `setup.py` for 2.1.0 release (#4274)
Change `setup.py` for 2.1.0 release (#4274)
Tip revision: 3f8c4b8
pycbc_data_store
#!/usr/bin/env python
""" Create HDF strain cache file
"""
import logging, argparse, numpy, h5py
import pycbc, pycbc.strain, pycbc.dq
from pycbc.version import git_verbose_msg as version
from pycbc.fft.fftw import set_measure_level
from pycbc.events.veto import segments_to_start_end
set_measure_level(0)
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--version', action='version', version=version)
parser.add_argument('--verbose', action="store_true")
parser.add_argument("--science-name", help="Science flag definition")
parser.add_argument("--segment-server")
parser.add_argument("--veto-definer-file")
parser.add_argument("--instrument")
parser.add_argument("--output-file", required=True)
pycbc.strain.insert_strain_option_group(parser)
args = parser.parse_args()
pycbc.init_logging(args.verbose)
logging.info('Querying science segemnts')
segs = pycbc.dq.query_str(args.instrument,
args.science_name,
args.gps_start_time,
args.gps_end_time,
server=args.segment_server,
veto_definer=args.veto_definer_file)
logging.info('Found %s segments, %ss total', len(segs), abs(segs))
f = h5py.File(args.output_file, 'w')
starts, ends = segments_to_start_end(segs)
pad = 0 if args.pad_data is None else args.pad_data
f['{}/segments/start'.format(args.channel_name)] = starts + pad
f['{}/segments/end'.format(args.channel_name)] = ends - pad
for i, seg in enumerate(segs):
logging.info('Processing science segment %s/%s of duration %ss',
i, len(segs), abs(seg))
args.gps_start_time = seg[0] + pad
args.gps_end_time = seg[1] - pad
logging.info('Reading %s-%s', seg[0], seg[1])
ht = pycbc.strain.from_cli(args)
f.create_dataset("{}/{}".format(args.channel_name, i), data=ht.data[:],
compression_opts=9, compression='gzip')
logging.info('Done!')