Exemple #1
0
    def __init__(
        self,
        *data_tuples_list,
        extra_settings=None,
        instance_number=-1,
        folder_path="C:/"
    ):
        super().__init__()
        if instance_number < 0:
            self.metadata_fn = "stytra_last_config.json"
        else:
            self.metadata_fn = "stytra_last_config_{}.json".format(instance_number)

        # Check validity of directory:
        self.home_path = Path.home()
        self.folder_path = Path(folder_path)
        if not self.folder_path.is_dir():
            self.folder_path.mkdir(parents=True)

        # Try to find previously saved data_log:
        self.last_metadata = extra_settings or dict()
        metadata_files = list(self.home_path.glob("*" + self.metadata_fn))

        if metadata_files:
            with open(str(metadata_files[0]), "r") as f:
                recursive_update(self.last_metadata, json.load(f))

        self.log_data_dict = dict()
        self.params_metadata = None
        # Add all the data tuples provided upon instantiation:
        for data_element in data_tuples_list:
            self.add_static_data(*data_element)
Exemple #2
0
    def __init__(self, recording=None, exec=True, app=None, **kwargs):
        # Check if exist a default config file in the home (user) directory:
        mp.set_start_method("spawn", force=True)
        inum = kwargs.get("instance_number", -1)
        if inum >= 0:
            default_config_file = Path.home(
            ) / "stytra_setup_config_{}.json".format(inum)
        else:
            default_config_file = Path.home() / "stytra_setup_config.json"
        if default_config_file.is_file():
            config = json.load(open(str(default_config_file)))
        else:
            config = dict()

        # Get rest of configuration parameters from the protocol:
        try:
            extra_config = kwargs["protocol"].stytra_config
            recursive_update(config, extra_config)
        except AttributeError:
            pass

        recursive_update(config, kwargs)  # Use also keyword arguments

        if config.get("scope_triggering", None) == "zmq":
            # Automatically use zmqTrigger if zmq is specified
            from stytra.triggering import ZmqTrigger

            config["scope_triggering"] = ZmqTrigger(port="5555")

        if app is None:
            app = QApplication([])
            app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
            if app.devicePixelRatio() > 1:
                app.setAttribute(Qt.AA_UseHighDpiPixmaps)
        class_kwargs = dict(app=app)
        class_kwargs.update(config)

        base = VisualExperiment

        if "camera" in class_kwargs.keys():
            base = CameraVisualExperiment
            if "tracking" in class_kwargs.keys():
                base = TrackingExperiment
                if not class_kwargs["tracking"].get("embedded", True):
                    class_kwargs["calibrator"] = CircleCalibrator()

            if recording:
                base = VideoRecordingExperiment

        # Stytra logo
        app_icon = QIcon()
        for size in [32, 64, 128, 256]:
            app_icon.addFile(
                pkg_resources.resource_filename(__name__,
                                                "/icons/{}.png".format(size)),
                QSize(size, size),
            )
        app.setWindowIcon(app_icon)

        pg.setConfigOptions(imageAxisOrder="row-major")

        self.exp = base(**class_kwargs)

        self.exp.start_experiment()

        if exec:
            app.exec_()