def read_segment( self, # the 2 first keyword arguments are imposed by neo.io API lazy=False, cascade=True, # all following arguments are decied by this IO and are free segment_duration=15., num_analogsignal=4, num_spiketrain_by_channel=3, ): """ Return a fake Segment. The self.filename does not matter. In this IO read by default a Segment. This is just a example to be adapted to each ClassIO. In this case these 3 paramters are taken in account because this function return a generated segment with fake AnalogSignal and fake SpikeTrain. Parameters: segment_duration :is the size in secend of the segment. num_analogsignal : number of AnalogSignal in this segment num_spiketrain : number of SpikeTrain in this segment """ sampling_rate = 10000. #Hz t_start = -1. #time vector for generated signal timevect = np.arange(t_start, t_start + segment_duration, 1. / sampling_rate) # create an empty segment seg = Segment(name='it is a seg from exampleio') if cascade: # read nested analosignal for i in range(num_analogsignal): ana = self.read_analogsignal(lazy=lazy, cascade=cascade, channel_index=i, segment_duration=segment_duration, t_start=t_start) seg.analogsignals += [ana] # read nested spiketrain for i in range(num_analogsignal): for _ in range(num_spiketrain_by_channel): sptr = self.read_spiketrain( lazy=lazy, cascade=cascade, segment_duration=segment_duration, t_start=t_start, channel_index=i) seg.spiketrains += [sptr] # create an EventArray that mimic triggers. # note that ExampleIO do not allow to acess directly to EventArray # for that you need read_segment(cascade = True) eva = EventArray() if lazy: # in lazy case no data are readed # eva is empty pass else: # otherwise it really contain data n = 1000 # neo.io support quantities my vector use second for unit eva.times = timevect[(np.random.rand(n) * timevect.size).astype('i')] * pq.s # all duration are the same eva.durations = np.ones(n) * 500 * pq.ms # label l = [] for i in range(n): if np.random.rand() > .6: l.append('TriggerA') else: l.append('TriggerB') eva.labels = np.array(l) seg.eventarrays += [eva] create_many_to_one_relationship(seg) return seg
def read_segment(self, # the 2 first keyword arguments are imposed by neo.io API lazy = False, cascade = True, # all following arguments are decied by this IO and are free segment_duration = 15., num_analogsignal = 4, num_spiketrain_by_channel = 3, ): """ Return a fake Segment. The self.filename does not matter. In this IO read by default a Segment. This is just a example to be adapted to each ClassIO. In this case these 3 paramters are taken in account because this function return a generated segment with fake AnalogSignal and fake SpikeTrain. Parameters: segment_duration :is the size in secend of the segment. num_analogsignal : number of AnalogSignal in this segment num_spiketrain : number of SpikeTrain in this segment """ sampling_rate = 10000. #Hz t_start = -1. #time vector for generated signal timevect = np.arange(t_start, t_start+ segment_duration , 1./sampling_rate) # create an empty segment seg = Segment( name = 'it is a seg from exampleio') if cascade: # read nested analosignal for i in range(num_analogsignal): ana = self.read_analogsignal( lazy = lazy , cascade = cascade , channel_index = i ,segment_duration = segment_duration, t_start = t_start) seg.analogsignals += [ ana ] # read nested spiketrain for i in range(num_analogsignal): for _ in range(num_spiketrain_by_channel): sptr = self.read_spiketrain(lazy = lazy , cascade = cascade , segment_duration = segment_duration, t_start = t_start , channel_index = i) seg.spiketrains += [ sptr ] # create an EventArray that mimic triggers. # note that ExampleIO do not allow to acess directly to EventArray # for that you need read_segment(cascade = True) eva = EventArray() if lazy: # in lazy case no data are readed # eva is empty pass else: # otherwise it really contain data n = 1000 # neo.io support quantities my vector use second for unit eva.times = timevect[(np.random.rand(n)*timevect.size).astype('i')]* pq.s # all duration are the same eva.durations = np.ones(n)*500*pq.ms # label l = [ ] for i in range(n): if np.random.rand()>.6: l.append( 'TriggerA' ) else : l.append( 'TriggerB' ) eva.labels = np.array( l ) seg.eventarrays += [ eva ] seg.create_many_to_one_relationship() return seg