Esempio n. 1
0
def prepare_experiment(args, store_node, create_child=True):

    '''
    Given the arguments passed in via the command-line, configure the
    Experiment, Controller, Data and Paradigm class accordingly and return an
    instance of the model and controller class.
    '''

    # The HDF5 file that is used for the data
    store_file = store_node._v_file

    # If the user did not specify a list of parameters that the data should be
    # grouped into before analysis (i.e. for computing the hit and false alarm
    # fractions), then use the parameters specified via rove as the analysis
    # parameters.
    if len(args.analyze) == 0:
        args.analyze = args.rove[:]

    # Load the experiment from the launchers folder.  args.type should be the
    # name of the corresponding file in the launchers folder (without the .py
    # extension)
    module = get_experiment(args.type)
    
    # Pull out the classes
    paradigm_class = module.Paradigm
    experiment_class = module.Experiment
    controller_class = module.Controller
    data_class = module.Data
    node_name = module.node_name

    # Create the experiment and data nodes. Hint! This is where you would
    # change the default pathname for the experiment if you wished.
    if create_child:
        name = node_name + '_' + datetime.now().strftime(time_fmt)
        exp_node = store_file.createGroup(store_node, name)
    else:
        exp_node = store_node

    # Where the data is stored
    data_node = store_file.createGroup(exp_node, 'data')

    # Configure the TrialSetting/trial_setting_editor objects to contain the
    # parameters we wish to control in the experiment
    trial_setting.add_parameters(args.rove, paradigm_class, args.repeats)

    if args.att:
        # The user wants to specify values in terms of dB attenuation rather
        # than a calibrated dB SPL standard.  Prepare the calibration
        # accordingly.
        cal1 = calibration.Attenuation()
        cal2 = calibration.Attenuation()
    else:
        if args.cal is not None:
            cal1_filename, cal2_filename = args.cal
        else:
            cal1_filename = get_config('CAL_PRIMARY')
            cal2_filename = get_config('CAL_SECONDARY')

        if cal1_filename is None:
            raise IOError, 'Unable to find a calibration file for the ' \
                           'primary speaker'
        if cal2_filename is None:
            raise IOError, 'Unable to find a calibration file for the ' \
                           'secondary speaker'
        cal1 = calibration.load_mat_cal(cal1_filename, args.equalized)
        log.debug('Loaded calibration file %s for primary', cal1_filename)
        cal2 = calibration.load_mat_cal(cal2_filename, args.equalized)
        log.debug('Loaded calibration file %s for secondary', cal2_filename)

    controller_args = {
            'cal_primary':      cal1,
            'cal_secondary':    cal2,
            'address':          args.address,
            }
    
    log.debug('store_node: %s', store_node)
    log.debug('data_node: %s', data_node)
    log.debug('exp_node: %s', exp_node)
    
    # Prepare the classes. This really is a lot of boilerplate to link up
    # parameters with paradigms, etc, to facilitate analysis
    paradigm = paradigm_class()
    data = data_class(store_node=data_node,
                      save_microphone=args.save_microphone)
    data.parameters = args.analyze
    model = experiment_class(
            store_node=store_node, 
            experiment_node=exp_node,
            data_node=data_node, 
            data=data,
            paradigm=paradigm,
            spool_physiology=args.physiology,
            )
    
    if args.analyze:
        model.plot_index = args.analyze[0]
        model.plot_group = args.analyze[1:]

    controller = controller_class(**controller_args)
    return model, controller
Esempio n. 2
0
            label='Paradigm'
        ),
        VGroup(
            Include('dt_group'),
            Include('speaker_group'),
            label='Sound'
        )
    )

class Data(PositiveData, MLDataMixin, PumpDataMixin):
    pass

class Experiment(AbstractPositiveExperiment, MLExperimentMixin):

    data = Instance(Data, ())
    paradigm = Instance(Paradigm, ())

node_name = 'PositiveDTCLExperiment'

if __name__ == '__main__':
    import tables
    from os.path import join
    from cns import get_config
    filename = join(get_config('TEMP_ROOT'), 'test_experiment.hd5')
    file = tables.openFile(filename, 'w')
    from experiments.trial_setting import add_parameters
    add_parameters(['test'])
    data = Data(store_node=file.root)
    experiment = Experiment(data=data)
    experiment.configure_traits()