1
0
Fork 0
mirror of https://github.com/gwm17/spspy.git synced 2024-11-22 18:18:52 -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

1
.gitignore vendored
View File

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

View File

@ -2,6 +2,7 @@ from .SPSReaction import *
from .SPSTarget import * from .SPSTarget import *
from .data.NuclearData import * from .data.NuclearData import *
from dataclasses import dataclass, field from dataclasses import dataclass, field
import csv
@dataclass @dataclass
class Excitation: class Excitation:
@ -61,4 +62,10 @@ class SPSPlot:
rho = datum.rxn.convert_ejectile_KE_2_rho(ke) rho = datum.rxn.convert_ejectile_KE_2_rho(ke)
datum.excitations.append(Excitation(excitation, ke, rho)) 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) newReactionAction.triggered.connect(self.handle_new_reaction)
newTargetAction.triggered.connect(self.handle_new_target) 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: def create_inputs(self) -> None:
inputLayout = QHBoxLayout() inputLayout = QHBoxLayout()
self.inputGroupBox = QGroupBox("Adjustable Inputs", self.plotTab) self.inputGroupBox = QGroupBox("Adjustable Inputs", self.plotTab)
@ -109,7 +114,7 @@ class SPSPlotGUI(QMainWindow):
self.exButton.toggle() self.exButton.toggle()
self.keButton = QRadioButton("Ejectile Kinetic energy (MeV)", self.energyButtonGroup) self.keButton = QRadioButton("Ejectile Kinetic energy (MeV)", self.energyButtonGroup)
self.keButton.toggled.connect(self.handle_ke_switch) 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) self.zButton.toggled.connect(self.handle_z_switch)
buttonLayout.addWidget(self.exButton) buttonLayout.addWidget(self.exButton)
buttonLayout.addWidget(self.keButton) buttonLayout.addWidget(self.keButton)
@ -209,6 +214,11 @@ class SPSPlotGUI(QMainWindow):
self.plotType = PlotType.PLOT_Z self.plotType = PlotType.PLOT_Z
self.update_plot() 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: def add_reaction(self, rxnParams: RxnParameters, targName: str) -> None:
rxnParams.beamEnergy = self.bkeInput.value() rxnParams.beamEnergy = self.bkeInput.value()
rxnParams.spsAngle = self.angleInput.value() rxnParams.spsAngle = self.angleInput.value()