本文整理汇总了Python中sparkle.stim.stimulus_model.StimulusModel.samplerate方法的典型用法代码示例。如果您正苦于以下问题:Python StimulusModel.samplerate方法的具体用法?Python StimulusModel.samplerate怎么用?Python StimulusModel.samplerate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sparkle.stim.stimulus_model.StimulusModel
的用法示例。
在下文中一共展示了StimulusModel.samplerate方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_insert_remove_stim
# 需要导入模块: from sparkle.stim.stimulus_model import StimulusModel [as 别名]
# 或者: from sparkle.stim.stimulus_model.StimulusModel import samplerate [as 别名]
def test_insert_remove_stim(self):
tests = ProtocolTabelModel()
tests.setReferenceVoltage(100, 0.1)
model = QProtocolTabelModel(tests)
stim = StimulusModel()
component = PureTone()
stim.insertComponent(component, 0,0)
model.insertTest(stim,0)
headers = model.allHeaders()
repidx = headers.index('Reps')
lenidx = headers.index('Length')
totalidx = headers.index('Total')
fsidx = headers.index('Generation rate')
assert_equal(stim, model.data(model.index(0,0), role=QtCore.Qt.UserRole+1))
assert_equal([stim], model.stimulusList())
assert model.data(model.index(0,repidx), role=QtCore.Qt.DisplayRole) == 1
assert model.data(model.index(0,lenidx), role=QtCore.Qt.DisplayRole) == 1
assert model.data(model.index(0,totalidx), role=QtCore.Qt.DisplayRole) == 1
assert model.data(model.index(0,fsidx), role=QtCore.Qt.DisplayRole) == stim.samplerate()
assert model.rowCount() == 1
model.removeTest(0)
assert model.rowCount() == 0
assert_equal([], model.stimulusList())
示例2: test_chart_tone_protocol
# 需要导入模块: from sparkle.stim.stimulus_model import StimulusModel [as 别名]
# 或者: from sparkle.stim.stimulus_model.StimulusModel import samplerate [as 别名]
def test_chart_tone_protocol(self):
winsz = 0.1 #seconds
acq_rate = 50000
manager, fname = self.create_acqmodel(winsz, acq_rate)
manager.set(savechart=True)
#insert some stimuli
tone0 = PureTone()
tone0.setDuration(winsz)
stim0 = StimulusModel()
stim0.insertComponent(tone0)
manager.protocol_model().insert(stim0,0)
gen_rate = stim0.samplerate()
manager.start_chart()
t = manager.run_chart_protocol(0.15)
t.join()
manager.stop_chart()
manager.close_data()
# now check saved data
hfile = h5py.File(os.path.join(self.tempfolder, fname))
test = hfile['chart_1']
stim = json.loads(test.attrs['stim'])
# print 'stim', stim
# assert_in('components', stim[0])
# assert_equal(stim[0]['samplerate_da'], gen_rate)
assert len(test.shape) == 1
assert test.shape[0] >= winsz*acq_rate
hfile.close()
示例3: test_abort_protocol
# 需要导入模块: from sparkle.stim.stimulus_model import StimulusModel [as 别名]
# 或者: from sparkle.stim.stimulus_model.StimulusModel import samplerate [as 别名]
def test_abort_protocol(self):
winsz = 0.2 #seconds
acq_rate = 50000
manager, fname = self.create_acqmodel(winsz, acq_rate)
manager.set_calibration(None)
#insert some stimuli
tone0 = PureTone()
tone0.setDuration(0.02)
stim0 = StimulusModel()
stim0.insertComponent(tone0)
stim0.setRepCount(500) # set really high so we don't miss
manager.protocol_model().insert(stim0,0)
gen_rate = stim0.samplerate()
manager.setup_protocol(0.1)
t = manager.run_protocol()
manager.halt()
t.join()
manager.close_data()
# now check saved data
hfile = h5py.File(os.path.join(self.tempfolder, fname))
group = hfile['segment_1']
print 'AASERT AVERAGE', type(group.attrs['averaged'])
assert group.attrs['averaged'] == False
assert group.attrs.get('aborted') is not None
abort_msg = group.attrs['aborted']
assert abort_msg.startswith("test 1, trace 0, rep")
hfile.close()
示例4: test_tone_protocol_uncalibrated
# 需要导入模块: from sparkle.stim.stimulus_model import StimulusModel [as 别名]
# 或者: from sparkle.stim.stimulus_model.StimulusModel import samplerate [as 别名]
def test_tone_protocol_uncalibrated(self):
"""Test a protocol with a single tone stimulus"""
winsz = 0.2 #seconds
acq_rate = 50000
manager, fname = self.create_acqmodel(winsz, acq_rate)
manager.set_calibration(None)
#insert some stimuli
tone0 = PureTone()
tone0.setDuration(0.02)
stim0 = StimulusModel()
stim0.insertComponent(tone0)
manager.protocol_model().insert(stim0,0)
gen_rate = stim0.samplerate()
manager.setup_protocol(0.1)
t = manager.run_protocol()
t.join()
manager.close_data()
# now check saved data
hfile = h5py.File(os.path.join(self.tempfolder, fname))
test = hfile['segment_1']['test_1']
stim = json.loads(test.attrs['stim'])
check_result(test, stim0, winsz, acq_rate)
assert hfile['segment_1'].attrs['calibration_used'] == ''
assert hfile['segment_1'].attrs['averaged'] == False
hfile.close()
示例5: test_correct_data_groups_created_protocol
# 需要导入模块: from sparkle.stim.stimulus_model import StimulusModel [as 别名]
# 或者: from sparkle.stim.stimulus_model.StimulusModel import samplerate [as 别名]
def test_correct_data_groups_created_protocol(self):
winsz = 0.2 #seconds
acq_rate = 50000
manager, fname = self.create_acqmodel(winsz, acq_rate)
self.fake_calibration(manager)
#insert some stimuli
tone0 = PureTone()
tone0.setDuration(0.02)
stim0 = StimulusModel()
stim0.insertComponent(tone0)
manager.protocol_model().insert(stim0,0)
gen_rate = stim0.samplerate()
# two calls to setup should not leave and empty group
manager.setup_protocol(0.1)
manager.setup_protocol(0.1)
t = manager.run_protocol()
t.join()
manager.close_data()
# now check saved data
hfile = h5py.File(os.path.join(self.tempfolder, fname))
groups = hfile.keys()
assert 'segment_1' in groups
assert 'segment_2' not in groups
test = hfile['segment_1']['test_1']
check_result(test, stim0, winsz, acq_rate)
assert 'calibration_' in hfile['segment_1'].attrs['calibration_used']
assert hfile['segment_1'].attrs['averaged'] == False
hfile.close()
示例6: test_tone_protocol_over_voltage
# 需要导入模块: from sparkle.stim.stimulus_model import StimulusModel [as 别名]
# 或者: from sparkle.stim.stimulus_model.StimulusModel import samplerate [as 别名]
def test_tone_protocol_over_voltage(self):
"""Test a protocol with a single tone stimulus"""
winsz = 0.2 #seconds
acq_rate = 50000
manager, fname = self.create_acqmodel(winsz, acq_rate)
self.fake_calibration(manager)
#insert some stimuli
tone0 = PureTone()
tone0.setDuration(0.02)
tone0.setIntensity(120)
tone0.setFrequency(90000)
stim0 = StimulusModel()
stim0.insertComponent(tone0)
manager.protocol_model().insert(stim0,0)
gen_rate = stim0.samplerate()
manager.setup_protocol(0.1)
t = manager.run_protocol()
t.join()
manager.close_data()
# now check saved data
hfile = h5py.File(os.path.join(self.tempfolder, fname))
test = hfile['segment_1']['test_1']
stim = json.loads(test.attrs['stim'])
# stim 0 is control window
assert_in('components', stim[1])
assert_equal(stim[1]['samplerate_da'], gen_rate)
assert_equal(test.shape,(2,1,1,winsz*acq_rate))
assert stim[1]['overloaded_attenuation'] > 0
assert hfile['segment_1'].attrs['averaged'] == False
hfile.close()
示例7: CalibrationRunner
# 需要导入模块: from sparkle.stim.stimulus_model import StimulusModel [as 别名]
# 或者: from sparkle.stim.stimulus_model.StimulusModel import samplerate [as 别名]
class CalibrationRunner(AbstractCalibrationRunner):
"""Handles Calibration acquistion, where there is a single unique
stimulus used to capture the frequency response of the system.
This class may hold many different types of stimuli (currently 2),
but only one is presented per calibration run."""
def __init__(self, *args):
super(AbstractCalibrationRunner, self).__init__(*args)
self.player = FinitePlayer()
self.stimulus = StimulusModel()
# # insert stim component... either noise or chirp
self.stim_components = [WhiteNoise(), FMSweep()]
self.stimulus.insertComponent(self.stim_components[0])
self.protocol_model.insert(self.stimulus, 0)
# reference tone for setting the refence voltage==db
self.refstim = StimulusModel()
tone = PureTone()
tone.setRisefall(0.001)
self.refstim.insertComponent(tone, 0,0)
self.reftone = tone
self.save_data = True
self.group_name = 'calibration_'
self.calibration_vector = None
self.calibration_freqs = None
self.calibration_frange = None
def get_stims(self):
"""Gets the stimuli available for setting as the current calibration stimulus
:returns: list<:class:`StimulusModel<sparkle.stim.stimulus_model.StimulusModel>`>
"""
return self.stim_components
def set_stim_by_index(self, index):
"""Sets the stimulus to be generated to the one referenced by index
:param index: index number of stimulus to set from this class's internal list of stimuli
:type index: int
"""
# remove any current components
self.stimulus.clearComponents()
# add one to index because of tone curve
self.stimulus.insertComponent(self.stim_components[index])
def set_duration(self, dur):
"""See :meth:`AbstractCalibrationRunner<sparkle.run.calibration_runner.AbstractCalibrationRunner.set_duration>`"""
# this may be set at any time, and is not checked before run, so set
# all stim components
for comp in self.stim_components:
comp.setDuration(dur)
self.reftone.setDuration(dur)
def _initialize_run(self):
self.player.set_aochan(self.aochan)
self.player.set_aichan(self.aichan)
if self.apply_cal:
self.protocol_model.setCalibration(self.calibration_vector, self.calibration_freqs, self.calibration_frange)
# calibration testing doesn't save anything
self.save_data = False
else:
data_items = self.datafile.keys()
self.current_dataset_name = next_str_num(self.group_name, data_items)
self.datafile.init_group(self.current_dataset_name, mode='calibration')
logger = logging.getLogger('main')
logger.debug('Calibrating with fs %s' % self.stimulus.samplerate())
self.datafile.init_data(self.current_dataset_name, mode='calibration',
dims=(self.stimulus.repCount(), self.stimulus.duration()*self.stimulus.samplerate()))
info = {'samplerate_ad': self.player.aifs}
self.datafile.set_metadata(self.current_dataset_name, info)
# point is to output the signal at the specificed voltage, to we set
# the intensity of the components to match whatever the caldb is now
self.save_data = True
self.stimulus.component(0,0).setIntensity(self.caldb)
print 'USING {} V, {} Hz, {} dBSPL'.format(self.calv, self.calf, self.caldb)
self.reftone.setIntensity(self.caldb)
self.reftone.setFrequency(self.calf)
self.protocol_model.insert(self.refstim,0)
self.calname = None
self.protocol_model.setCalibration(None, None, None)
self.datafile.init_data(self.current_dataset_name, mode='calibration',
nested_name='reference_tone',
dims=(self.stimulus.repCount(), self.stimulus.duration()*self.stimulus.samplerate()))
def _initialize_test(self, test):
assert test.samplerate() == self.player.aifs
def _process_response(self, response, trace_info, irep):
if self.save_data:
if trace_info['components'][0]['stim_type'] == 'Pure Tone':
#.........这里部分代码省略.........
示例8: TestStimModel
# 需要导入模块: from sparkle.stim.stimulus_model import StimulusModel [as 别名]
# 或者: from sparkle.stim.stimulus_model.StimulusModel import samplerate [as 别名]
class TestStimModel():
def setup(self):
self.model = StimulusModel()
self.model.setReferenceVoltage(100, 0.1)
self.model.setMaxVoltage(MAXV, DEVICE_MAXV)
self.model.setMinVoltage(0.005)
def test_insert_data(self):
fake_component0 = 'ducks'
fake_component1 = 'frogs'
self.model.insertComponent(fake_component0, 0, 0)
self.model.insertComponent(fake_component1, 0, 0)
assert self.model.component(0,0) == fake_component1
assert self.model.component(0,1) == fake_component0
def test_remove_data(self):
fake_component0 = 'ducks'
self.model.insertComponent(fake_component0, 0, 0)
self.model.removeComponent(0,0)
assert self.model.component(0,0) == None
def test_component_index(self):
fake_component0 = 'ducks'
# component will be added to the lowest index in row
self.model.insertComponent(fake_component0, 0, 2)
index = self.model.indexByComponent(fake_component0)
assert index == (0,0)
@raises(IndexError)
def test_set_data(self):
fake_component0 = 'ducks'
self.model.overwriteComponent(fake_component0, 0, 0)
def test_row_column_count(self):
fake_component0 = 'ducks'
self.model.insertComponent(fake_component0, 0, 0)
assert self.model.columnCountForRow(0) == 1
assert self.model.rowCount() == 1
def test_trace_count_no_auto(self):
component0 = PureTone()
component1 = PureTone()
self.model.insertComponent(component0, 0,0)
self.model.insertComponent(component1, 0,0)
assert self.model.traceCount() == 1
def test_trace_count_no_components(self):
self.add_auto_param(self.model)
assert self.model.traceCount() == 0
def test_trace_count_with_auto(self):
component = PureTone()
self.model.insertComponent(component, 0,0)
nsteps = self.add_auto_param(self.model)
assert self.model.traceCount() == nsteps
def test_model_contains(self):
component = PureTone()
self.model.insertComponent(component, 0,0)
assert self.model.contains('PureTone')
def test_expanded_stim_no_auto(self):
"""signal of a model without any auto parameters"""
component = PureTone()
self.model.insertComponent(component, 0,0)
signals, doc, ovld = self.model.expandedStim()
assert len(signals) == 1
assert_equal(signals[0][0].shape[0], component.duration()*self.model.samplerate())
assert len(doc) == 1
assert doc[0]['samplerate_da'] == self.model.samplerate()
def test_expanded_stim_with_auto(self):
component = PureTone()
self.model.insertComponent(component, 0,0)
nsteps = self.add_auto_param(self.model)
signals, doc, ovld = self.model.expandedStim()
assert len(signals) == nsteps
assert len(doc) == nsteps
assert doc[0]['samplerate_da'] == self.model.samplerate()
def test_expaned_stim_with_vocal_auto(self):
component = Vocalization()
component.setFile(sample.samplewav())
self.model.insertComponent(component, 0,0)
nsteps = self.add_vocal_param(self.model)
signals, doc, ovld = self.model.expandedStim()
assert len(signals) == nsteps
assert len(doc) == nsteps
assert doc[0]['samplerate_da'] == self.model.samplerate()
def test_signal_eq_caldb(self):
caldb = 100
#.........这里部分代码省略.........
示例9: SearchRunner
# 需要导入模块: from sparkle.stim.stimulus_model import StimulusModel [as 别名]
# 或者: from sparkle.stim.stimulus_model.StimulusModel import samplerate [as 别名]
class SearchRunner(AbstractAcquisitionRunner):
"""Handles the presentation of data where changes are allowed to
be made to the stimulus while running"""
def __init__(self, *args):
self._stimulus = StimulusModel()
super(SearchRunner, self).__init__(*args)
self.player = FinitePlayer()
self.save_data = False
self.set_name = 'explore_1'
# stimuli_types = get_stimuli_models()
# self._explore_stimuli = [x() for x in stimuli_types if x.explore]
# self.delay = Silence()
# self._stimulus.insertfComponent(self.delay)
def stimulus(self):
"""Gets a list of all the stimuli this runner has access to. Order
of the list matches the index order which stimuli can be set by.
:returns: (subclasses of) list<:class:`AbstractStimulusComponent<sparkle.stim.abstract_component.AbstractStimulusComponent>`>
"""
return self._stimulus
def set_calibration(self, attenuations, freqs, frange, calname):
"""See :meth:`AbstractAcquisitionRunner<sparkle.run.abstract_acquisition.AbstractAcquisitionRunner.set_calibration>`"""
self._stimulus.setCalibration(attenuations, freqs, frange)
def update_reference_voltage(self):
"""See :meth:`AbstractAcquisitionRunner<sparkle.run.abstract_acquisition.AbstractAcquisitionRunner.update_reference_voltage>`"""
self._stimulus.setReferenceVoltage(self.caldb, self.calv)
# def set_delay(self, duration):
# self.delay.setDuration(duration)
# def set_stim_by_index(self, index):
# """Sets the stimulus to be generated to the one referenced by index
# :param index: index number of stimulus to set from this class's internal list of stimuli
# :type index: int
# """
# # remove any current components
# self._stimulus.clearComponents()
# self._stimulus.insertComponent(self.delay)
# self._stimulus.insertComponent(self._explore_stimuli[index], 0, 1)
# signal, atten, overload = self._stimulus.signal()
# self.player.set_stim(signal, self._stimulus.samplerate(), attenuation=atten)
# self.putnotify('over_voltage', (overload,))
# return signal, overload
def reset_stim(self):
signal, atten, overload = self._stimulus.signal()
self.player.set_stim(signal, self._stimulus.samplerate(), attenuation=atten)
self.putnotify('over_voltage', (overload,))
self.nreps = self._stimulus.repCount()
self.irep = 0
return signal, overload
def set_current_stim_parameter(self, param, val):
"""Sets a parameter on the current stimulus
:param param: name of the parameter of the stimulus to set
:type param: str
:param val: new value to set the parameter to
"""
component = self._stimulus.component(0,1)
component.set(param, val)
def current_signal(self):
"""Signal of the currently set stimulus
:returns: numpy.ndarray
"""
return self._stimulus.signal()
# def stim_names(self):
# """The names of the all the stimuli this class can generate, in order
# :returns: list<str>
# """
# stim_names = []
# for stim in self._explore_stimuli:
# stim_names.append(stim.name)
# return stim_names
def run(self, interval):
"""See :meth:`AbstractAcquisitionRunner<sparkle.run.abstract_acquisition.AbstractAcquisitionRunner.run>`"""
self._halt = False
# TODO: some error checking to make sure valid paramenters are set
if self.save_data:
# initize data set
self.current_dataset_name = self.set_name
self.datafile.init_data(self.current_dataset_name, self.aitimes.shape, mode='open')
self.set_name = increment_title(self.set_name)
# save the start time and set last tick to expired, so first
# acquisition loop iteration executes immediately
#.........这里部分代码省略.........