Commit 592dae6a authored by channa's avatar channa
Browse files

rio.py: copyright, verbosity fixes, bug fix for non injection file

parent 43682b25
Pipeline #212732 passed with stages
in 31 minutes and 29 seconds
#!/usr/bin/env python
# Copyright (C) 2021 Chad Hanna (crh184@psu.edu)
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import sqlite3
import sys
from collections import UserDict
......@@ -92,7 +108,7 @@ Example:
def __load_tables(self, names):
for name, keys in names:
try:
print ('loading ... %s' % name, end = ' ')
if self.verbose: print ('loading ... %s' % name, end = ' ', file = sys.stderr)
res = self.con.cursor().execute('SELECT * FROM %s' % name)
out = {}
for row in res.fetchall():
......@@ -100,9 +116,9 @@ Example:
for key in keys:
out.setdefault(row[key], []).append(rd)
self.tables[name] = out
print('... %d' % len(self.tables[name]))
if self.verbose: print('... %d' % len(self.tables[name]), file = sys.stderr)
except sqlite3.OperationalError:
print('... NOT FOUND!')
if self.verbose: print('... NOT FOUND!', file = sys.stderr)
def __process_injections(self):
self.__not_analyzed_injections = set([])
......@@ -116,8 +132,9 @@ Example:
else:
self.__not_analyzed_injections.add(sid)
self.__found_injections = {}
for cid, event in tuple(self['sim_inspiral<-->coinc_event coincidences (exact)'].values())[0].items():
self.__found_injections.setdefault(event['sim_inspiral'][0]['simulation_id'], []).append(event)
if "sim_inspiral" in self.tables:
for cid, event in tuple(self['sim_inspiral<-->coinc_event coincidences (exact)'].values())[0].items():
self.__found_injections.setdefault(event['sim_inspiral'][0]['simulation_id'], []).append(event)
self.__missed_injections = self.__analyzed_ids - set(self.__found_injections)
def missed_injections(self):
......@@ -159,7 +176,7 @@ Example:
yield tid, row
def __to_dict(self):
print ('computing time slides ...')
if self.verbose: print ('computing time slides ...', file = sys.stderr)
tids = {}
for tid, rows in self.itertable('time_slide'):
for row in rows:
......@@ -172,7 +189,7 @@ Example:
for description, coinc_type in coinc_types.items():
for offsets, tid in tids.items():
print ('getting coinc events for %s and time slide %s ...' % (description, offsets))
if self.verbose: print ('getting coinc events for %s and time slide %s ...' % (description, offsets), file = sys.stderr)
# get all the coinc events for this timeslide
# we can use v[0] because there will be one row per coinc_event_id in this case
coinc_type[offsets] = {k:v[0] for k,v in self.tables['coinc_event'].items() if v[0]['time_slide_id'] == tid and v[0]['coinc_def_id'] == defids[description]}
......
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