本文整理匯總了Python中sparkle.stim.stimulus_model.StimulusModel.duration方法的典型用法代碼示例。如果您正苦於以下問題:Python StimulusModel.duration方法的具體用法?Python StimulusModel.duration怎麽用?Python StimulusModel.duration使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sparkle.stim.stimulus_model.StimulusModel
的用法示例。
在下文中一共展示了StimulusModel.duration方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: CalibrationRunner
# 需要導入模塊: from sparkle.stim.stimulus_model import StimulusModel [as 別名]
# 或者: from sparkle.stim.stimulus_model.StimulusModel import duration [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':
#.........這裏部分代碼省略.........