From ad0c38e313c880bfab407b509f500f3335e942fb Mon Sep 17 00:00:00 2001 From: gwm17 Date: Tue, 6 Dec 2022 14:30:16 -0500 Subject: [PATCH] Add in levels export for SPSPlot. Fix some unit label typos. --- .gitignore | 3 ++- spspy/SPSPlot.py | 9 ++++++++- spspy/SPSPlotUI.py | 12 +++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index b6f8507..8840362 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ __pycache__/ .vscode/ .vs/ *.sps -*.spanc \ No newline at end of file +*.spanc +*.csv \ No newline at end of file diff --git a/spspy/SPSPlot.py b/spspy/SPSPlot.py index c1c2a0c..dbed18b 100644 --- a/spspy/SPSPlot.py +++ b/spspy/SPSPlot.py @@ -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}"]) diff --git a/spspy/SPSPlotUI.py b/spspy/SPSPlotUI.py index 59f5c99..d4d7cc8 100644 --- a/spspy/SPSPlotUI.py +++ b/spspy/SPSPlotUI.py @@ -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()