Пример #1
0
Файл: main.py Проект: cplab/ceed
    def __init__(self, **kwargs):
        self.view_controller = ViewSideViewControllerBase()
        self.ceed_data = CeedDataWriterBase()
        self.data_serializer = DataSerializerBase()
        self.function_factory = FunctionFactoryBase()
        register_all_functions(self.function_factory)
        self.shape_factory = CeedPaintCanvasBehavior()
        self.stage_factory = StageFactoryBase(
            function_factory=self.function_factory,
            shape_factory=self.shape_factory)

        super(CeedViewApp, self).__init__(**kwargs)
Пример #2
0
    def load_experiment(self, experiment):
        self._block = block = self._nix_file.blocks[
            CeedDataWriterBase.get_experiment_block_name(experiment)]
        section = self._nix_file.sections['experiment{}_metadata'.format(
            experiment)]
        self.loaded_experiment = experiment

        self.experiment_stage_name = section['stage']
        self.experiment_notes = section['notes'] if 'notes' in section else ''
        self.experiment_start_time = float(
            section['save_time']) if 'save_time' in section else 0
        config = section.sections['app_config']

        config_data = {}
        for prop in config.props:
            config_data[prop.name] = yaml_loads(read_nix_prop(prop))

        view = self.view_controller = ViewControllerBase()
        ser = self.data_serializer = DataSerializerBase()
        func = self.function_factory = FunctionFactoryBase()
        register_all_functions(func)
        shape = self.shape_factory = CeedPaintCanvasBehavior()
        stage = self.stage_factory = StageFactoryBase(function_factory=func,
                                                      shape_factory=shape)

        for name, obj in {
                'view': view,
                'serializer': ser,
                'function': func
        }.items():
            if name in config_data['app_settings']:
                apply_config(obj, config_data['app_settings'][name])
        self.populate_config(config_data, shape, func, stage)

        self.experiment_cam_image = self.read_image_from_block(self._block)

        data = self.shapes_intensity = {}
        for item in block.data_arrays:
            if not item.name.startswith('shape_'):
                continue
            data[item.name[6:]] = item

        self.led_state = block.data_arrays['led_state']

        if ('ceed_mcs_alignment' in self._nix_file.blocks
                and 'experiment_{}'.format(experiment)
                in self._nix_file.blocks['ceed_mcs_alignment'].data_arrays):
            self.electrode_intensity_alignment = self._nix_file.blocks[
                'ceed_mcs_alignment'].data_arrays['experiment_{}'.format(
                    experiment)]
        else:
            self.electrode_intensity_alignment = None
Пример #3
0
 def __init__(self, open_player_thread=True, **kwargs):
     self.drag_controller = CeedDragNDrop()
     self.function_factory = FunctionFactoryBase()
     register_all_functions(self.function_factory)
     self.stage_factory = StageFactoryBase(
         function_factory=self.function_factory, shape_factory=None)
     self.player = CeedPlayer(open_player_thread=open_player_thread)
     self.view_controller = ControllerSideViewControllerBase()
     self.ceed_data = CeedDataWriterBase()
     self.data_serializer = DataSerializerBase()
     super(CeedApp, self).__init__(**kwargs)
     self.load_app_settings_from_file()
     self.apply_app_settings()
Пример #4
0
    def load_application_data(self):
        self.app_logs = self.app_notes = ''
        if 'app_logs' in self._nix_file.sections:
            self.app_logs = self._nix_file.sections['app_logs']['log_data']
            self.app_notes = self._nix_file.sections['app_logs']['notes']

        config = self._nix_file.sections['app_config']

        config_data = {}
        for prop in config.props:
            config_data[prop.name] = yaml_loads(read_nix_prop(prop))

        self.ceed_version = config_data.get('ceed_version', '')

        view = ViewControllerBase()
        ser = DataSerializerBase()
        func = FunctionFactoryBase()
        register_all_functions(func)
        shape = CeedPaintCanvasBehavior()
        stage = StageFactoryBase(function_factory=func, shape_factory=shape)

        for name, obj in {
                'view': view,
                'serializer': ser,
                'function': func
        }.items():
            if name in config_data['app_settings']:
                apply_config(obj, config_data['app_settings'][name])
        self.populate_config(config_data, shape, func, stage)

        self.app_config = {
            'view_controller': view,
            'data_serializer': ser,
            'function_factory': func,
            'shape_factory': shape,
            'stage_factory': stage,
        }
Пример #5
0
def test_serializer_with_config(n_sub_frames):
    serializer = DataSerializerBase()
    config, num_handshake_ticks, counter, short_values, clock_values = \
        set_serializer_even_count_bits(serializer, n_sub_frames)
    serializer.projector_to_aquisition_map = {i: i for i in range(16)}

    bits = serializer.get_bits(config)
    next(bits)

    assert serializer.num_ticks_handshake(len(config),
                                          n_sub_frames) == num_handshake_ticks
    assert serializer.num_ticks_handshake(
        len(config), 1) * n_sub_frames == num_handshake_ticks

    i = 0
    for count, short, clock in zip(counter, short_values, clock_values):
        value = bits.send(i * n_sub_frames + 1)
        print(i, f'{value:010b}, {count:010b}, {short:010b}, {clock:08b}')
        assert value == count | short | clock

        i += 1

    assert i == len(counter)
