当前位置: 首页>>代码示例>>Python>>正文


Python DataArray.attrs['samplerate']方法代码示例

本文整理汇总了Python中xarray.DataArray.attrs['samplerate']方法的典型用法代码示例。如果您正苦于以下问题:Python DataArray.attrs['samplerate']方法的具体用法?Python DataArray.attrs['samplerate']怎么用?Python DataArray.attrs['samplerate']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xarray.DataArray的用法示例。


在下文中一共展示了DataArray.attrs['samplerate']方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_event_data_xray

# 需要导入模块: from xarray import DataArray [as 别名]
# 或者: from xarray.DataArray import attrs['samplerate'] [as 别名]

#.........这里部分代码省略.........
                (hasattr(events, 'dtype') and events.dtype.names is None)):
            # they just passed in a list
            event_offsets = events
        elif ((hasattr(events, 'dtype') and (eoffset in events.dtype.names)) or
                  (hasattr(events, 'columns') and (eoffset in events.columns))):
            event_offsets = events[eoffset]
        else:
            raise ValueError(eoffset + ' must be a valid fieldname ' +
                             'specifying the offset for the data.')

        # Sanity checks:
        if (dur < 0):
            raise ValueError('Duration must not be negative! ' +
                             'Specified duration: ' + str(dur))
        if (np.min(event_offsets) < 0):
            raise ValueError('Event offsets must not be negative!')

        # make sure the events are an actual array:
        event_offsets = np.asarray(event_offsets)
        if eoffset_in_time:
            # convert to samples
            event_offsets = np.atleast_1d(np.int64(
                np.round(event_offsets * self.samplerate)))

        # set event durations from rate
        # get the samplesize
        samplesize = 1. / self.samplerate

        # get the number of buffer samples
        buf_samp = int(np.ceil(buf / samplesize))

        # calculate the offset samples that contains the desired offset
        offset_samp = int(np.ceil((np.abs(offset) - samplesize * .5) / samplesize) *
                          np.sign(offset))

        # finally get the duration necessary to cover the desired span
        # dur_samp = int(np.ceil((dur - samplesize*.5)/samplesize))
        dur_samp = (int(np.ceil((dur + offset - samplesize * .5) / samplesize)) -
                    offset_samp + 1)

        # add in the buffer
        dur_samp += 2 * buf_samp
        offset_samp -= buf_samp

        # check that we have all the data we need before every event:
        if (np.min(event_offsets + offset_samp) < 0):
            bad_evs = ((event_offsets + offset_samp) < 0)
            raise ValueError('The specified values for offset and buffer ' +
                             'require more data than is available before ' +
                             str(np.sum(bad_evs)) + ' of all ' +
                             str(len(bad_evs)) + ' events.')

        # process the channels
        if isinstance(channels, dict):
            # turn into indices
            ch_info = self.channels
            key = list(channels.keys())[0]
            channels = [np.nonzero(ch_info[key] == c)[0][0] for c in channels[key]]
        elif isinstance(channels, str):
            # find that channel by name
            channels = np.nonzero(self.channels['name'] == channels)[0][0]
        if channels is None or len(np.atleast_1d(channels)) == 0:
            channels = np.arange(self.nchannels)
        channels = np.atleast_1d(channels)
        channels.sort()

        # load the timeseries (this must be implemented by subclasses)
        eventdata = self._load_data(channels, event_offsets, dur_samp, offset_samp)

        # calc the time range
        # get the samplesize
        samp_start = offset_samp * samplesize
        samp_end = samp_start + (dur_samp - 1) * samplesize
        time_range = np.linspace(samp_start, samp_end, dur_samp)

        # when channels is and array of channels labels i.e. strings like  '002','003',...
        # we need to use xray arrays to do fancy indexing

        self.channels_xray = DataArray(self.channels.number, coords=[self.channels.name], dims=['name'])

        if channels.dtype.char == 'S':

            self.channels_xray = self.channels_xray.loc[channels]

        else:

            self.channels_xray = self.channels_xray[channels]

        # ORIGINAL CODE
        # self.channels_xray = np.rec.fromarrays([self.channels_xray.values, self.channels_xray.coords['name'].values],
        #                                        names='number,name')


        self.channels_xray = self.channels_xray.coords['name'].values

        eventdata = DataArray(eventdata, coords=[self.channels_xray, events, time_range],
                              dims=['channels', 'events', 'time'])
        eventdata.attrs['samplerate'] = self.samplerate

        return eventdata
开发者ID:ctw,项目名称:ptsa_new,代码行数:104,代码来源:BaseWrapperXray.py

示例2: get_event_data_xray_simple

# 需要导入模块: from xarray import DataArray [as 别名]
# 或者: from xarray.DataArray import attrs['samplerate'] [as 别名]
    def get_event_data_xray_simple(self,channels,events,start_offset,end_offset,buffer=0):


            # process the channels
        if isinstance(channels, dict):
            # turn into indices
            ch_info = self.channels
            key = list(channels.keys())[0]
            channels = [np.nonzero(ch_info[key]==c)[0][0] for c in channels[key]]
        elif isinstance(channels, str):
            # find that channel by name
            channels = np.nonzero(self.channels['name']==channels)[0][0]
        if channels is None or len(np.atleast_1d(channels))==0:
            channels = np.arange(self.nchannels)
        channels = np.atleast_1d(channels)
        channels.sort()

        # load the timeseries (this must be implemented by subclasses)

        event_offsets = np.array(start_offset,ndmin=1)
        dur_samp = end_offset-start_offset + 2*buffer
        offset_samp = -buffer

        eventdata = self._load_data(channels,event_offsets,dur_samp,offset_samp)
        # eventdata = self._load_all_data(channels,start_offset-buffer)

        # calc the time range
        # get the samplesize
        samplesize = 1.0/self.samplerate
        samp_start = (start_offset-buffer)*samplesize
        samp_end =   (end_offset+buffer)*samplesize

        time_range = np.linspace(samp_start,samp_end,dur_samp)
        eegoffset = np.arange(start_offset-buffer,  end_offset+buffer)


        time_axis = np.rec.fromarrays([time_range,eegoffset],names='time,eegoffset')



        # when channels is and array of channels labels i.e. strings like  '002','003',...
        # we need to use xray arrays to do fancy indexing

        self.channels_xray = DataArray(self.channels.number,coords=[self.channels.name],dims=['name'])

        if channels.dtype.char=='S':

            self.channels_xray = self.channels_xray.loc[channels]

        else:

            self.channels_xray = self.channels_xray[channels]

        self.channels_xray=np.rec.fromarrays([self.channels_xray.values,self.channels_xray.coords['name'].values],names='number,name')


        # eventdata = DataArray(eventdata,coords=[self.channels_xray,np.arange(len(events)),time_range],dims=['channels','events','time'])
        eventdata = DataArray(eventdata,coords=[self.channels_xray,np.arange(len(events)),time_axis],dims=['channels','events','time'])
        eventdata.attrs['samplerate'] = self.samplerate

        return eventdata
开发者ID:ctw,项目名称:ptsa_new,代码行数:63,代码来源:BaseWrapperXray.py


注:本文中的xarray.DataArray.attrs['samplerate']方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。