Exemplo n.º 1
0
 def __init__(self):
     super(SThread, self).__init__()
     self.lock = Locker()
     self.info = []
     self.img = None
     self.generic_count = 0
     self.final_image_name = None
Exemplo n.º 2
0
 def __init__(self, parent):
     super(CameraQThread, self).__init__()
     self.fan = Fan()
     self.lock = Locker()
     self.parent = parent
     self.conditional = None
     self.text = None
Exemplo n.º 3
0
    def __init__(self):
        self.lock = Locker()
        self.console = ConsoleThreadOutput()
        self.settings = SettingsCamera()
        self.settings.setup_settings()
        self.fan = Fan()

        # Campos da janela principal para as informações da câmera
        self.firmware_field = None
        self.model_field = None

        self.main = Status()
        self.now_plus_10 = datetime.now()
        self.settedhour = datetime.now()
        self.continuousShooterThread = ContinuousShooterThread(
            int(self.settings.get_camera_settings()[4]))
        self.ephemerisShooterThread = EphemerisShooter()

        self.sthread = SThread()

        self.commands = CameraQThread(self)
        self.shooting = False
        # Initiating the Slots
        self.init_slots()

        self.info_ini = []

        info_ini = self.get_camera_settings_ini()
        self.aux_temperature = int(info_ini[0])

        self.temp = 0
        self.temp_contador = 0
        self.temp_contador_manual = 0
Exemplo n.º 4
0
class CameraQThread(QtCore.QThread):
    """
    Threads são fluxos de programas que executam em paralelo dentro de uma aplicação, isto é,
    uma ramificação de uma parte da aplicação que é executada de forma independente e
    escalonada independentemente do fluxo inicial da aplicação.
    Fonte: http://imasters.com.br/artigo/20127/py/threads-em-python/?trace=1519021197&source=single
    Essa thread controla a camera
    """
    connectSignal = QtCore.pyqtSignal()
    disconnectSignal = QtCore.pyqtSignal()
    fanOnSignal = QtCore.pyqtSignal()
    fanOffSignal = QtCore.pyqtSignal()

    def __init__(self, parent):
        super(CameraQThread, self).__init__()
        self.fan = Fan()
        self.lock = Locker()
        self.parent = parent
        self.conditional = None
        self.text = None

    def set_conditional(self, conditional):
        self.conditional = conditional

    def set_text(self, text):
        self.text = text

    def run(self):
        try:
            if self.conditional == cam.CONNECT:
                self.camera_connect()
                self.connectSignal.emit()
            elif self.conditional == cam.DISCONNECT:
                self.disconnectSignal.emit()
            elif self.conditional == cam.FAN_ON:
                self.fanOnSignal.emit()
            elif self.conditional == cam.FAN_OFF:
                self.fanOffSignal.emit()
            else:
                print('Nothing')
        except Exception as e:
            print(e)
        finally:
            self.conditional = None

    def camera_connect(self):
        try:
            self.lock.set_acquire()
            a = open_driver()
            open_deviceusb()
            c = establishinglink()
            if a is True and c is True:
                self.text = "Successfully connected! {} {}".format(a, c)
            else:
                self.text = "Error in connection"
        except Exception as e:
            self.text = 'Failed to connect to camera!\n{}'.format(e)
        finally:
            self.lock.set_release()
Exemplo n.º 5
0
    def __init__(self, parent=None):
        super(SettingsImageWindow, self).__init__(parent)

        # Instance attributes create_image_contrast_group
        self.getlevel1 = None
        self.getlevel1l = None
        self.getlevel2 = None
        self.getlevel2l = None

        # Instance attributes create_crop_group

        self.ignore_crop_l = None
        self.crop_msg = None
        self.crop_xi = None
        self.getcropxi_l = None
        self.crop_xf = None
        self.getcropxf_l = None
        self.crop_yi = None
        self.getcropyi_l = None
        self.crop_yf = None
        self.getcropyf_l = None

        # Instance attributes create_type_image_group
        # self.image_png_l = None
        self.image_tif_l = None
        self.image_fit_l = None

        # Instance attributes create_push_button_group
        self.saveButton = None
        self.cancelButton = None
        self.clearButton = None

        self.image_settings = SettingsImage()

        self.camera = Camera()

        self.console = ConsoleThreadOutput()

        self.image_parent = parent

        self.lock = Locker()

        self.x_pixels, self.y_pixels = self.get_pixels()

        grid = QGridLayout()
        grid.addWidget(self.create_image_contrast_group())
        grid.addWidget(self.create_crop_group())
        grid.addWidget(self.create_type_image_group())
        grid.addWidget(self.create_push_button_group())
        self.setLayout(grid)

        self.setWindowTitle("Imager Box")

        self.setting_values()
Exemplo n.º 6
0
class CameraQThread(QtCore.QThread):
    connectSignal = QtCore.pyqtSignal()
    disconnectSignal = QtCore.pyqtSignal()
    fanOnSignal = QtCore.pyqtSignal()
    fanOffSignal = QtCore.pyqtSignal()

    def __init__(self, parent):
        super(CameraQThread, self).__init__()
        self.fan = Fan()
        self.lock = Locker()
        self.parent = parent
        self.conditional = None
        self.text = None

    def set_conditional(self, conditional):
        self.conditional = conditional

    def set_text(self, text):
        self.text = text

    def run(self):
        try:
            if self.conditional == cam.CONNECT:
                self.camera_connect()
                self.connectSignal.emit()
            elif self.conditional == cam.DISCONNECT:
                self.disconnectSignal.emit()
            elif self.conditional == cam.FAN_ON:
                self.fanOnSignal.emit()
            elif self.conditional == cam.FAN_OFF:
                self.fanOffSignal.emit()
            else:
                print('Nothing')
        except Exception as e:
            print(e)
        finally:
            self.conditional = None

    def camera_connect(self):
        try:
            self.lock.set_acquire()
            a = open_driver()
            open_deviceusb()
            c = establishinglink()
            if a is True and c is True:
                self.text = "Successfully connected! {} {}".format(a, c)
            else:
                self.text = "Error in connection"
        except Exception as e:
            self.text = 'Failed to connect to camera!\n{}'.format(e)
        finally:
            self.lock.set_release()
Exemplo n.º 7
0
class CameraQThread(QtCore.QThread):
    connectSignal = QtCore.pyqtSignal()
    disconnectSignal = QtCore.pyqtSignal()
    fanOnSignal = QtCore.pyqtSignal()
    fanOffSignal = QtCore.pyqtSignal()

    def __init__(self, parent):
        super(CameraQThread, self).__init__()
        self.fan = Fan()
        self.lock = Locker()
        self.parent = parent
        self.conditional = None
        self.text = None

    def set_conditional(self, conditional):
        self.conditional = conditional

    def set_text(self, text):
        self.text = text

    def run(self):
        try:
            if self.conditional == cam.CONNECT:
                self.camera_connect()
                self.connectSignal.emit()
            elif self.conditional == cam.DISCONNECT:
                self.disconnectSignal.emit()
            elif self.conditional == cam.FAN_ON:
                self.fanOnSignal.emit()
            elif self.conditional == cam.FAN_OFF:
                self.fanOffSignal.emit()
            else:
                print("Nothing")
        except Exception as e:
            print(e)
        finally:
            self.conditional = None

    def camera_connect(self):
        try:
            self.lock.set_acquire()
            a = open_driver()
            open_deviceusb()
            c = establishinglink()
            if a is True and c is True:
                self.text = "Successfully connected! {} {}".format(a, c)
            else:
                self.text = "Error in connection"
        except Exception as e:
            self.text = "Failed to connect to camera!\n{}".format(e)
        finally:
            self.lock.set_release()
Exemplo n.º 8
0
class SThread(QtCore.QThread):

    def __init__(self):
        super(SThread, self).__init__()
        self.lock = Locker()
        self.info = []
        self.img = None

    def get_camera_settings(self):
        settings = SettingsCamera()
        info = settings.get_camera_settings()
        return info

    def set_etime_pre_binning(self):
        try:
            info = self.get_camera_settings()
            self.etime = int(info[2])
            self.pre = str(info[1])
            self.b = int(info[3])
        except Exception as e:
            print(e)
            self.etime = 1
            if str(info[1]) != '':
                self.pre = str(info[1])
            else:
                self.pre = 'pre'
            self.b = 2

    def run(self):
        self.set_etime_pre_binning()
        self.lock.set_acquire()
        try:
            self.info = SbigDriver.photoshoot(self.etime * 100, self.pre, self.b)
            self.init_image()
        except Exception as e:
            print(e)
        finally:
            self.lock.set_release()

    def init_image(self):
        try:
            for i in self.info:
                print(i)

            self.img = Image(self.info[0], self.info[1], self.info[2], self.info[3], self.info[4])
        except Exception as e:
            self.img = Image('','','','','')
        return self.img

    def get_image_info(self):
        return self.img
Exemplo n.º 9
0
    def __init__(self):
        super(SThread, self).__init__()
        self.prefix = None
        self.exposure_time = None
        self.binning = None

        self.get_level1 = None
        self.get_level2 = None
        self.get_axis_xi = None
        self.get_axis_xf = None
        self.get_axis_yi = None
        self.get_axis_yf = None
        self.get_ignore_crop = None

        self.console = ConsoleThreadOutput()

        self.get_image_tif = None
        self.get_image_fit = None
        self.get_image_png = None

        self.temperatura = None

        self.eof = EphemObserverFactory()
        self.obs = None

        self.path = None
        self.tempo = None

        self.info_matrix = None
        self.img = None

        self.new_image_name = None

        self.selected_filter = None
        self.dark_or_open = "Closed"
        self.one_photo = None

        self.for_headers_dic = {}

        self.lock = Locker()
        self.info_matrix = []

        self.filter_split_label = None

        self.count_aux = 0
        self.kwargs = None

        self.message_console_one_photo = None

        self.roda_filtros = FilterControl()
Exemplo n.º 10
0
 def __init__(self, parent):
     super(CameraQThread, self).__init__()
     self.fan = Fan()
     self.lock = Locker()
     self.parent = parent
     self.conditional = None
     self.text = None
Exemplo n.º 11
0
    def __init__(self, parent=None):
        super(SettingsCCDInfos, self).__init__(parent)

        # Instance attributes create_ccd_info_group
        self.p = parent
        self.info_port_ccd_l = None
        self.info_port_ccd_f = None
        self.info_camera_model_l = None
        self.info_camera_model_f = None
        self.info_pixel_array_l = None
        self.info_pixel_array_f = None

        # Instance attributes create_ccd_camera_group
        self.close_open = None
        self.temp_set_point_l = None
        self.temp_set_point_f = None
        self.temp_init_l = None
        self.temp_init_f = None
        self.time_between_photos_l = None
        self.time_between_photos_f = None
        self.one_photoButton = None
        self.tempButton = None
        self.fanButton = None

        # Instance attributes create_push_button_group
        self.saveButton = None
        self.cancelButton = None
        self.clearButton = None

        self.imager_window = parent

        self.cam = Camera()

        self.var_save_ini_camera = SettingsCamera()

        self.console = ConsoleThreadOutput()

        self.fan = Fan(self.fanButton)

        self.one_photo = SThread()

        self.lock = Locker()

        self.firmware = "????"
        self.model = "????"
        self.y_pixels = "????"
        self.x_pixels = "????"

        grid = QGridLayout()
        # Additional Parameters (Apparently Useless) 0, 1 | 1, 1 | 2, 1
        grid.addWidget(self.create_ccd_info_group())
        grid.addWidget(self.create_ccd_camera_group())
        grid.addWidget(self.create_push_button_group())
        self.setLayout(grid)
        self.w = grid.geometry().width()
        self.h = grid.geometry().height()

        self.setWindowTitle("Imager Box")
Exemplo n.º 12
0
    def __init__(self):
        self.lock = Locker()
        self.console = ConsoleThreadOutput()
        self.settings = SettingsCamera()
        self.settings.setup_settings()
        self.fan = Fan()

        # Campos da janela principal para as informações da câmera
        self.firmware_field = None
        self.model_field = None
        self.valor_pixels_x = None
        self.valor_pixels_y = None

        self.main = Status()
        self.now_plus = datetime.now()
        self.settedhour = datetime.now()
        """
        executa o modo manual continuousShooterThread
        """
        self.continuousShooterThread = ContinuousShooterThread(
            int(self.settings.get_camera_settings()[4]))
        """
        executa o modo automatico ephemerisShooterThread
        """
        self.ephemerisShooterThread = EphemerisShooter()

        self.sthread = SThread()

        self.commands = CameraQThread(self)
        self.shooting = False
        # Initiating the Slots
        self.init_slots()

        self.info_ini = []
        self.pass_list = [1024, 1024]
        self.pass_list_str = ["1024", "1024"]

        info_ini = self.get_camera_settings_ini()
        self.aux_temperature = int(info_ini[0])

        self.temp = 0
        self.temp_contador = False
        self.temp_contador_manual = False
        self.is_connected = False
Exemplo n.º 13
0
    def __init__(self, parent=None):
        super(SettingsWindow, self).__init__(parent)
        self.cam = SettingsCamera()
        self.camera = Camera()
        self.console = ConsoleThreadOutput()
        self.create_cam_widgets()
        self.p = parent
        self.fan = Fan(self.fanButton)

        self.lock = Locker()

        self.setting_values()

        self.one_photo = SThread()

        self.setLayout(
            set_lvbox(
                set_hbox(self.setField_temperature_label,
                         self.setField_temperature),
                set_hbox(self.pre, self.prel), set_hbox(self.exp, self.expl),
                set_hbox(self.binning, self.combo),
                set_hbox(self.dark, self.close_open),
                set_hbox(self.tempo_fotos_label, self.tempo_fotos),
                set_hbox(self.time_colling_label, self.time_colling),
                set_hbox(self.contrast_msg),
                set_hbox(self.getlevel1, self.getlevel1l, self.getlevel2,
                         self.getlevel2l), set_hbox(self.ignore_crop_l),
                set_hbox(self.crop_msg),
                set_hbox(self.crop_xi, self.getcropxi_l, self.crop_xf,
                         self.getcropxf_l),
                set_hbox(self.crop_yi, self.getcropyi_l, self.crop_yf,
                         self.getcropyf_l), set_hbox(self.image_tif_l),
                set_hbox(self.image_fit_l),
                set_hbox(self.btn_one_photo,
                         self.tempButton,
                         self.fanButton,
                         stretch2=1),
                set_hbox(self.buttonok,
                         self.button_clear,
                         self.buttoncancel,
                         stretch2=1)))
Exemplo n.º 14
0
class TempRegulation(QtWidgets.QWidget):
    lock = Locker()

    def __init__(self, parent=None):
        super(TempRegulation, self).__init__(parent)
        self.cam = Camera()

        self.setBtn = QtWidgets.QPushButton("Set Temp.", self)
        self.setBtn.clicked.connect(self.btn_temperature)

        self.setField = QtWidgets.QLineEdit(self)

        # self.setLayout(set_hbox(self.setBtn, self.setField))

    def btn_temperature(self):
        try:
            value = self.setField.text()
            if value is not '':
                self.cam.set_temperature(float(value))
        except Exception as e:
            print("Exception -> {}".format(e))
Exemplo n.º 15
0
    def __init__(self):
        self.lock = Locker()
        self.console = ConsoleThreadOutput()
        self.settings = SettingsCamera()
        self.settings.setup_settings()
        self.fan = Fan()

        # Campos da janela principal para as informações da câmera
        self.firmware_field = None
        self.model_field = None

        self.main = Status()
        self.settedhour = datetime.now()
        self.continuousShooterThread = ContinuousShooterThread(int(self.settings.get_camera_settings()[4]))
        self.ephemerisShooterThread = EphemerisShooter()

        self.commands = CameraQThread(self)
        self.shooting = False

        # Initiating the Slots
        self.init_slots()

        self.temp = 0
        self.temp_contador = 0
Exemplo n.º 16
0
class SettingsWindow(QtWidgets.QWidget):
    '''
    Cria os campos e espaços no menu settings window
    '''
    def __init__(self, parent=None):
        super(SettingsWindow, self).__init__(parent)
        self.cam = SettingsCamera()
        self.camera = Camera()
        self.console = ConsoleThreadOutput()
        self.create_cam_widgets()
        self.p = parent
        self.fan = Fan(self.fanButton)

        self.lock = Locker()

        self.setting_values()

        self.one_photo = SThread()

        self.setLayout(
            set_lvbox(
                set_hbox(self.setField_temperature_label,
                         self.setField_temperature),
                set_hbox(self.pre, self.prel), set_hbox(self.exp, self.expl),
                set_hbox(self.binning, self.combo),
                set_hbox(self.dark, self.close_open),
                set_hbox(self.tempo_fotos_label, self.tempo_fotos),
                set_hbox(self.time_colling_label, self.time_colling),
                set_hbox(self.contrast_msg),
                set_hbox(self.getlevel1, self.getlevel1l, self.getlevel2,
                         self.getlevel2l), set_hbox(self.ignore_crop_l),
                set_hbox(self.crop_msg),
                set_hbox(self.crop_xi, self.getcropxi_l, self.crop_xf,
                         self.getcropxf_l),
                set_hbox(self.crop_yi, self.getcropyi_l, self.crop_yf,
                         self.getcropyf_l), set_hbox(self.image_tif_l),
                set_hbox(self.image_fit_l),
                set_hbox(self.btn_one_photo,
                         self.tempButton,
                         self.fanButton,
                         stretch2=1),
                set_hbox(self.buttonok,
                         self.button_clear,
                         self.buttoncancel,
                         stretch2=1)))

    def get_camera_settings(self):
        settings = SettingsCamera()
        info = settings.get_camera_settings()
        return info

    def get_pixels(self):
        info = self.get_info_pixels()
        return int(info[-2]), int(info[-1])

    def get_info_pixels(self):
        '''
        Function to get the CCD Info
        This function will return [Pixels]
        '''
        ret = None
        self.lock.set_acquire()
        try:
            ret = tuple(ccdinfo())
        except Exception as e:
            self.console.raise_text(
                "Failed to get camera information.\n{}".format(e))
        finally:
            self.lock.set_release()
        return ret

    def get_values(self):
        return self.cam.get_camera_settings()

    def setting_values(self):
        info = self.get_values()
        self.set_values(info[0], info[1], info[2], info[3], info[4], info[5], info[6], info[7], info[8], info[9],\
                        info[10], info[11], info[12], info[13], info[14], info[15])

    def set_values(self, temperature_camera, prefixo, exposicao, binning, tempo_entre_fotos, time_colling, get_level1,\
                   get_level2, dark_photo, crop_xi, crop_xf, crop_yi, crop_yf, ignore_crop, image_tif, image_fit):
        self.setField_temperature.setText(temperature_camera)
        self.prel.setText(prefixo)
        self.expl.setText(exposicao)

        try:
            b = int(binning)
        except:
            b = 0

        try:
            open_or_close = int(dark_photo)
        except:
            open_or_close = 0

        self.tempo_fotos.setText(tempo_entre_fotos)
        self.time_colling.setText(time_colling)
        self.combo.setCurrentIndex(b)
        self.close_open.setCurrentIndex(open_or_close)

        self.getlevel1l.setText(get_level1)
        self.getlevel2l.setText(get_level2)

        self.getcropxi_l.setText(crop_xi)
        self.getcropxf_l.setText(crop_xf)
        self.getcropyi_l.setText(crop_yi)
        self.getcropyf_l.setText(crop_yf)

        self.ignore_crop_l.setChecked(ignore_crop)

        self.image_tif_l.setChecked(image_tif)
        self.image_fit_l.setChecked(image_fit)

    def create_cam_widgets(self):
        self.setField_temperature_label = QtWidgets.QLabel(
            "CCD Temperature(°C):", self)
        self.setField_temperature_label.setAlignment(QtCore.Qt.AlignRight
                                                     | QtCore.Qt.AlignVCenter)

        self.setField_temperature = QtWidgets.QLineEdit(self)
        self.setField_temperature.setMaximumWidth(100)

        self.pre = QtWidgets.QLabel("Filter Name:", self)
        self.pre.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)

        self.prel = QtWidgets.QLineEdit(self)
        self.prel.setMaximumWidth(100)

        self.exp = QtWidgets.QLabel("Exposure time (s):", self)
        self.exp.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)

        self.expl = QtWidgets.QLineEdit(self)
        self.expl.setMaximumWidth(100)

        self.binning = QtWidgets.QLabel("Binning:", self)
        self.binning.setAlignment(QtCore.Qt.AlignRight
                                  | QtCore.Qt.AlignVCenter)

        self.combo = QtWidgets.QComboBox(self)
        self.combo.setMaximumWidth(100)
        self.fill_combo()

        self.dark = QtWidgets.QLabel("Shutter:", self)
        self.dark.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)

        self.close_open = QtWidgets.QComboBox(self)
        self.close_open.setMaximumWidth(100)
        self.fill_combo_close_open()

        self.tempo_fotos_label = QtWidgets.QLabel("Time Between Images (s):",
                                                  self)
        self.tempo_fotos_label.setAlignment(QtCore.Qt.AlignRight
                                            | QtCore.Qt.AlignVCenter)

        self.tempo_fotos = QtWidgets.QLineEdit(self)
        self.tempo_fotos.setMaximumWidth(100)

        self.time_colling_label = QtWidgets.QLabel("CCD Cooling Time (s):",
                                                   self)
        self.time_colling_label.setAlignment(QtCore.Qt.AlignRight
                                             | QtCore.Qt.AlignVCenter)

        self.time_colling = QtWidgets.QLineEdit(self)
        self.time_colling.setMaximumWidth(100)

        self.contrast_msg = QtWidgets.QLabel("Image Contrast:", self)
        self.getlevel1 = QtWidgets.QLabel("Bottom Level:", self)
        self.getlevel1.setAlignment(QtCore.Qt.AlignRight
                                    | QtCore.Qt.AlignVCenter)

        self.getlevel1l = QtWidgets.QLineEdit(self)
        self.getlevel1l.setMaximumWidth(50)

        self.getlevel2 = QtWidgets.QLabel("Top Level:", self)
        self.getlevel2.setAlignment(QtCore.Qt.AlignRight
                                    | QtCore.Qt.AlignVCenter)

        self.getlevel2l = QtWidgets.QLineEdit(self)
        self.getlevel2l.setMaximumWidth(50)

        self.ignore_crop_l = QtWidgets.QCheckBox('Ignore Crop Image', self)

        self.crop_msg = QtWidgets.QLabel("Crop Image", self)
        self.crop_xi = QtWidgets.QLabel("Width: Wi:", self)
        self.crop_xi.setAlignment(QtCore.Qt.AlignRight
                                  | QtCore.Qt.AlignVCenter)

        self.getcropxi_l = QtWidgets.QLineEdit(self)
        self.getcropxi_l.setMaximumWidth(50)

        self.crop_xf = QtWidgets.QLabel("Wf:", self)
        self.crop_xf.setAlignment(QtCore.Qt.AlignRight
                                  | QtCore.Qt.AlignVCenter)

        self.getcropxf_l = QtWidgets.QLineEdit(self)
        self.getcropxf_l.setMaximumWidth(50)

        self.crop_yi = QtWidgets.QLabel("Height: Hi:", self)
        self.crop_yi.setAlignment(QtCore.Qt.AlignRight
                                  | QtCore.Qt.AlignVCenter)

        self.getcropyi_l = QtWidgets.QLineEdit(self)
        self.getcropyi_l.setMaximumWidth(50)

        self.crop_yf = QtWidgets.QLabel("Hf:", self)
        self.crop_yf.setAlignment(QtCore.Qt.AlignRight
                                  | QtCore.Qt.AlignVCenter)

        self.getcropyf_l = QtWidgets.QLineEdit(self)
        self.getcropyf_l.setMaximumWidth(50)

        self.image_tif_l = QtWidgets.QCheckBox('Image .tif', self)

        self.image_fit_l = QtWidgets.QCheckBox('Image .fit', self)

        self.button_clear = QtWidgets.QPushButton('Clear', self)
        self.button_clear.clicked.connect(self.clear_all)

        self.btn_one_photo = QtWidgets.QPushButton('Take Photo', self)
        self.btn_one_photo.clicked.connect(self.camera.start_one_photo)

        self.tempButton = QtWidgets.QPushButton("Set Temp", self)
        self.tempButton.clicked.connect(self.btn_temperature)

        self.fanButton = QtWidgets.QPushButton("Fan (On/Off)")
        self.fanButton.clicked.connect(self.button_fan_func)

        self.buttonok = QtWidgets.QPushButton("Save", self)
        self.buttonok.clicked.connect(self.button_ok_func)

        self.buttoncancel = QtWidgets.QPushButton("Cancel", self)
        self.buttoncancel.clicked.connect(self.func_cancel)

    def button_ok_func(self):
        try:
            y_pixels, x_pixels = self.get_pixels()

            # Saving the Settings
            if int(self.getcropxi_l.text()) > int(self.getcropxf_l.text()) or\
                            int(self.getcropyi_l.text()) > int(self.getcropyf_l.text()) or\
                            int(self.getcropxf_l.text()) >= x_pixels/(int(self.combo.currentIndex() + 1)) or \
                            int(self.getcropyf_l.text()) >= y_pixels/(int(self.combo.currentIndex() + 1)):
                self.console.raise_text("Wrong values for image crop.", 3)
            else:
                self.cam.set_camera_settings(self.setField_temperature.text(),
                                             self.time_colling.text(),
                                             self.tempo_fotos.text())
                self.cam.save_settings()
                self.console.raise_text("Camera settings successfully saved!",
                                        1)
                """
                self.setField_temperature.text(), self.prel.text(), self.expl.text(),
                self.combo.currentIndex(), self.tempo_fotos.text(), self.time_colling.text(),
                self.getlevel1l.text(), self.getlevel2l.text(), self.close_open.currentIndex(),
                self.getcropxi_l.text(), self.getcropxf_l.text(),
                self.getcropyi_l.text(), self.getcropyf_l.text(),
                self.ignore_crop_l.isChecked(),
                self.image_tif_l.isChecked(),
                self.image_fit_l.isChecked()
                """
        except Exception as e:
            self.console.raise_text("Camera settings were not saved.", 3)

    def clear_all(self):
        self.setField_temperature.clear()
        self.prel.clear()
        self.expl.clear()
        self.tempo_fotos.clear()

    def take_one_photo(self):
        try:
            info = self.get_camera_settings()
            if int(info[8]) == 1:
                self.console.raise_text("Taking dark photo", 1)
                self.one_photo.start()
            else:
                self.console.raise_text("Taking photo", 1)
                self.one_photo.start()
        except Exception:
            self.console.raise_text("Not possible taking photo", 1)

    def func_cancel(self):
        self.p.close()

    def button_fan_func(self):
        if getlinkstatus() is True:
            try:
                self.fan.set_fan()
                self.console.raise_text('State changed Fan!', 2)
            except Exception:
                self.console.raise_text("The camera is not connected!", 3)
                self.console.raise_text('State Fan unchanged', 3)
        else:
            self.console.raise_text("The camera is not connected!", 3)
            self.console.raise_text('State Fan unchanged', 3)

    def fill_combo(self):
        self.combo.addItem("1x1", 0)
        self.combo.addItem("2x2", 1)
        self.combo.addItem("3x3", 2)

    def fill_combo_close_open(self):
        self.close_open.addItem("Open", 0)
        self.close_open.addItem("Close", 1)

    def btn_temperature(self):
        try:
            value = self.setField_temperature.text()
            if value is '':
                pass
            else:
                self.camera.set_temperature(float(value))
        except Exception as e:
            print("Exception -> {}".format(e))
Exemplo n.º 17
0
 def __init__(self):
     self.lock = Locker()
     self.console = ConsoleThreadOutput()
Exemplo n.º 18
0
    def __init__(self, parent=None):
        super(SettingsCCDInfos, self).__init__(parent)

        # Instance attributes create_filter_wheel_info_group
        self.serial_filter_wheel_info_l = None
        self.serial_filter_wheel_info_f = None
        self.tempt_filter_wheel_info_l = None
        self.tempt_filter_wheel_info_f = None
        self.slots_filter_wheel_info_l = None
        self.slots_filter_wheel_info_f = None

        # Instance attributes create_filter_wheel_group
        self.shutter_l = None
        self.close_open_filter_wheel = None
        self.close_open_filter_wheel_info = None
        self.btn_set_shutter = None
        self.get_filter_l = None
        self.filter_position = None
        self.btn_set_filter = None
        self.set_filter_position = None
        self.btn_home_position_filter = None

        # Instance attributes create_ccd_info_group
        self.info_port_ccd_l = None
        self.info_port_ccd_f = None
        self.info_camera_model_l = None
        self.info_camera_model_f = None
        self.info_pixel_array_l = None
        self.info_pixel_array_f = None

        # Instance attributes create_ccd_camera_group
        self.close_open = None
        self.temp_set_point_l = None
        self.temp_set_point_f = None
        self.temp_init_l = None
        self.temp_init_f = None
        self.one_photoButton = None
        self.tempButton = None
        self.fanButton = None

        # Instance attributes create_push_button_group
        self.saveButton = None
        self.cancelButton = None
        self.clearButton = None

        self.select_filter_manual = 1
        self.select_filter_shutter = "Closed"

        self.imager_window = parent

        self.cam = Camera()

        self.roda_filtros = FilterControl()

        self.var_save_ini_camera = SettingsCamera()

        self.console = ConsoleThreadOutput()

        self.fan = Fan(self.fanButton)

        self.one_photo = SThread()

        self.lock = Locker()

        self.firmware = "????"
        self.model = "????"
        self.y_pixels = "????"
        self.x_pixels = "????"

        grid = QGridLayout()
        grid.addWidget(self.create_filter_wheel_info_group(), 0, 0)
        grid.addWidget(self.create_filter_wheel_group(), 1, 0)
        grid.addWidget(self.create_ccd_info_group(), 0, 1)
        grid.addWidget(self.create_ccd_camera_group(), 1, 1)
        grid.addWidget(self.create_push_button_group(), 2, 1)
        self.setLayout(grid)

        self.button_settings()

        self.setWindowTitle("Imager Box")
        self.resize(500, 340)
        self.info_cam()
Exemplo n.º 19
0
 def __init__(self):
     super(SThread, self).__init__()
     self.lock = Locker()
     self.info = []
     self.img = None
Exemplo n.º 20
0
Arquivo: fan.py Projeto: hiyoku/ccd10
class Fan(metaclass=Singleton):

    def __init__(self):
        self.lock = Locker()
        self.console = ConsoleThreadOutput()

    def set_fanField(self, fanField):
        self.fanField = fanField

    def fan_status(self):
        # Acquiring the Lock
        self.lock.set_acquire()
        status = True

        try:
            # Doing requisition to Driver
            status = SbigDriver.is_fanning()
        except Exception as e:
            self.console.raise_text("Error acquiring the status of Fan.\n{}".format(e))

        # Release the Lock
        self.lock.set_release()

        return "ON" if status else "OFF"

    def refresh_fan_status(self):
        self.fanField.setText(self.fan_status())

    def set_fan(self):
        t = Thread(target=self.s_fan)
        t.start()

    def s_fan(self):
        self.lock.set_acquire()
        try:
            if SbigDriver.is_fanning():
                SbigDriver.stop_fan()
                self.fanField.setText('Fan Off')
            else:
                SbigDriver.start_fan()
                self.fanField.setText('Fan On')
        except Exception as e:
            self.console.raise_text("Error off/on the Fan.\n{}".format(e))
        finally:
            self.lock.set_release()
            self.fanField.setText(self.fan_status())

    def set_fan_off(self):
        self.lock.set_acquire()
        try:
            SbigDriver.stop_fan()
        except Exception as e:
            self.console.raise_text("Error off/on the Fan.\n{}".format(e))
        finally:
            self.lock.set_release()
            self.fanField.setText(self.fan_status())

    def set_fan_on(self):
        self.lock.set_acquire()
        try:
            SbigDriver.start_fan()
        except Exception as e:
            self.console.raise_text("Error off/on the Fan.\n{}".format(e))
        finally:
            self.lock.set_release()
            self.fanField.setText(self.fan_status())
Exemplo n.º 21
0
class SThread(QtCore.QThread):
    """
    Threads são fluxos de programas que executam em paralelo dentro de uma aplicação, isto é,\
    uma ramificação de uma parte da aplicação que é executada de forma independente e\
    escalonada independentemente do fluxo inicial da aplicação.
    Fonte: http://imasters.com.br/artigo/20127/py/threads-em-python/?trace=1519021197&source=single
    """
    def __init__(self):
        super(SThread, self).__init__()
        self.prefix = None
        self.exposure_time = None
        self.binning = None

        self.get_level1 = None
        self.get_level2 = None
        self.get_axis_xi = None
        self.get_axis_xf = None
        self.get_axis_yi = None
        self.get_axis_yf = None
        self.get_ignore_crop = None

        self.console = ConsoleThreadOutput()

        self.get_image_tif = None
        self.get_image_fit = None
        self.get_image_png = None

        self.temperatura = None

        self.eof = EphemObserverFactory()
        self.obs = None

        self.path = None
        self.tempo = None

        self.info_matrix = None
        self.img = None

        self.new_image_name = None

        self.selected_filter = None
        self.dark_or_open = "Closed"
        self.one_photo = None

        self.for_headers_dic = {}

        self.lock = Locker()
        self.info_matrix = []

        self.filter_split_label = None

        self.count_aux = 0
        self.kwargs = None

        self.message_console_one_photo = None

        self.roda_filtros = FilterControl()

    def set_config_take_image(self):
        """
        seta as configuracoes para se tirar uma foto
        """
        try:
            info_cam = get_camera_settings()
            self.for_headers_dic['Set Temperature'] = info_cam[0]
            self.for_headers_dic['????Tempo de espera'] = info_cam[1]

            info_image = get_image_settings()

            try:
                self.get_level1 = float(info_image[0])
            except Exception as e:
                # print("self.get_level1 = 0.1 -> {}".format(e))
                self.get_level1 = 0.1

            try:
                self.get_level2 = float(info_image[1])
            except Exception as e:
                # print("self.get_level2 = 0.99 -> {}".format(e))
                self.get_level2 = 0.99

            try:
                self.get_axis_xi = float(info_image[2])
            except Exception as e:
                # print("self.get_axis_xi = 0 -> {}".format(e))
                self.get_axis_xi = 0

            try:
                self.get_axis_xf = float(info_image[3])
            except Exception as e:
                # print("self.get_axis_xf = 0 -> {}".format(e))
                self.get_axis_xf = 0

            try:
                self.get_axis_yi = float(info_image[4])
            except Exception as e:
                # print("self.get_axis_yi = 0 -> {}".format(e))
                self.get_axis_yi = 0

            try:
                self.get_axis_yf = float(info_image[5])
            except Exception as e:
                # print("self.get_axis_yf = 0 -> {}".format(e))
                self.get_axis_yf = 0

            try:
                self.get_ignore_crop = info_image[6]
            except Exception as e:
                print("self.get_ignore_crop = True -> {}".format(e))
                self.get_ignore_crop = True

            try:
                self.get_image_png = info_image[7]
            except Exception as e:
                print("self.get_image_png  = True -> {}".format(e))
                self.get_image_png = True

            try:
                self.get_image_tif = info_image[8]
            except Exception as e:
                print("self.get_image_tif = True -> {}".format(e))
                self.get_image_tif = True

            try:
                self.get_image_fit = info_image[9]
            except Exception as e:
                print("self.get_image_fit = True -> {}".format(e))
                self.get_image_fit = True

            try:
                self.filter_split_label = get_filter_settings()
            except Exception as e:
                print("get_filter_settings() -> {}".format(e))

            try:
                self.append_camera_settings()
            except Exception as e:
                print(
                    "self.append_camera_settings() in set_config_take_image -> {}"
                    .format(e))

        except Exception as e:
            print("Try ini definitive -> {}".format(e))

    def recebe_argumento(self, kwargs):
        self.kwargs = kwargs

    def args_one_photo(self, filter_args, kwargs):
        self.selected_filter = filter_args
        if kwargs == "Closed":
            self.kwargs = 1
        else:
            self.kwargs = 0
        self.one_photo = True

    def run(self):
        if self.kwargs == 0:
            try:
                self.create_image_open()
            except Exception as e:
                print("self.create_image_open() -> {}".format(e))
        else:
            try:
                self.create_image_close()
            except Exception as e:
                print("self.create_image_close() -> {}".format(e))

    def create_image_open(self):
        self.roda_filtros.open_shutter()
        self.set_config_take_image()
        self.lock.set_acquire()

        my_list = get_wish_filters_settings()  # list of schedule

        try:
            if self.count_aux < len(my_list):
                if self.one_photo:
                    index_of_dic = self.selected_filter
                else:
                    index_of_dic = str(my_list[self.count_aux])
                self.valores_principais_wish_filter(index_of_dic)
                self.count_aux += 1

            else:
                self.count_aux = 0
                if self.one_photo:
                    index_of_dic = self.selected_filter
                else:
                    index_of_dic = str(my_list[self.count_aux])
                self.valores_principais_wish_filter(index_of_dic)
                self.count_aux += 1

        except Exception as e:
            print("Try filter ini -> {}".format(e))

        project_infos = get_project_settings()

        name_observatory = project_infos[2][1]

        self.path, self.tempo = set_path()

        self.new_image_name = str(
            self.prefix) + "_" + str(name_observatory) + "_" + str(self.tempo)

        new_image_name = self.path + str(self.new_image_name)

        try:
            self.info_matrix = SbigDriver.photoshoot(self.exposure_time,
                                                     self.binning, 0)
        except Exception as e:
            print("self.info_matrix = SbigDriver.photoshoot ERROR -> " +
                  str(e))

        self.for_headers_dic['Open or close shutter'] = "OPEN"

        self.save_image_format(new_image_name)

        self.for_headers_dic = {}
        self.one_photo = False
        self.init_image()
        self.lock.set_release()

    def create_image_close(self):
        self.roda_filtros.close_shutter()

        my_list = get_wish_filters_settings()  # list of schedule
        my_list = set(my_list)
        my_list = sorted(my_list)
        count_aux = 0

        while count_aux < len(my_list):
            self.set_config_take_image()
            self.lock.set_acquire()

            if self.one_photo:
                index_of_dic = self.selected_filter
                count_aux = 100
            else:
                index_of_dic = str(my_list[count_aux])

            self.valores_principais_wish_filter(index_of_dic)

            project_infos = get_project_settings()

            name_observatory = project_infos[2][1]

            self.path, self.tempo = set_path()

            self.new_image_name = "DARK-" + str(
                self.prefix) + "_" + str(name_observatory) + "_" + str(
                    self.tempo)

            new_image_name = self.path + str(self.new_image_name)

            try:
                self.info_matrix = SbigDriver.photoshoot(
                    self.exposure_time, self.binning, 1)
            except Exception as e:
                print("self.info_matrix = SbigDriver.photoshoot ERROR -> " +
                      str(e))

            self.for_headers_dic['Open or close shutter'] = "CLOSED"

            self.save_image_format(new_image_name)

            self.for_headers_dic = {}
            count_aux += 1
            self.init_image()
            self.lock.set_release()

            self.one_photo = False

    def filter_wheel_control(self, wish_filter_int):
        try:
            sleep(1)
            wish_filter_int = int(wish_filter_int)
            self.roda_filtros.filter_wheel_control(wish_filter_int)
            sleep(1)
        except Exception as e:
            self.roda_filtros.home_reset()
            print(e)

    def save_image_format(self, new_image_name):
        if not os.path.isdir(self.path):
            os.makedirs(self.path)

        if self.one_photo:
            print(self.path)

        self.for_headers_dic['Start Time'] = self.tempo

        try:
            self.temperatura = SbigDriver.get_temperature()
            self.temperatura = "{0:.2f}".format(float(self.temperatura[3]))
            # self.temperatura = "25"
            self.for_headers_dic['Temperature'] = self.temperatura
        except Exception as e:
            print("Exception self.temperatura -> {}".format(e))
            self.for_headers_dic['Temperature'] = "???"

        if self.get_image_png:
            try:
                save_png(self.info_matrix, new_image_name,
                         self.for_headers_dic)
            except Exception as e:
                print("Exception save_png() -> {}".format(e))
        if self.get_image_tif:
            try:
                save_tif(self.info_matrix, new_image_name)
                if self.one_photo:
                    print(new_image_name)
            except Exception as e:
                print("Exception save_tif() -> {}".format(e))
        if self.get_image_fit:
            try:
                save_fit(self.info_matrix, new_image_name,
                         self.for_headers_dic)
            except Exception as e:
                print("Exception save_fit() -> {}".format(e))
        if not self.get_image_fit and not self.get_image_tif and not self.get_image_fit:
            try:
                save_png(self.info_matrix, new_image_name,
                         self.for_headers_dic)
            except Exception as e:
                print("Exception save_png() -> {}".format(e))

    def valores_principais_wish_filter(self, index_of_dic):
        aux = self.filter_split_label[str(index_of_dic)][0]

        aux = list(aux)
        '''
        aux[0] = self.prefix
        aux[2] = self.exposure_time
        aux[3] = self.binning
        aux[4] = wish filter
        '''

        self.prefix = str(aux[0])

        self.exposure_time = float(aux[2])
        if self.exposure_time <= 0.12:
            self.exposure_time = 0.12 * 100
        elif self.exposure_time >= 3600:
            self.exposure_time = 3600 * 100
        else:
            self.exposure_time = float(aux[2]) * 100
        self.exposure_time = int(self.exposure_time)

        self.binning = int(aux[3])

        self.filter_wheel_control(int(aux[4]))

        self.append_filters_settings(aux)

    def append_camera_settings(self):
        try:
            project_infos = get_project_settings()

            try:
                self.obs = self.eof.create_observer(
                    longitude=project_infos[0][1],
                    latitude=project_infos[0][0],
                    elevation=project_infos[1][0])

                now_datetime = datetime.utcnow()
                self.obs.date = ephem.date(now_datetime)

                sun = ephem.Sun(self.obs)

                moon = ephem.Moon(self.obs)
                frac = moon.moon_phase

                sun_alt = ephem.degrees(sun.alt)
                moon_alt = ephem.degrees(moon.alt)

                sun_elevation = "{:.2f}".format(float(math.degrees(sun_alt)))
                moon_elevation = "{:.2f}".format(float(math.degrees(moon_alt)))
                moon_phase = "{0:.2f}".format(frac * 100)
            except Exception as e:
                print("ephem update -> {}".format(e))

            self.for_headers_dic['Latitude'] = str(project_infos[0][0])
            self.for_headers_dic['Longitude'] = str(project_infos[0][1])
            self.for_headers_dic['Elevation(m)'] = str(project_infos[0][2])
            self.for_headers_dic['Pressure(mb)'] = str(project_infos[0][3])
            self.for_headers_dic['Sun Elevation'] = str(sun_elevation)
            self.for_headers_dic['Ignore Lunar Position'] = str(
                project_infos[1][1])
            self.for_headers_dic['Moon Elevation'] = str(moon_elevation)
            self.for_headers_dic['Moon Phase'] = str(moon_phase)
            self.for_headers_dic['Name'] = str(project_infos[2][0])
            self.for_headers_dic['Observatory'] = str(project_infos[2][1])
            self.for_headers_dic['Imager ID'] = str(project_infos[2][2])
            self.for_headers_dic['get_level1'] = str(self.get_level1)
            self.for_headers_dic['get_level2'] = str(self.get_level2)
            self.for_headers_dic['get_axis_xi'] = str(self.get_axis_xi)
            self.for_headers_dic['get_axis_xf'] = str(self.get_axis_xf)
            self.for_headers_dic['get_axis_yi'] = str(self.get_axis_yi)
            self.for_headers_dic['get_axis_yf'] = str(self.get_axis_yf)
            self.for_headers_dic['get_ignore_crop'] = str(self.get_ignore_crop)
        except Exception as e:
            print("run append_camera_settings() -> {}".format(e))

    def append_filters_settings(self, aux):
        try:
            self.for_headers_dic['Filter Label'] = str(aux[0])
            self.for_headers_dic['Filter Wavelength'] = str(aux[1])
            self.for_headers_dic['Exposure'] = str(self.exposure_time)
            self.for_headers_dic['Binning'] = str(aux[3])
            self.for_headers_dic['Filter Position'] = str(aux[4])
        except Exception as e:
            print("run append_filters_settings() -> {}".format(e))

    def get_new_image_name(self, local_name_image):
        self.console.raise_text(
            "Image saved in " + str(local_name_image) + ".png", 1)

    def init_image(self):
        try:
            print("\nAAAAAAAAAAAAAAAAAAAAAA\n")
            # for i in self.info_matrix:
            #     print(i)
            self.img = Image(self.path, self.new_image_name)
        except Exception as e:
            print("Image('', '') -> {}".format(e))
            self.img = Image('', '')
        return self.img

    def get_image_info(self):
        return self.img
Exemplo n.º 22
0
class Camera(metaclass=Singleton):
    '''
        classe de controle que faz comunicao com a camera fisica.
    '''
    def __init__(self):
        self.lock = Locker()
        self.console = ConsoleThreadOutput()
        self.settings = SettingsCamera()
        self.settings.setup_settings()
        self.fan = Fan()

        # Campos da janela principal para as informações da câmera
        self.firmware_field = None
        self.model_field = None
        self.valor_pixels_x = None
        self.valor_pixels_y = None

        self.main = Status()
        self.now_plus = datetime.now()
        self.settedhour = datetime.now()
        """
        executa o modo manual continuousShooterThread
        """
        self.continuousShooterThread = ContinuousShooterThread(
            int(self.settings.get_camera_settings()[4]))
        """
        executa o modo automatico ephemerisShooterThread
        """
        self.ephemerisShooterThread = EphemerisShooter()

        self.sthread = SThread()

        self.commands = CameraQThread(self)
        self.shooting = False
        # Initiating the Slots
        self.init_slots()

        self.info_ini = []
        self.pass_list = [1024, 1024]
        self.pass_list_str = ["1024", "1024"]

        info_ini = self.get_camera_settings_ini()
        self.aux_temperature = int(info_ini[0])

        self.temp = 0
        self.temp_contador = False
        self.temp_contador_manual = False
        self.is_connected = False

    def init_slots(self):
        """
        Ephemeris Shooter Slots
        """
        self.ephemerisShooterThread.started.connect(self.eshooter_started)
        self.ephemerisShooterThread.finished.connect(self.eshooter_finished)
        self.ephemerisShooterThread.signal_started_shooting.connect(
            self.shooter_mode)
        self.ephemerisShooterThread.signal_temp.connect(self.check_temp)
        self.ephemerisShooterThread.continuousShooterThread.signal_temp.connect(
            self.check_temp)

        self.ephemerisShooterThread.continuousShooterThread.started.connect(
            self.eshooter_observation_started)
        self.ephemerisShooterThread.continuousShooterThread.finished.connect(
            self.eshooter_observation_finished)
        """
        Criando connect da temperatura
        """
        # self.ephemerisShooterThread.continuousShooterThread.signalAfterShooting.connect()
        self.continuousShooterThread.signal_temp.connect(
            self.check_temp_manual)
        self.continuousShooterThread.finished.connect(self.standby_mode)

        # Camera Commands Slots
        self.commands.finished.connect(self.eita)
        self.commands.connectSignal.connect(self.connect_mainwindow_update)

    def get_firmware_and_model_and_pixels(self):
        info = self.get_info()
        return str(info[0]), str(info[2])[2:len(str(info[2])) - 1], str(
            info[-2]), str(info[-1])

    def get_model_and_pixels_new(self):
        return self.model_field.text(), self.valor_pixels_x.text(
        ), self.valor_pixels_y.text()

    def set_firmware_and_model_fields(self, modelField, X_Pixels, Y_Pixels):
        # self.firmware_field = firmwareField
        self.model_field = modelField
        self.valor_pixels_x = X_Pixels
        self.valor_pixels_y = Y_Pixels

    def set_firmware_and_model_values(self):
        firmware, model, y_pixels, x_pixels = self.get_firmware_and_model_and_pixels(
        )
        # self.firmware_field.setText("Firmware: " + firmware)
        self.model_field.setText("Camera: " + model)
        self.valor_pixels_x.setText(x_pixels + "       X ")
        self.valor_pixels_y.setText(y_pixels + " Pixels")
        self.pass_list = [
            int(self.valor_pixels_x.text().split(" ")[0]),
            int(self.valor_pixels_y.text().split(" ")[0])
        ]
        self.pass_list_str = [
            self.valor_pixels_x.text().split(" ")[0],
            self.valor_pixels_y.text().split(" ")[0]
        ]

    def clear_firmware_and_model_values(self):
        # self.firmware_field.setText("Firmware: ")
        self.model_field.setText("Camera: ")

    def get_info(self):
        '''
        Function to get the CCD Info
        This function will return [CameraFirmware, CameraType, CameraName, Pixels]
        '''
        ret = None
        self.lock.set_acquire()
        try:
            ret = tuple(ccdinfo())
        except Exception as e:
            self.console.raise_text(
                "Failed to get camera information.\n{}".format(e))
        finally:
            self.lock.set_release()
        return ret

    def connect(self):
        try:
            a = open_driver()
            open_deviceusb()
            c = establishinglink()
            if a is True and c is True:
                self.console.raise_text("Open Device = {}".format(a), 2)
                time.sleep(1)
                # self.console.save_log("Open Device = {}".format(a))
                self.console.raise_text("Established Link = {}".format(c), 2)
                time.sleep(1)
                # self.console.save_log("Established Link = {}".format(c))
                self.console.raise_text("Successfully connected!", 2)
                time.sleep(1)
                # self.console.save_log("Successfully connected!")
                self.set_firmware_and_model_values()
                self.is_connected = True
                '''
                Fan Field sera atualizado automaticamente
                atualizado pela thread de refresh temp.
                '''
                # self.fan.refresh_fan_status()
                return True
            else:
                self.is_connected = False
                self.console.raise_text("Connection error", 3)

        except Exception as e:
            self.is_connected = False
            self.console.raise_text(
                'Failed to connect the camera!\n{}'.format(e), 3)

        return False

    def disconnect(self):
        try:
            self.standby_mode()
            cd = close_device()
            cdr = close_driver()

            if cd and cdr:
                self.console.raise_text("Close Device = {}".format(cd), 2)
                self.console.raise_text("Close Driver = {}".format(cdr), 2)
                self.console.raise_text("Successfully disconnected", 2)
                self.clear_firmware_and_model_values()
                self.is_connected = False
            else:
                self.console.raise_text(
                    "Error disconnect! {} {}".format(cd, cdr), 3)
        except Exception as e:
            self.console.raise_text(
                "It failed to disconnect the camera!\n{}".format(e), 3)

    def set_temperature(self, value):
        if getlinkstatus() is True:
            self.lock.set_acquire()
            try:
                set_temperature(regulation=True,
                                setpoint=value,
                                autofreeze=False)
            except Exception as e:
                self.console.raise_text(
                    "Error setting the temperature.\n{}".format(e), 3)
            finally:
                self.lock.set_release()
                self.console.raise_text(
                    "Temperature set to {}°C".format(int(value)), 1)
                time.sleep(1)
                # self.check_fan()
                # self.console.save_log("Temperature set to {}°C".format(int(value)))
        else:
            self.console.raise_text("The camera is not connected!", 3)

    def get_temperature(self):
        temp = "NAN"
        try:
            if getlinkstatus() is True:
                if not self.lock.is_locked():
                    self.lock.set_acquire()
                    temp = get_temperature()[3]
                    self.temp = temp
                    self.lock.set_release()
            # else:
            # if getlinkstatus() is True:
            #     sleep(1)
            #     self.lock.set_acquire()
            #     temp = tuple(get_temperature())[3]
            #     self.lock.set_release()
            # temp = "None",
        except Exception as e:
            self.console.raise_text(
                "Unable to retrieve the temperature.\n{}".format(e), 3)
            time.sleep(1)
            temp = "NAN"

        return temp

    def check_link(self):
        return getlinkstatus()

    def get_camera_settings_ini(self):
        settings = SettingsCamera()
        info_ini = settings.get_camera_settings()
        return info_ini

    # Camera Mode
    def standby_mode(self):
        self.set_temperature(15.00)
        self.fan.set_fan_off()
        self.check_fan()

    def check_fan(self):
        if SbigDriver.is_fanning():
            self.console.raise_text("Fan: ON", 2)
            time.sleep(1)
        else:
            self.console.raise_text("Fan: OFF", 2)
            time.sleep(1)

    def shooter_mode(self):
        info_ini = self.get_camera_settings_ini()
        self.aux_temperature = int(info_ini[0])
        self.set_temperature(int(self.aux_temperature))
        self.fan.set_fan_on()
        self.check_fan()
        self.console.raise_text(
            "Waiting temperature to " + str(self.aux_temperature) + "°C", 2)
        time.sleep(1)

    # Shooters
    def start_one_photo(self):

        try:
            self.continuousShooterThread.one_photo = True
            self.continuousShooterThread.wait_temperature = True
            self.continuousShooterThread.start_continuous_shooter()
            self.continuousShooterThread.start()
        except Exception as e:
            print(e)

    def start_taking_photo(self):
        try:
            if getlinkstatus() is True:
                self.shooter_mode()
                self.continuousShooterThread.start_continuous_shooter()
                self.continuousShooterThread.start()
            else:
                self.console.raise_text("The camera is not connected", 3)
        except Exception as e:
            print(e)

    def stop_taking_photo(self):
        if getlinkstatus() is True:
            if not self.continuousShooterThread.wait_temperature:
                self.continuousShooterThread.stop_continuous_shooter()
            self.continuousShooterThread.stop_continuous_shooter()
            # self.standby_mode()
        else:
            self.console.raise_text("The camera is not connected!", 3)

    def log_ephem_infos(self):
        info_start_end = result()
        start_time = str(info_start_end[0])
        start_field = start_time[:-10] + " UTC"
        end_time = str(info_start_end[1])
        end_field = end_time[:-10] + " UTC"
        '''
        time_obs_time = str(info_start_end[2]).split(":")
        time_obs_time = [z.split(".")[0] for z in time_obs_time]
        time_obs_field = time_obs_time[0] + ":" + time_obs_time[1] + " Hours"
        '''
        # self.console.raise_text("Start Time: " + start_field + "; End Time: " + end_field, 2)
        self.console.save_log("Start Time: " + start_field + "; End Time: " +
                              end_field)
        time.sleep(1)

    def start_ephemeris_shooter(self):
        if getlinkstatus() is True:
            self.ephemerisShooterThread.start()
        else:
            self.console.raise_text("The camera is not connected!", 3)

    def stop_ephemeris_shooter(self):
        if getlinkstatus() is True:
            self.ephemerisShooterThread.stop_shooter()
            # self.standby_mode()
        else:
            self.console.raise_text("The camera is not connected!", 3)

    # All PyQt Slots

    def eshooter_started(self):
        self.console.raise_text("Shooter Ephemeris Started!", 1)
        time.sleep(1)
        # self.console.save_log("Shooter Ephemeris Started!")
        self.log_ephem_infos()
        self.standby_mode()

    def eshooter_finished(self):
        self.console.raise_text('Shooter Finished\n', 2)
        time.sleep(1)
        self.log_ephem_infos()
        self.standby_mode()

    def eshooter_observation_started(self):
        self.shooting = True
        self.console.raise_text("Observation Started\n", 2)
        time.sleep(1)
        self.log_ephem_infos()

    def eshooter_observation_finished(self):
        self.console.raise_text("Observation Finalized", 2)
        self.standby_mode()
        self.continuousShooterThread.wait_temperature = False
        self.continuousShooterThread.one_photo = False
        self.ephemerisShooterThread.wait_temperature = False
        self.ephemerisShooterThread.continuousShooterThread.wait_temperature = False
        self.temp_contador_manual = 0
        self.shooting = False
        self.log_ephem_infos()

    # Commands Slots
    def check_temp_manual(self):
        '''
        funcao que espera temperatura setada ou tempo pre-determinado
        '''
        try:
            now = datetime.now()
            if not self.temp_contador_manual:
                self.now_plus = now + timedelta(
                    seconds=int(self.settings.get_camera_settings()[5]))
                self.temp_contador_manual = True
            elif self.temp <= int(
                    self.aux_temperature) or now >= self.now_plus:
                self.continuousShooterThread.wait_temperature = True
                self.temp_contador_manual = False
            else:
                self.temp_contador_manual = True

        except Exception as e:
            print(e)

    def check_temp(self):
        '''
        funcao que espera temperatura setada ou tempo pre-determinado
        '''
        try:
            now = datetime.now()
            if not self.temp_contador:
                self.now_plus = now + timedelta(
                    seconds=int(self.settings.get_camera_settings()[5]))
                self.temp_contador = True
            if self.temp <= int(self.aux_temperature) or now >= self.now_plus:
                self.ephemerisShooterThread.wait_temperature = True
                self.ephemerisShooterThread.continuousShooterThread.wait_temperature = True

                self.temp_contador = False
        except Exception as e:
            print(e)

    def connect_mainwindow_update(self):
        self.set_firmware_and_model_values()
        self.fan.refresh_fan_status()

    def eita(self):
        self.console.raise_text(self.commands.text, 1)
Exemplo n.º 23
0
class SettingsCCDInfos(QWidget):
    def __init__(self, parent=None):
        super(SettingsCCDInfos, self).__init__(parent)

        # Instance attributes create_filter_wheel_info_group
        self.serial_filter_wheel_info_l = None
        self.serial_filter_wheel_info_f = None
        self.tempt_filter_wheel_info_l = None
        self.tempt_filter_wheel_info_f = None
        self.slots_filter_wheel_info_l = None
        self.slots_filter_wheel_info_f = None

        # Instance attributes create_filter_wheel_group
        self.shutter_l = None
        self.close_open_filter_wheel = None
        self.close_open_filter_wheel_info = None
        self.btn_set_shutter = None
        self.get_filter_l = None
        self.filter_position = None
        self.btn_set_filter = None
        self.set_filter_position = None
        self.btn_home_position_filter = None

        # Instance attributes create_ccd_info_group
        self.info_port_ccd_l = None
        self.info_port_ccd_f = None
        self.info_camera_model_l = None
        self.info_camera_model_f = None
        self.info_pixel_array_l = None
        self.info_pixel_array_f = None

        # Instance attributes create_ccd_camera_group
        self.close_open = None
        self.temp_set_point_l = None
        self.temp_set_point_f = None
        self.temp_init_l = None
        self.temp_init_f = None
        self.one_photoButton = None
        self.tempButton = None
        self.fanButton = None

        # Instance attributes create_push_button_group
        self.saveButton = None
        self.cancelButton = None
        self.clearButton = None

        self.select_filter_manual = 1
        self.select_filter_shutter = "Closed"

        self.imager_window = parent

        self.cam = Camera()

        self.roda_filtros = FilterControl()

        self.var_save_ini_camera = SettingsCamera()

        self.console = ConsoleThreadOutput()

        self.fan = Fan(self.fanButton)

        self.one_photo = SThread()

        self.lock = Locker()

        self.firmware = "????"
        self.model = "????"
        self.y_pixels = "????"
        self.x_pixels = "????"

        grid = QGridLayout()
        grid.addWidget(self.create_filter_wheel_info_group(), 0, 0)
        grid.addWidget(self.create_filter_wheel_group(), 1, 0)
        grid.addWidget(self.create_ccd_info_group(), 0, 1)
        grid.addWidget(self.create_ccd_camera_group(), 1, 1)
        grid.addWidget(self.create_push_button_group(), 2, 1)
        self.setLayout(grid)

        self.button_settings()

        self.setWindowTitle("Imager Box")
        self.resize(500, 340)
        self.info_cam()

    def create_filter_wheel_info_group(self):
        group_box = QGroupBox("&Filter Wheel Info")

        self.serial_filter_wheel_info_l = QtWidgets.QLabel("Serial Port: ", self)
        self.serial_filter_wheel_info_l.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)

        try:
            motor_door_aux = str(self.roda_filtros.motor_door)
        except Exception as e:
            print(e)
            motor_door_aux = "???"

        self.serial_filter_wheel_info_f = QtWidgets.QLabel(motor_door_aux, self)
        self.serial_filter_wheel_info_f.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)

        self.slots_filter_wheel_info_l = QtWidgets.QLabel("Filter Slot: ", self)
        self.slots_filter_wheel_info_l.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
        self.slots_filter_wheel_info_f = QtWidgets.QLabel("6", self)
        self.slots_filter_wheel_info_f.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)

        self.tempt_filter_wheel_info_l = QtWidgets.QLabel("Filter Temperature: ", self)
        self.tempt_filter_wheel_info_l.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
        self.tempt_filter_wheel_info_f = QtWidgets.QLabel("25 °C", self)
        self.tempt_filter_wheel_info_f.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)

        group_box.setLayout(set_lvbox(set_hbox(self.serial_filter_wheel_info_l, self.serial_filter_wheel_info_f),
                                      set_hbox(self.slots_filter_wheel_info_l, self.slots_filter_wheel_info_f),
                                      set_hbox(self.tempt_filter_wheel_info_l, self.tempt_filter_wheel_info_f)))

        return group_box

    def create_filter_wheel_group(self):
        group_box = QGroupBox("&Filter Wheel Control")
        group_box.setCheckable(True)
        group_box.setChecked(False)
        self.shutter_l = QtWidgets.QLabel("Shutter status:", self)
        self.shutter_l.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
        self.close_open_filter_wheel_info = QtWidgets.QLabel("Closed")
        self.close_open_filter_wheel_info.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)

        self.btn_set_shutter = QtWidgets.QPushButton('Set shutter', self)
        self.close_open_filter_wheel = QtWidgets.QComboBox(self)
        self.close_open_filter_wheel.setMaximumWidth(100)
        self.fill_combo_close_open_filter_wheel_shutter()

        filter_position = self.roda_filtros.get_current_filter()

        if filter_position == "None":
            filter_position = "1"

        self.get_filter_l = QtWidgets.QLabel('Current filter:', self)
        self.filter_position = QtWidgets.QLabel(filter_position)
        self.filter_position.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
        self.filter_position.setMinimumWidth(60)

        self.btn_set_filter = QtWidgets.QPushButton('Set filter', self)
        self.set_filter_position = QtWidgets.QComboBox(self)
        self.set_filter_position.setMaximumWidth(100)
        self.fill_combo_filter_position()

        self.btn_home_position_filter = QtWidgets.QPushButton('Home Reset', self)

        group_box.setLayout(set_lvbox(set_hbox(self.shutter_l, self.close_open_filter_wheel_info),
                                      set_hbox(self.btn_set_shutter, self.close_open_filter_wheel),
                                      set_hbox(self.get_filter_l, self.filter_position, stretch2=1),
                                      set_hbox(self.btn_set_filter, self.set_filter_position),
                                      set_hbox(self.btn_home_position_filter)))
        return group_box

    def create_ccd_info_group(self):
        group_box = QGroupBox("Info CCD")

        self.info_port_ccd_l = QtWidgets.QLabel("Camera Firmware: ", self)
        self.info_port_ccd_l.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
        self.info_port_ccd_f = QtWidgets.QLabel(self.firmware)
        self.info_port_ccd_f.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)

        self.info_camera_model_l = QtWidgets.QLabel("Camera Model: ", self)
        self.info_camera_model_l.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
        self.info_camera_model_f = QtWidgets.QLabel(self.model)
        self.info_camera_model_f.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)

        self.info_pixel_array_l = QtWidgets.QLabel("Pixel array: ", self)
        self.info_pixel_array_l.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
        self.info_pixel_array_f = QtWidgets.QLabel(self.x_pixels + " X " + self.y_pixels + " Pixels")
        self.info_pixel_array_f.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)

        group_box.setLayout(set_lvbox(set_hbox(self.info_port_ccd_l, self.info_port_ccd_f),
                                      set_hbox(self.info_camera_model_l, self.info_camera_model_f),
                                      set_hbox(self.info_pixel_array_l, self.info_pixel_array_f)))
        return group_box

    def create_ccd_camera_group(self):
        group_box = QGroupBox("Settings")
        group_box.setCheckable(True)
        group_box.setChecked(False)

        self.shutter_l = QtWidgets.QLabel("Shutter:", self)
        self.shutter_l.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
        self.close_open = QtWidgets.QLabel("Closed")
        self.close_open.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)

        self.temp_set_point_l = QtWidgets.QLabel("CCD Temp Set Point (°C):", self)
        self.temp_set_point_l.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
        self.temp_set_point_f = QtWidgets.QLineEdit(self)
        self.temp_set_point_f.setMaximumWidth(100)
        self.temp_set_point_f.setValidator(QIntValidator(-100, 30))

        self.temp_init_l = QtWidgets.QLabel("Tempo para iniciar(s):", self)
        self.temp_init_l.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
        self.temp_init_f = QtWidgets.QLineEdit(self)
        self.temp_init_f.setMaximumWidth(100)
        self.temp_init_f.setValidator(QIntValidator(0, 600))

        self.one_photoButton = QtWidgets.QPushButton('Take Photo', self)
        self.one_photoButton.clicked.connect(self.take_one_photo)

        self.tempButton = QtWidgets.QPushButton("Set Temp", self)
        self.tempButton.clicked.connect(self.btn_temperature)

        self.fanButton = QtWidgets.QPushButton("Fan (On/Off)")
        self.fanButton.clicked.connect(self.button_fan_func)

        self.setting_values()

        group_box.setLayout(set_lvbox(set_hbox(self.shutter_l, self.close_open),
                                      set_hbox(self.temp_set_point_l, self.temp_set_point_f),
                                      set_hbox(self.temp_init_l, self.temp_init_f),
                                      set_hbox(self.one_photoButton, self.tempButton, self.fanButton, stretch2=1)))
        return group_box

    def create_push_button_group(self):
        group_box = QGroupBox("&Push Buttons")
        # group_box.setCheckable(True)
        # group_box.setChecked(True)

        self.saveButton = QPushButton("Save")
        self.saveButton.clicked.connect(self.button_ok_func)

        self.cancelButton = QPushButton("Cancel")
        self.cancelButton.clicked.connect(self.func_cancel)

        self.clearButton = QPushButton("Clear")
        self.clearButton.clicked.connect(self.clear_all)

        group_box.setLayout(set_lvbox(set_hbox(self.saveButton, self.clearButton, self.cancelButton)))

        return group_box

    def get_info_pixels(self):
        # Function to get the CCD Info
        # This function will return [Pixels]

        ret = None
        self.lock.set_acquire()
        try:
            ret = tuple(ccdinfo())
        except Exception as e:
            self.console.raise_text("Failed to get camera information.\n{}".format(e))
        finally:
            self.lock.set_release()
        return ret

    def fill_combo_close_open_filter_wheel_shutter(self):
        self.close_open_filter_wheel.addItem("Closed", 2)
        self.close_open_filter_wheel.addItem("Opened", 1)

    def func_close_open_shutter(self):
        my_slot_close_open_shutter = self.close_open_filter_wheel.currentIndex()

        if my_slot_close_open_shutter == 0:
            self.roda_filtros.close_shutter()
            self.select_filter_shutter = "Closed"
            self.console.raise_text("Shutter Filter Wheel Closed", 1)
            self.close_open.setText("Closed")
            self.close_open_filter_wheel_info.setText("Closed")
        else:
            self.roda_filtros.open_shutter()
            self.select_filter_shutter = "Opened"
            self.console.raise_text("Shutter Filter Wheel Opened ", 1)
            self.close_open.setText("Opened")
            self.close_open_filter_wheel_info.setText("Opened")

    def fill_combo_filter_position(self):
        self.set_filter_position.addItem("1", 1)
        self.set_filter_position.addItem("2", 2)
        self.set_filter_position.addItem("3", 3)
        self.set_filter_position.addItem("4", 4)
        self.set_filter_position.addItem("5", 5)
        self.set_filter_position.addItem("6", 6)

    def func_filter_position(self):
        available_filters_list_and_commons = get_filter_settings()
        available_filters_list_and_commons = list(available_filters_list_and_commons)

        permited_filters = ''

        for x in available_filters_list_and_commons:
            permited_filters += str(x)

        try:
            if self.roda_filtros.connect_state:
                sleep(1)
                wish_filter_int = self.set_filter_position.currentIndex() + 1
                aux = 1
                for x in permited_filters:
                    if int(wish_filter_int) == int(x):
                        aux = 0

                if aux == 0:
                    self.roda_filtros.filter_wheel_control(int(wish_filter_int))
                else:
                    self.console.raise_text("There is no filter on slot number " + str(wish_filter_int) + "!", 3)
                    self.console.raise_text("Please include a new filter on the Filters Settings Menu!", 3)

                sleep(1)
        except Exception as e:
            print("def func_filter_position(self): -> " + str(e))

        finally:
            if aux == 0:
                if self.roda_filtros.connect_state:
                    self.select_filter_manual = wish_filter_int

                    self.filter_position.setText(str(wish_filter_int))
                    self.console.raise_text("Filter Position: {}".format(str(wish_filter_int)), 2)
                else:
                    self.filter_position.setText("?")
                    self.console.raise_text("Filter Wheel is not connect!", 3)

    def button_settings(self):
        self.btn_set_shutter.clicked.connect(self.func_close_open_shutter)
        self.btn_set_filter.clicked.connect(self.func_filter_position)
        self.btn_home_position_filter.clicked.connect(self.func_home_position)

    def func_home_position(self):
        try:
            if self.roda_filtros.connect_state:
                sleep(0.5)
                print("Home Position")
                self.roda_filtros.home_reset()
                sleep(1)
        except Exception as e:
            print(e)
        finally:
            if self.roda_filtros.connect_state:
                self.filter_position.setText("1")
                self.console.raise_text("Filter Position: 1", 2)
                self.console.raise_text("Shutter Filter Wheel Closed", 1)
                self.close_open.setText("Closed")
                self.close_open_filter_wheel_info.setText("Closed")
            else:
                self.filter_position.setText("?")
                self.console.raise_text("Filter Wheel is not connect!", 3)

    def get_values(self):
        return self.var_save_ini_camera.get_camera_settings()

    def setting_values(self):
        info = self.get_values()
        self.set_values(info[0], info[1])

    def set_values(self, temperature_camera, temp_init_f):
        self.temp_set_point_f.setText(temperature_camera)
        self.temp_init_f.setText(temp_init_f)

    def button_ok_func(self):
        try:
            self.var_save_ini_camera.set_camera_settings(self.temp_set_point_f.text(),
                                                         self.temp_init_f.text())

            self.var_save_ini_camera.save_settings()
            self.console.raise_text("Camera settings successfully saved!", 1)

        except Exception as e:
            print(e)

    def clear_all(self):
        self.temp_set_point_f.clear()
        self.temp_init_f.clear()

    def func_cancel(self):
        self.imager_window.close()

    def take_one_photo(self):
        try:
            if self.select_filter_shutter == "Closed":
                self.console.raise_text("AQUI dark photo", 1)
                self.cam.start_one_photo(self.select_filter_manual, self.select_filter_shutter)
                # self.one_photo.args_one_photo(self.select_filter_manual, self.select_filter_shutter)
                # self.one_photo.start()
            else:
                self.console.raise_text("AQUI photo", 1)
                self.cam.start_one_photo(self.select_filter_manual, self.select_filter_shutter)
        except Exception as e:
            self.console.raise_text("Not possible taking photo -> {}".format(e), 1)

    def button_fan_func(self):
        if getlinkstatus() is True:
            try:
                self.fan.set_fan()
                self.console.raise_text('State changed Fan!', 2)
            except Exception as e:
                self.console.raise_text("The camera is not connected!", 3)
                self.console.raise_text('State Fan unchanged', 3)
                self.console.raise_text("Exception -> {}".format(e))
        else:
            self.console.raise_text("The camera is not connected!", 3)
            self.console.raise_text('State Fan unchanged', 3)

    def btn_temperature(self):
        try:
            value = self.temp_set_point_f.text()
            if value is '':
                pass
            else:
                try:
                    self.cam.set_temperature(float(value))
                except TypeError:
                    self.cam.set_temperature(float(20.0))
        except Exception as e:
            print("Exception -> {}".format(e))

    def info_cam(self):
        try:
            if getlinkstatus() is True:
                self.firmware, self.model, self.y_pixels, self.x_pixels = \
                    self.cam.get_firmware_and_model_and_pixels()
            else:
                self.firmware, self.model, self.y_pixels, self.x_pixels = "????", "????", \
                                                                          "????", "????"

            self.info_port_ccd_f.setText(self.firmware)
            self.info_camera_model_f.setText(self.model)
            self.info_pixel_array_f.setText(str(self.y_pixels) + " x " + str(self.x_pixels))

        except Exception as e:
            print("CCDInfos get_firmware_and_model_and_pixels -> {}".format(e))
            self.firmware, self.model, self.y_pixels, self.x_pixels = "????", "????", \
                                                                      "????", "????"
Exemplo n.º 24
0
class SThread(QtCore.QThread):
    """
    Threads são fluxos de programas que executam em paralelo dentro de uma aplicação, isto é,\
    uma ramificação de uma parte da aplicação que é executada de forma independente e\
    escalonada independentemente do fluxo inicial da aplicação.
    Fonte: http://imasters.com.br/artigo/20127/py/threads-em-python/?trace=1519021197&source=single
    """
    def __init__(self):
        super(SThread, self).__init__()
        self.lock = Locker()
        self.info = []
        self.img = None
        self.generic_count = 0

    def get_camera_settings(self):
        '''
        pega os valores no ini camera
        info[0] = temperature_camera
        info[1] = prefixo/filter name
        info[2] = tempo_exposicao
        info[3] = binning
        info[4] = tempo_fotos(tempo entre fotos)
        info[5] = time_cooling(CCD cooling time)
        info[6] = Image contrast: bottom
        info[7] = Image contrast: top level
        info[8] = Booleano para decidir se a foto é dark
        info[9] = axis_xi inicial
        info[10] = axis_xf final
        info[11] = axis_yi inicial
        info[12] = axis_yf final
        info[13] = ignore_crop
        info[14] = image_tif
        info[15] = image_fit
        '''
        settings = SettingsCamera()
        info = settings.get_camera_settings()

        return info

    def take_dark(self):
        '''
        Manda instrução para o SbigDriver para tirar uma foto dark(shooter fechado)\
        com os valores na info[]
        '''
        try:
            self.set_etime_pre_binning()
            self.lock.set_acquire()
            self.info = SbigDriver.photoshoot(
                self.etime, self.pre, self.b, 1, self.get_level1,
                self.get_level2, self.get_axis_xi, self.get_axis_xf,
                self.get_axis_yi, self.get_axis_yf, self.get_ignore_crop,
                self.get_image_tif, self.get_image_fit)
            self.init_image()
        except Exception as e:
            print(e)
        finally:
            time.sleep(1)
            self.lock.set_release()

    def set_etime_pre_binning(self):
        '''
        seta os valores para o tempo de exposição = etime, prefixo, binning, se a foto é dark ou não,\
        e valores Image contrast: bottom e top level
        '''

        try:
            info = self.get_camera_settings()

            self.pre = str(info[1])

            self.etime = float(info[2])
            if self.etime <= 0.12:
                self.etime = 0.12 * 100
            elif self.etime >= 3600:
                self.etime = 3600 * 100
            else:
                self.etime = float(info[2]) * 100
            self.etime = int(self.etime)

            self.b = int(info[3])

            self.get_level1 = float(info[6])
            self.get_level2 = float(info[7])

            self.dark_photo = int(info[8])

            self.get_axis_xi = int(info[9])
            self.get_axis_xf = int(info[10])
            self.get_axis_yi = int(info[11])
            self.get_axis_yf = int(info[12])

            self.get_ignore_crop = info[13]

            self.get_image_tif = info[14]
            self.get_image_fit = info[15]

        except Exception as e:
            print(e)
            self.etime = 100
            self.b = 0
            self.dark_photo = 1
            self.get_level1 = 0.1
            self.get_level2 = 0.99

            if str(info[1]) != '':
                self.pre = str(info[1])
            else:
                self.pre = 'pre'

            self.get_axis_xi = info[9]
            self.get_axis_xf = info[10]
            self.get_axis_yi = info[11]
            self.get_axis_yf = info[12]

            self.get_ignore_crop = True

            self.get_image_tif = True
            self.get_image_fit = True

    def run(self):
        self.set_etime_pre_binning()
        self.lock.set_acquire()
        try:
            self.info = SbigDriver.photoshoot(
                self.etime, self.pre, self.b, self.dark_photo, self.get_level1,
                self.get_level2, self.get_axis_xi, self.get_axis_xf,
                self.get_axis_yi, self.get_axis_yf, self.get_ignore_crop,
                self.get_image_tif, self.get_image_fit)
            self.init_image()
        except Exception as e:
            print(e)
        finally:
            self.lock.set_release()

    def init_image(self):
        try:
            for i in self.info:
                print(i)

            self.img = Image(self.info[0], self.info[1], self.info[2],
                             self.info[3], self.info[4])
        except Exception as e:
            self.img = Image('', '', '', '', '')
        return self.img

    def get_image_info(self):
        return self.img
Exemplo n.º 25
0
class SThread(QtCore.QThread):
    """
    Threads são fluxos de programas que executam em paralelo dentro de uma aplicação, isto é,\
    uma ramificação de uma parte da aplicação que é executada de forma independente e\
    escalonada independentemente do fluxo inicial da aplicação.
    Fonte: http://imasters.com.br/artigo/20127/py/threads-em-python/?trace=1519021197&source=single
    """
    def __init__(self):
        super(SThread, self).__init__()
        self.lock = Locker()
        self.info = []
        self.img = None
        self.generic_count = 0
        self.final_image_name = None

    @staticmethod
    def check_connection():
        return SbigDriver.getlinkstatus()

    @staticmethod
    def reconnect():
        return SbigDriver.open_driver(), SbigDriver.open_deviceusb(
        ), SbigDriver.establishinglink()

    def take_dark(self):
        '''
        Manda instrução para o SbigDriver para tirar uma foto dark(shooter fechado)\
        com os valores na info[]
        '''
        try:
            self.set_etime_pre_binning()
            self.lock.set_acquire()
            self.info = SbigDriver.photoshoot(
                self.etime, self.pre, self.b, 1, self.get_axis_xi,
                self.get_axis_xf, self.get_axis_yi, self.get_axis_yf,
                self.get_ignore_crop, self.get_image_tif, self.get_image_fit)
            self.final_image_name = self.info[0] + self.info[1]
            self.init_image()
        except Exception as e:
            print(e)
        finally:
            time.sleep(1)
            self.lock.set_release()

    def set_etime_pre_binning(self):
        '''
        seta os valores para o tempo de exposição = etime, prefixo, binning, se a foto é dark ou não,\
        e valores Image contrast: bottom e top level
        '''

        try:
            info = get_camera_settings()

            self.pre = str(info[1])

            self.etime = float(info[2])
            if self.etime <= 0.12:
                self.etime = 0.12 * 100
            elif self.etime >= 3600:
                self.etime = 3600 * 100
            else:
                self.etime = float(info[2]) * 100
            self.etime = int(self.etime)

            self.b = int(info[3])

            self.get_level1 = float(info[6])
            self.get_level2 = float(info[7])

            self.dark_photo = int(info[8])

            self.get_axis_xi = int(info[9])
            self.get_axis_xf = int(info[10])
            self.get_axis_yi = int(info[11])
            self.get_axis_yf = int(info[12])

            self.get_ignore_crop = info[13]

            self.get_image_tif = info[14]
            self.get_image_fit = info[15]

        except Exception as e:
            print(e)
            self.etime = 100
            self.b = 0
            self.dark_photo = 1
            self.get_level1 = 0.1
            self.get_level2 = 0.99

            if str(info[1]) != '':
                self.pre = str(info[1])
            else:
                self.pre = 'pre'

            self.get_axis_xi = info[9]
            self.get_axis_xf = info[10]
            self.get_axis_yi = info[11]
            self.get_axis_yf = info[12]

            self.get_ignore_crop = True

            self.get_image_tif = True
            self.get_image_fit = True

    def run(self):
        self.set_etime_pre_binning()
        self.lock.set_acquire()
        try:
            self.info = SbigDriver.photoshoot(
                self.etime, self.pre, self.b, self.dark_photo,
                self.get_axis_xi, self.get_axis_xf, self.get_axis_yi,
                self.get_axis_yf, self.get_ignore_crop, self.get_image_tif,
                self.get_image_fit)
            self.final_image_name = self.info[0] + self.info[1]
            self.init_image()
        except Exception as e:
            print(e)
        finally:
            self.lock.set_release()

    def init_image(self):
        try:
            for i in self.info:
                print(i)

            self.img = Image(self.final_image_name)
        except Exception as e:
            self.img = Image('')
        return self.img

    def get_image_info(self):
        return self.img
