Example #1
0
 def on_login_button_clicked(self):
     #project_valid, username_valid = self.validate_entries()
     tmp = "/mnt/BMIT_data/BMIT-USERS-DATA/"
     if self.project_name != '':
         project_valid = self.validate_entries()
         if project_valid:
             self.login_parameters_dict.update({'bl': self.bl_name})
             self.login_parameters_dict.update(
                 {'project': self.project_name})
             tmp = os.path.join(tmp, self.project_name)
             # add fileExistsError exception later in Py3
             try:
                 os.makedirs(tmp)  #, exist_ok=True)
             except:
                 pass
             self.login_parameters_dict.update({'expdir': tmp})
             self.accept()
         #elif not username_valid:
         #    error_message("Username should be alpha-numeric ")
         elif not project_valid:
             error_message("The project should be in format: CCTNNNNN, \n"
                           "where CC is cycle number, "
                           "T is one-letter type, "
                           "and NNNNN is project number")
     elif self.expdir_name != '':
         if self.validate_dir:
             self.login_parameters_dict.update({'expdir': self.expdir_name})
             self.accept()
         else:
             error_message("Cannot write in the selected directory")
Example #2
0
 def get_outer_motor_grid(self):
     if self.scan_controls_group.outer_steps > 0:
         self.number_of_scans = self.scan_controls_group.outer_steps
         if self.scan_controls_group.outer_loop_endpoint:
             return linspace(
                 self.scan_controls_group.outer_start,
                 self.scan_controls_group.outer_start +
                 self.scan_controls_group.outer_range,
                 self.scan_controls_group.outer_steps)
         else:
             return linspace(
                 self.scan_controls_group.outer_start,
                 self.scan_controls_group.outer_start +
                 self.scan_controls_group.outer_range,
                 self.scan_controls_group.outer_steps, False)
     elif self.scan_controls_group.outer_steps == 0:
         self.number_of_scans = 1
         if self.scan_controls_group.outer_motor != 'Timer [sec]':
             return [
                 self.motors[self.scan_controls_group.outer_motor].position.
                 magnitude
             ]
         else:
             return [0]
     else:
         error_message("Outer motor start/steps/range entered incorrectly ")
         self.abort()
Example #3
0
 def set_camera_params(self):
     self.log.info("Setting camera parameters")
     if self.camera_model_label.text() == 'Dummy camera':
         return -1
     try:
         if self.camera.state == 'recording':
             self.camera.stop_recording()
         self.camera.exposure_time = self.exp_time * q.msec
         if self.camera_model_label.text() == "PCO Dimax":
             self.camera.frame_rate = self.fps * q.hertz
         else:
             self.camera.sensor_pixelrate = int(
                 self.sensor_pix_rate_entry.currentText())
         self.camera.buffered = self.buffered
         if self.camera.buffered:
             self.camera.num_buffers = self.buffnum
         self.set_time_stamp()
         self.setROI()
     except:
         tmp = "Can not set camera parameters"
         self.log.error(tmp)
         error_message(tmp)
         return True
     else:
         return False
Example #4
0
 def fps(self):
     try:
         x = float(self.fps_entry.text())
     except ValueError:
         warning_message("{:}".format(
             "FPS a positive number. Setting FPS based on exp. time"))
         x = self.relate_fps_to_exptime()
     if x < 0:
         error_message("{:}".format("FPS must be positive"))
         self.all_cam_params_correct = False
     if self.camera_model_label.text() == 'PCO Dimax':
         if x < 25:
             warning_message(
                 "{:}".format("Dimax FPS must be greater than 25"))
             x = 25
         if self.trig_mode == "EXTERNAL" and \
                 int(x) < int(1000.0 / (self.exp_time + self.dead_time)):
             warning_message("{:}".format(
                 "Dimax FPS must be greater than frequency of external triggers"
             ))
             x = int(1000.0 / self.exp_time)
     # if self.camera_model_label.text() == 'PCO Edge' and (x > 100):
     #     error_message("{:}".format("PCO Edge max FPS is 100"))
     #     self.all_cam_params_correct = False
     # if int(x) < int(1000.0 / (self.exp_time + self.dead_time)): #because of round of errors
     #     #warning_message("FPS [Hz] cannot exceed 1/exp.time[s]; setting fps=1/exp.time")
     #     self.relate_fps_to_exptime()
     elif self.trig_mode == "EXTERNAL":
         x = self.relate_fps_to_exptime()
     self.fps_entry.setText("{:.02f}".format(x))
     return x
