本文整理汇总了Python中neo.core.Segment.analogsignals方法的典型用法代码示例。如果您正苦于以下问题:Python Segment.analogsignals方法的具体用法?Python Segment.analogsignals怎么用?Python Segment.analogsignals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neo.core.Segment
的用法示例。
在下文中一共展示了Segment.analogsignals方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test__children
# 需要导入模块: from neo.core import Segment [as 别名]
# 或者: from neo.core.Segment import analogsignals [as 别名]
def test__children(self):
signal = self.signals[0]
segment = Segment(name='seg1')
segment.analogsignals = [signal]
segment.create_many_to_one_relationship()
chx = ChannelIndex(name='chx1', index=np.arange(signal.shape[1]))
chx.analogsignals = [signal]
chx.create_many_to_one_relationship()
self.assertEqual(signal._single_parent_objects, ('Segment', 'ChannelIndex'))
self.assertEqual(signal._multi_parent_objects, ())
self.assertEqual(signal._single_parent_containers, ('segment', 'channel_index'))
self.assertEqual(signal._multi_parent_containers, ())
self.assertEqual(signal._parent_objects, ('Segment', 'ChannelIndex'))
self.assertEqual(signal._parent_containers, ('segment', 'channel_index'))
self.assertEqual(len(signal.parents), 2)
self.assertEqual(signal.parents[0].name, 'seg1')
self.assertEqual(signal.parents[1].name, 'chx1')
assert_neo_object_is_compliant(signal)
示例2: test__children
# 需要导入模块: from neo.core import Segment [as 别名]
# 或者: from neo.core.Segment import analogsignals [as 别名]
def test__children(self):
signal = self.signals[0]
segment = Segment(name='seg1')
segment.analogsignals = [signal]
segment.create_many_to_one_relationship()
rchan = RecordingChannel(name='rchan1')
rchan.analogsignals = [signal]
rchan.create_many_to_one_relationship()
self.assertEqual(signal._single_parent_objects,
('Segment', 'RecordingChannel'))
self.assertEqual(signal._multi_parent_objects, ())
self.assertEqual(signal._single_parent_containers,
('segment', 'recordingchannel'))
self.assertEqual(signal._multi_parent_containers, ())
self.assertEqual(signal._parent_objects,
('Segment', 'RecordingChannel'))
self.assertEqual(signal._parent_containers,
('segment', 'recordingchannel'))
self.assertEqual(len(signal.parents), 2)
self.assertEqual(signal.parents[0].name, 'seg1')
self.assertEqual(signal.parents[1].name, 'rchan1')
assert_neo_object_is_compliant(signal)
示例3: proc_dam
# 需要导入模块: from neo.core import Segment [as 别名]
# 或者: from neo.core.Segment import analogsignals [as 别名]
def proc_dam(filename):
'''Load an dam file that has already been processed by the official matlab
file converter. That matlab data is saved to an m-file, which is then
converted to a numpy '.npz' file. This numpy file is the file actually
loaded. This function converts it to a neo block and returns the block.
This block can be compared to the block produced by BrainwareDamIO to
make sure BrainwareDamIO is working properly
block = proc_dam(filename)
filename: The file name of the numpy file to load. It should end with
'*_dam_py?.npz'. This will be converted to a neo 'file_origin' property
with the value '*.dam', so the filename to compare should fit that pattern.
'py?' should be 'py2' for the python 2 version of the numpy file or 'py3'
for the python 3 version of the numpy file.
example: filename = 'file1_dam_py2.npz'
dam file name = 'file1.dam'
'''
with np.load(filename) as damobj:
damfile = damobj.items()[0][1].flatten()
filename = os.path.basename(filename[:-12]+'.dam')
signals = [res.flatten() for res in damfile['signal']]
stimIndexes = [int(res[0, 0].tolist()) for res in damfile['stimIndex']]
timestamps = [res[0, 0] for res in damfile['timestamp']]
block = Block(file_origin=filename)
rcg = RecordingChannelGroup(file_origin=filename)
chan = RecordingChannel(file_origin=filename, index=0, name='Chan1')
rcg.channel_indexes = np.array([1])
rcg.channel_names = np.array(['Chan1'], dtype='S')
block.recordingchannelgroups.append(rcg)
rcg.recordingchannels.append(chan)
params = [res['params'][0, 0].flatten() for res in damfile['stim']]
values = [res['values'][0, 0].flatten() for res in damfile['stim']]
params = [[res1[0] for res1 in res] for res in params]
values = [[res1 for res1 in res] for res in values]
stims = [dict(zip(param, value)) for param, value in zip(params, values)]
fulldam = zip(stimIndexes, timestamps, signals, stims)
for stimIndex, timestamp, signal, stim in fulldam:
sig = AnalogSignal(signal=signal*pq.mV,
t_start=timestamp*pq.d,
file_origin=filename,
sampling_period=1.*pq.s)
segment = Segment(file_origin=filename,
index=stimIndex,
**stim)
segment.analogsignals = [sig]
block.segments.append(segment)
create_many_to_one_relationship(block)
return block
示例4: _read_segment
# 需要导入模块: from neo.core import Segment [as 别名]
# 或者: from neo.core.Segment import analogsignals [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
示例5: test__children
# 需要导入模块: from neo.core import Segment [as 别名]
# 或者: from neo.core.Segment import analogsignals [as 别名]
def test__children(self):
signal = self.signals[0]
segment = Segment(name="seg1")
segment.analogsignals = [signal]
segment.create_many_to_one_relationship()
rchan = RecordingChannel(name="rchan1")
rchan.analogsignals = [signal]
rchan.create_many_to_one_relationship()
self.assertEqual(signal._container_child_objects, ())
self.assertEqual(signal._data_child_objects, ())
self.assertEqual(signal._single_parent_objects, ("Segment", "RecordingChannel"))
self.assertEqual(signal._multi_child_objects, ())
self.assertEqual(signal._multi_parent_objects, ())
self.assertEqual(signal._child_properties, ())
self.assertEqual(signal._single_child_objects, ())
self.assertEqual(signal._container_child_containers, ())
self.assertEqual(signal._data_child_containers, ())
self.assertEqual(signal._single_child_containers, ())
self.assertEqual(signal._single_parent_containers, ("segment", "recordingchannel"))
self.assertEqual(signal._multi_child_containers, ())
self.assertEqual(signal._multi_parent_containers, ())
self.assertEqual(signal._child_objects, ())
self.assertEqual(signal._child_containers, ())
self.assertEqual(signal._parent_objects, ("Segment", "RecordingChannel"))
self.assertEqual(signal._parent_containers, ("segment", "recordingchannel"))
self.assertEqual(signal.children, ())
self.assertEqual(len(signal.parents), 2)
self.assertEqual(signal.parents[0].name, "seg1")
self.assertEqual(signal.parents[1].name, "rchan1")
signal.create_many_to_one_relationship()
signal.create_many_to_many_relationship()
signal.create_relationship()
assert_neo_object_is_compliant(signal)
示例6: _read_segment
# 需要导入模块: from neo.core import Segment [as 别名]
# 或者: from neo.core.Segment import analogsignals [as 别名]
def _read_segment(self, fobject, lazy):
"""
Read a single segment with a single analogsignal
Returns the segment or None if there are no more segments
"""
try:
# float64 -- start time of the AnalogSignal
t_start = np.fromfile(fobject, dtype=np.float64, count=1)[0]
except IndexError:
# if there are no more Segments, return
return False
# int16 -- index of the stimulus parameters
seg_index = np.fromfile(fobject, dtype=np.int16, count=1)[0].tolist()
# int16 -- number of stimulus parameters
numelements = np.fromfile(fobject, dtype=np.int16, count=1)[0]
# read the name strings for the stimulus parameters
paramnames = []
for _ in range(numelements):
# unit8 -- the number of characters in the string
numchars = np.fromfile(fobject, dtype=np.uint8, count=1)[0]
# char * numchars -- a single name string
name = np.fromfile(fobject, dtype=np.uint8, count=numchars)
# exclude invalid characters
name = str(name[name >= 32].view("c").tostring())
# add the name to the list of names
paramnames.append(name)
# float32 * numelements -- the values for the stimulus parameters
paramvalues = np.fromfile(fobject, dtype=np.float32, count=numelements)
# combine parameter names and the parameters as a dict
params = dict(zip(paramnames, paramvalues))
# int32 -- the number elements in the AnalogSignal
numpts = np.fromfile(fobject, dtype=np.int32, count=1)[0]
# int16 * numpts -- the AnalogSignal itself
signal = np.fromfile(fobject, dtype=np.int16, count=numpts)
# handle lazy loading
if lazy:
sig = AnalogSignal(
[],
t_start=t_start * pq.d,
file_origin=self._filename,
sampling_period=1.0 * pq.s,
units=pq.mV,
dtype=np.float,
)
sig.lazy_shape = len(signal)
else:
sig = AnalogSignal(
signal.astype(np.float) * pq.mV,
t_start=t_start * pq.d,
file_origin=self._filename,
sampling_period=1.0 * pq.s,
copy=False,
)
# Note: setting the sampling_period to 1 s is arbitrary
# load the AnalogSignal and parameters into a new Segment
seg = Segment(file_origin=self._filename, index=seg_index, **params)
seg.analogsignals = [sig]
return seg
示例7: read_segment
# 需要导入模块: from neo.core import Segment [as 别名]
# 或者: from neo.core.Segment import analogsignals [as 别名]
def read_segment(self, gid_list=None, time_unit=pq.ms, t_start=None,
t_stop=None, sampling_period=None, id_column_dat=0,
time_column_dat=1, value_columns_dat=2,
id_column_gdf=0, time_column_gdf=1, value_types=None,
value_units=None, lazy=False):
"""
Reads a Segment which contains SpikeTrain(s) with specified neuron IDs
from the GDF data.
Arguments
----------
gid_list : list, default: None
A list of GDF IDs of which to return SpikeTrain(s). gid_list must
be specified if the GDF file contains neuron IDs, the default None
then raises an error. Specify an empty list [] to retrieve the spike
trains of all neurons.
time_unit : Quantity (time), optional, default: quantities.ms
The time unit of recorded time stamps in DAT as well as GDF files.
t_start : Quantity (time), optional, default: 0 * pq.ms
Start time of SpikeTrain.
t_stop : Quantity (time), default: None
Stop time of SpikeTrain. t_stop must be specified, the default None
raises an error.
sampling_period : Quantity (frequency), optional, default: None
Sampling period of the recorded data.
id_column_dat : int, optional, default: 0
Column index of neuron IDs in the DAT file.
time_column_dat : int, optional, default: 1
Column index of time stamps in the DAT file.
value_columns_dat : int, optional, default: 2
Column index of the analog values recorded in the DAT file.
id_column_gdf : int, optional, default: 0
Column index of neuron IDs in the GDF file.
time_column_gdf : int, optional, default: 1
Column index of time stamps in the GDF file.
value_types : str, optional, default: None
Nest data type of the analog values recorded, eg.'V_m', 'I', 'g_e'
value_units : Quantity (amplitude), default: None
The physical unit of the recorded signal values.
lazy : bool, optional, default: False
Returns
-------
seg : Segment
The Segment contains one SpikeTrain and one AnalogSignal for
each ID in gid_list.
"""
assert not lazy, 'Do not support lazy'
if isinstance(gid_list, tuple):
if gid_list[0] > gid_list[1]:
raise ValueError('The second entry in gid_list must be '
'greater or equal to the first entry.')
gid_list = range(gid_list[0], gid_list[1] + 1)
# __read_xxx() needs a list of IDs
if gid_list is None:
gid_list = [None]
# create an empty Segment
seg = Segment(file_origin=",".join(self.filenames))
seg.file_datetime = datetime.fromtimestamp(os.stat(self.filenames[0]).st_mtime)
# todo: rather than take the first file for the timestamp, we should take the oldest
# in practice, there won't be much difference
# Load analogsignals and attach to Segment
if 'dat' in self.avail_formats:
seg.analogsignals = self.__read_analogsignals(
gid_list,
time_unit,
t_start,
t_stop,
sampling_period=sampling_period,
id_column=id_column_dat,
time_column=time_column_dat,
value_columns=value_columns_dat,
value_types=value_types,
value_units=value_units)
if 'gdf' in self.avail_formats:
seg.spiketrains = self.__read_spiketrains(
gid_list,
time_unit,
t_start,
t_stop,
id_column=id_column_gdf,
time_column=time_column_gdf)
return seg