本文整理汇总了Python中sparkle.stim.stimulus_model.StimulusModel.setRepCount方法的典型用法代码示例。如果您正苦于以下问题:Python StimulusModel.setRepCount方法的具体用法?Python StimulusModel.setRepCount怎么用?Python StimulusModel.setRepCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sparkle.stim.stimulus_model.StimulusModel
的用法示例。
在下文中一共展示了StimulusModel.setRepCount方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_abort_protocol
# 需要导入模块: from sparkle.stim.stimulus_model import StimulusModel [as 别名]
# 或者: from sparkle.stim.stimulus_model.StimulusModel import setRepCount [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()
示例2: stim_with_double_auto
# 需要导入模块: from sparkle.stim.stimulus_model import StimulusModel [as 别名]
# 或者: from sparkle.stim.stimulus_model.StimulusModel import setRepCount [as 别名]
def stim_with_double_auto(self):
model = StimulusModel()
model.setReferenceVoltage(100, 0.1)
model.setRepCount(7)
component = Vocalization()
component.setFile(sample.samplewav())
model.insertComponent(component, 0,0)
nsteps0 = self.add_vocal_param(model)
nsteps1 = self.add_auto_param(model)
nsteps = nsteps0*nsteps1
return model
示例3: __init__
# 需要导入模块: from sparkle.stim.stimulus_model import StimulusModel [as 别名]
# 或者: from sparkle.stim.stimulus_model.StimulusModel import setRepCount [as 别名]
def __init__(self, *args):
super(MphoneCalibrationRunner, self).__init__(*args)
self.save_data = False
self.silence_window = False
self.player = FinitePlayer()
# acquistiion without a stimulus is not allowed, so use silence
stim = StimulusModel()
stim.setRepCount(self._reps)
stim.insertComponent(Silence())
self.protocol_model.insert(stim,0)
示例4: create_tone_stim
# 需要导入模块: from sparkle.stim.stimulus_model import StimulusModel [as 别名]
# 或者: from sparkle.stim.stimulus_model.StimulusModel import setRepCount [as 别名]
def create_tone_stim(nreps):
component = PureTone()
stim_model = StimulusModel()
stim_model.insertComponent(component, 0,0)
stim_model.setRepCount(nreps)
auto_model = stim_model.autoParams()
auto_model.insertRow(0)
auto_model.toggleSelection(0,component)
# values = ['frequency', 0, 100, 10]
values = ['duration', 0.065, 0.165, 0.010] # had caused problem in past
auto_model.setParamValue(0, parameter=values[0], start=values[1],
stop=values[2], step=values[3])
return stim_model
示例5: tone_protocol
# 需要导入模块: from sparkle.stim.stimulus_model import StimulusModel [as 别名]
# 或者: from sparkle.stim.stimulus_model.StimulusModel import setRepCount [as 别名]
def tone_protocol(self, manager, intensity=70):
#insert some stimuli
tone = PureTone()
tone.setDuration(0.02)
tone.setIntensity(intensity)
stim = StimulusModel()
stim.insertComponent(tone)
stim.setRepCount(3)
manager.protocol_model().insert(stim,0)
manager.setup_protocol(0.1)
t = manager.run_protocol()
t.join()
return stim
示例6: create_vocal_stim
# 需要导入模块: from sparkle.stim.stimulus_model import StimulusModel [as 别名]
# 或者: from sparkle.stim.stimulus_model.StimulusModel import setRepCount [as 别名]
def create_vocal_stim(nreps):
component = Vocalization()
component.setFile(sample.samplewav())
delay = Silence()
stim_model = StimulusModel()
stim_model.insertComponent(delay, 0,0)
stim_model.insertComponent(component, 0,0)
stim_model.setRepCount(nreps)
auto_model = stim_model.autoParams()
auto_model.insertRow(0)
p = {'parameter' : 'filename',
'names' : [sample.samplewav(), sample.samplewav()],
'selection' : []
}
auto_model.overwriteParam(0,p)
auto_model.toggleSelection(0,component)
return stim_model
示例7: create
# 需要导入模块: from sparkle.stim.stimulus_model import StimulusModel [as 别名]
# 或者: from sparkle.stim.stimulus_model.StimulusModel import setRepCount [as 别名]
def create():
stim = StimulusModel()
tone = PureTone()
tone.setDuration(CCFactory.defaultInputs['duration'])
tone.setRisefall(CCFactory.defaultInputs['risefall'])
stim.insertComponent(tone)
tuning_curve = stim.autoParams()
tuning_curve.insertRow(0)
tuning_curve.toggleSelection(0, tone)
tuning_curve.setParamValue(0, parameter='frequency', start=CCFactory.defaultInputs['freqStart'], stop=CCFactory.defaultInputs['freqStop'], step=CCFactory.defaultInputs['freqStep'])
tuning_curve.insertRow(1)
tuning_curve.toggleSelection(1, tone)
tuning_curve.setParamValue(1, parameter='intensity', start=CCFactory.defaultInputs['intenStart'], stop=CCFactory.defaultInputs['intenStop'], step=CCFactory.defaultInputs['intenStep'])
stim.setRepCount(CCFactory.defaultInputs['reps'])
stim.setStimType(CCFactory.name)
return stim
示例8: setUp
# 需要导入模块: from sparkle.stim.stimulus_model import StimulusModel [as 别名]
# 或者: from sparkle.stim.stimulus_model.StimulusModel import setRepCount [as 别名]
def setUp(self):
self.tempfile = os.path.join(os.path.abspath(os.path.dirname(__file__)), u"tmp", 'testsave.json')
model = StimulusModel()
model.setMaxVoltage(1.5, 10.0)
model.setReferenceVoltage(100, 0.1)
model.setRepCount(7)
# add tone, vocalization, and silence components
component = PureTone()
component.setIntensity(34)
component.setDuration(0.2)
model.insertComponent(component, 0,0)
vocal = Vocalization()
vocal.setFile(sample.samplewav())
model.insertEmptyRow()
model.insertComponent(vocal, 1,0)
silence = Silence()
# have gap between tone and vocal
silence.setDuration(0.5)
model.insertComponent(silence, 1,0)
nsteps = self.add_auto_param(model)
editor = StimulusEditor()
editor.setModel(QStimulusModel(model))
self.editor = editor
self.stim = model
示例9: create
# 需要导入模块: from sparkle.stim.stimulus_model import StimulusModel [as 别名]
# 或者: from sparkle.stim.stimulus_model.StimulusModel import setRepCount [as 别名]
def create(self):
stim = StimulusModel()
stim.setStimType(StimulusEditor.name)
stim.setRepCount(StimulusEditor.defaultReps())
return stim
示例10: CalibrationRunner
# 需要导入模块: from sparkle.stim.stimulus_model import StimulusModel [as 别名]
# 或者: from sparkle.stim.stimulus_model.StimulusModel import setRepCount [as 别名]
#.........这里部分代码省略.........
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':
self.datafile.append(self.current_dataset_name, response, nested_name='reference_tone')
elif trace_info['components'][0]['stim_type'] == 'FM Sweep' or trace_info['components'][0]['stim_type'] == 'White Noise':
self.datafile.append(self.current_dataset_name, response)
else:
raise Exception("Improper calibration stimulus : {}".format(trace_info['components'][0]['stim_type']))
def process_calibration(self, save=True):
"""processes calibration control signal. Determines transfer function
of speaker to get frequency vs. attenuation curve.
:param save: Whether to save this calibration data to file
:type save: bool
:returns: numpy.ndarray, str, int, float -- frequency response (in dB), dataset name, calibration reference frequency, reference intensity
"""
if not self.save_data:
raise Exception("Cannot process an unsaved calibration")
avg_signal = np.mean(self.datafile.get_data(self.current_dataset_name + '/signal'), axis=0)
diffdB = attenuation_curve(self.stimulus.signal()[0], avg_signal,
self.stimulus.samplerate(), self.calf)
logger = logging.getLogger('main')
logger.debug('The maximum dB attenuation is {}, caldB {}'.format(max(diffdB), self.caldb))
# save a vector of only the calibration intensity results
self.datafile.init_data(self.current_dataset_name, mode='calibration',
dims=diffdB.shape,
nested_name='calibration_intensities')
self.datafile.append(self.current_dataset_name, diffdB,
nested_name='calibration_intensities')
relevant_info = {'frequencies': 'all', 'calibration_dB':self.caldb,
'calibration_voltage': self.calv, 'calibration_frequency': self.calf,
}
self.datafile.set_metadata('/'.join([self.current_dataset_name, 'calibration_intensities']),
relevant_info)
mean_reftone = np.mean(self.datafile.get_data(self.current_dataset_name + '/reference_tone'), axis=0)
tone_amp = signal_amplitude(mean_reftone, self.player.get_aifs())
db = calc_db(tone_amp, self.mphonesens, self.mphonedb)
# remove the reference tone from protocol
self.protocol_model.remove(0)
return diffdB, self.current_dataset_name, self.calf, db
def set_reps(self, reps):
"""set the number of repetitions for the stimuli (reference tone and cal stim)
:param reps: number of times to present the same stimulus
:type reps: int
"""
self.stimulus.setRepCount(reps)
self.refstim.setRepCount(reps)
def count(self):
return self.stimulus.repCount()
示例11: TestStimModel
# 需要导入模块: from sparkle.stim.stimulus_model import StimulusModel [as 别名]
# 或者: from sparkle.stim.stimulus_model.StimulusModel import setRepCount [as 别名]
#.........这里部分代码省略.........
component1 = PureTone()
component0.setIntensity(caldb)
component1.setIntensity(caldb)
self.model.insertComponent(component0, 0, 0)
self.model.insertComponent(component1, 1, 0)
self.model.setReferenceVoltage(caldb, calv)
signal, atten, ovld = self.model.signal()
assert atten == 0
print 'maxv', MAXV, 'signal max', np.amax(signal), 'overload', ovld
assert round(np.amax(signal),2) == MAXV
# do math to make this more accurate
assert ovld > 0
def test_square_wave_overload_voltage(self):
component0 = SquareWave()
component0.set('amplitude', 11.)
self.model.insertComponent(component0, 0, 0)
signal, atten, ovld = self.model.signal()
assert atten == 0
print 'maxv', DEVICE_MAXV, 'signal max', np.amax(signal), 'overload', ovld
assert round(np.amax(signal),2) == DEVICE_MAXV
# do math to make this more accurate
assert ovld > 0
def test_corrent_number_of_traces(self):
self.model = self.stim_with_double_auto()
n = self.model.traceCount()
sig, doc, over = self.model.expandedStim()
assert len(sig) == n
def test_template_no_auto_params(self):
self.model.setRepCount(7)
component = PureTone()
component.setIntensity(34)
self.model.insertComponent(component, 0,0)
vocal = Vocalization()
vocal.setFile(sample.samplewav())
self.model.insertComponent(vocal, 1,0)
template = self.model.templateDoc()
clone = StimulusModel.loadFromTemplate(template)
clone.setReferenceVoltage(100, 0.1)
signal0, atten0, ovld = clone.signal()
signal1, atten1, ovld = self.model.signal()
assert clone.stimid != self.model.stimid
np.testing.assert_array_equal(signal0, signal1)
assert atten0 == atten1
assert clone.repCount() == self.model.repCount()
def test_template_with_auto_params(self):
self.model.setRepCount(7)
component = PureTone()
component.setIntensity(34)
self.model.insertComponent(component, 0,0)
nsteps = self.add_auto_param(self.model)
template = self.model.templateDoc()
clone = StimulusModel.loadFromTemplate(template)
clone.setReferenceVoltage(100, 0.1)