Example #5
0
 def outer_steps(self):
     if self.outer_loop_steps_entry.text() == "":
         return 0
     try:
         return int(self.outer_loop_steps_entry.text())
     except ValueError:
         error_message("Number of steps must be positive integer number")
         return None
Example #6
0
 def run(self):  # .start() calls this function
     while self.thread_running:
         try:
             self.motor.home().join()
             self.thread_running = False
         except TransitionNotAllowed:
             error_message(
                 "Stage is moving. Wait until motion has stopped.")
             self.thread_running = False
Example #7
0
 def set_scan_params(self):
     self.log.info("Setting scan parameters")
     '''To be called before Experiment.run
        to set all parameters required for correct data acquisition'''
     problem_with_params = False
     # SET CAMERA PARAMETER
     if not self.camera_controls_group.ttl_scan.isChecked():
         problem_with_params = self.camera_controls_group.set_camera_params(
         )
     # SET ACQUISITION PARAMETERS
     try:
         # Times as floating point numbers [msec] to compute the CT stage motion
         self.concert_scan.acq_setup.dead_time = self.camera_controls_group.dead_time
         self.concert_scan.acq_setup.exp_time = self.camera_controls_group.exp_time
         # Inner motor and scan intervals
         self.concert_scan.acq_setup.motor = self.motors[
             self.scan_controls_group.inner_motor]
         if self.scan_controls_group.inner_motor == 'CT stage [deg]':
             self.concert_scan.acq_setup.units = q.deg
         self.concert_scan.acq_setup.cont = self.scan_controls_group.inner_cont
         self.concert_scan.acq_setup.start = self.scan_controls_group.inner_start
         self.concert_scan.acq_setup.nsteps = self.scan_controls_group.inner_steps
         self.concert_scan.acq_setup.range = self.scan_controls_group.inner_range
         self.concert_scan.acq_setup.endp = self.scan_controls_group.inner_endpoint
         self.concert_scan.acq_setup.calc_step()
         self.concert_scan.acq_setup.flats_before = self.scan_controls_group.ffc_before
         self.concert_scan.acq_setup.flats_after = self.scan_controls_group.ffc_after
         # SET shutter
         if self.shutter is None:
             self.concert_scan.ffc_setup.shutter = DummyShutter()
         else:
             self.concert_scan.ffc_setup.shutter = self.shutter
     except:
         self.log.error("Scan params defined incorrectly. Aborting")
         info_message(
             "Select flat field motor and define parameters correctly")
         problem_with_params = True
     # SET FFC parameters
     if self.scan_controls_group.ffc_before or self.scan_controls_group.ffc_after or \
             self.scan_controls_group.ffc_before_outer or self.scan_controls_group.ffc_after_outer:
         try:
             self.concert_scan.ffc_setup.flat_motor = self.motors[
                 self.ffc_controls_group.flat_motor]
             self.concert_scan.ffc_setup.radio_position = self.ffc_controls_group.radio_position * q.mm
             self.concert_scan.ffc_setup.flat_position = self.ffc_controls_group.flat_position * q.mm
             self.concert_scan.acq_setup.num_flats = self.ffc_controls_group.num_flats
             self.concert_scan.acq_setup.num_darks = self.ffc_controls_group.num_darks
         except:
             self.log.error(
                 "Flat-field params defined incorrectly. Aborting")
             error_message(
                 "Select flat field motor and define parameters correctly")
             problem_with_params = True
     if problem_with_params:
         self.number_of_scans = 0
         self.end_of_scan()
Example #8
0
 def setROI(self):
     try:
         self.camera.roi_x0 = self.roi_x0 * q.pixels
         self.camera.roi_y0 = self.roi_y0 * q.pixels
         self.camera.roi_width = self.roi_width * q.pixels
         self.camera.roi_height = self.roi_height * q.pixels
     except:
         error_message(
             "ROI is not correctly defined for the sensor, check multipliers and centering"
         )
Example #9
0
 def num_flats(self):
     try:
         tmp = int(self.numflats_entry.text())
     except ValueError:
         error_message('Number of flats must be positive integer number')
     if tmp < 1:
         info_message('Number of flats must be larger than 0')
         self.numflats_entry.setText('10')
         tmp = 10
     return tmp