Пример #6
0
def set_serializer_even_count_bits(
        serializer: DataSerializerBase, n_sub_frames):
    serializer_config_bytes = [
        0b00000001, 0b00010010, 0b00100011, 0b00110100, 0b01000101, 0b01010110,
        0b01100111
    ]

    serializer.clock_idx = 3
    serializer.count_indices = [0, 2, 4, 5]
    serializer.short_count_indices = [1, 6, 8]
    serializer.counter_bit_width = 32

    num_handshake_ticks = 3 * 2 * 8 * n_sub_frames

    counter = [
        # length of config is 2 ints, duplicated
        0b0000_0100, 0b0000_0100,
        0b0000_0000, 0b0000_0000,
        0b0000_0000, 0b0000_0000,
        0b0000_0000, 0b0000_0000,
        0b0000_0000, 0b0000_0000,
        0b0000_0000, 0b0000_0000,
        0b0000_0000, 0b0000_0000,
        0b0000_0000, 0b0000_0000,
        # first 4 config bytes
        0b0000_0001, 0b0000_0001,
        0b0000_0000, 0b0000_0000,
        0b0000_0100, 0b0000_0100,
        0b0000_0001, 0b0000_0001,
        0b0000_0101, 0b0000_0101,
        0b0000_0100, 0b0000_0100,
        0b0001_0000, 0b0001_0000,
        0b0000_0101, 0b0000_0101,
        # next 3 config bytes
        0b0001_0001, 0b0001_0001,
        0b0001_0000, 0b0001_0000,
        0b0001_0100, 0b0001_0100,
        0b0001_0001, 0b0001_0001,
        0b0001_0101, 0b0001_0101,
        0b0001_0100, 0b0001_0100,
        0b0000_0000, 0b0000_0000,
        0b0000_0000, 0b0000_0000,
    ]
    # counter is incremented once per sub-frame, short counter is the same
    # for all sub-frames
    if n_sub_frames == 1:
        counter += [
            # counter is now 49 frames (started at 1)
            0b0000_0001, 0b0000_0001,
            0b0000_0101, 0b0011_0000,
            0b0000_0000, 0b0011_0101,
            0b0000_0000, 0b0011_0101,
            0b0000_0000, 0b0011_0101,
            0b0000_0000, 0b0011_0101,
            0b0000_0000, 0b0011_0101,
            0b0000_0000, 0b0011_0101,
            # counter is now 65 frames
            0b0000_0001, 0b0000_0001,
            0b0001_0000, 0b0010_0101,
            0b0000_0000, 0b0011_0101,
            0b0000_0000, 0b0011_0101,
            0b0000_0000, 0b0011_0101,
            0b0000_0000, 0b0011_0101,
            0b0000_0000, 0b0011_0101,
            0b0000_0000, 0b0011_0101,
        ]
    elif n_sub_frames == 4:
        counter += [
            # counter is now 193 frames (started at 1)
            0b0000_0001, 0b0000_0001,
            0b0011_0000, 0b0000_0101,
            0b0000_0000, 0b0011_0101,
            0b0000_0000, 0b0011_0101,
            0b0000_0000, 0b0011_0101,
            0b0000_0000, 0b0011_0101,
            0b0000_0000, 0b0011_0101,
            0b0000_0000, 0b0011_0101,
            # counter is now 257 frames
            0b0000_0001, 0b0000_0001,
            0b0000_0000, 0b0011_0101,
            0b0000_0001, 0b0011_0100,
            0b0000_0000, 0b0011_0101,
            0b0000_0000, 0b0011_0101,
            0b0000_0000, 0b0011_0101,
            0b0000_0000, 0b0011_0101,
            0b0000_0000, 0b0011_0101,
        ]
    elif n_sub_frames == 12:
        counter += [
            # counter is now 577 frames (started at 1)
            0b0000_0001, 0b0000_0001,
            0b0001_0000, 0b0010_0101,
            0b0000_0100, 0b0011_0001,
            0b0000_0000, 0b0011_0101,
            0b0000_0000, 0b0011_0101,
            0b0000_0000, 0b0011_0101,
            0b0000_0000, 0b0011_0101,
            0b0000_0000, 0b0011_0101,
            # counter is now 767 frames
            0b0000_0001, 0b0000_0001,
            0b0000_0000, 0b0011_0101,
            0b0000_0101, 0b0011_0000,
            0b0000_0000, 0b0011_0101,
            0b0000_0000, 0b0011_0101,
            0b0000_0000, 0b0011_0101,
            0b0000_0000, 0b0011_0101,
            0b0000_0000, 0b0011_0101,
        ]

    clock_values = cycle([0b1000, 0])
    short_values = cycle([
        0b0_0000_0000,
        0b0_0000_0010,
        0b0_0100_0000,
        0b0_0100_0010,
        0b1_0000_0000,
        0b1_0000_0010,
        0b1_0100_0000,
        0b1_0100_0010,
    ])

    return bytes(serializer_config_bytes), num_handshake_ticks, counter, \
        short_values, clock_values