ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/osprai/osprai/trunk/ba_class.py
(Generate patch)
# Line 98 | Line 98
98          
99      def time2dp(self, t):
100          """Find datapoint closest to given time."""
101 <        pos2 = self.time.searchsorted(t)  ## Time point just after t.
102 <        pos1 = max(pos2-1,0)
103 <        #TEMP! There is a bug here.
104 <        print pos1, pos2
101 >        pos2 = self.time.searchsorted(t)    ## Time point just after t.
102 >        pos2 = min(pos2, len(self.time)-1)  ## Avoid indexing error.
103 >        pos1 = max(pos2-1,0)                ## Time point just before t.
104          t2 = abs(self.time[pos2] - t)
105          t1 = abs(self.time[pos1] - t)
106 +        ## Decide if time point just before or just after is closer.
107          if (t2<t1):
108              return pos2
109          else:
# Line 112 | Line 112
112      def time2val(self, t1, t2):
113          """Return list of SPR values between t1 and t2"""
114          dp1, dp2 = self.time2dp(t1), self.time2dp(t2)
115 <        return [self.value(i) for i in range(dp1, dp2)]
115 >        return [self.value[i] for i in range(dp1, dp2)]
116      
117      ## End of RegOfInterest definition.
118  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines