1
0
Fork 0
mirror of https://github.com/gwm17/spspy.git synced 2024-11-26 20:18:50 -05:00

Compare commits

..

3 Commits

3 changed files with 58 additions and 29 deletions

View File

@ -80,6 +80,12 @@ class Spanc:
self.calibrations[data.peakID] = data self.calibrations[data.peakID] = data
return return
def remove_calibration(self, data: Peak) -> bool:
if data.peakID not in self.calibrations.keys():
return False
self.calibrations.pop(data.peakID)
return True
def add_output(self, data: Peak) -> None: def add_output(self, data: Peak) -> None:
if data.peakID == INVALID_PEAK_ID: if data.peakID == INVALID_PEAK_ID:
data.peakID = len(self.outputs) data.peakID = len(self.outputs)

View File

@ -116,6 +116,7 @@ class SpancGUI(QMainWindow):
self.tablelayout.addWidget(self.targetGroup) self.tablelayout.addWidget(self.targetGroup)
self.targetTable.resizeColumnsToContents() self.targetTable.resizeColumnsToContents()
self.targetTable.cellDoubleClicked.connect(self.handle_update_target) self.targetTable.cellDoubleClicked.connect(self.handle_update_target)
self.targetTable.setEditTriggers(QTableWidget.EditTrigger.NoEditTriggers)
def create_reaction_table(self) -> None: def create_reaction_table(self) -> None:
self.rxnGroup = QGroupBox("Reactions", self.tableTab) self.rxnGroup = QGroupBox("Reactions", self.tableTab)
@ -128,30 +129,33 @@ class SpancGUI(QMainWindow):
self.tablelayout.addWidget(self.rxnGroup) self.tablelayout.addWidget(self.rxnGroup)
self.reactionTable.resizeColumnsToContents() self.reactionTable.resizeColumnsToContents()
self.reactionTable.cellDoubleClicked.connect(self.handle_update_reaction) self.reactionTable.cellDoubleClicked.connect(self.handle_update_reaction)
self.reactionTable.setEditTriggers(QTableWidget.EditTrigger.NoEditTriggers)
def create_calibration_table(self) -> None: def create_calibration_table(self) -> None:
self.calGroup = QGroupBox("Calibration Peaks", self.tableTab) self.calGroup = QGroupBox("Calibration Peaks", self.tableTab)
calLayout = QVBoxLayout() calLayout = QVBoxLayout()
self.calibrationTable = QTableWidget(self.calGroup) self.calibrationTable = QTableWidget(self.calGroup)
self.calibrationTable.setColumnCount(8) self.calibrationTable.setColumnCount(9)
self.calibrationTable.setHorizontalHeaderLabels(["Reaction","x(mm)","ux stat.(mm)","ux sys.(mm)","rho(cm)","urho(cm)","Ex(MeV)","uEx(MeV)"]) self.calibrationTable.setHorizontalHeaderLabels(["Peak ID","Reaction","x(mm)","ux stat.(mm)","ux sys.(mm)","rho(cm)","urho(cm)","Ex(MeV)","uEx(MeV)"])
calLayout.addWidget(self.calibrationTable) calLayout.addWidget(self.calibrationTable)
self.calGroup.setLayout(calLayout) self.calGroup.setLayout(calLayout)
self.tablelayout.addWidget(self.calGroup) self.tablelayout.addWidget(self.calGroup)
self.calibrationTable.resizeColumnsToContents() self.calibrationTable.resizeColumnsToContents()
self.calibrationTable.cellDoubleClicked.connect(self.handle_update_calibration) self.calibrationTable.cellDoubleClicked.connect(self.handle_update_calibration)
self.calibrationTable.setEditTriggers(QTableWidget.EditTrigger.NoEditTriggers)
def create_output_table(self) -> None: def create_output_table(self) -> None:
self.outGroup = QGroupBox("Output Peaks", self.tableTab) self.outGroup = QGroupBox("Output Peaks", self.tableTab)
outLayout = QVBoxLayout() outLayout = QVBoxLayout()
self.outputTable = QTableWidget(self.outGroup) self.outputTable = QTableWidget(self.outGroup)
self.outputTable.setColumnCount(12) self.outputTable.setColumnCount(13)
self.outputTable.setHorizontalHeaderLabels(["Reaction","x(mm)","ux stat.(mm)","ux sys.(mm)","rho(cm)","urho(cm)","Ex(MeV)","uEx(MeV)","FWHM(mm)","uFWHM(mm)","FWHM(MeV)","uFWHM(MeV)"]) self.outputTable.setHorizontalHeaderLabels(["Peak ID", "Reaction","x(mm)","ux stat.(mm)","ux sys.(mm)","rho(cm)","urho(cm)","Ex(MeV)","uEx(MeV)","FWHM(mm)","uFWHM(mm)","FWHM(MeV)","uFWHM(MeV)"])
outLayout.addWidget(self.outputTable) outLayout.addWidget(self.outputTable)
self.outGroup.setLayout(outLayout) self.outGroup.setLayout(outLayout)
self.tablelayout.addWidget(self.outGroup) self.tablelayout.addWidget(self.outGroup)
self.outputTable.resizeColumnsToContents() self.outputTable.resizeColumnsToContents()
self.outputTable.cellDoubleClicked.connect(self.handle_update_output) self.outputTable.cellDoubleClicked.connect(self.handle_update_output)
self.outputTable.setEditTriggers(QTableWidget.EditTrigger.NoEditTriggers)
def create_fit_result_text(self) -> None: def create_fit_result_text(self) -> None:
self.fitTextGroup = QGroupBox("Fit Results", self.plotTab) self.fitTextGroup = QGroupBox("Fit Results", self.plotTab)
@ -234,11 +238,15 @@ class SpancGUI(QMainWindow):
return return
def handle_update_calibration(self, row: int, col: int) -> None: def handle_update_calibration(self, row: int, col: int) -> None:
peakData = self.spanc.calibrations[row] peakID = int(self.calibrationTable.item(row, 0).text())
peakData = self.spanc.calibrations[peakID]
calDia = PeakDialog(PeakType.CALIBRATION, self.spanc.reactions.keys(), self, peak=peakData) calDia = PeakDialog(PeakType.CALIBRATION, self.spanc.reactions.keys(), self, peak=peakData)
calDia.new_peak.connect(self.spanc.add_calibration) calDia.new_peak.connect(self.spanc.add_calibration)
calDia.delete_peak.connect(self.spanc.remove_calibration)
if calDia.exec(): if calDia.exec():
self.update_calibration_table() self.update_calibration_table()
if self.spanc.isFit == True:
self.handle_run_fit()
return return
def handle_new_output(self) -> None: def handle_new_output(self) -> None:
@ -249,7 +257,8 @@ class SpancGUI(QMainWindow):
return return
def handle_update_output(self, row: int, col: int) -> None: def handle_update_output(self, row: int, col: int) -> None:
peakData = self.spanc.calibrations[row] peakID = int(self.calibrationTable.item(row, 0).text())
peakData = self.spanc.outputs[peakID]
outDia = PeakDialog(PeakType.OUTPUT, self.spanc.reactions.keys(), self, peak=peakData) outDia = PeakDialog(PeakType.OUTPUT, self.spanc.reactions.keys(), self, peak=peakData)
outDia.new_peak.connect(self.spanc.add_output) outDia.new_peak.connect(self.spanc.add_output)
if outDia.exec(): if outDia.exec():
@ -319,14 +328,15 @@ class SpancGUI(QMainWindow):
self.calibrationTable.setRowCount(len(self.spanc.calibrations)) self.calibrationTable.setRowCount(len(self.spanc.calibrations))
self.calibrationTable.setVerticalHeaderLabels(self.spanc.calibrations.keys()) self.calibrationTable.setVerticalHeaderLabels(self.spanc.calibrations.keys())
for row, peak in enumerate(self.spanc.calibrations.values()): for row, peak in enumerate(self.spanc.calibrations.values()):
self.calibrationTable.setItem(row, 0, QTableWidgetItem(peak.rxnName)) self.calibrationTable.setItem(row, 0, QTableWidgetItem(str(peak.peakID)))
self.calibrationTable.setItem(row, 1, QTableWidgetItem(str(peak.position))) self.calibrationTable.setItem(row, 1, QTableWidgetItem(peak.rxnName))
self.calibrationTable.setItem(row, 2, QTableWidgetItem(str(peak.positionErrStat))) self.calibrationTable.setItem(row, 2, QTableWidgetItem(str(peak.position)))
self.calibrationTable.setItem(row, 3, QTableWidgetItem(str(peak.positionErrSys))) self.calibrationTable.setItem(row, 3, QTableWidgetItem(str(peak.positionErrStat)))
self.calibrationTable.setItem(row, 4, QTableWidgetItem(str(peak.rho))) self.calibrationTable.setItem(row, 4, QTableWidgetItem(str(peak.positionErrSys)))
self.calibrationTable.setItem(row, 5, QTableWidgetItem(str(peak.rhoErr))) self.calibrationTable.setItem(row, 5, QTableWidgetItem(str(peak.rho)))
self.calibrationTable.setItem(row, 6, QTableWidgetItem(str(peak.excitation))) self.calibrationTable.setItem(row, 6, QTableWidgetItem(str(peak.rhoErr)))
self.calibrationTable.setItem(row, 7, QTableWidgetItem(str(peak.excitationErr))) self.calibrationTable.setItem(row, 7, QTableWidgetItem(str(peak.excitation)))
self.calibrationTable.setItem(row, 8, QTableWidgetItem(str(peak.excitationErr)))
self.calibrationTable.resizeColumnsToContents() self.calibrationTable.resizeColumnsToContents()
self.calibrationTable.resizeRowsToContents() self.calibrationTable.resizeRowsToContents()
@ -334,18 +344,19 @@ class SpancGUI(QMainWindow):
self.outputTable.setRowCount(len(self.spanc.outputs)) self.outputTable.setRowCount(len(self.spanc.outputs))
self.outputTable.setVerticalHeaderLabels(self.spanc.outputs.keys()) self.outputTable.setVerticalHeaderLabels(self.spanc.outputs.keys())
for row, peak in enumerate(self.spanc.outputs.values()): for row, peak in enumerate(self.spanc.outputs.values()):
self.outputTable.setItem(row, 0, QTableWidgetItem(peak.rxnName)) self.outputTable.setItem(row, 0, QTableWidgetItem(str(peak.peakID)))
self.outputTable.setItem(row, 1, QTableWidgetItem(str(peak.position))) self.outputTable.setItem(row, 1, QTableWidgetItem(peak.rxnName))
self.outputTable.setItem(row, 2, QTableWidgetItem(str(peak.positionErrStat))) self.outputTable.setItem(row, 2, QTableWidgetItem(str(peak.position)))
self.outputTable.setItem(row, 3, QTableWidgetItem(str(peak.positionErrSys))) self.outputTable.setItem(row, 3, QTableWidgetItem(str(peak.positionErrStat)))
self.outputTable.setItem(row, 4, QTableWidgetItem(str(peak.rho))) self.outputTable.setItem(row, 4, QTableWidgetItem(str(peak.positionErrSys)))
self.outputTable.setItem(row, 5, QTableWidgetItem(str(peak.rhoErr))) self.outputTable.setItem(row, 5, QTableWidgetItem(str(peak.rho)))
self.outputTable.setItem(row, 6, QTableWidgetItem(str(peak.excitation))) self.outputTable.setItem(row, 6, QTableWidgetItem(str(peak.rhoErr)))
self.outputTable.setItem(row, 7, QTableWidgetItem(str(peak.excitationErr))) self.outputTable.setItem(row, 7, QTableWidgetItem(str(peak.excitation)))
self.outputTable.setItem(row, 8, QTableWidgetItem(str(peak.positionFWHM))) self.outputTable.setItem(row, 8, QTableWidgetItem(str(peak.excitationErr)))
self.outputTable.setItem(row, 9, QTableWidgetItem(str(peak.positionFWHMErr))) self.outputTable.setItem(row, 9, QTableWidgetItem(str(peak.positionFWHM)))
self.outputTable.setItem(row, 10, QTableWidgetItem(str(peak.excitationFWHM))) self.outputTable.setItem(row, 10, QTableWidgetItem(str(peak.positionFWHMErr)))
self.outputTable.setItem(row, 11, QTableWidgetItem(str(peak.excitationFWHMErr))) self.outputTable.setItem(row, 11, QTableWidgetItem(str(peak.excitationFWHM)))
self.outputTable.setItem(row, 12, QTableWidgetItem(str(peak.excitationFWHMErr)))
self.outputTable.resizeColumnsToContents() self.outputTable.resizeColumnsToContents()
self.outputTable.resizeRowsToContents() self.outputTable.resizeRowsToContents()

