def __init__(self, app): super().__init__(app) self._widget = QtWidgets.QWidget() outer_layout = QtWidgets.QFormLayout() self._widget.setLayout(outer_layout) self.rbtn_data_group = QtWidgets.QButtonGroup() self.rbtn_data_vswr = QtWidgets.QRadioButton("VSWR") self.rbtn_data_resistance = QtWidgets.QRadioButton("Resistance") self.rbtn_data_reactance = QtWidgets.QRadioButton("Reactance") self.rbtn_data_s21_gain = QtWidgets.QRadioButton("S21 Gain") self.rbtn_data_group.addButton(self.rbtn_data_vswr) self.rbtn_data_group.addButton(self.rbtn_data_resistance) self.rbtn_data_group.addButton(self.rbtn_data_reactance) self.rbtn_data_group.addButton(self.rbtn_data_s21_gain) self.rbtn_data_s21_gain.setChecked(True) self.rbtn_peak_group = QtWidgets.QButtonGroup() self.rbtn_peak_positive = QtWidgets.QRadioButton("Highest value") self.rbtn_peak_negative = QtWidgets.QRadioButton("Lowest value") self.rbtn_peak_group.addButton(self.rbtn_peak_positive) self.rbtn_peak_group.addButton(self.rbtn_peak_negative) self.rbtn_peak_positive.setChecked(True) self.checkbox_move_marker = QtWidgets.QCheckBox() outer_layout.addRow(QtWidgets.QLabel("<b>Settings</b>")) outer_layout.addRow("Data source", self.rbtn_data_vswr) outer_layout.addRow("", self.rbtn_data_resistance) outer_layout.addRow("", self.rbtn_data_reactance) outer_layout.addRow("", self.rbtn_data_s21_gain) outer_layout.addRow(PeakSearchAnalysis.QHLine()) outer_layout.addRow("Peak type", self.rbtn_peak_positive) outer_layout.addRow("", self.rbtn_peak_negative) outer_layout.addRow(PeakSearchAnalysis.QHLine()) outer_layout.addRow("Move marker to peak", self.checkbox_move_marker) outer_layout.addRow(PeakSearchAnalysis.QHLine()) outer_layout.addRow(QtWidgets.QLabel("<b>Results</b>")) self.peak_frequency = QtWidgets.QLabel() self.peak_value = QtWidgets.QLabel() outer_layout.addRow("Peak frequency:", self.peak_frequency) outer_layout.addRow("Peak value:", self.peak_value)
def __init__(self, app: QtWidgets.QWidget): super().__init__() self.app = app self.setWindowTitle("Sweep analysis") self.setWindowIcon(self.app.icon) QtWidgets.QShortcut(QtCore.Qt.Key_Escape, self, self.hide) layout = QtWidgets.QVBoxLayout() self.setLayout(layout) select_analysis_box = QtWidgets.QGroupBox("Select analysis") select_analysis_layout = QtWidgets.QFormLayout(select_analysis_box) self.analysis_list = QtWidgets.QComboBox() self.analysis_list.addItem("Low-pass filter", LowPassAnalysis(self.app)) self.analysis_list.addItem("Band-pass filter", BandPassAnalysis(self.app)) self.analysis_list.addItem("High-pass filter", HighPassAnalysis(self.app)) self.analysis_list.addItem("Band-stop filter", BandStopAnalysis(self.app)) self.analysis_list.addItem("Simple Peak search", SimplePeakSearchAnalysis(self.app)) self.analysis_list.addItem("Peak search", PeakSearchAnalysis(self.app)) self.analysis_list.addItem("VSWR analysis", VSWRAnalysis(self.app)) self.analysis_list.addItem("Resonance analysis", ResonanceAnalysis(self.app)) self.analysis_list.addItem("HWEF analysis", EFHWAnalysis(self.app)) self.analysis_list.addItem("MagLoop analysis", MagLoopAnalysis(self.app)) select_analysis_layout.addRow("Analysis type", self.analysis_list) self.analysis_list.currentIndexChanged.connect(self.updateSelection) btn_run_analysis = QtWidgets.QPushButton("Run analysis") btn_run_analysis.clicked.connect(self.runAnalysis) select_analysis_layout.addRow(btn_run_analysis) self.checkbox_run_automatically = QtWidgets.QCheckBox( "Run automatically") self.checkbox_run_automatically.stateChanged.connect( self.toggleAutomaticRun) select_analysis_layout.addRow(self.checkbox_run_automatically) analysis_box = QtWidgets.QGroupBox("Analysis") analysis_box.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding) self.analysis_layout = QtWidgets.QVBoxLayout(analysis_box) self.analysis_layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(select_analysis_box) layout.addWidget(analysis_box) self.updateSelection()
def runAnalysis(self): max_dips_shown = self.max_dips_shown data = [d.vswr for d in self.app.data.s11] # min_idx = np.argmin(data) # # logger.debug("Minimum at %d", min_idx) # logger.debug("Value at minimum: %f", data[min_idx]) # logger.debug("Frequency: %d", self.app.data.s11[min_idx].freq) # # if self.checkbox_move_marker.isChecked(): # self.app.markers[0].setFrequency(str(self.app.data.s11[min_idx].freq)) # self.app.markers[0].frequencyInput.setText(str(self.app.data.s11[min_idx].freq)) threshold = self.input_vswr_limit.value() minimums = self.find_minimums(data, threshold) logger.debug("Found %d sections under %f threshold", len(minimums), threshold) results_header = self.layout.indexOf(self.results_label) logger.debug("Results start at %d, out of %d", results_header, self.layout.rowCount()) for _ in range(results_header, self.layout.rowCount()): self.layout.removeRow(self.layout.rowCount() - 1) if len(minimums) > max_dips_shown: self.layout.addRow( QtWidgets.QLabel("<b>More than " + str(max_dips_shown) + " dips found. Lowest shown.</b>")) dips = [] for m in minimums: start, lowest, end = m dips.append(data[lowest]) best_dips = [] for _ in range(max_dips_shown): min_idx = np.argmin(dips) best_dips.append(minimums[min_idx]) dips.remove(dips[min_idx]) minimums.remove(minimums[min_idx]) minimums = best_dips self.minimums = minimums if len(minimums) > 0: for m in minimums: start, lowest, end = m if start != end: logger.debug("Section from %d to %d, lowest at %d", start, end, lowest) self.layout.addRow( "Start", QtWidgets.QLabel( format_frequency(self.app.data.s11[start].freq))) self.layout.addRow( "Minimum", QtWidgets.QLabel( f"{format_frequency(self.app.data.s11[lowest].freq)}" f" ({round(data[lowest], 2)})")) self.layout.addRow( "End", QtWidgets.QLabel( format_frequency(self.app.data.s11[end].freq))) self.layout.addRow( "Span", QtWidgets.QLabel( format_frequency(self.app.data.s11[end].freq - self.app.data.s11[start].freq))) else: self.layout.addRow( "Low spot", QtWidgets.QLabel( format_frequency(self.app.data.s11[lowest].freq))) self.layout.addWidget(PeakSearchAnalysis.QHLine()) # Remove the final separator line self.layout.removeRow(self.layout.rowCount() - 1) else: self.layout.addRow( QtWidgets.QLabel("No areas found with VSWR below " + str(round(threshold, 2)) + "."))
def runAnalysis(self): self.reset() # self.results_label = QtWidgets.QLabel("<b>Results</b>") # max_dips_shown = self.max_dips_shown description = self.input_description.text() if description: filename = os.path.join("/tmp/", "{}.csv".format(description)) else: filename = None crossing = self._get_crossing() logger.debug("Found %d sections ", len(crossing)) results_header = self.layout.indexOf(self.results_label) logger.debug("Results start at %d, out of %d", results_header, self.layout.rowCount()) for _ in range(results_header, self.layout.rowCount()): self.layout.removeRow(self.layout.rowCount() - 1) # if len(crossing) > max_dips_shown: # self.layout.addRow(QtWidgets.QLabel("<b>More than " + str(max_dips_shown) + # " dips found. Lowest shown.</b>")) # self.crossing = crossing[:max_dips_shown] if len(crossing) > 0: extended_data = [] for m in crossing: start, lowest, end = m my_data = self._get_data(lowest) extended_data.append(my_data) if start != end: logger.debug("Section from %d to %d, lowest at %d", start, end, lowest) self.layout.addRow( "Resonance", QtWidgets.QLabel( f"{format_frequency(self.app.data.s11[lowest].freq)}" f" ({format_complex_imp(self.app.data.s11[lowest].impedance())})" )) else: self.layout.addRow( "Resonance", QtWidgets.QLabel( format_frequency(self.app.data.s11[lowest].freq))) self.layout.addWidget(PeakSearchAnalysis.QHLine()) # Remove the final separator line self.layout.removeRow(self.layout.rowCount() - 1) if filename and extended_data: with open(filename, 'w', newline='') as csvfile: fieldnames = extended_data[0].keys() writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() for row in extended_data: writer.writerow(row) else: self.layout.addRow(QtWidgets.QLabel("No resonance found"))
def runAnalysis(self): max_dips_shown = 3 data = [] for d in self.app.data: data.append(d.vswr) # min_idx = np.argmin(data) # # logger.debug("Minimum at %d", min_idx) # logger.debug("Value at minimum: %f", data[min_idx]) # logger.debug("Frequency: %d", self.app.data[min_idx].freq) # # if self.checkbox_move_marker.isChecked(): # self.app.markers[0].setFrequency(str(self.app.data[min_idx].freq)) # self.app.markers[0].frequencyInput.setText(str(self.app.data[min_idx].freq)) minimums = [] min_start = -1 min_idx = -1 threshold = self.input_vswr_limit.value() min_val = threshold for i, d in enumerate(data): if d < threshold and i < len(data) - 1: if d < min_val: min_val = d min_idx = i if min_start == -1: min_start = i elif min_start != -1: # We are above the threshold, and were in a section that was below minimums.append((min_start, min_idx, i - 1)) min_start = -1 min_idx = -1 min_val = threshold logger.debug("Found %d sections under %f threshold", len(minimums), threshold) results_header = self.layout.indexOf(self.results_label) logger.debug("Results start at %d, out of %d", results_header, self.layout.rowCount()) for i in range(results_header, self.layout.rowCount()): self.layout.removeRow(self.layout.rowCount() - 1) if len(minimums) > max_dips_shown: self.layout.addRow( QtWidgets.QLabel("<b>More than " + str(max_dips_shown) + " dips found. Lowest shown.</b>")) dips = [] for m in minimums: start, lowest, end = m dips.append(data[lowest]) best_dips = [] for i in range(max_dips_shown): min_idx = np.argmin(dips) best_dips.append(minimums[min_idx]) dips.remove(dips[min_idx]) minimums.remove(minimums[min_idx]) minimums = best_dips if len(minimums) > 0: for m in minimums: start, lowest, end = m if start != end: logger.debug("Section from %d to %d, lowest at %d", start, end, lowest) self.layout.addRow( "Start", QtWidgets.QLabel( RFTools.formatFrequency( self.app.data[start].freq))) self.layout.addRow( "Minimum", QtWidgets.QLabel( RFTools.formatFrequency(self.app.data[lowest].freq) + " (" + str(round(data[lowest], 2)) + ")")) self.layout.addRow( "End", QtWidgets.QLabel( RFTools.formatFrequency(self.app.data[end].freq))) self.layout.addRow( "Span", QtWidgets.QLabel( RFTools.formatFrequency( self.app.data[end].freq - self.app.data[start].freq))) self.layout.addWidget(PeakSearchAnalysis.QHLine()) else: self.layout.addRow( "Low spot", QtWidgets.QLabel( RFTools.formatFrequency( self.app.data[lowest].freq))) self.layout.addWidget(PeakSearchAnalysis.QHLine()) # Remove the final separator line self.layout.removeRow(self.layout.rowCount() - 1) else: self.layout.addRow( QtWidgets.QLabel("No areas found with VSWR below " + str(round(threshold, 2)) + "."))