Commit 49b733b1 authored by Kipp Cannon's avatar Kipp Cannon

defer offsetvector import to work around non-LDG environments

- re-enable unit tests for table, lsctables and utils.segments
parent 4e768fc7
Pipeline #47524 passed with stages
in 7 minutes and 21 seconds
......@@ -48,7 +48,6 @@ import warnings
from ligo import segments
from glue import git_version
from glue import offsetvector
from . import ilwd
from . import ligolw
from . import table
......@@ -878,7 +877,9 @@ class TimeSlideTable(DBTable):
Return a ditionary mapping time slide IDs to offset
dictionaries.
"""
return dict((ilwd.ilwdchar(time_slide_id), offsetvector.offsetvector((instrument, offset) for time_slide_id, instrument, offset in values)) for time_slide_id, values in itertools.groupby(self.cursor.execute("SELECT time_slide_id, instrument, offset FROM time_slide ORDER BY time_slide_id"), lambda time_slide_id_instrument_offset: time_slide_id_instrument_offset[0]))
# FIXME: deferred to work around non-LDG environments
from lalburst.offsetvector import offsetvector
return dict((ilwd.ilwdchar(time_slide_id), offsetvector((instrument, offset) for time_slide_id, instrument, offset in values)) for time_slide_id, values in itertools.groupby(self.cursor.execute("SELECT time_slide_id, instrument, offset FROM time_slide ORDER BY time_slide_id"), lambda time_slide_id_instrument_offset: time_slide_id_instrument_offset[0]))
def get_time_slide_id(self, offsetdict, create_new = None, superset_ok = False, nonunique_ok = False):
"""
......
......@@ -47,7 +47,6 @@ from ligo import segments
from glue import git_version
from glue import iterutils
from glue import offsetvector
import lal
from lal import LIGOTimeGPS
from . import ligolw
......@@ -3002,7 +3001,7 @@ class SimInspiral(table.Table.RowType):
else:
self.spin2x, self.spin2y, self.spin2z = spin
def time_at_instrument(self, instrument, offsetvector):
def time_at_instrument(self, instrument, offsetvect):
"""
Return the "time" of the injection, delay corrected for the
displacement from the geocentre to the given instrument.
......@@ -3025,7 +3024,7 @@ class SimInspiral(table.Table.RowType):
# injections are done this way so that when the triggers
# that result from an injection have the offset vector
# added to their times the triggers will form a coinc
t_geocent = self.time_geocent - offsetvector[instrument]
t_geocent = self.time_geocent - offsetvect[instrument]
ra, dec = self.ra_dec
return t_geocent + lal.TimeDelayFromEarthCenter(lal.cached_detector_by_prefix[instrument].location, ra, dec, t_geocent)
......@@ -3146,7 +3145,7 @@ class SimBurst(table.Table.RowType):
else:
self.ra, self.dec = radec
def time_at_instrument(self, instrument, offsetvector):
def time_at_instrument(self, instrument, offsetvect):
"""
Return the "time" of the injection, delay corrected for the
displacement from the geocentre to the given instrument.
......@@ -3169,7 +3168,7 @@ class SimBurst(table.Table.RowType):
# injections are done this way so that when the triggers
# that result from an injection have the offset vector
# added to their times the triggers will form a coinc
t_geocent = self.time_geocent - offsetvector[instrument]
t_geocent = self.time_geocent - offsetvect[instrument]
ra, dec = self.ra_dec
return t_geocent + lal.TimeDelayFromEarthCenter(lal.cached_detector_by_prefix[instrument].location, ra, dec, t_geocent)
......@@ -3827,10 +3826,12 @@ class TimeSlideTable(table.Table):
Return a ditionary mapping time slide IDs to offset
dictionaries.
"""
# FIXME: deferred to work around non-LDG environments
from lalburst.offsetvector import offsetvector
d = {}
for row in self:
if row.time_slide_id not in d:
d[row.time_slide_id] = offsetvector.offsetvector()
d[row.time_slide_id] = offsetvector()
if row.instrument in d[row.time_slide_id]:
raise KeyError("'%s': duplicate instrument '%s'" % (row.time_slide_id, row.instrument))
d[row.time_slide_id][row.instrument] = row.offset
......@@ -3855,10 +3856,10 @@ class TimeSlideTable(table.Table):
self.append(row)
return time_slide_id
def get_time_slide_id(self, offsetdict, create_new = None, superset_ok = False, nonunique_ok = False):
def get_time_slide_id(self, offsetvect, create_new = None, superset_ok = False, nonunique_ok = False):
"""
Return the time_slide_id corresponding to the offset vector
described by offsetdict, a dictionary of instrument/offset
described by offsetvect, a dictionary of instrument/offset
pairs.
If the optional create_new argument is None (the default),
......@@ -3894,25 +3895,25 @@ class TimeSlideTable(table.Table):
"""
# look for matching offset vectors
if superset_ok:
ids = [id for id, slide in self.as_dict().items() if offsetdict == dict((instrument, offset) for instrument, offset in slide.items() if instrument in offsetdict)]
ids = [id for id, slide in self.as_dict().items() if offsetvect == dict((instrument, offset) for instrument, offset in slide.items() if instrument in offsetvect)]
else:
ids = [id for id, slide in self.as_dict().items() if offsetdict == slide]
ids = [id for id, slide in self.as_dict().items() if offsetvect == slide]
if len(ids) > 1:
# found more than one
if nonunique_ok:
# and that's OK
return ids[0]
# and that's not OK
raise KeyError("%s not unique" % repr(offsetdict))
raise KeyError("%s not unique" % repr(offsetvect))
if len(ids) == 1:
# found one
return ids[0]
# offset vector not found in table
if create_new is None:
# and that's not OK
raise KeyError("%s not found" % repr(offsetdict))
raise KeyError("%s not found" % repr(offsetvect))
# that's OK, create new vector, return its ID
return self.append_offsetvector(offsetdict, create_new)
return self.append_offsetvector(offsetvect, create_new)
class TimeSlide(table.Table.RowType):
......
......@@ -2,7 +2,6 @@
import doctest
import sys
sys.exit(0) # FIXME: remove when git.ligo.org's test environment is fixed
from glue.ligolw import lsctables
if __name__ == '__main__':
......
......@@ -2,7 +2,6 @@
import doctest
import sys
sys.exit(0) # FIXME: remove when git.ligo.org's test environment is fixed
from glue.ligolw import table
if __name__ == '__main__':
......
......@@ -2,7 +2,6 @@
import doctest
import sys
sys.exit(0) # FIXME: remove when git.ligo.org's test environment is fixed
from glue.ligolw.utils import segments as ligolw_segments
if __name__ == '__main__':
......
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