Commit f92247db authored by Kipp Cannon's avatar Kipp Cannon
Browse files

snglscoinc: rearrange class definition order

parent 90f0270b
......@@ -74,12 +74,68 @@ from .git_version import version as __version__
#
# =============================================================================
#
# Streaming Double Coincidence Generator
# Utilities
#
# =============================================================================
#
class multidict(UserDict):
"""
Read-only dictionary view into a collection of dictionaries.
Example:
>>> x = {"a": 10., "b": 100.}
>>> y = {"c": 1000., "d": 10000.}
>>> z = multidict(x, y)
>>> z["a"]
10.0
>>> z["c"]
1000.0
>>> "d" in z
True
>>> "e" in z
False
"""
def __init__(self, *dicts):
self.dicts = dicts
if not self.dicts:
raise ValueError("len(dicts) must be > 0")
def __getitem__(self, x):
for d in self.dicts:
if x in d:
return d[x]
raise KeyError(x)
def __nonzero__(self):
return any(self.dicts)
def __contains__(self, x):
return any(x in d for d in self.dicts)
def __len__(self):
return sum(len(d) for d in self.dicts)
def __iter__(self):
return itertools.chain(*(iter(d) for d in self.dicts))
def iteritems(self):
warnings.warn(
"this method is deprecated, and will be removed in a "
"future release. please use .items() instead.",
DeprecationWarning,
)
return self.items()
def items(self):
return itertools.chain(*(d.items() for d in self.dicts))
def keys(self):
return list(self)
def light_travel_time(instrument1, instrument2):
"""
Compute and return the time required for light to travel through
......@@ -93,6 +149,15 @@ def light_travel_time(instrument1, instrument2):
return math.sqrt((dx * dx).sum()) / lal.C_SI
#
# =============================================================================
#
# Streaming Double Coincidence Generator
#
# =============================================================================
#
#
# Some comments about this code.
#
......@@ -323,62 +388,6 @@ class singlesqueue(object):
return events, other_events
class multidict(UserDict):
"""
Read-only dictionary view into a collection of dictionaries.
Example:
>>> x = {"a": 10., "b": 100.}
>>> y = {"c": 1000., "d": 10000.}
>>> z = multidict(x, y)
>>> z["a"]
10.0
>>> z["c"]
1000.0
>>> "d" in z
True
>>> "e" in z
False
"""
def __init__(self, *dicts):
self.dicts = dicts
if not self.dicts:
raise ValueError("len(dicts) must be > 0")
def __getitem__(self, x):
for d in self.dicts:
if x in d:
return d[x]
raise KeyError(x)
def __nonzero__(self):
return any(self.dicts)
def __contains__(self, x):
return any(x in d for d in self.dicts)
def __len__(self):
return sum(len(d) for d in self.dicts)
def __iter__(self):
return itertools.chain(*(iter(d) for d in self.dicts))
def iteritems(self):
warnings.warn(
"this method is deprecated, and will be removed in a "
"future release. please use .items() instead.",
DeprecationWarning,
)
return self.items()
def items(self):
return itertools.chain(*(d.items() for d in self.dicts))
def keys(self):
return list(self)
class coincgen_doubles(object):
"""
Using a pair of singlesqueue objects, constructs pairs of
......
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