示例#1
0
def list_io():
    io_path = get_config('IO_ROOT')
    result = list(io_path.glob('*.enaml'))
    io_map = {
        p.stem: p
        for p in list_io_templates() if not p.stem.startswith('_')
    }
    result.extend(io_map[c] for c in get_config('STANDARD_IO'))
    return result
示例#2
0
def _main(args):
    set_config('EXPERIMENT', args.experiment)

    if args.debug:
        # Show debugging information. This includes full tracebacks for
        # warnings.
        dt_string = dt.datetime.now().strftime('%Y-%m-%d %H%M')
        filename = '{} {}'.format(dt_string, args.experiment)
        log_root = get_config('LOG_ROOT')
        configure_logging('DEBUG', os.path.join(log_root, filename))

        log.debug('Logging configured')
        log.info('Logging information captured in {}'.format(filename))
        log.info('Python executable: {}'.format(sys.executable))
        if args.debug_warning:
            warnings.showwarning = warn_with_traceback

    from psi.experiment.workbench import PSIWorkbench

    workbench = PSIWorkbench()
    plugins = [p.manifest for p in args.controller.plugins \
               if p.selected or p.required]
    workbench.register_core_plugins(args.io, plugins)

    if args.pathname is None:
        log.warn('All data will be destroyed at end of experiment')

    workbench.start_workspace(args.experiment,
                              args.pathname,
                              commands=args.commands,
                              load_preferences=not args.no_preferences,
                              load_layout=not args.no_layout,
                              preferences_file=args.preferences,
                              calibration_file=args.calibration)
示例#3
0
def get_default_io():
    '''
    Attempt to figure out the default IO configuration file

    Rules
    -----
    * If no files are defined, raise ValueError
    * If only one file is defined, return it
    * If more than one file is defined, check for one named "default" first. If
      none are named "default", check to see if one matches the hostname.
    * Finally, just return the first one found.
    '''
    system = get_config('SYSTEM')
    available_io = list_io()
    log.debug('Found the following IO files: %r', available_io)

    if len(available_io) == 0:
        raise ValueError('No IO configured for system')
    elif len(available_io) == 1:
        return available_io[0]

    # First, check for one named "default"
    for io in available_io:
        if 'default' in io.stem.lower():
            return io

    # Next, check to see if it matches hostname
    for io in available_io:
        if io.stem == system:
            return io

    # Give up
    return available_io[0]
示例#4
0
def launch_experiment(args):
    set_config('ARGS', args)
    set_config('PROFILE', args.profile)
    if args.profile:
        import cProfile, pstats
        pr = cProfile.Profile()
        pr.enable()

    try:
        _main(args)
    except Exception as e:
        if args.pdb:
            type, value, tb = sys.exc_info()
            traceback.print_exc()
            pdb.post_mortem(tb)
        else:
            log.exception(e)
            critical(None, 'Error starting experiment', str(e))

    if args.profile:
        pr.disable()
        path = get_config('LOG_ROOT') / 'main_thread.pstat'
        pr.dump_stats(path)
        stat_files = [str(p) for p in path.parent.glob('*.pstat')]
        merged_stats = pstats.Stats(*stat_files)
        merged_stats.dump_stats(path.parent / 'merged.pstat')
示例#5
0
def get_io_manifest(system=None):
    if system is None:
        from psi import get_config
        system = get_config('SYSTEM')
    module_name = 'psi.application.io.{}'.format(system)
    module = import_manifest(module_name)
    return module.IOManifest
示例#6
0
def _launch(klass, experiment_type, root_folder=None):
    app = QtApplication()
    if root_folder is None:
        root_folder = get_config('DATA_ROOT')
    launcher = klass(root_folder=root_folder, experiment_type=experiment_type)
    view = LauncherView(launcher=launcher)
    view.show()
    app.start()
示例#7
0
 def __call__(self, parser, namespace, value, option_string=None):
     path = Path(value)
     if not path.exists():
         path = get_config('IO_ROOT') / value
         path = path.with_suffix('.enaml')
         if not path.exists():
             raise ValueError('%s does not exist'.format(value))
     setattr(namespace, self.dest, path)
示例#8
0
def list_preferences(experiment):
    from psi.experiment.util import PREFERENCES_WILDCARD
    if not isinstance(experiment, str):
        experiment = experiment.name
    p_root = get_config('PREFERENCES_ROOT') / experiment
    p_glob = PREFERENCES_WILDCARD[:-1].split('(')[1]
    matches = p_root.glob(p_glob)
    return sorted(Path(p) for p in matches)
