def set_otherCols_fromMat(self, units, matName, doseItem): if matName: if not doseItem.text(): doseItem.setText('0.1') if not units.text(): textSet = False if self.comboDetectorSelect.currentIndex() == 0: detector_list = [ detector for detector in Session().query(Detector) ] else: detector_list = [ Session().query(Detector).filter_by( name=self.comboDetectorSelect.currentText()).first( ) ] for detector in detector_list: for baseSpectrum in detector.base_spectra: if baseSpectrum.material.name == matName and not textSet: units.tableWidget().blockSignals(True) if isinstance(baseSpectrum.rase_sensitivity, float): units.setText(units_labels['DOSE']) units.setData(Qt.UserRole, 'DOSE') textSet = True else: units.setText(units_labels['FLUX']) units.setData(Qt.UserRole, 'FLUX') units.tableWidget().blockSignals(False)
def showDetailView(self, index): scen_det_key = self.results_model.headerData(index.row(), Qt.Vertical, Qt.UserRole) resultMap = self.parent.result_super_map[scen_det_key] scen_id = scen_det_key.split('*')[0] det_name = "".join(scen_det_key.split('*')[1:]) scenario = Session().query(Scenario).filter_by(id=scen_id).first() detector = Session().query(Detector).filter_by(name=det_name).first() DetailedResultsDialog(resultMap, scenario, detector).exec_()
def createEditor(self, parent, option, index): if index.column() == self.matCol: # generate material list fd_units = self.tblMat.item(index.row(), self.unitsCol).data(Qt.UserRole) material_list = [] if not self.selected_detname: for detector in Session().query(Detector): for baseSpectrum in detector.base_spectra: if baseSpectrum.material.name not in material_list: if ((isinstance(baseSpectrum.rase_sensitivity, float) and (fd_units == 'DOSE')) or (isinstance(baseSpectrum.flux_sensitivity, float) and (fd_units == 'FLUX')) or not fd_units): material_list.append( baseSpectrum.material.name) material_list = sorted(material_list) else: detector = Session().query(Detector).filter_by( name=self.selected_detname).first() material_list = sorted([ baseSpectrum.material.name for baseSpectrum in detector.base_spectra if ((isinstance(baseSpectrum.rase_sensitivity, float) and (fd_units == 'DOSE')) or (isinstance(baseSpectrum.flux_sensitivity, float) and (fd_units == 'FLUX')) or not fd_units) ]) # remove any materials already used for row in range(self.tblMat.rowCount()): item = self.tblMat.item(row, self.matCol) if item and item.text() in material_list: material_list.remove(item.text()) #create and populate comboEdit comboEdit = QComboBox(parent) comboEdit.setEditable(self.editable) comboEdit.setSizeAdjustPolicy(0) comboEdit.setMaxVisibleItems(25) comboEdit.addItem('') comboEdit.addItems(material_list) return comboEdit elif index.column() == self.intensityCol: editor = QLineEdit(parent) editor.setValidator(RegExpSetValidator(editor, self.auto_s)) return editor elif index.column() == self.unitsCol: return self.unitsEditor(parent, index) else: return super(MaterialDoseDelegate, self).createEditor(parent, option, index)
def viewResults(r, scenIdall, detector): """ Opens Results table """ # need a correspondence table in order to display results! session = Session() settings = RaseSettings() default_corr_table = session.query(CorrespondenceTable).filter_by( is_default=True).one_or_none() if not default_corr_table: msgbox = QMessageBox( QMessageBox.Question, 'No Correspondence Table set!', 'No correspondence table set! Would you like to set a correspondence table now?' ) msgbox.addButton(QMessageBox.Yes) msgbox.addButton(QMessageBox.No) answer = msgbox.exec() if answer == QMessageBox.Yes: CorrespondenceTableDialog().exec_() settings.setIsAfterCorrespondenceTableCall(True) else: return selected_scenarios = scenIdall r.calculateScenarioStats(1, selected_scenarios, detector) ViewResultsDialog(r, selected_scenarios, detector).exec_()
def __init__(self, resultMap, scenario, detector): QDialog.__init__(self) self.setupUi(self) self.settings = RaseSettings() self.headerLabels = ['File', 'Tp', 'Fn', 'Fp', 'Precision', 'Recall', 'Fscore', 'IDs'] self.NUM_COLS = len(self.headerLabels) self.session = Session() self.scenario = scenario self.detector = detector self.tblDetailedResults.setContextMenuPolicy(Qt.CustomContextMenu) self.tblDetailedResults.setColumnCount(self.NUM_COLS) self.tblDetailedResults.setHorizontalHeaderLabels(self.headerLabels) self.tblDetailedResults.horizontalHeader().setSectionResizeMode(0, QHeaderView.Stretch) self.tblDetailedResults.setRowCount(0) row=0 for file in sorted(resultMap, key=natural_keys): results = resultMap[file] results.insert(0, file) self.tblDetailedResults.insertRow(row) for col in range(self.NUM_COLS): self.tblDetailedResults.setItem(row, col, QTableWidgetItem(results[col])) row = row + 1 results.pop(0) self.tblDetailedResults.resizeColumnsToContents() self.tblDetailedResults.horizontalHeader().setSectionResizeMode(0, QHeaderView.Stretch) self.buttonOK.clicked.connect(self.closeSelected) self.buttonExport.clicked.connect(self.handleExport)
def __init__(self, parent=None, groups=[], scens=None, del_groups=False): QDialog.__init__(self, parent) self.groups = groups self.scens = scens self.del_groups = del_groups self.session = Session() self.makeLayout()
def export_scenarios(scenarios_ids, file_path): """ Export scenarios from database to xml file """ session = Session() scenarios = [session.query(Scenario).filter_by(id=scenid).first() for scenid in scenarios_ids] scen_io = ScenariosIO() xml_str = scen_io.scenario_export(scenarios) Path(file_path).write_text(xml_str)
def set_otherCols_fromUnit(self, units, matName, doseItem): textKeep = False if self.comboDetectorSelect.currentIndex() == 0: detector_list = [ detector for detector in Session().query(Detector) ] else: detector_list = [ Session().query(Detector).filter_by( name=self.comboDetectorSelect.currentText()).first() ] for detector in detector_list: for baseSpectrum in detector.base_spectra: if baseSpectrum.material.name == matName.text( ) and not textKeep: if (units.data(Qt.UserRole) == 'DOSE' and isinstance(baseSpectrum.rase_sensitivity, float)) or \ (units.data(Qt.UserRole) == 'FLUX' and isinstance(baseSpectrum.flux_sensitivity, float)): textKeep = True if not textKeep: matName.setText('')
def cleanup_scenarios(rangefind_rep, scenIds): """Remove scenarios from the database that were rangefinders, i.e.: low replication scenarios""" settings = RaseSettings() session = Session() scenarios = [] for scen in scenIds: scenarios.append(session.query(Scenario).filter_by(id=scen).first()) scens_to_delete = [] for scen in scenarios: if scen.replication == rangefind_rep: scens_to_delete.append(scen.id) delete_scenario(scens_to_delete, settings.getSampleDirectory()) session.commit()
def delete_scenario(scenario_ids, sample_root_dir): """ Delete scenarios from database and cleanup sample folders """ session = Session() for id in scenario_ids: scenDelete = session.query(Scenario).filter(Scenario.id == id) matDelete = session.query(ScenarioMaterial).filter(ScenarioMaterial.scenario_id == id) backgMatDelete = session.query(ScenarioBackgroundMaterial).filter(ScenarioBackgroundMaterial.scenario_id == id) # folders folders = [name for name in glob.glob(os.path.join(sample_root_dir, "*" + id + "*"))] for folder in folders: shutil.rmtree(folder) # database scenObj = scenDelete.first() scenObj.scenario_groups.clear() matDelete.delete() backgMatDelete.delete() scenDelete.delete() session.commit() session.close()
def __init__(self, rase_gui, id=None, duplicate=[], auto_s=False): QDialog.__init__(self) self.setupUi(self) self.rase_gui = rase_gui self.tblMaterial.setContextMenuPolicy(Qt.CustomContextMenu) self.tblBackground.setContextMenuPolicy(Qt.CustomContextMenu) self.id = id self.auto_s = auto_s self.settings = RaseSettings() self.scenarioHasChanged = False self.groupHasChanged = False self.duplicate = duplicate self.session = Session() self.txtAcqTime.setText('30') self.txtAcqTime.setToolTip( "Enter comma-separated values OR range as min-max:step OR range followed by comma-separated values" ) self.txtReplication_2.setText('100') int_validator = QIntValidator() self.txtAcqTime.setValidator(RegExpSetValidator()) self.txtReplication_2.setValidator(int_validator) self.tblMaterial.setHorizontalHeaderItem(INTENSITY, QTableWidgetItem('Intensity')) self.tblBackground.setHorizontalHeaderItem( INTENSITY, QTableWidgetItem('Intensity')) self.tblMaterial.customContextMenuRequested.connect( lambda x, table=self.tblMaterial: self.context_auto_range( x, self.tblMaterial)) self.tblBackground.customContextMenuRequested.connect( lambda x, table=self.tblBackground: self.context_auto_range( x, self.tblBackground)) # set material table self.tblMaterial.setItemDelegate( MaterialDoseDelegate(self.tblMaterial, unitsCol=UNITS, materialCol=MATERIAL, intensityCol=INTENSITY)) self.tblMaterial.setRowCount(10) for row in range(self.tblMaterial.rowCount()): self.tblMaterial.setItem(row, UNITS, QTableWidgetItem()) self.tblMaterial.setItem(row, INTENSITY, QTableWidgetItem()) self.tblMaterial.setItem(row, MATERIAL, QTableWidgetItem()) self.tblMaterial.item(row, INTENSITY).setToolTip( "Enter comma-separated values OR range as min-max:step OR range followed by comma-separated values" ) self.tblMaterial.setRowHeight(row, 22) # set background table self.tblBackground.setItemDelegate( MaterialDoseDelegate(self.tblBackground, unitsCol=UNITS, materialCol=MATERIAL, intensityCol=INTENSITY, auto_s=self.auto_s)) self.tblBackground.setRowCount(10) for row in range(self.tblBackground.rowCount()): self.tblBackground.setItem(row, UNITS, QTableWidgetItem()) self.tblBackground.setItem(row, INTENSITY, QTableWidgetItem()) self.tblBackground.setItem(row, MATERIAL, QTableWidgetItem()) self.tblBackground.item(row, INTENSITY).setToolTip( "Enter comma-separated values OR range as min-max:step OR range followed by comma-separated values" ) self.tblBackground.setRowHeight(row, 22) # fill influence list for influence in self.session.query(Influence): self.lstInfluences.addItem(QListWidgetItem(influence.name)) self.comboDetectorSelect.addItems( ["all detectors"] + [s.name for s in self.session.query(Detector).all()]) self.comboDetectorSelect.currentIndexChanged.connect( self.updateTableDelegate) # display a previous scenario if defined if self.id: if not self.duplicate: self.setWindowTitle("Scenario Edit") scenario = self.session.query(Scenario).get(id) materials = scenario.scen_materials bckg_materials = scenario.scen_bckg_materials influences = scenario.influences for table, mat_list in zip( (self.tblMaterial, self.tblBackground), (materials, bckg_materials)): for rowCount, mat in enumerate(mat_list): item = QTableWidgetItem(units_labels[mat.fd_mode]) item.setData(Qt.UserRole, mat.fd_mode) table.setItem(rowCount, 0, item) table.setItem(rowCount, 1, QTableWidgetItem(mat.material_name)) table.setItem(rowCount, 2, QTableWidgetItem(str(mat.dose))) self.txtAcqTime.setText(str(scenario.acq_time)) self.txtReplication_2.setText(str(scenario.replication)) for influence in influences: lst = self.lstInfluences.findItems(influence.name, Qt.MatchExactly)[0] lst.setSelected(True) self.groups = self.getGroups() else: self.setWindowTitle("Build Scenario from Other Scenario") scens = [ self.session.query(Scenario).filter_by(id=scen).first() for scen in self.duplicate ] scenario = scens[0] materials = scenario.scen_materials back_materials = scenario.scen_bckg_materials influences = scenario.influences mat_dict = {} back_dict = {} mat_fd = [] back_fd = [] for mat in materials: mat_fd.append((mat.material_name, mat.fd_mode)) mat_dict[mat.material_name] = set([mat.dose]) for back in back_materials: back_fd.append((back.material_name, back.fd_mode)) back_dict[back.material_name] = set([back.dose]) if len(scens) > 1: for scen in scens[1:]: mat_dict = self.make_matDict(scen.scen_materials, mat_dict) back_dict = self.make_matDict(scen.scen_bckg_materials, back_dict) if influences: influences.append[scen.influences] else: influences = scen.influences for table, material_dictionary, fd_list in \ zip((self.tblMaterial, self.tblBackground), (mat_dict, back_dict), (mat_fd, back_fd)): mat_list_tup = [(k, v) for k, v in material_dictionary.items()] for rowCount, (mat, fd_mode) in enumerate( zip(mat_list_tup, fd_list)): doses = [str(d) for d in sorted(mat[1])] item = QTableWidgetItem(units_labels[fd_mode[1]]) item.setData(Qt.UserRole, fd_mode[1]) table.setItem(rowCount, 0, item) table.setItem(rowCount, 1, QTableWidgetItem(str(mat[0]))) table.setItem(rowCount, 2, QTableWidgetItem(str(','.join(doses)))) self.txtAcqTime.setText(str(scenario.acq_time)) for influence in influences: lst = self.lstInfluences.findItems(influence.name, Qt.MatchExactly)[0] lst.setSelected(True) self.groups = self.getGroups() else: self.groups = [] if self.auto_s and self.rase_gui.static_background: for rowCount, mat in enumerate(self.rase_gui.static_background): mat = mat[0] item = QTableWidgetItem(units_labels[mat[0]]) item.setData(Qt.UserRole, mat[0]) self.tblBackground.setItem(rowCount, 0, item) self.tblBackground.setItem(rowCount, 1, QTableWidgetItem(mat[1].name)) self.tblBackground.setItem(rowCount, 2, QTableWidgetItem(str(mat[2]))) # signal/slot connections (this has to be done after_ the previous scenario is loaded) self.tblMaterial.cellChanged.connect(self.scenarioChanged) self.tblBackground.cellChanged.connect(self.scenarioChanged) self.tblMaterial.cellChanged.connect(self.updateScenariosList) self.tblBackground.cellChanged.connect(self.updateScenariosList) self.lstInfluences.itemSelectionChanged.connect(self.scenarioChanged) self.txtAcqTime.textChanged.connect(self.scenarioChanged) self.txtReplication_2.textChanged.connect(self.scenarioChanged) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject)
def _getCountsDoseAndSensitivity(scenario, detector, degradations=None): """ :param scenario: :param detector: :return: """ session = Session() # distortion: distort ecal with influence factors ecal = [detector.ecal3, detector.ecal2, detector.ecal1, detector.ecal0] energies = np.polyval(ecal, np.arange(detector.chan_count)) new_influences = [] bin_widths = np.zeros([len(scenario.influences), len(energies)]) for index, influence in enumerate(scenario.influences): detInfl = session.query(DetectorInfluence).filter_by(influence_name=influence.name).first() new_infl = [detInfl.infl_0, detInfl.infl_1, detInfl.infl_2, detInfl.fixed_smear, detInfl.linear_smear] if degradations: new_infl = [infl + deg for infl, deg in zip(new_infl, degradations[index])] # deal with potential negative values for position, n_inf in enumerate(new_infl): if n_inf < 0: if not position == 1: new_infl[position] = 0 else: new_infl[position] = 0.0001 new_influences.append(new_infl) if new_infl[0] != 0 or new_infl[2] != 0 or new_infl[1] != 1: energies = np.polyval([new_infl[2], (new_infl[1]), new_infl[0]], energies) # convert fixed energy smear distortion from energy to bins if new_infl[3] != 0: e_width = new_infl[3] / 2 for sub_index, energy in enumerate(energies): b0 = np.roots([new_infl[2], new_infl[1], new_infl[0] - (energy - e_width)]) b1 = np.roots([new_infl[2], new_infl[1], new_infl[0] - (energy + e_width)]) bin_widths[index][sub_index] = max(b1) - max(b0) # get dose, counts and sensitivity for each material countsDoseAndSensitivity = [] for scenMaterial in scenario.scen_materials + scenario.scen_bckg_materials: baseSpectrum = (session.query(BaseSpectrum) .filter_by(detector_name=detector.name, material_name=scenMaterial.material_name) ).first() counts = baseSpectrum.get_counts_as_np() if scenario.influences: for index, infl in enumerate(new_influences): counts = apply_distortions(infl, counts, bin_widths[index], energies, ecal) if scenMaterial.fd_mode == 'FLUX': countsDoseAndSensitivity.append((counts, scenMaterial.dose, baseSpectrum.flux_sensitivity)) else: countsDoseAndSensitivity.append((counts, scenMaterial.dose, baseSpectrum.rase_sensitivity)) # if the detector has an internal calibration source, it needs to be added with special treatment if detector.includeSecondarySpectrum and detector.secondary_type == secondary_type['internal']: secondary_spectrum = (session.query(BackgroundSpectrum).filter_by(detector_name=detector.name)).first() counts = secondary_spectrum.get_counts_as_np() # apply distortion on counts if scenario.influences: for index, infl in enumerate(new_influences): counts = apply_distortions(infl, counts, bin_widths[index], energies, ecal) # extract counts per second cps = sum(counts)/secondary_spectrum.livetime # the internal calibration spectrum is scaled only by time # so the sensitivity parameter is set to the cps and the dose to 1 countsDoseAndSensitivity.append((counts, 1.0, cps)) return countsDoseAndSensitivity
def generate_curve(r, input_data, advanced): """Primary function where the points that make up the S-curve are determined""" session = Session() if advanced['custom_name'] == '[Default]': group_name = ("AutoScurve_" + input_data['instrument'] + '_' + input_data['source']) else: suffix = 0 while True: if session.query(ScenarioGroup).filter_by( name=advanced['custom_name']).first(): if not session.query(ScenarioGroup).filter_by( name=advanced['custom_name']).first().scenarios: group_name = (advanced['custom_name']) break else: suffix += 1 advanced['custom_name'] = advanced[ 'custom_name'] + '_' + str(suffix) else: group_name = (advanced['custom_name']) break detName = [input_data['instrument']] detector = session.query(Detector).filter_by(name=detName[0]).first() condition = False already_done = False expand = 0 first_run = True # All scenarios within the group that have the same source/backgrounds make_scen_group(session, group_name, input_data) scenIdall = make_scenIdall(session, input_data) # scenarios that will be rerun in this run scenIds_no_persist = [] maxback = 0 if input_data['background']: for bmat in input_data['background']: bmat = bmat[0] if bmat[0] == input_data['source_fd']: if maxback == 0: maxback = float(bmat[2]) else: maxback = max(maxback, float(bmat[2])) if not maxback: maxback = 0.1 while not condition: # newly generated scenIds, and all scenIds with source/backgrounds as defined in the auto s-curve gui scenIds, scenIds_no_persist, scenIdall = gen_scens( input_data, advanced, session, scenIdall, scenIds_no_persist, group_name, advanced['repetitions']) abort = run_scenarios(r, scenIds, detector, input_data['replay'], condition, expand, first_run) first_run = False if abort: cleanup_scenarios(advanced['repetitions'], scenIds_no_persist) return r.calculateScenarioStats(1, scenIdall, detName) if input_data['results_type'] == 'C&C': results = r.scenario_stats_df['C&C'] elif input_data['results_type'] == 'TP': results = r.scenario_stats_df['TP'] elif input_data['results_type'] == 'Precision': results = r.scenario_stats_df['Precision'] elif input_data['results_type'] == 'Recall': results = r.scenario_stats_df['Recall'] elif input_data['results_type'] == 'Fscore': results = r.scenario_stats_df['F_Score'] else: # to add more later results = r.scenario_stats_df['PID'] if not input_data['invert_curve']: results = results.sort_values() else: results = results.sort_values(ascending=False) if max(results) >= advanced['upper_bound'] and min( results) <= advanced['lower_bound']: """If there are values surrounding the rising edge""" # find scenarios in for cases ids_on_edge = [] start_list = [] end_list = [] prev_point = False for index, result in enumerate(results): if (not input_data['invert_curve'] and result <= advanced['lower_bound']) or \ (input_data['invert_curve'] and result >= advanced['upper_bound']): start_list.append(results.index[index].split('*')[0]) if prev_point: ids_on_edge = [ ] # rose and then dropped back down (i.e.: fluctuations) prev_point = False elif advanced['lower_bound'] <= result <= advanced[ 'upper_bound']: ids_on_edge.append(results.index[index].split('*')[0]) prev_point = True elif (not input_data['invert_curve'] and result >= advanced['upper_bound']) or \ (input_data['invert_curve'] and result <= advanced['lower_bound']): end_list.append(results.index[index].split('*')[0]) # Grab doses for scenarios on the edges of the S-curve. The first value in each list is # the value that is the second closest to the rising edge, and the second is the closest start_val = [-1, -1] end_val = [-1, -1] for scenid in scenIdall: scen = session.query(Scenario).filter_by(id=scenid).first() if scenid in start_list: if start_val[1] == -1 or scen.scen_materials[ 0].dose >= start_val[1]: start_val = set_bounds(start_val, scen.scen_materials[0].dose) if scen.id in end_list: if end_val[1] == -1 or scen.scen_materials[ 0].dose < end_val[1]: end_val = set_bounds(end_val, scen.scen_materials[0].dose) # check if there are enough points on the rising edge if len(ids_on_edge) >= advanced['rise_points']: condition = True # to avoid persistence errors by reusing a value with the same ID but different replications edge_count, bound_scens_start, bound_scens_end = check_edge_ids( session, input_data['input_reps'], start_list, end_list, ids_on_edge, detector) if edge_count < advanced[ 'rise_points'] or bound_scens_start < 2 or bound_scens_end < 2: advanced['min_guess'] = start_val[0] * 0.9 advanced['max_guess'] = end_val[0] * 1.1 advanced['num_points'] = advanced['rise_points'] + 4 else: already_done = True else: # avoid infinite loop due to being stuck on edge cases. Moves slightly inward to better populate edge if start_val[1] == advanced['min_guess']: advanced['min_guess'] = start_val[1] + ( end_val[1] - start_val[1]) * 0.01 else: advanced['min_guess'] = start_val[1] if end_val[1] == advanced['max_guess']: advanced['max_guess'] = end_val[1] - (end_val[1] - start_val[1]) * 0.01 else: advanced['max_guess'] = end_val[1] advanced['num_points'] = advanced['rise_points'] # + 4 elif min(results) >= advanced['lower_bound']: """If the quoted results aren't small enough yet""" expand += 1 dose_list = [] for scenId in scenIdall: scen = session.query(Scenario).filter_by(id=scenId).first() dose_list.append(scen.scen_materials[0].dose) dose_list.sort() if not input_data['invert_curve']: dose_bound = dose_list[0] if (0 < dose_bound <= 1E-9 * maxback and len(scenIdall) >= 9) or 0 < dose_bound <= 1E-12: fail_never(r, scenIdall, [input_data['instrument']]) return if len(dose_list) > 1: step_ratio = dose_list[0] / dose_list[1] else: step_ratio = dose_list[0] * 0.9 advanced['min_guess'] = advanced['min_guess'] * step_ratio advanced['max_guess'] = advanced['min_guess'] advanced['num_points'] = 1 else: dose_bound = dose_list[-1] if dose_bound >= 40 * maxback and len(scenIdall) >= 9: fail_never(r, scenIdall, [input_data['instrument']]) return if len(dose_list) > 1: step_ratio = dose_list[-1] / dose_list[-2] else: step_ratio = dose_list[0] * 1.1 advanced['min_guess'] = advanced['max_guess'] * step_ratio advanced['max_guess'] = advanced['min_guess'] advanced['num_points'] = 1 elif max(results) <= advanced['upper_bound']: """If the quoted results aren't large enough yet""" expand += 1 dose_list = [] for scenId in scenIdall: scen = session.query(Scenario).filter_by(id=scenId).first() # for scen in session.query(ScenarioGroup).filter_by(name=group_name).first().scenarios: dose_list.append(scen.scen_materials[0].dose) dose_list.sort() if not input_data['invert_curve']: dose_bound = dose_list[-1] if dose_bound >= 40 * maxback and len(scenIdall) >= 9: fail_always(r, scenIdall, [input_data['instrument']]) return if len(dose_list) > 1: step_ratio = dose_list[-1] / dose_list[-2] else: step_ratio = dose_list[0] * 1.1 advanced['min_guess'] = advanced['max_guess'] * step_ratio advanced['max_guess'] = advanced['min_guess'] advanced['num_points'] = 1 else: dose_bound = dose_list[0] if (0 < dose_bound <= 1E-9 * maxback and len(scenIdall) >= 9) or 0 < dose_bound <= 1E-12: fail_always(r, scenIdall, [input_data['instrument']]) return if len(dose_list) > 1: step_ratio = dose_list[0] / dose_list[1] else: step_ratio = dose_list[0] * 0.9 advanced['min_guess'] = advanced['min_guess'] * step_ratio advanced['max_guess'] = advanced['min_guess'] advanced['num_points'] = 1 if condition: if not already_done: scenIds, _, _ = gen_scens(input_data, advanced, session, scenIdall, scenIds_no_persist, group_name, input_data['input_reps'], condition) detector = session.query(Detector).filter_by( name=detName[0]).first() abort = run_scenarios(r, scenIds, detector, input_data['replay'], condition) if abort: cleanup_scenarios(advanced['repetitions'], scenIds_no_persist) cleanup_scenarios(input_data['input_reps'], scenIds) return if advanced['cleanup']: cleanup_scenarios(advanced['repetitions'], scenIds_no_persist) r.populateScenarios() msgbox = QMessageBox(QMessageBox.Question, 'S-Curve generation complete!', 'Would you like to view the results?') msgbox.addButton(QMessageBox.Yes) msgbox.addButton(QMessageBox.No) answer = msgbox.exec() if answer == QMessageBox.Yes: viewResults(r, scenIds, [input_data['instrument']])
def __init__(self, parent): QDialog.__init__(self, parent) self.setWindowTitle('Automated S-Curve Generation') self.Rase = parent self.settings = RaseSettings() self.setupUi(self) self.session = Session() # setting default states self.detName = None self.detReplay = None self.static_background = [] self.setInstrumentItems() self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) # Validators self.line_rep.setValidator( QRegularExpressionValidator(QRegularExpression("[0-9]{0,9}"))) self.line_initrep.setValidator( QRegularExpressionValidator(QRegularExpression("[0-9]{0,9}"))) self.line_edge.setValidator( QRegularExpressionValidator(QRegularExpression("[0-9]{0,9}"))) self.line_dwell.setValidator( QRegularExpressionValidator( QRegularExpression("((\d*\.\d*)|(\d*))"))) self.line_minx.setValidator( QRegularExpressionValidator( QRegularExpression("((\d*\.\d*)|(\d*))"))) self.line_maxx.setValidator( QRegularExpressionValidator( QRegularExpression("((\d*\.\d*)|(\d*))"))) self.line_addpoints.setValidator( QRegularExpressionValidator( QRegularExpression( r"((((\d+\.\d*)|(\d*\.\d+))|(\d+))((((,\d*\.\d+)|(,\d+\.\d*))|(,\d+))*)(,|,\.)?)" ))) self.line_lowerbound.setValidator( QRegularExpressionValidator( QRegularExpression("((\d*\.\d*)|(\d*))"))) self.line_upperbound.setValidator( QRegularExpressionValidator( QRegularExpression("((\d*\.\d*)|(\d*))"))) # connections self.combo_inst.currentTextChanged.connect(self.updateMaterials) self.combo_mat.currentTextChanged[str].connect( lambda mat: self.updateUnits(mat, self.combo_matdose)) self.btn_bgnd.clicked.connect(self.defineBackground) # Confirm enables self.combo_matdose.currentTextChanged.connect(self.enableOk) # Set values of various things based on user inputs self.line_rep.editingFinished.connect( lambda: self.setminval(self.line_rep, '2')) self.line_initrep.editingFinished.connect( lambda: self.setminval(self.line_initrep, '1')) self.line_edge.editingFinished.connect( lambda: self.setminval(self.line_edge, '1')) self.line_dwell.editingFinished.connect( lambda: self.setminval(self.line_dwell, '1', '0.00000000001')) self.line_minx.editingFinished.connect(lambda: self.setminval( self.line_minx, '0.00000001', '0.00000000001')) self.line_maxx.editingFinished.connect( lambda: self.setminval(self.line_maxx, '0.001', '0.00000000001')) self.line_lowerbound.editingFinished.connect( lambda: self.setminval(self.line_lowerbound, '0')) self.line_lowerbound.editingFinished.connect( lambda: self.setmaxval(self.line_lowerbound, '.99')) self.line_upperbound.editingFinished.connect( lambda: self.setmaxval(self.line_upperbound, '1')) self.line_minx.editingFinished.connect(self.checkMaxX) self.line_maxx.editingFinished.connect(self.checkMaxX) self.line_lowerbound.editingFinished.connect(self.checkMaxY) self.line_upperbound.editingFinished.connect(self.checkMaxY) self.line_addpoints.editingFinished.connect(self.removeZeroPoint) self.check_minx.stateChanged.connect(self.setDefaultMin) self.check_maxx.stateChanged.connect(self.setDefaultMax) self.check_addpoints.stateChanged.connect(self.setAddPoints) self.check_name.stateChanged.connect(self.setDefaultName)