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


Python StimulusModel.clearComponents方法代码示例

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


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

示例1: CalibrationRunner

# 需要导入模块: from sparkle.stim.stimulus_model import StimulusModel [as 别名]
# 或者: from sparkle.stim.stimulus_model.StimulusModel import clearComponents [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':
#.........这里部分代码省略.........
开发者ID:Joel-U,项目名称:sparkle,代码行数:103,代码来源:calibration_runner.py


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