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


Python Segment.block方法代码示例

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


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

示例1: _handle_epochs_group

# 需要导入模块: from neo.core import Segment [as 别名]
# 或者: from neo.core.Segment import block [as 别名]
 def _handle_epochs_group(self, block):
     # Note that an NWB Epoch corresponds to a Neo Segment, not to a Neo Epoch.
     epochs = self._file.get('epochs')
     # todo: handle epochs.attrs.get('tags')
     for name, epoch in epochs.items():
         # todo: handle epoch.attrs.get('links')
         timeseries = []
         for key, value in epoch.items():
             if key == 'start_time':
                 t_start = value * pq.second
             elif key == 'stop_time':
                 t_stop = value * pq.second
             else:
                 # todo: handle value['count']
                 # todo: handle value['idx_start']
                 timeseries.append(self._handle_timeseries(key, value.get('timeseries')))
         segment = Segment(name=name)
         for obj in timeseries:
             obj.segment = segment
             if isinstance(obj, AnalogSignal):
                 segment.analogsignals.append(obj)
             elif isinstance(obj, IrregularlySampledSignal):
                 segment.irregularlysampledsignals.append(obj)
             elif isinstance(obj, Event):
                 segment.events.append(obj)
             elif isinstance(obj, Epoch):
                 segment.epochs.append(obj)
         segment.block = block
         block.segments.append(segment)
开发者ID:MartinHeroux,项目名称:ScientificallySound_files,代码行数:31,代码来源:nwbio_LOCAL_4246.py

示例2: _read_segment

# 需要导入模块: from neo.core import Segment [as 别名]
# 或者: from neo.core.Segment import block [as 别名]
    def _read_segment(self, node, parent):
        attributes = self._get_standard_attributes(node)
        segment = Segment(**attributes)

        signals = []
        for name, child_node in node['analogsignals'].items():
            if "AnalogSignal" in name:
                signals.append(self._read_analogsignal(child_node, parent=segment))
        if signals and self.merge_singles:
            segment.unmerged_analogsignals = signals  # signals will be merged later
            signals = []
        for name, child_node in node['analogsignalarrays'].items():
            if "AnalogSignalArray" in name:
                signals.append(self._read_analogsignalarray(child_node, parent=segment))
        segment.analogsignals = signals

        irr_signals = []
        for name, child_node in node['irregularlysampledsignals'].items():
            if "IrregularlySampledSignal" in name:
                irr_signals.append(self._read_irregularlysampledsignal(child_node, parent=segment))
        if irr_signals and self.merge_singles:
            segment.unmerged_irregularlysampledsignals = irr_signals
            irr_signals = []
        segment.irregularlysampledsignals = irr_signals

        epochs = []
        for name, child_node in node['epochs'].items():
            if "Epoch" in name:
                epochs.append(self._read_epoch(child_node, parent=segment))
        if self.merge_singles:
            epochs = self._merge_data_objects(epochs)
        for name, child_node in node['epocharrays'].items():
            if "EpochArray" in name:
                epochs.append(self._read_epocharray(child_node, parent=segment))
        segment.epochs = epochs

        events = []
        for name, child_node in node['events'].items():
            if "Event" in name:
                events.append(self._read_event(child_node, parent=segment))
        if self.merge_singles:
            events = self._merge_data_objects(events)
        for name, child_node in node['eventarrays'].items():
            if "EventArray" in name:
                events.append(self._read_eventarray(child_node, parent=segment))
        segment.events = events

        spiketrains = []
        for name, child_node in node['spikes'].items():
            raise NotImplementedError('Spike objects not yet handled.')
        for name, child_node in node['spiketrains'].items():
            if "SpikeTrain" in name:
                spiketrains.append(self._read_spiketrain(child_node, parent=segment))
        segment.spiketrains = spiketrains

        segment.block = parent
        return segment
开发者ID:CINPLA,项目名称:python-neo,代码行数:59,代码来源:hdf5io.py

