-
Notifications
You must be signed in to change notification settings - Fork 3
/
init_download_data.py
45 lines (40 loc) · 1.6 KB
/
init_download_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
The user must run this script prior to submitting a job in order to point gwpy.TimeSeries.read to data
and avoid downloading the same data for every job
"""
import bilby as bb
import python_code.utils as utils
import gwpy
import argparse
# Set up the argument parser
parser = argparse.ArgumentParser("Download the data for an event")
parser.add_argument("-e", "--event", help="GW-name of the event")
args = parser.parse_args()
# Outdir
outdir = "submissions/" + args.event + "/event_data/"
# Get the data for the right segment
duration = utils.event_duration[args.event]
detectors = utils.event_detectors[args.event]
trigger_time = utils.trigger_time[args.event]
post_trigger_duration = 2
sampling_frequency = 4096
start = trigger_time + post_trigger_duration - duration
end = start + duration
# Set up the interferometers with event data
interferometers = bb.gw.detector.InterferometerList(detectors)
channel_dict = {
key: key + ":" + utils.event_channels[args.event][key] for key in detectors
}
bb.core.utils.check_directory_exists_and_if_not_mkdir(outdir)
for ifo in interferometers:
try:
data = gwpy.timeseries.TimeSeries.get(
channel_dict[ifo.name], start, end, verbose=False
)
except RuntimeError:
data = gwpy.timeseries.TimeSeries.fetch_open_data(ifo.name, start, end)
data = data.resample(sampling_frequency)
ifo.strain_data.set_from_gwpy_timeseries(data)
with open(outdir + '/' + ifo.name + '_time_domain_strain_data.csv', 'w') as f:
for i, t in enumerate(ifo.time_array):
f.write(str(t) + ',' + str(ifo.time_domain_strain[i]) + '\n')