Beispiel #1
0
 def send_CaImaging_Stop_signal(self):
     self.statusBar.showMessage('sending stop signal for 2-Photon acq.')
     acq = Acquisition(
         dt=1e-3,  # 1kHz
         Nchannel_analog_in=1,
         Nchannel_digital_in=0,
         max_time=1.1,
         buffer_time=0.1,
         output_steps=[self.config['STEP_FOR_CA_IMAGING_TRIGGER']],
         filename=None)
     acq.launch()
     time.sleep(1.1)
     acq.close()
Beispiel #2
0
            original_freq=metadata['NIdaq-acquisition-frequency'],
            new_freq=50.,
            post_smoothing=2. / 50.,
            verbose=True)
        print('mean speed: %.1f cm/s' % np.mean(speed))
        plt.plot(t_array, speed)
        plt.ylabel('speed (cm/s)')
        plt.xlabel('time (s)')
        plt.show()

    else:
        import time
        from hardware_control.NIdaq.main import Acquisition

        acq = Acquisition(dt=args.acq_time_step,
                          Nchannel_analog_in=0,
                          Nchannel_digital_in=2,
                          max_time=args.recording_time)

        print('You have %i s to do 5 rotations of the disk [...]' %
              args.recording_time)

        acq.launch()

        time.sleep(args.recording_time)

        _, digital_inputs, dt = acq.close(return_data=True)
        t_array = np.arange(len(digital_inputs[0])) * dt

        A, B = process_binary_signal(digital_inputs[0, :])

        plt.plot(t_array, A)
Beispiel #3
0
    def initialize(self):

        self.bufferButton.setEnabled(
            False)  # should be already blocked, but for security
        self.runButton.setEnabled(False)  # acq blocked during init

        self.metadata = self.check_gui_to_init_metadata()
        self.set_filename_and_folder()

        max_time = 2 * 60 * 60  # 2 hours by default, so should be stopped manually
        if self.metadata['VisualStim']:
            self.statusBar.showMessage(
                '[...] initializing acquisition & stimulation')
            self.init_visual_stim()
            np.save(
                os.path.join(str(self.datafolder.get()), 'visual-stim.npy'),
                self.stim.experiment)
            print('[ok] Visual-stimulation data saved as "%s"' %
                  os.path.join(str(self.datafolder.get()), 'visual-stim.npy'))
            if ('time_stop'
                    in self.stim.experiment) and self.stim.buffer is not None:
                # if buffered, it won't be much longer than the scheduled time
                max_time = 1.5 * np.max(self.stim.experiment['time_stop'])
        else:
            self.statusBar.showMessage('[...] initializing acquisition')
            self.stim = None

        print('max_time of NIdaq recording: %.2dh:%.2dm:%.2ds' %
              (max_time / 3600, (max_time % 3600) / 60, (max_time % 60)))

        output_steps = []
        if self.metadata['CaImaging']:
            output_steps.append(self.config['STEP_FOR_CA_IMAGING_TRIGGER'])

        self.NIdaq_metadata_init()

        if not self.demoW.isChecked():
            try:
                self.acq = Acquisition(
                    dt=1. / self.metadata['NIdaq-acquisition-frequency'],
                    Nchannel_analog_in=self.
                    metadata['NIdaq-analog-input-channels'],
                    Nchannel_digital_in=self.
                    metadata['NIdaq-digital-input-channels'],
                    max_time=max_time,
                    output_steps=output_steps,
                    filename=self.filename.replace('metadata', 'NIdaq'))
            except BaseException as e:
                print(e)
                print(' /!\ PB WITH NI-DAQ /!\ ')
                self.acq = None

        self.init = True
        if self.stim is not None:
            self.bufferButton.setEnabled(True)
        self.runButton.setEnabled(True)

        self.save_experiment(
            self.metadata)  # saving all metadata after full initialization

        if self.metadata['VisualStim']:
            self.statusBar.showMessage('Acquisition & Stimulation ready !')
        else:
            self.statusBar.showMessage('Acquisition ready !')
Beispiel #4
0
    def initialize(self):

        ### set up all metadata
        self.metadata = {
            'config': self.cbc.currentText(),
            'protocol': self.cbp.currentText(),
            'notes': self.qmNotes.toPlainText(),
            'subject_ID': self.cbs.currentText(),
            'subject_props': self.subjects[self.cbs.currentText()]
        }

        for d in [self.config, self.protocol]:
            if d is not None:
                for key in d:
                    self.metadata[key] = d[key]

        # Setup configuration
        for modality, button in zip([
                'VisualStim', 'Locomotion', 'Electrophy', 'FaceCamera',
                'CaImaging'
        ], [
                self.VisualStimButton, self.LocomotionButton,
                self.ElectrophyButton, self.FaceCameraButton,
                self.CaImagingButton
        ]):
            self.metadata[modality] = bool(button.isChecked())

        if self.cbp.currentText() == 'None':
            self.statusBar.showMessage('[...] initializing acquisition')
        else:
            self.statusBar.showMessage(
                '[...] initializing acquisition & stimulation')

        self.filename = generate_filename_path(
            self.root_datafolder,
            filename='metadata',
            extension='.npy',
            with_FaceCamera_frames_folder=self.metadata['FaceCamera'],
            with_screen_frames_folder=self.metadata['VisualStim'])
        self.datafolder.set(os.path.dirname(self.filename))

        if self.metadata['protocol'] != 'None':
            with open(
                    os.path.join(base_path, 'protocols',
                                 self.metadata['protocol'] + '.json'),
                    'r') as fp:
                self.protocol = json.load(fp)
        else:
            self.protocol = {}

        # init visual stimulation
        if self.metadata['VisualStim'] and len(self.protocol.keys()) > 0:
            self.protocol['screen'] = self.metadata['Screen']
            self.stim = build_stim(self.protocol)
            np.save(
                os.path.join(str(self.datafolder.get()), 'visual-stim.npy'),
                self.stim.experiment)
            print('[ok] Visual-stimulation data saved as "%s"' %
                  os.path.join(str(self.datafolder.get()), 'visual-stim.npy'))
            if 'time_stop' in self.stim.experiment:
                max_time = int(
                    1.5 *
                    self.stim.experiment['time_stop'][-1])  # for security
            else:
                max_time = 1 * 60 * 60  # 1 hour, should be stopped manually
        else:
            max_time = 1 * 60 * 60  # 1 hour, should be stopped manually
            self.stim = None

        output_steps = []
        if self.metadata['CaImaging']:
            output_steps.append(self.config['STEP_FOR_CA_IMAGING_TRIGGER'])

        # --------------- #
        ### NI daq init ###   ## we override parameters based on the chosen modalities if needed
        # --------------- #
        if self.metadata['VisualStim'] and (
                self.metadata['NIdaq-analog-input-channels'] < 1):
            self.metadata['NIdaq-analog-input-channels'] = 1  # at least one
        if self.metadata['Electrophy'] and (
                self.metadata['NIdaq-analog-input-channels'] < 2):
            self.metadata['NIdaq-analog-input-channels'] = 2
        if self.metadata['Locomotion'] and (
                self.metadata['NIdaq-digital-input-channels'] < 2):
            self.metadata['NIdaq-digital-input-channels'] = 2
        try:
            print(max_time)
            self.acq = Acquisition(
                dt=1. / self.metadata['NIdaq-acquisition-frequency'],
                Nchannel_analog_in=self.
                metadata['NIdaq-analog-input-channels'],
                Nchannel_digital_in=self.
                metadata['NIdaq-digital-input-channels'],
                max_time=max_time,
                output_steps=output_steps,
                filename=self.filename.replace('metadata', 'NIdaq'))
        except BaseException as e:
            print(e)
            print(' /!\ PB WITH NI-DAQ /!\ ')
            self.acq = None

        self.init = True
        self.save_experiment()  # saving all metadata after full initialization

        if self.cbp.currentText() == 'None':
            self.statusBar.showMessage('Acquisition ready !')
        else:
            self.statusBar.showMessage('Acquisition & Stimulation ready !')