Example #10
0
 def root_dir(self):
     try:
         tmp = self.root_dir_entry.text()
     except ValueError:
         error_message("Incorrect path to root directory")
     if os.access(tmp, os.W_OK):
         return tmp
     else:
         error_message(
             "Cannot write into root dir. Check filewriter params")
         return None
Example #11
0
 def num_darks(self):
     try:
         tmp = int(self.numdarks_entry.text())
     except ValueError:
         error_message(
             'Number of darks must be non-negative integer number')
     if tmp < 0:
         info_message('Number of darks must be 0 or larger')
         self.numdarks_entry.setText('10')
         tmp = 10
     return tmp
Example #12
0
 def exp_time(self):
     try:
         x = float(self.exposure_entry.text())
     except ValueError:
         error_message("{:}".format(
             "Exp. time must be a positive number. Setting to default"))
         x = 13
         self.all_cam_params_correct = False
     if x < 0:
         error_message(
             "{:}".format("Exp. time must be positive. Setting to default"))
         x = 13
         self.exposure_entry.setText('13')
         self.all_cam_params_correct = False
     if self.camera_model_label.text() == 'PCO Dimax' and (x > 40):
         error_message("{:}".format("Max exp. time for Dimax is 40 msec"))
         self.all_cam_params_correct = False
         x = 39.9999
         self.exposure_entry.setText('39.9999')
     if self.camera_model_label.text() == 'PCO Edge' and (x > 2000):
         error_message("{:}".format("Max exp. time for Edge is 2 sec"))
         x = 1999.9
         self.exposure_entry.setText('1999.9')
         self.all_cam_params_correct = False
     return x
Example #13
0
 def roi_width(self):
     try:
         h = int(self.roi_width_entry.text())
     except ValueError:
         error_message(
             "ROI height must be  positive integer number smaller then {}".
             format(self.camera.sensor_height.magnitude))
     if self.camera_model_label.text() == 'PCO Dimax':
         h = int(h / 4) * 4
         if h > 2000:
             h = 2000
         self.roi_width_entry.setText(str(h))
         return h
     else:
         return h
Example #14
0
 def connect_hor_motor_func(self):
     """Connect to horizontal stage motor."""
     try:
         self.hor_motor = CLSLinear("SMTR1605-2-B10-11:mm", encoded=True)
     except:
         error_message("Can not connect to horizontal stage, try again")
     if self.hor_motor is not None:
         self.hor_mot_value.setText("Position [mm]")
         self.connect_hor_mot_button.setEnabled(False)
         self.move_hor_mot_button.setEnabled(True)
         self.move_hor_rel_plus.setEnabled(True)
         self.move_hor_rel_minus.setEnabled(True)
         self.hor_mot_monitor = EpicsMonitorFloat(self.hor_motor.RBV)
         self.hor_mot_monitor.i0_state_changed_signal.connect(
             self.hor_mot_value.setText)
         self.hor_mot_monitor.i0.run_callback(self.hor_mot_monitor.call_idx)
Example #15
0
 def connect_shutter_func(self):
     """Connect the shutter."""
     try:
         self.shutter = CLSShutter("ABRS1605-01:fis")
     except:
         error_message(
             "Could not connect to fast imaging shutter, try again")
     if self.shutter is not None:
         self.shutter_status.setText("Connected")
         self.connect_shutter_button.setEnabled(False)
         self.open_shutter_button.setEnabled(True)
         self.close_shutter_button.setEnabled(True)
         self.shutter_monitor = EpicsMonitorFIS(self.shutter.STATE,
                                                self.shutter_status)
         self.shutter_monitor.i0_state_changed_signal.connect(
             self.shutter_status.setText)
         self.shutter_monitor.i0.run_callback(self.shutter_monitor.call_idx)
Example #16
0
 def roi_x0(self):
     try:
         h = int(self.roi_x0_entry.text())
     except ValueError:
         if self.camera_model_label.text() == 'PCO Dimax':
             error_message(
                 "ROI height must be positive integer number divisible by 4 and smaller then {:}"
                 .format(996))
         else:
             error_message(
                 "ROI height must be positive integer number smaller then {:}"
                 .format(self.camera.sensor_height.magnitude))
     if self.camera_model_label.text() == 'PCO Dimax':
         h = 1000 - self.roi_width / 2
         self.roi_x0_entry.setText(str(h))
         return h
     else:
         return h
Example #17
0
 def roi_height(self):
     try:
         h = int(self.roi_height_entry.text())
     except ValueError:
         error_message(
             "ROI height must be  positive integer number smaller then {}".
             format(self.camera.sensor_height.magnitude))
     if self.camera_model_label.text() == 'PCO Dimax':
         h = int(h / 4) * 4
         if h > 2000:
             h = 2000
         self.roi_height_entry.setText(str(h))
         return h
     if self.camera_model_label.text() == 'PCO Edge':
         h = int(h / 2) * 2
         if h > 2160:
             h = 2160
         self.roi_y0_entry.setText(str(1080 - int(h / 2)))
         self.roi_height_entry.setText(str(h))
     return h
Example #18
0
 def connect_CT_motor_func(self):
     """Connect to CT stage.
     In this case, ABRS is an air-bearing rotation stage."""
     try:
         self.CT_motor = ABRS("ABRS1605-01:deg", encoded=True)
     except:
         error_message("Could not connect to CT stage, try again")
     if self.CT_motor is not None:
         self.CT_mot_value.setText("Position [deg]")
         self.connect_CT_mot_button.setEnabled(False)
         self.move_CT_mot_button.setEnabled(True)
         self.move_CT_rel_plus.setEnabled(True)
         self.move_CT_rel_minus.setEnabled(True)
         self.home_CT_mot_button.setEnabled(True)
         self.reset_CT_mot_button.setEnabled(True)
         self.CT_vel_select.setEnabled(True)
         self.CT_motor.base_vel = 5 * q.deg / q.sec
         self.CT_mot_monitor = EpicsMonitorFloat(self.CT_motor.RBV)
         self.CT_mot_monitor.i0_state_changed_signal.connect(
             self.CT_mot_value.setText)
         self.CT_mot_monitor.i0.run_callback(self.CT_mot_monitor.call_idx)
Example #19
0
 def run(self):  # .start() calls this function
     while self.thread_running:
         final_pos = self.motor.position
         self.is_moving = True
         try:
             if not hasattr(self.motor, 'timer'):
                 if self.rel_position is None:
                     final_pos = self.position * self.motor.UNITS
                 else:
                     final_pos += (self.rel_position * self.direction *
                                   self.motor.UNITS)
                 self.motor.position = final_pos
             else:
                 sleep(self.position)
             self.is_moving = False
             self.motion_over_signal.emit(True)
             self.thread_running = False
         except TransitionNotAllowed:
             error_message(
                 "Stage is moving. Wait until motion has stopped.")
             self.is_moving = False
             self.thread_running = False
Example #20
0
 def outer_range(self):
     try:
         return float(self.outer_loop_range_entry.text())
     except ValueError:
         error_message("Range must be floating point number")
         return None
