analogsignal.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:NeoAnalysis 作者: neoanalysis 项目源码 文件源码
def time_slice(self, t_start, t_stop):
        '''
        Creates a new AnalogSignal corresponding to the time slice of the
        original AnalogSignal between times t_start, t_stop. Note, that for
        numerical stability reasons if t_start, t_stop do not fall exactly on
        the time bins defined by the sampling_period they will be rounded to
        the nearest sampling bins.
        '''

        # checking start time and transforming to start index
        if t_start is None:
            i = 0
        else:
            t_start = t_start.rescale(self.sampling_period.units)
            i = (t_start - self.t_start) / self.sampling_period
            i = int(np.rint(i.magnitude))

        # checking stop time and transforming to stop index
        if t_stop is None:
            j = len(self)
        else:
            t_stop = t_stop.rescale(self.sampling_period.units)
            j = (t_stop - self.t_start) / self.sampling_period
            j = int(np.rint(j.magnitude))

        if (i < 0) or (j > len(self)):
            raise ValueError('t_start, t_stop have to be withing the analog \
                              signal duration')

        # we're going to send the list of indicies so that we get *copy* of the
        # sliced data
        obj = super(AnalogSignal, self).__getitem__(np.arange(i, j, 1))
        obj.t_start = self.t_start + i * self.sampling_period

        return obj
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号