示例#9
0
    def run(self):
        profile = get_config('PROFILE')
        if profile:
            import cProfile
            pr = cProfile.Profile()
            pr.enable()

        log.debug('Starting acquisition thread')
        while not self.stop_requested.wait(self.poll_interval):
            stop = self.callback()
            if stop:
                break

        if profile:
            pr.disable()
            path = get_config('LOG_ROOT') / f'{self.name}_thread.pstat'
            pr.dump_stats(path)

        log.debug('Exiting acquistion thread')
示例#10
0
def load_paradigm_descriptions():
    '''
    Loads paradigm descriptions
    '''
    from psi.experiment.api import ParadigmDescription

    default = list_paradigm_descriptions()
    descriptions = get_config('PARADIGM_DESCRIPTIONS', default)
    for description in descriptions:
        importlib.import_module(description)
示例#11
0
def launch(klass, experiment_type, root_folder='DATA_ROOT', view_klass=None):
    app = QtApplication()
    load_paradigm_descriptions()
    try:
        if root_folder.endswith('_ROOT'):
            root_folder = get_config(root_folder)
        if view_klass is None:
            view_klass = LauncherView
        launcher = klass(root_folder=root_folder,
                         experiment_type=experiment_type)
        view = view_klass(launcher=launcher)
        view.show()
        app.start()
        return True
    except Exception as e:
        mesg = f'Unable to load configuration data.\n\n{e}'
        critical(None, 'Software not configured', mesg)
        raise
示例#12
0
if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Run experiment")
    parser.add_argument("experiment", type=str, help="Experiment to run")
    parser.add_argument("--io", type=str, default=None, help="Hardware configuration")
    parser.add_argument("--debug", default=False, action="store_true", help="Debug mode?")
    args = parser.parse_args()

    if args.debug:
        configure_logging()
        log.debug("Logging configured")

    from psi import application
    from psi import get_config, set_config

    for config in ["LAYOUT_ROOT", "PREFERENCES_ROOT", "CONTEXT_ROOT"]:
        path = get_config(config)
        new_path = os.path.join(path, args.experiment)
        set_config(config, new_path)
        if not os.path.exists(new_path):
            os.makedirs(new_path)

    experiment_description = experiment_descriptions[args.experiment]
    manifests = application.get_manifests(experiment_description["manifests"])
    manifests += [application.get_io_manifest(args.io)]
    workbench = application.initialize_workbench(manifests)

    core = workbench.get_plugin("enaml.workbench.core")

    core.invoke_command("enaml.workbench.ui.select_workspace", {"workspace": "psi.experiment.workspace"})

    with tb.open_file("c:/users/bburan/desktop/test.h5", "w") as fh:
示例#13
0
 def _default_root_folder(self):
     return get_config('DATA_ROOT')
示例#14
0
    def _observe_animal(self, event):
        self._update()


class EarLauncher(AnimalLauncher):

    ear = Enum('right', 'left').tag(template=True)

    template = '{{date_time}} {experimenter} {animal} {ear} {note} {experiment}'
    wildcard_template = '*{animal} {ear}*{experiment}'

    def _observe_ear(self, event):
        self._update()


def _launch(klass, experiment_type, root_folder=None):
    app = QtApplication()
    if root_folder is None:
        root_folder = get_config('DATA_ROOT')
    launcher = klass(root_folder=root_folder, experiment_type=experiment_type)
    view = LauncherView(launcher=launcher)
    view.show()
    app.start()


main_calibration = partial(_launch, SimpleLauncher, 'calibration',
                           get_config('CAL_ROOT'))
main_cohort = partial(_launch, SimpleLauncher, 'cohort')
main_animal = partial(_launch, AnimalLauncher, 'animal')
main_ear = partial(_launch, EarLauncher, 'ear')
示例#15
0
def list_io():
    io_path = get_config('IO_ROOT')
    return list(io_path.glob('*.enaml'))
示例#16
0
def list_preferences(experiment):
    p_root = get_config('PREFERENCES_ROOT') / experiment.name
    p_wildcard = get_config('PREFERENCES_WILDCARD')
    p_glob = p_wildcard[:-1].split('(')[1]
    matches = p_root.glob(p_glob)
    return sorted(Path(p) for p in matches)