View File

@ -2,11 +2,12 @@ from ..Spanc import Peak, PeakType, INVALID_PEAK_ID
from PySide6.QtWidgets import QLabel from PySide6.QtWidgets import QLabel
from PySide6.QtWidgets import QVBoxLayout, QFormLayout, QGroupBox from PySide6.QtWidgets import QVBoxLayout, QFormLayout, QGroupBox
from PySide6.QtWidgets import QComboBox, QDoubleSpinBox from PySide6.QtWidgets import QComboBox, QDoubleSpinBox
from PySide6.QtWidgets import QDialog, QDialogButtonBox from PySide6.QtWidgets import QDialog, QDialogButtonBox, QPushButton
from PySide6.QtCore import Signal from PySide6.QtCore import Signal
class PeakDialog(QDialog): class PeakDialog(QDialog):
new_peak = Signal(Peak) new_peak = Signal(Peak)
delete_peak = Signal(Peak)
def __init__(self, peakType: PeakType, rxnList: list[str], parent=None, peak: Peak=None): def __init__(self, peakType: PeakType, rxnList: list[str], parent=None, peak: Peak=None):
super().__init__(parent) super().__init__(parent)
@ -26,14 +27,19 @@ class PeakDialog(QDialog):
if peakType == PeakType.CALIBRATION: if peakType == PeakType.CALIBRATION:
self.create_calibration_inputs() self.create_calibration_inputs()
if peak is not None: if peak is not None:
self.setWindowTitle(f"Update A {peakType.value} Peak")
self.set_calibration_inputs(peak) self.set_calibration_inputs(peak)
self.peakID = peak.peakID self.peakID = peak.peakID
self.buttonBox.accepted.connect(self.send_update_calibration_peak) self.buttonBox.accepted.connect(self.send_update_calibration_peak)
self.deleteButton = QPushButton("Delete", self)
self.deleteButton.clicked.connect(self.send_delete_calibration_peak)
self.centralLayout.addWidget(self.deleteButton)
else: else:
self.buttonBox.accepted.connect(self.send_calibration_peak) self.buttonBox.accepted.connect(self.send_calibration_peak)
elif peakType == PeakType.OUTPUT: elif peakType == PeakType.OUTPUT:
self.create_output_inputs() self.create_output_inputs()
if peak is not None: if peak is not None:
self.setWindowTitle(f"Update A {peakType.value} Peak")
self.set_output_inputs(peak) self.set_output_inputs(peak)
self.peakID = peak.peakID self.peakID = peak.peakID
self.buttonBox.accepted.connect(self.send_update_output_peak) self.buttonBox.accepted.connect(self.send_update_output_peak)
@ -58,8 +64,8 @@ class PeakDialog(QDialog):
self.uexInput = QDoubleSpinBox(self.inputGroupBox) self.uexInput = QDoubleSpinBox(self.inputGroupBox)
self.uexInput.setDecimals(6) self.uexInput.setDecimals(6)
inputLayout.addRow("Position(mm)", self.xInput) inputLayout.addRow("Position(mm)", self.xInput)
inputLayout.addRow("Position Stat. Error(mm)", self.uxstatInput)
inputLayout.addRow("Position Sys. Error(mm)", self.uxsysInput) inputLayout.addRow("Position Sys. Error(mm)", self.uxsysInput)
inputLayout.addRow("Position Stat. Error(mm)", self.uxstatInput)
inputLayout.addRow("Excitation Energy(MeV)", self.exInput) inputLayout.addRow("Excitation Energy(MeV)", self.exInput)
inputLayout.addRow("Excitation Energy Error(MeV)", self.uexInput) inputLayout.addRow("Excitation Energy Error(MeV)", self.uexInput)
self.inputGroupBox.setLayout(inputLayout) self.inputGroupBox.setLayout(inputLayout)
@ -82,8 +88,8 @@ class PeakDialog(QDialog):
self.ufwhmInput = QDoubleSpinBox(self.inputGroupBox) self.ufwhmInput = QDoubleSpinBox(self.inputGroupBox)
self.ufwhmInput.setDecimals(6) self.ufwhmInput.setDecimals(6)
inputLayout.addRow("Position(mm)", self.xInput) inputLayout.addRow("Position(mm)", self.xInput)
inputLayout.addRow("Position Stat. Error(mm)", self.uxstatInput)
inputLayout.addRow("Position Sys. Error(mm)", self.uxsysInput) inputLayout.addRow("Position Sys. Error(mm)", self.uxsysInput)
inputLayout.addRow("Position Stat. Error(mm)", self.uxstatInput)
inputLayout.addRow("Position FWHM(mm)", self.fwhmInput) inputLayout.addRow("Position FWHM(mm)", self.fwhmInput)
inputLayout.addRow("Position FWHM Error(mm)", self.ufwhmInput) inputLayout.addRow("Position FWHM Error(mm)", self.ufwhmInput)
self.inputGroupBox.setLayout(inputLayout) self.inputGroupBox.setLayout(inputLayout)
@ -115,6 +121,12 @@ class PeakDialog(QDialog):
positionErrStat=self.uxstatInput.value(), positionErrSys=self.uxsysInput.value(), rxnName=self.rxnNameBox.currentText(), peakID=self.peakID) positionErrStat=self.uxstatInput.value(), positionErrSys=self.uxsysInput.value(), rxnName=self.rxnNameBox.currentText(), peakID=self.peakID)
self.new_peak.emit(peak) self.new_peak.emit(peak)
def send_delete_calibration_peak(self) -> None:
peak = Peak(excitation=self.exInput.value(), excitationErr=self.uexInput.value(), position=self.xInput.value(),
positionErrStat=self.uxstatInput.value(), positionErrSys=self.uxsysInput.value(), rxnName=self.rxnNameBox.currentText(), peakID=self.peakID)
self.delete_peak.emit(peak)
self.done(3)
def send_output_peak(self) -> None: def send_output_peak(self) -> None:
peak = Peak(position=self.xInput.value(), positionErrStat=self.uxstatInput.value(), positionErrSys=self.uxsysInput.value(), peak = Peak(position=self.xInput.value(), positionErrStat=self.uxstatInput.value(), positionErrSys=self.uxsysInput.value(),
positionFWHM=self.fwhmInput.value(), positionFWHMErr=self.ufwhmInput.value(), rxnName=self.rxnNameBox.currentText(), peakID=INVALID_PEAK_ID) positionFWHM=self.fwhmInput.value(), positionFWHMErr=self.ufwhmInput.value(), rxnName=self.rxnNameBox.currentText(), peakID=INVALID_PEAK_ID)