gstlal 1.13.0
Loading...
Searching...
No Matches
io.py
1# Copyright (C) 2020 Patrick Godwin (patrick.godwin@ligo.org)
2#
3# This program is free software; you can redistribute it and/or modify it
4# under the terms of the GNU General Public License as published by the
5# Free Software Foundation; either version 2 of the License, or (at your
6# option) any later version.
7#
8# This program is distributed in the hope that it will be useful, but
9# WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11# Public License for more details.
12#
13# You should have received a copy of the GNU General Public License along
14# with this program; if not, write to the Free Software Foundation, Inc.,
15# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16
17
18from gstlal import plugins
19from gstlal.datafind import DataType, DataCache
20from gstlal.dags import Option
21from gstlal.dags.layers import Layer, Node
22
23
24def create_frames_layer(config, dag, psd_cache):
25 layer = Layer(
26 "gstlal_fake_frames",
27 requirements={
28 "request_cpus": 2,
29 "request_memory": 2000,
30 "request_disk": "2GB",
31 **config.condor.submit
32 },
33 transfer_files=config.condor.transfer_files,
34 )
35
36 frame_cache = DataCache.generate(DataType.FRAMES, config.ifo_combos, config.time_bins, create_dirs=False)
37
38 # if given a single PSD, assign this to all times
39 if len(psd_cache) == 1:
40 psds = {key: psd_cache for key in frame_cache.groupby("ifo", "time").keys()}
41 else:
42 psds = psd_cache.groupby("ifo", "time")
43
44 # set options
45 common_opts = [
46 Option("data-source", "frames"),
47 Option("frame-segments-name", config.source.frame_segments_name),
48 Option("data-find-server", config.source.data_find_server),
49 ]
50 if config.frames.injections:
51 common_opts.append(Option("injections", config.frames.injections))
52 if config.frames.recolor_psd:
53 common_opts.append(Option("color-psd", config.frames.recolor_psd))
54 if config.frames.track_psd:
55 common_opts.append(Option("whiten-track-psd"))
56 if config.frames.shift:
57 common_opts.append(Option("shift", config.frames.shift))
58 if config.frames.frame_duration:
59 common_opts.append(Option("output-frame-duration", config.frames.frame_duration))
60 if config.frames.frames_per_file:
61 common_opts.append(Option("output-frames-per-file", config.frames.frames_per_file))
62
63 for (ifo_combo, span), frames in frame_cache.groupby("ifo", "time").items():
64 ifos = config.to_ifo_list(ifo_combo)
65 start, end = span
66
67 for ifo in ifos:
68 frame_opts = [
69 Option("gps-start-time", int(start)),
70 Option("gps-end-time", int(end)),
71 Option("channel-name", f"{ifo}={config.source.channel_name[ifo]}"),
72 Option("frame-type", f"{ifo}={config.source.frame_type[ifo]}"),
73 Option("output-channel-name", f"{ifo}={config.frames.output_channel_name[ifo]}"),
74 Option("output-frame-type", f"{ifo}_{config.frames.output_frame_type[ifo]}"),
75 ]
76 frame_opts.extend(common_opts)
77
78 layer += Node(
79 arguments = frame_opts,
80 inputs = [
81 Option("whiten-reference-psd", psds[(ifo_combo, span)].files),
82 Option("frame-segments-file", config.source.frame_segments_file),
83 ],
84 outputs = Option("output-path", config.frames.get("output_path", "frames"))
85 )
86
87 dag.attach(layer)
88 return frame_cache
89
90
91@plugins.register
92def layers():
93 return {
94 "create_frames": create_frames_layer,
95 }