def __init__(self):
        super(ElectrophysiologyGui, self).__init__()
        uic.loadUi('OPTIMAQS/view/electrophysiology/electrophysiology.ui',
                   self)
        self.show()
        self.import_electrophysiology_model()
        self.initialize_electrophysiology_parameters()
        self.actions()

        ## paths and timings
        self.path = jsonFunctions.open_json(
            'OPTIMAQS/config_files/last_experiment.json')
        self.timings_logfile_path = self.path + '/experiment_' + self.path[
            -1] + '_timings.json'
        self.timings_logfile_dict = {}
        self.timings_logfile_dict['ephy'] = {}
        self.timings_logfile_dict['ephy']['on'] = []
        self.timings_logfile_dict['ephy']['off'] = []
        self.timings_logfile_dict['ephy_stim'] = {}
        self.timings_logfile_dict['ephy_stim']['on'] = []
        self.timings_logfile_dict['ephy_stim']['off'] = []

        ## ephys data
        self.ephy_data = []
        self.end_expe = False
        self.channel_number = [2, 6, 10, 14, 16, 18, 20, 22]
        self.sampling_rate = 1000

        ## timings
        self.perf_counter_init = jsonFunctions.open_json(
            'OPTIMAQS/config_files/perf_counter_init.json')
Example #2
0
    def __init__(self,
                 path=None,
                 path_raw_data=None,
                 info_logfile_path=None,
                 timings_logfile_path=None):
        """
        Initialize the ui and load the camera functions
        """
        super().__init__()

        ## GUI related
        self.camera_ui = uic.loadUi('OPTIMAQS/view/camera/camera.ui', self)

        self.camera_ui.show()

        self.import_camera_model()
        self.initialize_camera_parameters()
        self.actions()
        self.threadpool = QThreadPool()

        self.info_logfile_path = info_logfile_path
        self.timings_logfile_path = timings_logfile_path

        self.path_init = jsonFunctions.open_json(
            'OPTIMAQS/config_files/path_init.json')
        self.path_experiment = jsonFunctions.open_json(
            'OPTIMAQS/config_files/last_experiment.json')
        self.path_raw_data = self.path_experiment + '\\raw_data'
        self.save_images = False
        self.simulated = False
        self.images = []
        self.image_list = []
        self.image_reshaped = []
        self.roi_list = []
        self.times_bis = []

        ## timings
        self.perf_counter_init = jsonFunctions.open_json(
            'OPTIMAQS/config_files/perf_counter_init.json')

        #import camera related log variables. Another way to do that ?
        #        self.info_logfile_path = self.path_experiment + '/experiment_' + \
        #                                 self.path_experiment[-1] + '_info.json'
        self.info_logfile_path = info_logfile_path
        self.info_logfile_dict = {}
        self.info_logfile_dict['roi'] = []
        self.info_logfile_dict['exposure time'] = []
        self.info_logfile_dict['binning'] = []
        self.info_logfile_dict['fov'] = []
        self.info_logfile_dict['fps'] = []
        #        self.timings_logfile_path = self.path_experiment + '/experiment_' + \
        #                                    self.path_experiment[-1] + '_timings.json'
        self.timings_logfile_path = timings_logfile_path
        self.timings_logfile_dict = {}
        self.timings_logfile_dict['camera'] = []
        self.timings_logfile_dict['camera_bis'] = []
