Commit 1261a767 authored by channa's avatar channa
Browse files add a convenience method to create a tsv file

parent 592dae6a
Pipeline #212747 passed with stages
in 32 minutes and 57 seconds
......@@ -168,7 +168,45 @@ Example:
del out['coinc_event']['sngl_inspiral']
out['coinc_inspiral'] = self.tables['coinc_inspiral'][eid][0]
yield out
def zl_event_tsv(self, sort_by = {"coinc_inspiral": "combined_far"}, sngl_inspiral_columns = ['snr', 'chisq'], coinc_event_columns = ['likelihood'], coinc_inspiral_columns = ["end_time", "end_time_ns", "mchirp", "mass"], limit = 10, ifos = ('H1', 'L1', 'V1', 'K1')):
Iterate over strings representing rows in a tsv table with data given by the arguments to this function
>>> from gstlal import rio
>>> D = rio.load('H1L1V1-ALL_LLOID-1256655642-732465.sqlite')
>>> with open("blah.tsv", "w") as f:
... for row in D.zl_event_tsv(limit = 100000000):
... print (row, file = f)
data = []
skey, scol = tuple(sort_by.items())[0]
for event in self.zl_events():
# first column will be the sort by
row = [event[skey][scol]]
row.extend([event['coinc_event'][c] for c in coinc_event_columns])
row.extend([event['coinc_inspiral'][c] for c in coinc_inspiral_columns])
sngls = {e['ifo']:e for e in event['sngl_inspiral']}
for ifo in ifos:
if ifo in sngls:
row.extend([sngls[ifo][c] for c in sngl_inspiral_columns])
row.extend(['---' for c in sngl_inspiral_columns])
columns = [scol] + coinc_event_columns + coinc_inspiral_columns + ["%s_%s" % (ifo, c) for ifo in ifos for c in sngl_inspiral_columns]
yield "\t".join(columns)
for row in data[:limit]:
yield "\t".join([str(r) for r in row])
def itertable(self, table):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment