110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248 | def read_banks(filename, contenthandler, verbose=False):
"""Read SVD banks from a LIGO_LW xml file."""
# Load document
xmldoc = ligolw_utils.load_url(
filename, contenthandler=contenthandler, verbose=verbose
)
banks = []
# FIXME in principle this could be different for each bank included in
# this file, but we only put one in the file for now
# FIXME, right now there is only one instrument so we just pull out the
# only psd there is
try:
raw_psd = list(lal.series.read_psd_xmldoc(xmldoc).values())[0]
except ValueError:
# the bank file does not contain psd ligolw element.
raw_psd = None
for root in (
elem
for elem in xmldoc.getElementsByTagName(ligolw.LIGO_LW.tagName)
if elem.hasAttribute("Name") and elem.Name == "gstlal_svd_bank_Bank"
):
# Create new SVD bank object
bank = Bank.__new__(Bank)
# Read sngl inspiral table
bank.sngl_inspiral_table = lsctables.SnglInspiralTable.get_table(root)
bank.sngl_inspiral_table.parentNode.removeChild(bank.sngl_inspiral_table)
# Read root-level scalar parameters
bank.filter_length = ligolw_param.get_pyvalue(root, "filter_length")
bank.gate_threshold = ligolw_param.get_pyvalue(root, "gate_threshold")
bank.logname = ligolw_param.get_pyvalue(root, "logname") or None
bank.snr_threshold = ligolw_param.get_pyvalue(root, "snr_threshold")
bank.template_bank_filename = ligolw_param.get_pyvalue(
root, "template_bank_filename"
)
bank.bank_id = ligolw_param.get_pyvalue(root, "bank_id")
bank.bank_type = ligolw_param.get_pyvalue(root, "bank_type")
try:
bank.newdeltaF = ligolw_param.get_pyvalue(root, "new_deltaf")
bank.working_f_low = ligolw_param.get_pyvalue(root, "working_f_low")
bank.f_low = ligolw_param.get_pyvalue(root, "f_low")
bank.sample_rate_max = ligolw_param.get_pyvalue(root, "sample_rate_max")
except ValueError:
pass
# Read root-level arrays
bank.autocorrelation_bank = (
ligolw_array.get_array(root, "autocorrelation_bank_real").array
+ 1j * ligolw_array.get_array(root, "autocorrelation_bank_imag").array
)
bank.autocorrelation_mask = ligolw_array.get_array(
root, "autocorrelation_mask"
).array
bank.sigmasq = ligolw_array.get_array(root, "sigmasq").array
bank_correlation_real = ligolw_array.get_array(
root, "bank_correlation_matrix_real"
).array
bank_correlation_imag = ligolw_array.get_array(
root, "bank_correlation_matrix_imag"
).array
bank.bank_correlation_matrix = (
bank_correlation_real + 1j * bank_correlation_imag
)
# prepare the horizon distance factors
bank.horizon_factors = dict(
(row.template_id, sigmasq**0.5)
for row, sigmasq in zip(bank.sngl_inspiral_table, bank.sigmasq)
)
if raw_psd is not None:
# reproduce the whitening psd and attach a reference to the psd
bank.processed_psd = condition_psd(
raw_psd,
bank.newdeltaF,
minfs=(bank.working_f_low, bank.f_low),
maxfs=(bank.sample_rate_max / 2.0 * 0.90, bank.sample_rate_max / 2.0),
)
else:
bank.processed_psd = None
# Read bank fragments
bank.bank_fragments = []
for el in (
node for node in root.childNodes if node.tagName == ligolw.LIGO_LW.tagName
):
frag = BankFragment(
rate=ligolw_param.get_pyvalue(el, "rate"),
start=ligolw_param.get_pyvalue(el, "start"),
end=ligolw_param.get_pyvalue(el, "end"),
)
# Read arrays
frag.chifacs = ligolw_array.get_array(el, "chifacs").array
try:
frag.mix_matrix = ligolw_array.get_array(el, "mix_matrix").array
except ValueError:
frag.mix_matrix = None
frag.orthogonal_template_bank = ligolw_array.get_array(
el, "orthogonal_template_bank"
).array
try:
frag.singular_values = ligolw_array.get_array(
el, "singular_values"
).array
except ValueError:
frag.singular_values = None
try:
frag.sum_of_squares_weights = ligolw_array.get_array(
el, "sum_of_squares_weights"
).array
except ValueError:
frag.sum_of_squares_weights = None
bank.bank_fragments.append(frag)
banks.append(bank)
template_id, func = horizon_distance_func(banks)
template_id = abs(
template_id
) # make sure horizon_distance_func did not pick the noise model template
horizon_norm = None
for bank in banks:
if template_id in bank.horizon_factors and bank.bank_type == "signal_model":
assert horizon_norm is None
horizon_norm = bank.horizon_factors[template_id]
for bank in banks:
bank.horizon_distance_func = func
bank.horizon_factors = dict(
(tid, f / horizon_norm) for (tid, f) in bank.horizon_factors.items()
)
xmldoc.unlink()
return banks
|