def exposure_seconds_changed(self): """Validate and store changed exposure seconds field""" proposed_value = self.ui.exposureSeconds.text() # print("exposureSecondsChanged: " + proposed_value) if self.ui.biasButton.isChecked(): # Bias frame - exposure field can be blank or zero if proposed_value.strip() == "": self._exposureValid = True elif Validators.valid_float_in_range(proposed_value, 0, 0) is not None: self._exposureValid = True else: self.ui.exposureSeconds.setText("INVALID") self._exposureValid = False else: # Dark frame - exposure field must be positive number assert (self.ui.darkButton.isChecked()) if Validators.valid_float_in_range(proposed_value, 0, 24 * 60 * 60) is not None: # print(f" Set exposure time to {float(proposed_value)}") self._exposureValid = True else: self.ui.exposureSeconds.setText("INVALID") self._exposureValid = False self.enableControls()
def add_new_student(student): students_dict = Student.mongoDB.get_all_students() Validators.all_required_fields(student) Validators.validate_name(student['first_name'], student['last_name']) Validators.validate_email(student['email']) # Validators.validate_id(student['student_id']) Validators.unique_email(student['email'], students_dict) return student
def setData(self, index: QModelIndex, value: str, role: int): proposed_value = value.strip() if index.isValid() and (role == Qt.EditRole) and (len(proposed_value) > 0): # print(f"setData on {index.row()},{index.column()}: {proposed_value}") converted_value = Validators.valid_int_in_range( proposed_value, 0, 32767) validity_index_string = f"{index.row()},{index.column()}" raw_row_index: int = self._data_model.map_display_to_raw_filter_index( index.row()) raw_column_index: int = self._data_model.map_display_to_raw_binning_index( index.column()) if converted_value is None: # Invalid data. Signal it by turning the cell red and tell # the user interface about this so the proceed button will be # disabled until it's fixed self.set_cell_validity(index, False) self._validity_reporting_method(validity_index_string, False) self._data_model.get_flat_frame_count_table().set_table_item( raw_row_index, raw_column_index, proposed_value) else: self._data_model.get_flat_frame_count_table().set_table_item( raw_row_index, raw_column_index, converted_value) self._dirty_reporting_method(True) # Turn of any error colour that might have been set for this cell self.set_cell_validity(index, True) self._validity_reporting_method(validity_index_string, True) return True
def dither_max_radius_changed(self): proposed_new_number: str = self.ui.ditherMaxRadius.text() new_number = Validators.valid_float_in_range(proposed_new_number, 0, 12*60*60) valid = new_number is not None if valid: self._preferences.set_dither_max_radius(new_number) SharedUtils.background_validity_color(self.ui.ditherMaxRadius, valid)
def get_camera_temperature(self) -> (bool, float, str): """Determine the temperature of the camera""" # print(f"get_camera_temperature()") # For testing, return a constant temperature a few times, then gradually let it rise # to test if the "abort on temperature rising above a threshold" feature is OK # TheSkyX.simulated_temp_counter += 1 # if TheSkyX.simulated_temp_counter > 3: # TheSkyX.simulated_temp_rise += 0.5 # print(f"get_camera_temperature returning simulated temperature of {TheSkyX.simulated_temp_rise}") # return (True, TheSkyX.simulated_temp_rise, "Simulated temperature") command_with_return = "var temp=ccdsoftCamera.Temperature;" \ + "var Out;" \ + "Out=temp+\"\\n\";" temperature = 0 (success, temperature_result, message) = self.send_command_with_return(command_with_return) if success: temperature = Validators.valid_float_in_range( temperature_result, -270, +200) if temperature is None: success = False temperature = 0 message = "Invalid Temperature Returned" return success, temperature, message
def prevalidate_all_cells(self): for row_index in range(self.rowCount(QModelIndex())): for column_index in range(self.columnCount(QModelIndex())): raw_row_index: int = self._data_model.map_display_to_raw_filter_index( row_index) raw_column_index: int = self._data_model.map_display_to_raw_binning_index( column_index) cell_contents = str( self._data_model.get_flat_frame_count_table( ).get_table_item(raw_row_index, raw_column_index)) converted_value = Validators.valid_int_in_range( cell_contents, 0, 32767) validity_index_string = f"{row_index},{column_index}" index: QModelIndex = self.index(row_index, column_index) if converted_value is None: # Invalid data. Signal it by turning the cell red and tell # the user interface about this so the proceed button will be # disabled until it's fixed self.set_cell_validity(index, False) self._validity_reporting_method(validity_index_string, False) else: # Turn of any error colour that might have been set for this cell self.set_cell_validity(index, True) self._validity_reporting_method(validity_index_string, True)
def validate_folder_name(cls, proposed: str): """Validate the proposed file name. It must be a legit system file name, except it can also contain the strings %d or %t or %f zero or more times each. We'll just remove those temporarily for purposes of validation.""" upper = proposed.upper() specials_removed = upper.replace("%D", "").replace("%T", "").replace("%F", "") return Validators.valid_file_name(specials_removed, 1, 31)
def source_az_changed(self): """Validate and store light source azimuth""" proposed_new_number: str = self.ui.sourceAz.text() new_number: Optional[float] = Validators.valid_float_in_range(proposed_new_number, -360, +360) valid = new_number is not None if valid: self._preferences.set_source_az(new_number) SharedUtils.background_validity_color(self.ui.sourceAz, valid)
def port_number_changed(self): """Validate and store a changed 'server port number' value""" proposed_new_number: str = self.ui.portNumber.text() new_number = Validators.valid_int_in_range(proposed_new_number, 1, 65536) valid = new_number is not None if valid: self._preferences.set_port_number(new_number) SharedUtils.background_validity_color(self.ui.portNumber, valid)
def target_adus_changed(self): """Validate and store a changed 'target ADUs' value""" proposed_new_number: str = self.ui.targetADUs.text() new_number = Validators.valid_float_in_range(proposed_new_number, 1, 500000) valid = new_number is not None if valid: self._preferences.set_target_adus(new_number) SharedUtils.background_validity_color(self.ui.targetADUs, valid)
def adu_tolerance_changed(self): """Validate and store a changed 'ADU tolerance' value""" proposed_new_number: str = self.ui.aduTolerance.text() new_number = Validators.valid_float_in_range(proposed_new_number, 0, 100) valid = new_number is not None if valid: self._preferences.set_adu_tolerance(new_number / 100.0) SharedUtils.background_validity_color(self.ui.aduTolerance, valid)
def number_of_flats_changed(self): """Validate and store a changed 'number of flat frames' value""" proposed_new_number: str = self.ui.numFlats.text() new_number = Validators.valid_int_in_range(proposed_new_number, 0, 256) valid = new_number is not None if valid: self._preferences.set_default_frame_count(new_number) SharedUtils.background_validity_color(self.ui.numFlats, valid)
def minimum_group_size_changed(self): """User has entered value in minimum group size field. Validate and save""" proposed_new_number: str = self.ui.minimumGroupSize.text() new_number = Validators.valid_int_in_range(proposed_new_number, 1, 32767) valid = new_number is not None if valid: self._preferences.set_minimum_group_size(new_number) SharedUtils.background_validity_color(self.ui.minimumGroupSize, valid)
def min_max_drop_changed(self): """the field giving the number of minimum and maximum values to drop has been changed. Validate it (integer > 0) and store if valid""" proposed_new_number: str = self.ui.minMaxNumDropped.text() new_number = Validators.valid_int_in_range(proposed_new_number, 0, 256) valid = new_number is not None if valid: self._preferences.set_min_max_number_clipped_per_end(new_number) SharedUtils.background_validity_color(self.ui.minMaxNumDropped, valid)
def temperature_group_bandwidth_changed(self): """User has entered value in temperature group bandwidth field. Validate and save""" proposed_new_number: str = self.ui.temperatureGroupBandwidth.text() new_number = Validators.valid_float_in_range(proposed_new_number, 0.1, 50.0) valid = new_number is not None if valid: self._preferences.set_temperature_group_bandwidth(new_number) SharedUtils.background_validity_color( self.ui.temperatureGroupBandwidth, valid)
def pedestal_amount_changed(self): """User has entered value in precalibration pedestal field. Validate and save""" proposed_new_number: str = self.ui.fixedPedestalAmount.text() new_number = Validators.valid_int_in_range(proposed_new_number, 0, 32767) valid = new_number is not None if valid: self._preferences.set_precalibration_pedestal(new_number) SharedUtils.background_validity_color(self.ui.fixedPedestalAmount, valid)
def sigma_threshold_changed(self): """the field giving the sigma limit beyond which values are ignored has changed Validate it (floating point > 0) and store if valid""" proposed_new_number: str = self.ui.sigmaThreshold.text() new_number = Validators.valid_float_in_range(proposed_new_number, 0.01, 100.0) valid = new_number is not None if valid: self._preferences.set_sigma_clip_threshold(new_number) SharedUtils.background_validity_color(self.ui.sigmaThreshold, valid)
def completed_frames_changed(self): """Validate and store changed 'completed frames' field""" proposed_value = self.ui.completedFrames.text() # print("completedFramesChanged, proposed \"" + proposed_value + "\"") if Validators.valid_int_in_range(proposed_value, 0, 32767) is not None: # print(f" Set number of Completed Frames to {int(proposed_value)}") self._completedValid = True else: self.ui.completedFrames.setText("INVALID") self._completedValid = False self.enableControls()
def number_of_frames_changed(self): """Validate and store change number of frames field""" proposed_value = self.ui.numberOfFrames.text() # print("numberOfFramesChanged: " + proposed_value) if Validators.valid_int_in_range(proposed_value, 1, 32767) is not None: # print(f" Set number Of Frames to {int(proposed_value)}") self._numFramesValid = True else: self.ui.numberOfFrames.setText("INVALID") self._numFramesValid = False self.enableControls()
def exposure_group_bandwidth_changed(self): """User has entered value in exposure group bandwidth field. Validate and save""" proposed_new_number: str = self.ui.exposureGroupBandwidth.text() new_number = Validators.valid_float_in_range(proposed_new_number, 0.1, 50.0) valid = new_number is not None if valid: self._data_model.set_exposure_group_bandwidth(new_number) SharedUtils.background_validity_color(self.ui.exposureGroupBandwidth, valid) self._field_validity[self.ui.exposureGroupBandwidth] = valid
def dither_max_radius_changed(self): """Validate and store dither radius""" proposed_value = self.ui.ditherMaxRadius.text() converted_value = Validators.valid_float_in_range( proposed_value, 0, 12 * 60 * 60) valid = converted_value is not None if valid: if converted_value != self._data_model.get_dither_max_radius(): self.set_is_dirty(True) self._data_model.set_dither_max_radius(converted_value) self.set_field_validity(self.ui.ditherMaxRadius, valid) SharedUtils.background_validity_color(self.ui.ditherMaxRadius, valid)
def source_az_changed(self): """Validate and store the azimuth of the light source""" proposed_value: str = self.ui.sourceAz.text() converted_value: Optional[float] = Validators.valid_float_in_range( proposed_value, -360, +360) valid = converted_value is not None if valid: if converted_value != self._data_model.get_source_az(): self.set_is_dirty(True) self._data_model.set_source_az(converted_value) self.set_field_validity(self.ui.sourceAz, valid) SharedUtils.background_validity_color(self.ui.sourceAz, valid)
def target_adus_changed(self): """Validate and store target ADU level""" proposed_value: str = self.ui.targetAdus.text() converted_value = Validators.valid_float_in_range( proposed_value, 0, 1000000) valid = converted_value is not None if valid: if converted_value != self._data_model.get_target_adus(): self.set_is_dirty(True) self._data_model.set_target_adus(converted_value) self.set_field_validity(self.ui.targetAdus, valid) SharedUtils.background_validity_color(self.ui.targetAdus, valid)
def minimum_group_size_changed(self): """the field giving the minimum group size to recognize has been changed. Validate it (integer > 1) and store if valid""" proposed_new_number: str = self.ui.minimumGroupSize.text() new_number = Validators.valid_int_in_range(proposed_new_number, 1, 32767) valid = new_number is not None if valid: self._data_model.set_minimum_group_size(new_number) SharedUtils.background_validity_color(self.ui.minimumGroupSize, valid) self._field_validity[self.ui.minimumGroupSize] = valid self.enable_buttons()
def edit_student(student): students_dict = Student.mongoDB.get_all_students() Validators.all_required_fields(student) Validators.validate_name(student["first_name"], student["last_name"]) Validators.validate_email(student["email"]) # Validators.validate_student_exists(student, students_dict) student["last_update"] = str(datetime.now())
def validate_folder_name(cls, proposed: str): """ Validate the proposed file name. It must be a legit system file name, except it can also contain the strings %d or %t or %f zero or more times each. We'll just remove those temporarily for purposes of validation. :param proposed: File name we're thinking of using :return: Indicator that it's valid (syntactically, no availability test) """ upper = proposed.upper() specials_removed = upper.replace("%D", "").replace("%T", "").replace("%F", "") return Validators.valid_file_name(specials_removed, 1, 31)
def adu_tolerance_changed(self): """Validate and store ADU tolerance percentage""" proposed_value = self.ui.aduTolerance.text() converted_value = Validators.valid_float_in_range( proposed_value, 0, 100) valid = converted_value is not None if valid: to_fraction = converted_value / 100.0 if to_fraction != self._data_model.get_adu_tolerance(): self.set_is_dirty(True) self._data_model.set_adu_tolerance(to_fraction) self.set_field_validity(self.ui.targetAdus, valid) SharedUtils.background_validity_color(self.ui.aduTolerance, valid)
def dark_frames_count_changed(self): """validate and store changed dark frame count field""" # print("darkFramesCountChanged") proposed_value: str = self.ui.darkFramesCount.text() self.ui.darkMessage.setText("") value: int = Validators.valid_int_in_range(proposed_value, 1, 32767) if value is not None: self._numDarkFrames = value else: self._numDarkFrames = 0 if proposed_value != "": self.ui.darkMessage.setText("Invalid Dark frame count") self.enable_buttons()
def pedestal_amount_changed(self): """the field giving the fixed calibration pedestal amount has been changed. Validate it (integer > 0) and store if valid""" proposed_new_number: str = self.ui.fixedPedestalAmount.text() new_number = Validators.valid_int_in_range(proposed_new_number, 0, 32767) valid = new_number is not None if valid: self._data_model.set_precalibration_pedestal(new_number) SharedUtils.background_validity_color(self.ui.fixedPedestalAmount, valid) self._field_validity[self.ui.fixedPedestalAmount] = valid self.enable_buttons()
def get_camera_temperature(self) -> (bool, float, str): """Retrieve the current CCD temperature from the camera""" command_with_return = "var temp=ccdsoftCamera.Temperature;" \ + "var Out;" \ + "Out=temp+\"\\n\";" temperature = 0 (success, temperature_result, message) = self.send_command_with_return(command_with_return) if success: temperature = Validators.valid_float_in_range( temperature_result, -270, +200) if temperature is None: success = False temperature = 0 message = "Invalid Temperature Returned" return success, temperature, message