def get_endpoints(self): if isnan(self.m) and isnan(self.b) : p1 = (self.originalX,self.x1) p2 = (self.originalX,self.x2) else: p1 = (self.x1,self.gety(self.x1)) p2 = (self.x2,self.gety(self.x2)) return p1,p2
def delNaN(xlist,ylist): """ If nan values found in ylist associated values in xlist will be removed INPUT : two lists of equal length OUTPUT: two lists of equal length """ xy_tuplelist = get_tuples_from_lists(xlist,ylist) for xy_tuple in xy_tuplelist[:]: if isnan(xy_tuple[1]): xy_tuplelist.remove(xy_tuple) xlist,ylist = get_lists_from_tuples(xy_tuplelist) return xlist,ylist
def gety(self,x): # gety function that remembers and starts with the previous found segment index # the assumption is that linesegs will be queried linearly, thereor saving muuultiple passes iRange = deque(range(len(self.segs))) iRange.rotate(self.iRemember) # cycles to last remembered index for i in iRange: seg = self.segs[i] y = seg.gety(x) # if x outside the bounds of seg, returns None if not isnan(y): self.iRemember=i return round(y,6) #if x>seg.x1 and x<seg.x2 and seg.originalX!=None: # self.iRemember=i # return seg.gety(x) # if no corresponging time found return nan return nan
def timeseries_subtraction(segs1, segs2, times): """ input two xbd_sensors and optionally xinterval in integer seconds xinterval=0 -> original-x points of both continuous-sensors is polled xinterval=positive -> second difference between polled points xinterval=negative -> output a new xbd_sensor containing cont1-cont2 y-data polled xinterval seconds appart """ nancount = 0 ylist = [] for x in times: # gety is a function from func_continuous.py's LineSegs class y = segs2.gety(x)-segs1.gety(x) ylist.append(y) if isnan(y): nancount += 1 print 'len(x),len(y),nancount=',len(times),len(ylist), nancount return ylist