Example #3
0
    def __init__(self,
                 path=None,
                 info_logfile_path=None,
                 timings_logfile_path=None):
        """
        GUI for the Digital Light Processor / Digital Micromirror Device
        """
        super(DLPGui, self).__init__()

        ### GUI related
        self.dlp_ui = uic.loadUi('OPTIMAQS/view/dlp/dlp.ui', self)
        self.dlp_ui.show()

        self.path = self.path_experiment = jsonFunctions.open_json(
            'OPTIMAQS/config_files/last_experiment.json')
        self.camera_to_dlp_matrix = []
        self.calibration_dlp_camera_matrix_path = 'C:\\Users\\barral\\Desktop\\whole_optic_gui\\OPTIMAQS\\view\\dlp\\calibration_matrix.json'
        if os.path.isfile(self.calibration_dlp_camera_matrix_path):
            print('Calibration matrix already exists, using it as reference')
            with open(self.calibration_dlp_camera_matrix_path) as file:
                self.camera_to_dlp_matrix = np.array(json.load(file))
        else:
            print('no calibration matrix existing. Need to rerun calibration')
        ## initialize dlp
        self.import_dlp_model()
        self.actions()
        self.initialize_dlp_parameters()

        ## JSON files
        #        self.info_logfile_path = self.path + '/experiment_' + self.path[-1] + '_info.json'
        self.info_logfile_path = info_logfile_path
        self.info_logfile_dict = {}
        self.info_logfile_dict['roi'] = []

        #        self.timings_logfile_path = self.path + '/experiment_' + self.path  [-1] + '_timings.json'
        self.timings_logfile_path = timings_logfile_path
        self.timings_logfile_dict = {}
        self.timings_logfile_dict['dlp'] = {}
        self.timings_logfile_dict['dlp']['on'] = []
        self.timings_logfile_dict['dlp']['off'] = []

        ## timings
        self.perf_counter_init = jsonFunctions.open_json(
            'OPTIMAQS/config_files/perf_counter_init.json')

        ## threads
        self.threadpool = QThreadPool()
 def dlp_hdmi_video_gen(self):
     # getting value from automation gui to create video
     print('generating video for hdmi display')
     duration_of_each_image_stimulus = int(self.duration_of_each_image_stimulus_lineEdit.text())
     time_between_stimulus_image = int(self.time_between_stimulus_image_lineEdit.text())
     
     #TODO: other way to do that? To Simplify and reuse function in dlp_gui ? 
     self.info_logfile_dict = jsonFunctions.open_json(self.info_logfile_path)
     self.roi_list = self.info_logfile_dict['roi']
     self.dlp_gui.generate_one_image_per_roi(self.roi_list)
     self.dlp_gui.movie_from_images(time_stim_image=duration_of_each_image_stimulus, 
                                    inter_image_interval=time_between_stimulus_image)
Example #5
0
    def __init__(self, info_logfile_path=None, timings_logfile_path=None):
        super(LaserGui, self).__init__()
        uic.loadUi('OPTIMAQS/view/laser/laser.ui', self)
        self.show()
        self.import_laser_model()
        self.initialize_laser_parameters()
        self.actions()
        
        self.info_logfile_path = info_logfile_path
        self.timings_logfile_path = timings_logfile_path 
        
        
        self.path = jsonFunctions.open_json('OPTIMAQS/config_files/last_experiment.json')
#        self.timings_logfile_path = self.path + '/experiment_' + self.path[-1] + '_timings.json'
        self.timings_logfile_path = timings_logfile_path
        self.timings_logfile_dict = {}
        self.timings_logfile_dict['laser'] = {}
        self.timings_logfile_dict['laser']['on'] = []
        self.timings_logfile_dict['laser']['off'] = []

        ## timings
        self.perf_counter_init = jsonFunctions.open_json('OPTIMAQS/config_files/perf_counter_init.json')
 def __init__(self, info_logfile_path, timings_logfile_path):
     super(AutomationGui, self).__init__()
     self.automation_ui = uic.loadUi('OPTIMAQS/view/automation/automation.ui', self)
     self.automation_ui.show()
     
     self.actions()
     self.threadpool = QThreadPool()
     
     self.n_experiment = 1
     
     # Init path variables
     if jsonFunctions.find_json('OPTIMAQS/config_files/path_init.json'):
         self.path_init = self.set_main_path_from_config_file()
     else:   
         self.path_init = self.set_main_path_from_user_input()
     
     self.path = jsonFunctions.open_json('OPTIMAQS/config_files/path_init.json')
     self.path_experiment = jsonFunctions.open_json('OPTIMAQS/config_files/last_experiment.json')
     #self.initialize_experiment()
     
     self.info_logfile_path = info_logfile_path
     self.timings_logfile_path = timings_logfile_path 
     
     self.load_modules()
    def load_experiment(self):
        ## experiment json file
        self.path = QFileDialog.getExistingDirectory(None, 'Experiment folder:',
                                                        'C:/', QFileDialog.ShowDirsOnly)[0]
        experiment_path = QFileDialog.getOpenFileName(self, 'Select Experiment file',
                                                        'C:/',"Experiment file (*.json)")[0]
        # experiment_path = '/media/jeremy/Data/Data_Jeremy/2019_10_29/experiment_1/experiment_1_info.json'
        ## load/write camera related stuff
#        with open(experiment_path) as file:
#            self.info_logfile_dict = dict(json.load(file))
        self.info_logfile_dict = jsonFunctions.open_json(self.path)
        self.roi_list = self.info_logfile_dict['roi'][0]
        self.cam.write_exposure(self.info_logfile_dict['exposure time'][0])
        self.cam.write_binning(self.info_logfile_dict['binning'][0])
        self.cam.write_subarray_mode(2)
        self.x_init = self.info_logfile_dict['fov'][0][0]
        self.x_dim = self.info_logfile_dict['fov'][0][1]
        self.y_init = self.info_logfile_dict['fov'][0][2]
        self.y_dim = self.info_logfile_dict['fov'][0][3]
        self.cam.write_subarray_size(self.x_init, self.x_dim, self.y_init, self.y_dim)