Example #21
0
    def load_from_yaml(self):
        fname, _ = QFileDialog.getOpenFileName(
            self, "Select yaml file with BMITgui params",
            self.file_writer_group.root_dir, "Python Files (*.yaml)")

        if fname == '':
            warning_message('Select the file')
            return

        with open(fname) as f:
            p = yaml.load(f, Loader=yaml.FullLoader)

        if p['Camera'][
                'Model'] != self.camera_controls_group.camera_model_label.text(
                ):
            error_message('Selected params file is for different camera')
            return

        try:  ####### CAMERA  #######
            self.camera_controls_group.ttl_scan.setChecked(
                p['Camera']['External camera'])
            self.camera_controls_group.exposure_entry.setText(
                str(p['Camera']['Exposure time']))
            self.camera_controls_group.fps_entry.setText(
                str(p['Camera']['FPS']))
            self.camera_controls_group.roi_y0_entry.setText(
                str(p['Camera']['ROI first column']))
            self.camera_controls_group.roi_width_entry.setText(
                str(p['Camera']['ROI width']))
            self.camera_controls_group.roi_x0_entry.setText(
                str(p['Camera']['ROI first row']))
            self.camera_controls_group.roi_height_entry.setText(
                str(p['Camera']['ROI height']))
            tmp = self.camera_controls_group.buffered_entry.findText(
                str(p['Camera']['Buffered']))
            self.camera_controls_group.buffered_entry.setCurrentIndex(tmp)
            self.camera_controls_group.n_buffers_entry.setText(
                str(p['Camera']['Number of buffers']))
            tmp = self.camera_controls_group.trigger_entry.findText(
                p['Camera']['Trigger'])
            self.camera_controls_group.delay_entry.setText(
                str(p['Camera']['Dead time']))
            self.camera_controls_group.trigger_entry.setCurrentIndex(tmp)
            tmp = self.camera_controls_group.sensor_pix_rate_entry.\
                findText(p['Camera']['Sensor clocking'])
            self.camera_controls_group.sensor_pix_rate_entry.setCurrentIndex(
                tmp)
            self.camera_controls_group.time_stamp.setChecked(
                p['Camera']['Time stamp'])
        except:
            warning_message('Cannot enter all camera parameters correctly')
        try:  ####### Scans' settings #######
            tmp = self.scan_controls_group.outer_loop_motor.\
                findText(p['Outer loop']['Motor'])
            self.scan_controls_group.outer_loop_motor.setCurrentIndex(tmp)
            self.scan_controls_group.outer_loop_start_entry.setText(
                str(p['Outer loop']['Start']))
            self.scan_controls_group.outer_loop_steps_entry.setText(
                str(p['Outer loop']['Steps']))
            self.scan_controls_group.outer_loop_range_entry.setText(
                str(p['Outer loop']['Range']))
            self.scan_controls_group.outer_loop_flats_0.setChecked(
                p['Outer loop']['Flats before'])
            self.scan_controls_group.outer_loop_flats_1.setChecked(
                p['Outer loop']['Flats after'])
            tmp = self.scan_controls_group.inner_loop_motor. \
                findText(p['Inner loop']['Motor'])
            self.scan_controls_group.inner_loop_motor.setCurrentIndex(tmp)
            self.scan_controls_group.inner_loop_start_entry.setText(
                str(p['Inner loop']['Start']))
            self.scan_controls_group.inner_loop_steps_entry.setText(
                str(p['Inner loop']['Steps']))
            self.scan_controls_group.inner_loop_range_entry.setText(
                str(p['Inner loop']['Range']))
            self.scan_controls_group.inner_loop_flats_0.setChecked(
                p['Inner loop']['Flats before'])
            self.scan_controls_group.inner_loop_flats_1.setChecked(
                p['Inner loop']['Flats after'])
            self.scan_controls_group.readout_intheend.setChecked(
                p['Readout in the end']['Readout in the end'])
        except:
            warning_message('Cannot enter scan parameters correctly')
        try:  ####### FFC settings #######
            tmp = self.ffc_controls_group.motor_options_entry.findText(
                p['FFC']['Motor'])
            self.ffc_controls_group.motor_options_entry.setCurrentIndex(tmp)
            self.ffc_controls_group.radio_position_entry.setText(
                p['FFC']['Radio position'])
            self.ffc_controls_group.flat_position_entry.setText(
                p['FFC']['Flat position'])
            self.ffc_controls_group.numflats_entry.setText(
                str(p['FFC']['Num flats']))
            self.ffc_controls_group.numdarks_entry.setText(
                str(p['FFC']['Num darks']))
        except:
            warning_message('Cannot enter flat-field parameters correctly')
        try:  ##### FILE WRITER ########
            self.file_writer_group.setChecked(p['Writer']['Enabled'])
            self.file_writer_group.root_dir_entry.setText(
                p['Writer']['Data dir'])
            self.file_writer_group.ctset_fmt_entry.setText(
                p['Writer']['CT scan name'])
            self.file_writer_group.dsetname_entry.setText(
                p['Writer']['Filename'])
            self.file_writer_group.bigtiff_checkbox.setChecked(
                p['Writer']['Big tiffs'])
            self.file_writer_group.separate_scans_checkbox.setChecked(
                p['Writer']['Separate scans'])
        except:
            warning_message('Cannot enter file-writer settings correctly')
Example #22
0
 def flat_position(self):
     try:
         return float(self.flat_position_entry.text())
     except ValueError:
         error_message(
             'Out-of-beam sample position is not defined correctly')
Example #23
0
 def radio_position(self):
     try:
         return float(self.radio_position_entry.text())
     except ValueError:
         error_message('In-beam sample position is not defined correctly')
Example #24
0
 def connect_time_motor_func(self):
     """Connect to a SimMotor."""
     try:
         self.time_motor = SimMotor(1.0 * q.mm)
     except:
         error_message("Can not connect to timer")
Example #25
0
 def outer_start(self):
     try:
         return float(self.outer_loop_start_entry.text())
     except ValueError:
         error_message("Starting point must be floating point number")
         return None
Example #26
0
 def live_on_func_stream2disk(self):
     if self.fname == None:
         error_message("Select the filename first")
         return
     self.lv_stream2disk_on = True
     self.lv_experiment.run()