Exemplo n.º 26
0
class Camera(metaclass=Singleton):
    '''
        classe de controle da camera
    '''
    def __init__(self):
        self.lock = Locker()
        self.console = ConsoleThreadOutput()
        self.settings = SettingsCamera()
        self.settings.setup_settings()
        self.fan = Fan()

        # Campos da janela principal para as informações da câmera
        self.firmware_field = None
        self.model_field = None

        self.main = Status()
        self.now_plus_10 = datetime.now()
        self.settedhour = datetime.now()
        self.continuousShooterThread = ContinuousShooterThread(
            int(self.settings.get_camera_settings()[4]))
        self.ephemerisShooterThread = EphemerisShooter()

        self.sthread = SThread()

        self.commands = CameraQThread(self)
        self.shooting = False
        # Initiating the Slots
        self.init_slots()

        self.info_ini = []

        info_ini = self.get_camera_settings_ini()
        self.aux_temperature = int(info_ini[0])

        self.temp = 0
        self.temp_contador = 0
        self.temp_contador_manual = 0

    def init_slots(self):
        # Ephemeris Shooter Slots
        self.ephemerisShooterThread.started.connect(self.eshooter_started)
        self.ephemerisShooterThread.finished.connect(self.eshooter_finished)
        self.ephemerisShooterThread.signal_started_shooting.connect(
            self.shooter_mode)
        self.ephemerisShooterThread.signal_temp.connect(self.check_temp)
        self.ephemerisShooterThread.continuousShooterThread.signal_temp.connect(
            self.check_temp)

        self.ephemerisShooterThread.continuousShooterThread.started.connect(
            self.eshooter_observation_started)
        self.ephemerisShooterThread.continuousShooterThread.finished.connect(
            self.eshooter_observation_finished)

        # Criando connect da temperatura
        # self.ephemerisShooterThread.continuousShooterThread.signalAfterShooting.connect()
        self.continuousShooterThread.signal_temp.connect(
            self.check_temp_manual)
        self.continuousShooterThread.finished.connect(self.standby_mode)

        # Camera Commands Slots
        self.commands.finished.connect(self.eita)
        self.commands.connectSignal.connect(self.connect_mainwindow_update)

    def get_firmware_and_model(self):
        info = self.get_info()
        return str(info[0]), str(info[2])[2:len(str(info[2])) - 1]

    def set_firmware_and_model_fields(self, firmwareField, modelField):
        self.firmware_field = firmwareField
        self.model_field = modelField

    def set_firmware_and_model_values(self):
        firmware, model = self.get_firmware_and_model()
        self.firmware_field.setText("Firmware: " + firmware)
        self.model_field.setText("Camera: " + model)

    def clear_firmware_and_model_values(self):
        self.firmware_field.setText("Firmware: ")
        self.model_field.setText("Camera: ")

    def get_info(self):
        '''
            Function to get the CCD Info
            This function will return [CameraFirmware, CameraType, CameraName]
        '''
        ret = None
        self.lock.set_acquire()
        try:
            ret = tuple(ccdinfo())
        except Exception as e:
            self.console.raise_text(
                "Failed to get camera information.\n{}".format(e))
        finally:
            self.lock.set_release()
        return ret

    def connect(self):
        try:
            a = open_driver()
            open_deviceusb()
            c = establishinglink()
            if a is True and c is True:
                self.console.raise_text("Open Device = {}".format(a), 2)
                self.console.raise_text("Established Link = {}".format(c), 2)
                self.console.raise_text("Successfully connected!", 2)
                self.set_firmware_and_model_values()
                '''
                    Fan Field sera atualizado automaticamente
                    atualizado pela thread de refresh temp.
                '''
                # self.fan.refresh_fan_status()
                return True
            else:
                self.console.raise_text("Connection error", 3)

        except Exception as e:
            self.console.raise_text(
                'Failed to connect the camera!\n{}'.format(e), 3)

        return False

    def disconnect(self):
        try:
            self.standby_mode()
            cd = close_device()
            cdr = close_driver()

            if cd and cdr:
                self.console.raise_text("Close Device = {}".format(cd), 2)
                self.console.raise_text("Close Driver = {}".format(cdr), 2)
                self.console.raise_text("Successfully disconnected", 2)
                self.clear_firmware_and_model_values()
            else:
                self.console.raise_text(
                    "Error disconnect! {} {}".format(cd, cdr), 3)
        except Exception as e:
            self.console.raise_text(
                "It failed to disconnect the camera!\n{}".format(e), 3)

    def set_temperature(self, value):
        if getlinkstatus() is True:
            self.lock.set_acquire()
            try:
                set_temperature(regulation=True,
                                setpoint=value,
                                autofreeze=False)
            except Exception as e:
                self.console.raise_text(
                    "Error setting the temperature.\n{}".format(e), 3)
            finally:
                self.lock.set_release()
                self.console.raise_text(
                    "Temperature set to {}°C".format(int(value)), 1)
        else:
            self.console.raise_text("The camera is not connected!", 3)

    def get_temperature(self):
        temp = "None"
        try:
            if getlinkstatus() is True:
                if not self.lock.is_locked():
                    self.lock.set_acquire()
                    temp = tuple(get_temperature())[3]
                    self.temp = temp
                    self.lock.set_release()
                else:
                    temp = "None"
            else:
                # if getlinkstatus() is True:
                #     sleep(1)
                #     self.lock.set_acquire()
                #     temp = tuple(get_temperature())[3]
                #     self.lock.set_release()
                temp = "None"
        except Exception as e:
            self.console.raise_text(
                "Unable to retrieve the temperature.\n{}".format(e), 3)

        return temp

    def check_link(self):
        return getlinkstatus()

    def get_camera_settings_ini(self):
        settings = SettingsCamera()
        info_ini = settings.get_camera_settings()
        return info_ini

    # Camera Mode
    def standby_mode(self):
        self.set_temperature(15.00)
        self.fan.set_fan_off()

    def shooter_mode(self):
        self.set_temperature(int(self.aux_temperature))
        self.fan.set_fan_on()
        self.console.raise_text(
            "Waiting temperature to " + str(self.aux_temperature) + "°C", 2)

    # Shooters
    def start_taking_photo(self):
        try:
            if getlinkstatus() is True:
                self.shooter_mode()
                self.continuousShooterThread.start_continuous_shooter()
                self.continuousShooterThread.start()
            else:
                self.console.raise_text("The camera is not connected", 3)
        except Exception as e:
            print(e)

    def stop_taking_photo(self):
        if getlinkstatus() is True:
            self.continuousShooterThread.stop_continuous_shooter()
        else:
            self.console.raise_text("The camera is not connected!", 3)

    def start_ephemeris_shooter(self):
        if getlinkstatus() is True:
            self.ephemerisShooterThread.start()
        else:
            self.console.raise_text("The camera is not connected!", 3)

    def stop_ephemeris_shooter(self):
        if getlinkstatus() is True:
            self.ephemerisShooterThread.stop_shooter()
        else:
            self.console.raise_text("The camera is not connected!", 3)

    # All PyQt Slots

    def eshooter_started(self):
        self.console.raise_text("Shooter Ephemeris Started!", 1)
        self.standby_mode()

    def eshooter_finished(self):
        self.console.raise_text('Shooter finalized\n', 1)

    def eshooter_observation_started(self):
        self.shooting = True
        self.console.raise_text("Observation Started", 1)

    def eshooter_observation_finished(self):
        self.console.raise_text("Observation Finalized", 1)
        self.standby_mode()
        self.continuousShooterThread.wait_temperature = False
        self.ephemerisShooterThread.wait_temperature = False
        self.ephemerisShooterThread.continuousShooterThread.wait_temperature = False
        self.temp_contador_manual = 0
        self.shooting = False

    # Commands Slots
    def check_temp_manual(self):
        '''
        funcao que espera temperatura setada ou tempo pre-determinada
        '''
        try:
            now = datetime.now()
            if self.temp_contador_manual == 0:
                self.now_plus_10 = datetime.now() + timedelta(minutes=10)
                self.temp_contador_manual += 2
            elif self.temp <= int(
                    self.aux_temperature) or now >= self.now_plus_10:
                self.continuousShooterThread.wait_temperature = True
                self.temp_contador_manual = 0
            else:
                self.temp_contador_manual += 2

        except Exception as e:
            print(e)

    def check_temp(self):
        '''
            funcao que espera temperatura setada ou tempo pre-determinada
        '''
        try:
            now = datetime.now()
            if self.temp_contador == 0:
                self.now_plus_10 = datetime.now() + timedelta(minutes=10)
                self.temp_contador += 1
            if self.temp <= int(
                    self.aux_temperature) or now >= self.now_plus_10:
                self.ephemerisShooterThread.wait_temperature = True
                self.ephemerisShooterThread.continuousShooterThread.wait_temperature = True

                self.temp_contador = 0
        except Exception as e:
            print(e)

    def connect_mainwindow_update(self):
        self.set_firmware_and_model_values()
        self.fan.refresh_fan_status()

    def eita(self):
        self.console.raise_text(self.commands.text, 1)
Exemplo n.º 27
0
class Fan(metaclass=Singleton):

    def __init__(self):
        self.lock = Locker()
        self.console = ConsoleThreadOutput()

    def set_fanField(self, fanField):
        self.fanField = fanField

    def fan_status(self):
        # Acquiring the Lock
        self.lock.set_acquire()
        status = True

        try:
            # Doing requisition to Driver
            status = SbigDriver.is_fanning()
        except Exception as e:
            self.console.raise_text("Error acquiring the status of Fan.\n{}".format(e))

        # Release the Lock
        self.lock.set_release()

        return "ON" if status else "OFF"

    def refresh_fan_status(self):
        self.fanField.setText(self.fan_status())

    def set_fan(self):
        t = Thread(target=self.s_fan)
        t.start()

    def s_fan(self):
        self.lock.set_acquire()
        try:
            if SbigDriver.is_fanning():
                SbigDriver.stop_fan()
                self.fanField.setText('Fan Off')
            else:
                SbigDriver.start_fan()
                self.fanField.setText('Fan On')
        except Exception as e:
            self.console.raise_text("Error off/on the Fan.\n{}".format(e))
        finally:
            self.lock.set_release()
            self.fanField.setText(self.fan_status())

    def set_fan_off(self):
        self.lock.set_acquire()
        try:
            SbigDriver.stop_fan()
        except Exception as e:
            self.console.raise_text("Error off/on the Fan.\n{}".format(e))
        finally:
            self.lock.set_release()
            self.fanField.setText(self.fan_status())

    def set_fan_on(self):
        self.lock.set_acquire()
        try:
            SbigDriver.start_fan()
        except Exception as e:
            self.console.raise_text("Error off/on the Fan.\n{}".format(e))
        finally:
            self.lock.set_release()
            self.fanField.setText(self.fan_status())
Exemplo n.º 28
0
class SThread(QtCore.QThread):

    def __init__(self):
        super(SThread, self).__init__()
        self.lock = Locker()
        self.info = []
        self.img = None
        self.generic_count = 0

    def get_camera_settings(self):
        '''
        pega os valores no ini camera
        info[0] = temperature_camera
        info[1] = prefixo/filter name
        info[2] = tempo_exposicao
        info[3] = tempo_fotos(tempo entre fotos)
        info[4] = time_cooling(CCD cooling time)
        info[5] = Image contrast: bottom
        info[6] = Image contrast: top level
        info[7] = Booleano para decidir se a foto é dark
        '''
        settings = SettingsCamera()
        info = settings.get_camera_settings()
        return info

    def take_dark(self):
        '''
        manda instrução para o SbigDriver para tirar uma foto dark
        '''
        try:
            self.set_etime_pre_binning()
            self.lock.set_acquire()
            self.info = SbigDriver.photoshoot(self.etime, self.pre, self.b, 1, self.get_level1, self.get_level2)
            self.init_image()
        except Exception as e:
            print(e)
        finally:
            time.sleep(1)
            self.lock.set_release()

    def set_etime_pre_binning(self):
        '''
        seta os valores para o tempo de exposição = etime, prefixo, binning, se a foto é dark ou não,\
        e valores Image contrast: bottom e top level
        :return:
        '''

        try:
            info = self.get_camera_settings()

            self.get_level1 = float(info[6])
            self.get_level2 = float(info[7])

            self.etime = float(info[2])
            if self.etime <= 0.12:
                self.etime = 0.12 * 100
            elif self.etime >= 3600:
                self.etime = 3600 * 100
            else:
                self.etime = float(info[2]) * 100
            self.etime = int(self.etime)

            self.pre = str(info[1])

            self.b = int(info[3])

            self.dark_photo = int(info[8])

        except Exception as e:
            print(e)
            self.etime = 100
            self.dark_photo = 1
            self.get_level1 = 0.1
            self.get_level2 = 0.99
            if str(info[1]) != '':
                self.pre = str(info[1])
            else:
                self.pre = 'pre'

    def run(self):
        self.set_etime_pre_binning()
        self.lock.set_acquire()
        try:
            self.info = SbigDriver.photoshoot(self.etime, self.pre, self.b, self.dark_photo, self.get_level1,\
                                              self.get_level2)
            self.init_image()
        except Exception as e:
            print(e)
        finally:
            self.lock.set_release()

    def init_image(self):
        try:
            for i in self.info:
                print(i)

            self.img = Image(self.info[0], self.info[1], self.info[2], self.info[3], self.info[4])
        except Exception as e:
            self.img = Image('','','','','')
        return self.img

    def get_image_info(self):
        return self.img
Exemplo n.º 29
0
Arquivo: fan.py Projeto: hiyoku/ccd10
 def __init__(self):
     self.lock = Locker()
     self.console = ConsoleThreadOutput()