示例3: create_segment

# 需要导入模块: from neo.core import Segment [as 别名]
# 或者: from neo.core.Segment import block [as 别名]
    def create_segment(self, parent=None, name='Segment'):
        segment = Segment()

        segment.block = parent

        self._assign_basic_attributes(segment, name=name)
        self._assign_datetime_attributes(segment)
        self._assign_index_attribute(segment)

        self._create_segment_children(segment)

        self._assign_annotations(segment)

        return segment
开发者ID:mpsonntag,项目名称:python-neo,代码行数:16,代码来源:test_nsdfio.py

示例4: read_block

# 需要导入模块: from neo.core import Segment [as 别名]
# 或者: from neo.core.Segment import block [as 别名]
    def read_block(self, lazy=False, cascade=True, signal_names=None, signal_units=None):
        block = Block(file_origin=self.filename)
        segment = Segment(name="default")
        block.segments.append(segment)
        segment.block = block

        spike_times = defaultdict(list)
        spike_file = self.filename + ".dat"
        print("SPIKEFILE: {}".format(spike_file))
        if os.path.exists(spike_file):
            print("Loading data from {}".format(spike_file))
            with open(spike_file, 'r') as fp:
                for line in fp:
                    if line[0] != '#':
                        entries = line.strip().split()
                        if len(entries) > 1:
                            time = float(entries[0])
                            for id in entries[1:]:
                                spike_times[id].append(time)
                t_stop = float(entries[0])
            if spike_times:
                min_id = min(map(int, spike_times))
            segment.spiketrains = [SpikeTrain(times, t_stop=t_stop, units="ms",
                                              id=int(id), source_index=int(id) - min_id)
                                   for id, times in spike_times.items()]
        signal_files = glob("{}_state.*.dat".format(self.filename))
        print(signal_files)
        for signal_file in signal_files:
            print("Loading data from {}".format(signal_file))
            population = os.path.basename(signal_file).split(".")[1]
            try:
                data = np.loadtxt(signal_file, delimiter=", ")
            except ValueError:
                print("Couldn't load data from file {}".format(signal_file))
                continue
            t_start = data[0, 1]
            ids = data[:, 0]
            unique_ids = np.unique(ids)
            for column in range(2, data.shape[1]):
                if signal_names is None:
                    signal_name = "signal{}".format(column - 2)
                else:
                    signal_name = signal_names[column - 2]
                if signal_units is None:
                    units = "mV"  # seems like a reasonable default
                else:
                    units = signal_units[column - 2]
                signals_by_id = {}
                for id in unique_ids:
                    times = data[ids==id, 1]
                    unique_times, idx = np.unique(times, return_index=True)  # some time points are represented twice
                    signals_by_id[id] = data[ids==id, column][idx]
                channel_ids = np.array(list(signals_by_id.keys()))
                if len(unique_times) > 1:
                    sampling_period = unique_times[1] - unique_times[0]
                    assert sampling_period != 0.0, sampling_period
                    signal_lengths = np.array([s.size for s in signals_by_id.values()])
                    min_length = signal_lengths.min()
                    if not (signal_lengths == signal_lengths[0]).all():
                        print("Warning: signals have different sizes: min={}, max={}".format(min_length,
                                                                                             signal_lengths.max()))
                        print("Truncating to length {}".format(min_length))
                    signal = AnalogSignal(np.vstack([s[:min_length] for s in signals_by_id.values()]).T,
                                          units=units,
                                          t_start=t_start * pq.ms,
                                          sampling_period=sampling_period*pq.ms,
                                          name=signal_name,
                                          population=population)
                    #signal.channel_index = ChannelIndex(np.arange(signal.shape[1], int),
                    #                                    channel_ids=channel_ids)
                    signal.channel_index = channel_ids
                    segment.analogsignals.append(signal)

        return block
开发者ID:INCF,项目名称:NineML_demo_2016,代码行数:76,代码来源:ninemltoolkitio.py


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