1
0
Fork 0
mirror of https://github.com/gwm17/spspy.git synced 2024-11-22 10:18:49 -05:00

Add in levels export for SPSPlot. Fix some unit label typos.

This commit is contained in:
Gordon McCann 2022-12-06 14:30:16 -05:00
parent 8ca50ee621
commit ad0c38e313
3 changed files with 21 additions and 3 deletions

3
.gitignore vendored
View File

@ -4,4 +4,5 @@ __pycache__/
.vscode/
.vs/
*.sps
*.spanc
*.spanc
*.csv

View File

@ -2,6 +2,7 @@ from .SPSReaction import *
from .SPSTarget import *
from .data.NuclearData import *
from dataclasses import dataclass, field
import csv
@dataclass
class Excitation:
@ -61,4 +62,10 @@ class SPSPlot:
rho = datum.rxn.convert_ejectile_KE_2_rho(ke)
datum.excitations.append(Excitation(excitation, ke, rho))
def export_reaction_data(self, fileName: str) -> None:
with open(fileName, "w", newline='') as outputFile:
csvWriter = csv.writer(outputFile, dialect="excel")
csvWriter.writerow(["Reaction", "Excitation(MeV)", "Rho(cm)", "EjectileKE(MeV)", "Z-Offset(cm)"])
for datum in self.data.values():
for point in datum.excitations:
csvWriter.writerow([repr(datum.rxn), f"{point.excitation:.3f}", f"{point.rho:.3f}", f"{point.kineticEnergy:.3f}", f"{point.fpZ:.3f}"])

View File

@ -76,6 +76,11 @@ class SPSPlotGUI(QMainWindow):
newReactionAction.triggered.connect(self.handle_new_reaction)
newTargetAction.triggered.connect(self.handle_new_target)
self.exportMenu = self.menuBar().addMenu("&Export")
exportLevels = QAction("Export levels to csv...", self)
self.exportMenu.addAction(exportLevels)
exportLevels.triggered.connect(self.handle_export_levels)
def create_inputs(self) -> None:
inputLayout = QHBoxLayout()
self.inputGroupBox = QGroupBox("Adjustable Inputs", self.plotTab)
@ -109,7 +114,7 @@ class SPSPlotGUI(QMainWindow):
self.exButton.toggle()
self.keButton = QRadioButton("Ejectile Kinetic energy (MeV)", self.energyButtonGroup)
self.keButton.toggled.connect(self.handle_ke_switch)
self.zButton = QRadioButton("Focal Plane Z Shift (mm)", self.energyButtonGroup)
self.zButton = QRadioButton("Focal Plane Z Shift (cm)", self.energyButtonGroup)
self.zButton.toggled.connect(self.handle_z_switch)
buttonLayout.addWidget(self.exButton)
buttonLayout.addWidget(self.keButton)
@ -209,6 +214,11 @@ class SPSPlotGUI(QMainWindow):
self.plotType = PlotType.PLOT_Z
self.update_plot()
def handle_export_levels(self) -> None:
fileName = QFileDialog.getSaveFileName(self, "Export Levels to CSV","./","Comma-Separated Values File (*.csv)")
if fileName[0]:
self.sps.export_reaction_data(fileName[0])
def add_reaction(self, rxnParams: RxnParameters, targName: str) -> None:
rxnParams.beamEnergy = self.bkeInput.value()
rxnParams.spsAngle = self.angleInput.value()