Example #8
0
 def set_main_path_from_config_file(self):
     """
     Set the main path of the experiment from the path saved in the
     path_init config file.
     """
     return jsonFunctions.open_json('OPTIMAQS/config_files/path_init.json')
Example #9
0
    def choose_action(self, index, dlp_image_path=None):
        ## Static image mode
        if self.display_mode_combobox.currentIndex() == 0:  ## load image
            if index == 0:  ## choose static image
                if dlp_image_path == None:
                    self.dlp_image_path = QFileDialog.getOpenFileName(
                        self, 'Open file', 'C:/', "Image files (*.jpg *.bmp)")
                    img = Image.open(self.dlp_image_path[0])
                    if img.size == (608, 684):
                        self.dlp.display_static_image(self.dlp_image_path[0])
                        self.dlp.set_display_mode('internal')
                        self.dlp.black()
                    else:
                        warped_image = cv2.warpPerspective(
                            img, self.camera_to_dlp_matrix, (608, 684))
                        warped_flipped_image = cv2.flip(warped_image, 0)
                        cv2.imwrite(self.dlp_image_path[0] + 'warped.bmp',
                                    warped_flipped_image)
                        # self.dlp.display_static_image(self.dlp_image_path[0] + 'warped.bmp')
                else:
                    img = Image.open(dlp_image_path)
                    if img.size == (608, 684):
                        self.dlp.display_static_image(dlp_image_path)
                        self.dlp.set_display_mode('internal')
                        self.dlp.black()
                    else:
                        warped_image = cv2.warpPerspective(
                            img, self.camera_to_dlp_matrix, (608, 684))
                        warped_flipped_image = cv2.flip(warped_image, 0)
                        cv2.imwrite(dlp_image_path + 'warped.bmp',
                                    warped_flipped_image)
                        # self.dlp.display_static_image(self.dlp_image_path[0] + 'warped.bmp')

            elif index == 1:  ##generate static image from ROI
                self.info_logfile_dict = jsonFunctions.open_json(
                    self.info_logfile_path)
                self.roi_list = self.info_logfile_dict['roi']
                black_image = Image.new(
                    '1', (2048, 2048),
                    color=0)  ## 2048 because we want the full fov
                black_image_with_ROI = black_image
                if self.roi_list == []:
                    print('no ROIs in ROI list, make sure to export ROIs')
                else:
                    for nb in range(len(self.roi_list[0])):
                        x0, y0 = (self.roi_list[0][nb]['pos'][0],
                                  self.roi_list[0][nb]['pos'][1])
                        x1, y1 = (self.roi_list[0][nb]['pos'][0] +
                                  self.roi_list[0][nb]['size'][0],
                                  self.roi_list[0][nb]['pos'][1] +
                                  self.roi_list[0][nb]['size'][1])
                        draw = ImageDraw.Draw(black_image_with_ROI)
                        draw.rectangle([(x0, y0), (x1, y1)],
                                       fill="white",
                                       outline=None)
                black_image_with_ROI = black_image_with_ROI.convert(
                    'RGB'
                )  ## for later the warpPerspective function needs a shape of (:,:,3)
                black_image_with_ROI = np.asarray(black_image_with_ROI)
                black_image_with_ROI_warped = cv2.warpPerspective(
                    black_image_with_ROI, self.camera_to_dlp_matrix,
                    (608, 684))

                center = (608 / 2, 684 / 2)
                M = cv2.getRotationMatrix2D(center, 270, 1.0)
                black_image_with_ROI_warped = cv2.warpAffine(
                    black_image_with_ROI_warped, M, (608, 684))

                black_image_with_ROI_warped_flipped = cv2.flip(
                    black_image_with_ROI_warped, 0)
                cv2.imwrite(self.path + '/dlp_images' + '/ROI_warped' + '.bmp',
                            black_image_with_ROI_warped_flipped)

            elif index == 2:  ### display static image
                self.dlp.set_display_mode('static')
                self.timings_logfile_dict['dlp']['on'].append(
                    (time.perf_counter() - self.perf_counter_init) * 1000)

            elif index == 3:  ## display static image on on/off timer set by the user
                worker = Worker(self.dlp_auto_control)
                self.dlp_auto_control.signals.result.connect(self.print_output)
                self.dlp_auto_control.signals.finished.connect(
                    self.thread_complete)
                #dlp_auto_control.signals.progress.connect(self.progress_fn)
                self.threadpool.start(worker)
                self.dlp_signal.finished.emit()
                self.camera_signal.finished.emit()
                self.laser_signal.finished.emit()

        ## Internal test pattern mode
        elif self.display_mode_combobox.currentIndex(
        ) == 1:  ## internal test pattern
            if index == 0:  ## Checkboard small
                self.dlp.checkboard_small()
                self.timings_logfile_dict['dlp']['on'].append(
                    (time.perf_counter() - self.perf_counter_init) * 1000)
            if index == 1:  # Black
                self.dlp.black()
                self.timings_logfile_dict['dlp']['off'].append(
                    (time.perf_counter() - self.perf_counter_init) * 1000)
            if index == 2:  ## White
                self.dlp.white()
                self.timings_logfile_dict['dlp']['on'].append(
                    (time.perf_counter() - self.perf_counter_init) * 1000)
            if index == 3:  ## Green
                self.dlp.green()
                self.timings_logfile_dict['dlp']['on'].append(
                    (time.perf_counter() - self.perf_counter_init) * 1000)
            if index == 4:  ## Blue
                self.dlp.blue()
                self.timings_logfile_dict['dlp']['on'].append(
                    (time.perf_counter() - self.perf_counter_init) * 1000)
            if index == 5:  ## Red
                self.dlp.red()
                self.timings_logfile_dict['dlp']['on'].append(
                    (time.perf_counter() - self.perf_counter_init) * 1000)
            if index == 6:  ## Vertical lines 1
                self.dlp.horizontal_lines_1()
                self.timings_logfile_dict['dlp']['on'].append(
                    (time.perf_counter() - self.perf_counter_init) * 1000)
            if index == 7:  ## Horizontal lines 1
                self.dlp.vertical_lines_1()
                self.timings_logfile_dict['dlp']['on'].append(
                    (time.perf_counter() - self.perf_counter_init) * 1000)
            if index == 8:  ## Vertical lines 2
                self.dlp.horizontal_lines_2()
                self.timings_logfile_dict['dlp']['on'].append(
                    (time.perf_counter() - self.perf_counter_init) * 1000)
            if index == 9:  ## Horizontal lines 2
                self.dlp.vertical_lines_2()
                self.timings_logfile_dict['dlp']['on'].append(
                    (time.perf_counter() - self.perf_counter_init) * 1000)
            if index == 10:  ## Diagonal lines
                self.dlp.diagonal_lines()
                self.timings_logfile_dict['dlp']['on'].append(
                    (time.perf_counter() - self.perf_counter_init) * 1000)
            if index == 11:  ## Grey Ramp Vertical
                self.dlp.grey_ramp_vertical()
                self.timings_logfile_dict['dlp']['on'].append(
                    (time.perf_counter() - self.perf_counter_init) * 1000)
            if index == 12:  ## Grey Ramp Horizontal
                self.dlp.grey_ramp_horizontal()
                self.timings_logfile_dict['dlp']['on'].append(
                    (time.perf_counter() - self.perf_counter_init) * 1000)
            if index == 13:  ## Checkerboard Big
                self.dlp.checkerboard_big()
                self.timings_logfile_dict['dlp']['on'].append(
                    (time.perf_counter() - self.perf_counter_init) * 1000)

        ## HDMI Video Input mode
        elif self.display_mode_combobox.currentIndex(
        ) == 2:  ## HDMI video sequence
            self.info_logfile_dict = jsonFunctions.open_json(
                self.info_logfile_path)
            self.roi_list = self.info_logfile_dict['roi']
            if index == 0:  ## Generate ROI Files and Compile Movie From Images
                self.generate_one_image_per_roi(self.roi_list)
                time.sleep(5)
                self.movie_from_images()
                # self.generate_every_paired_combination_movie(self.roi_list)
            elif index == 1:  ## Choose HDMI Video Sequence
                ## is the screen number working ? neede to test with dlp screen. shouhld work if dlp is screen 1
                run_vlc_worker = Worker(self.run_vlc)
                self.threadpool.start(run_vlc_worker)

        ## Pattern sequence mode
        elif self.display_mode_combobox.currentIndex(
        ) == 3:  ## Pattern sequence
            if index == 0:  # Choose Pattern Sequence To Load
                time_stim, ok = QInputDialog.getInt(
                    self, 'Input Dialog',
                    'Duration of pattern exposition (in µs)'
                )  ## time to be given in microseconds
                image_folder = QFileDialog.getExistingDirectory(
                    self, 'Select Image Folder where DLP images are stored')[0]
                InputTriggerDelay = 0
                AutoTriggerPeriod = 3333334
                ExposureTime = 3333334

            if index == 1:  ## Choose Pattern Sequence to Display
                print(image_folder)
                self.dlp.display_image_sequence(image_folder,
                                                InputTriggerDelay,
                                                AutoTriggerPeriod,
                                                ExposureTime)

            if index == 2:  ## Generate Multiple Images with One ROI Per Image
                self.generate_one_image_per_roi(self.roi_list)