Exemplo n.º 30
0
class Camera(metaclass=Singleton):

    def __init__(self):
        self.lock = Locker()
        self.console = ConsoleThreadOutput()
        self.settings = SettingsCamera()
        self.settings.setup_settings()
        self.fan = Fan()

        # Campos da janela principal para as informações da câmera
        self.firmware_field = None
        self.model_field = None

        self.main = Status()
        self.settedhour = datetime.now()
        self.continuousShooterThread = ContinuousShooterThread(int(self.settings.get_camera_settings()[4]))
        self.ephemerisShooterThread = EphemerisShooter()

        self.commands = CameraQThread(self)
        self.shooting = False

        # Initiating the Slots
        self.init_slots()

        self.temp = 0
        self.temp_contador = 0

    def init_slots(self):
        # Ephemeris Shooter Slots
        self.ephemerisShooterThread.started.connect(self.eshooter_started)
        self.ephemerisShooterThread.finished.connect(self.eshooter_finished)
        self.ephemerisShooterThread.signal_started_shooting.connect(self.shooter_mode)
        self.ephemerisShooterThread.signal_temp.connect(self.check_temp)

        self.ephemerisShooterThread.continuousShooterThread.started.connect(self.eshooter_observation_started)
        self.ephemerisShooterThread.continuousShooterThread.finished.connect(self.eshooter_observation_finished)

        # Criando connect da temperatura
        # self.ephemerisShooterThread.continuousShooterThread.signalAfterShooting.connect()

        self.continuousShooterThread.finished.connect(self.standby_mode)

        # Camera Commands Slots
        self.commands.finished.connect(self.eita)
        self.commands.connectSignal.connect(self.connect_mainwindow_update)

    def get_firmware_and_model(self):
        info = self.get_info()
        return str(info[0]), str(info[2])[2:len(str(info[2]))-1]

    def set_firmware_and_model_fields(self, firmwareField, modelField):
        self.firmware_field = firmwareField
        self.model_field = modelField

    def set_firmware_and_model_values(self):
        firmware, model = self.get_firmware_and_model()
        self.firmware_field.setText("Firmware: " + firmware)
        self.model_field.setText("Camera: " + model)

    def clear_firmware_and_model_values(self):
        self.firmware_field.setText("Firmware: ")
        self.model_field.setText("Camera: ")

    def get_info(self):
        """
            Function to get the CCD Info
            This function will return [CameraFirmware, CameraType, CameraName]
        """
        ret = None
        self.lock.set_acquire()
        try:
            ret = tuple(ccdinfo())
        except Exception as e:
            self.console.raise_text("Failed to get camera information.\n{}".format(e))
        finally:
            self.lock.set_release()
        return ret

    def connect(self):
        try:
            a = open_driver()
            open_deviceusb()
            c = establishinglink()
            if a is True and c is True:
                self.console.raise_text("Successfully connected! {} {}".format(a, c), 2)
                self.set_firmware_and_model_values()

                '''
                    Fan Field sera atualizado automaticamente
                    atualizado pela thread de refresh temp.
                '''
                # self.fan.refresh_fan_status()
                return True
            else:
                self.console.raise_text("Connection error", 3)

        except Exception as e:
            self.console.raise_text('Failed to connect the camera!\n{}'.format(e), 3)

        return False

    def disconnect(self):
        try:
            self.standby_mode()
            cd = close_device()
            cdr = close_driver()

            if cd and cdr:
                self.console.raise_text("Successfully disconnected!{} {}".format(cd, cdr), 2)
                self.clear_firmware_and_model_values()
            else:
                self.console.raise_text("Error disconnect! {} {}".format(cd, cdr), 3)
        except Exception as e:
            self.console.raise_text("It failed to disconnect the camera!\n{}".format(e), 3)

    def set_temperature(self, value):
        if getlinkstatus() is True:
            self.lock.set_acquire()
            try:
                set_temperature(regulation=True, setpoint=value, autofreeze=False)
            except Exception as e:
                self.console.raise_text("Error setting the temperature.\n{}".format(e), 3)
            finally:
                self.lock.set_release()
                self.console.raise_text("Temperature set to {}".format(int(value)), 1)
        else:
            self.console.raise_text("The camera is not connected!", 3)

    def get_temperature(self):
        temp = "None"
        try:
            if getlinkstatus() is True:
                if not self.lock.is_locked():
                    self.lock.set_acquire()
                    temp = tuple(get_temperature())[3]
                    self.temp = temp
                    self.lock.set_release()
                else:
                    temp = "None"
            else:
                # if getlinkstatus() is True:
                #     sleep(1)
                #     self.lock.set_acquire()
                #     temp = tuple(get_temperature())[3]
                #     self.lock.set_release()
            # else:
                temp = "None"
        except Exception as e:
            self.console.raise_text("Unable to retrieve the temperature.\n{}".format(e), 3)

        return temp

    def check_link(self):
        return getlinkstatus()

    # Camera Mode
    def standby_mode(self):
        self.set_temperature(15.00)
        self.fan.set_fan_off()

    def shooter_mode(self):
        self.set_temperature(-16.00)
        self.fan.set_fan_on()
        while self.get_temperature() < -15:
            sleep(1)

    # Shooters
    def start_taking_photo(self):
        try:
            if getlinkstatus() is True:
                self.continuousShooterThread.start_continuous_shooter()
                self.continuousShooterThread.start()
            else:
                self.console.raise_text("The camera is not connected", 3)
        except Exception as e:
            print(e)

    def stop_taking_photo(self):
        if getlinkstatus() is True:
            self.continuousShooterThread.stop_continuous_shooter()
        else:
            self.console.raise_text("The camera is not connected!", 3)

    def start_ephemeris_shooter(self):
        if getlinkstatus() is True:
            self.ephemerisShooterThread.start()
        else:
            self.console.raise_text("The camera is not connected!", 3)

    def stop_ephemeris_shooter(self):
        if getlinkstatus() is True:
            self.ephemerisShooterThread.stop_shooter()
        else:
            self.console.raise_text("The camera is not connected!", 3)

    # All PyQt Slots

    def eshooter_started(self):
        self.console.raise_text("Shooter Ephemeris Started!", 1)
        self.standby_mode()

    def eshooter_finished(self):
        self.console.raise_text('Shooter finalized', 1)

    def eshooter_observation_started(self):
        self.shooting = True
        self.console.raise_text("Observation Started", 1)

    def eshooter_observation_finished(self):
        self.console.raise_text("Observation Finalized", 1)
        self.standby_mode()
        self.shooting = False

    # Commands Slots
    def check_temp(self):
        if self.temp <= -15 or self.temp_contador == 60:
            self.ephemerisShooterThread.t = True
        else:
            self.console.raise_text("Temp_contador = " + str(self.temp_contador), 1)
            self.console.raise_text("CCD cooling to -15", 1)
            self.temp_contador += 1

    def connect_mainwindow_update(self):
        self.set_firmware_and_model_values()
        self.fan.refresh_fan_status()

    def eita(self):
        self.console.raise_text(self.commands.text, 1)
Exemplo n.º 31
0
class SettingsImageWindow(QtWidgets.QWidget):
    # Cria os campos e espaços no menu image window
    def __init__(self, parent=None):
        super(SettingsImageWindow, self).__init__(parent)

        # Instance attributes create_image_contrast_group
        self.getlevel1 = None
        self.getlevel1l = None
        self.getlevel2 = None
        self.getlevel2l = None

        # Instance attributes create_crop_group
        self.ignore_crop_l = None
        self.crop_msg = None
        self.crop_xi = None
        self.getcropxi_l = None
        self.crop_xf = None
        self.getcropxf_l = None
        self.crop_yi = None
        self.getcropyi_l = None
        self.crop_yf = None
        self.getcropyf_l = None

        # Instance attributes create_type_image_group
        self.image_png_l = None
        self.image_tif_l = None
        self.image_fit_l = None

        # Instance attributes create_push_button_group
        self.saveButton = None
        self.cancelButton = None
        self.clearButton = None

        self.image_settings = SettingsImage()

        self.camera = Camera()

        self.console = ConsoleThreadOutput()

        self.image_parent = parent

        self.lock = Locker()

        grid = QGridLayout()
        grid.addWidget(self.create_image_contrast_group(), 2, 0)
        grid.addWidget(self.create_crop_group(), 3, 0)
        grid.addWidget(self.create_type_image_group(), 4, 0)
        grid.addWidget(self.create_push_button_group(), 5, 0)
        self.setLayout(grid)

        self.setWindowTitle("Imager Box")

        self.setting_values()

    def get_image_settings(self):
        settings = SettingsImage()
        info = settings.get_image_settings()
        return info

    def get_pixels(self):
        info = self.get_info_pixels()

        return int(info[-2]), int(info[-1])

    def get_info_pixels(self):
        # Function to get the CCD Info
        # This function will return [Pixels]
        ret = None
        self.lock.set_acquire()
        try:
            ret = tuple(ccdinfo())
        except Exception as e:
            self.console.raise_text(
                "Failed to get camera information.\n{}".format(e))
        finally:
            self.lock.set_release()

        return ret

    def create_image_contrast_group(self):
        group_box = QGroupBox("&Image Contrast:")
        group_box.setCheckable(True)
        group_box.setChecked(True)

        self.getlevel1 = QtWidgets.QLabel("Bottom Level:", self)
        self.getlevel1.setAlignment(QtCore.Qt.AlignRight
                                    | QtCore.Qt.AlignVCenter)

        self.getlevel1l = QtWidgets.QLineEdit(self)
        self.getlevel1l.setMaximumWidth(50)
        self.getlevel1l.setValidator(QIntValidator(-100, 30))

        self.getlevel2 = QtWidgets.QLabel("Top Level:", self)
        self.getlevel2.setAlignment(QtCore.Qt.AlignRight
                                    | QtCore.Qt.AlignVCenter)

        self.getlevel2l = QtWidgets.QLineEdit(self)
        self.getlevel2l.setMaximumWidth(50)
        self.getlevel2l.setValidator(QIntValidator(-100, 30))

        group_box.setLayout(
            set_lvbox(
                set_hbox(self.getlevel1, self.getlevel1l, self.getlevel2,
                         self.getlevel2l)))

        return group_box

    def create_crop_group(self):
        group_box = QGroupBox("&Crop")
        group_box.setCheckable(True)
        group_box.setChecked(False)

        self.ignore_crop_l = QtWidgets.QCheckBox('Ignore Crop Image', self)

        self.crop_msg = QtWidgets.QLabel("Crop Image", self)
        self.crop_xi = QtWidgets.QLabel("Width: Wi:", self)
        self.crop_xi.setAlignment(QtCore.Qt.AlignRight
                                  | QtCore.Qt.AlignVCenter)

        self.getcropxi_l = QtWidgets.QLineEdit(self)
        self.getcropxi_l.setMaximumWidth(50)
        self.getcropxi_l.setValidator(QIntValidator(-100, 30))

        self.crop_xf = QtWidgets.QLabel("Wf:", self)
        self.crop_xf.setAlignment(QtCore.Qt.AlignRight
                                  | QtCore.Qt.AlignVCenter)

        self.getcropxf_l = QtWidgets.QLineEdit(self)
        self.getcropxf_l.setMaximumWidth(50)
        self.getcropxf_l.setValidator(QIntValidator(-100, 30))

        self.crop_yi = QtWidgets.QLabel("Height: Hi:", self)
        self.crop_yi.setAlignment(QtCore.Qt.AlignRight
                                  | QtCore.Qt.AlignVCenter)

        self.getcropyi_l = QtWidgets.QLineEdit(self)
        self.getcropyi_l.setMaximumWidth(50)
        self.getcropyi_l.setValidator(QIntValidator(-100, 30))

        self.crop_yf = QtWidgets.QLabel("Hf:", self)
        self.crop_yf.setAlignment(QtCore.Qt.AlignRight
                                  | QtCore.Qt.AlignVCenter)

        self.getcropyf_l = QtWidgets.QLineEdit(self)
        self.getcropyf_l.setMaximumWidth(50)
        self.getcropyf_l.setValidator(QIntValidator(-100, 30))

        group_box.setLayout(
            set_lvbox(
                set_hbox(self.ignore_crop_l), set_hbox(self.crop_msg),
                set_hbox(self.crop_xi, self.getcropxi_l, self.crop_xf,
                         self.getcropxf_l),
                set_hbox(self.crop_yi, self.getcropyi_l, self.crop_yf,
                         self.getcropyf_l)))

        return group_box

    def create_type_image_group(self):
        group_box = QGroupBox("&File to save")
        group_box.setCheckable(True)
        group_box.setChecked(True)

        self.image_png_l = QtWidgets.QCheckBox('Image .png', self)
        self.image_tif_l = QtWidgets.QCheckBox('Image .tif', self)
        self.image_fit_l = QtWidgets.QCheckBox('Image .fit', self)

        group_box.setLayout(
            set_lvbox(set_hbox(self.image_png_l), set_hbox(self.image_tif_l),
                      set_hbox(self.image_fit_l)))

        return group_box

    def create_push_button_group(self):
        group_box = QGroupBox()
        self.saveButton = QPushButton("Save")
        self.saveButton.clicked.connect(self.button_ok_func)

        self.cancelButton = QPushButton("Cancel")
        self.cancelButton.clicked.connect(self.func_cancel)

        self.clearButton = QPushButton("Clear")
        self.clearButton.clicked.connect(self.clear_all)

        group_box.setLayout(
            set_lvbox(
                set_hbox(self.saveButton, self.clearButton,
                         self.cancelButton)))

        return group_box

    def button_ok_func(self):
        try:
            y_pixels, x_pixels = self.get_pixels()
            """
            ATENCAO
            """
            # Saving the Settings
            # if int(self.getcropxi_l.text()) > int(self.getcropxf_l.text()) or \
            #    int(self.getcropyi_l.text()) > int(self.getcropyf_l.text()) or \
            #    int(self.getcropxf_l.text()) >= x_pixels or \
            #    int(self.getcropyf_l.text()) >= y_pixels:
            #
            #     self.console.raise_text("Wrong values for image crop.", 3)
            #
            # else:
            self.image_settings.set_image_settings(
                self.getlevel1l.text(), self.getlevel2l.text(),
                self.getcropxi_l.text(), self.getcropxf_l.text(),
                self.getcropyi_l.text(), self.getcropyf_l.text(),
                self.ignore_crop_l.isChecked(), self.image_png_l.isChecked(),
                self.image_tif_l.isChecked(), self.image_fit_l.isChecked())
            self.image_settings.save_settings()
            self.console.raise_text("Image settings successfully saved!", 1)

        except Exception as e:
            print("Image settings were not saved -> {}".format(e))
            self.console.raise_text("Image settings were not saved.", 3)

    def clear_all(self):
        self.getlevel1l.clear()
        self.getlevel2l.clear()
        self.getcropxi_l.clear()
        self.getcropxf_l.clear()
        self.getcropyi_l.clear()
        self.getcropyf_l.clear()

    def func_cancel(self):
        self.image_parent.close()

    def setting_values(self):
        info = self.get_image_settings()
        self.set_values(info[0], info[1], info[2], info[3], info[4], info[5],
                        info[6], info[7], info[8], info[9])

    def set_values(self, get_level1, get_level2, crop_xi, crop_xf, crop_yi,
                   crop_yf, ignore_crop, image_png, image_tif, image_fit):
        self.getlevel1l.setText(get_level1)
        self.getlevel2l.setText(get_level2)

        self.getcropxi_l.setText(crop_xi)
        self.getcropxf_l.setText(crop_xf)
        self.getcropyi_l.setText(crop_yi)
        self.getcropyf_l.setText(crop_yf)

        self.ignore_crop_l.setChecked(ignore_crop)
        self.image_png_l.setChecked(image_png)
        self.image_tif_l.setChecked(image_tif)
        self.image_fit_l.setChecked(image_fit)