Skip to content

Commit

Permalink
milang: enforce time limits also on At, AtTime calls (translating to …
Browse files Browse the repository at this point in the history
…get_time).

Removed limit_enabled logic: limits are always active for every curv, the must be explicitly disabled.
  • Loading branch information
Daniele Paganelli committed Apr 3, 2016
1 parent e9daac2 commit a708aeb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 31 deletions.
31 changes: 12 additions & 19 deletions misura/canon/indexer/dataops.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"""

from scipy.interpolate import UnivariateSpline, interp1d
import tables
import numpy as np
import functools
import numexpr as ne
Expand All @@ -17,9 +16,8 @@

class DataOperator(object):
_zerotime = -1
tlimit = False
limit = {}
limit_enabled = set([])
tlimit = False # Global time limit
limit = {} # Cached time limits

@property
def zerotime(self):
Expand All @@ -40,6 +38,7 @@ def get_zerotime(self):
return self.zerotime

def set_time_limit(self, start_time=0, end_time=-1):
"""Set global time limit"""
if start_time == 0 and end_time == -1:
self.tlimit = False
self.limit = {}
Expand All @@ -58,19 +57,13 @@ def get_time_limit(self):
return self.tlimit

@lockme
def set_limit(self, path, enable=False):
"""Enable time limits for data operations on `path`."""
# unbound get_time
if path in self.limit_enabled:
self.limit_enabled.remove(path)
if not enable:
return enable
def set_limit(self, path):
"""Enable time limits for data operations on `path`"""
if not self.tlimit or self.tlimit == (0, -1):
print 'no time limits defined'
self.tlimit = False
return False
if self.limit.has_key(path):
self.limit_enabled.add(path)
print 'returning cached limit', path, self.limit[path]
return self.limit[path]

Expand All @@ -82,23 +75,19 @@ def set_limit(self, path, enable=False):
end = None
print 'enabled limit', path, start, end
self.limit[path] = slice(start, end)
self.limit_enabled.add(path)
return enable
return self.limit[path]

def get_limit(self, path):
"""Get current time and index limits for curve path"""
if not self.tlimit:
return False
if path not in self.limit_enabled:
return False
r = self.limit.get(path, False)
if r is False:
try:
self._lock.release()
except:
pass
self.set_limit(path, True)
return self.limit[path]
return self.set_limit(path)
return r

def _xy(self, path=False, arr=False):
Expand Down Expand Up @@ -214,7 +203,7 @@ def search(self, path, op, cond='x==y', pos=-1):
print 'searching in ', path, cond
tab = self._get_node(path)
x, y = tab.cols.t, tab.cols.v
limit = self.limit.get(path, slice(None, None, None))
limit = self.get_limit(path)
y, m = op(y)
last = -1
# Handle special cases
Expand Down Expand Up @@ -292,6 +281,10 @@ def rises(self, path, val):

def _get_time(self, path, t, get=False, seed=None):
"""Optimized search of the nearest index to time `t` using the getter function `get` and starting from `seed` index."""
if self.tlimit and t<self.tlimit[0]:
t = self.tlimit[0]
elif self.tlimit and t> self.tlimit[1]:
t = self.tlimit[1]
n = self._get_node(path)
# lim=self.get_limit(path)
# if lim:
Expand Down
23 changes: 11 additions & 12 deletions misura/canon/milang/dataenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,7 @@ def _cname(self, curve):
else:
curve = self.prefix + curve
# Activate time limits for current curve
if self.limit != (0, -1):
print '_cname enabling limit', curve, self.limit
self.hdf.set_limit(curve, True)
else:
print '_cname disabling limit', curve, self.limit
self.hdf.set_limit(curve, False)
self.hdf.set_limit(curve)
print '_cname returning', curve
return curve

Expand All @@ -66,7 +61,7 @@ def _c(self, curve0):
The curve is already sliced.
If `curve` is not a string, returns the unchanged object."""
curve = self._cname(curve0)
if not curve:
if curve is False:
return curve0
print 'getting column', curve
c = self.hdf.col(curve)
Expand All @@ -91,7 +86,7 @@ def Point(self, t=None, curve=False, idx=None):
pt = self.AtTime('T', t)
self.t(pt[0])
self.T(pt[1])
if not curve:
if curve is False:
return
val = self.At(curve, t)
self.Value(val)
Expand Down Expand Up @@ -188,9 +183,10 @@ def SetCurve(self, curve, t, val):
def minmax(self, curve0, op=1):
"""Search global minimum/maximum value of curve."""
curve = self._cname(curve0)
if not curve: # curve is array
if curve is False: # curve is array
ops = (min, max)
return ops[op](curve0[self.limit[0]:self.limit[1]])
#FIXME: time limits are not applied in this case!
return ops[op](curve0)
else: # curve is an hdf path
ops = (self.hdf.min, self.hdf.max)
idx, t, v = ops[op](curve)
Expand All @@ -207,9 +203,10 @@ def Min(self, curve):
def Ini(self, curve):
"""Initial value of curve"""
c = self._cname(curve)
if not c:
if c is False:
return curve[0]
return self.hdf.col(c, 0)
limit = self.hdf.get_limit(c)
return self.hdf.col(c, limit.start)

def Equals(self, curve0, val):
"""Returns time of curve where its value is val"""
Expand All @@ -229,12 +226,14 @@ def Drops(self, curve0, val):
curve = self._cname(curve0)
if curve is not False:
return self.hdf.drops(curve, val)
# TODO: array was passed

def Raises(self, curve0, val):
"""Returns time where curve value raises above val"""
curve = self._cname(curve0)
if curve is not False:
return self.hdf.rises(curve, val)
# TODO: array was passed

def Len(self, curve0):
"""Length of the curve, according to the current selection"""
Expand Down

0 comments on commit a708aeb

Please sign in to comment.