Skip to content

Commit

Permalink
improved nions display | jue 18 abr 2024 11:11:22 CEST
Browse files Browse the repository at this point in the history
  • Loading branch information
DFreireF committed Apr 18, 2024
1 parent 7db276c commit 8e43188
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
30 changes: 15 additions & 15 deletions rionid/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,26 +90,26 @@ def controller(data_file, particles_to_simulate, alphap, ref_ion, ndivs, amplitu
log.info(f'Simulation performed. Now we are going to start the display.')

# View

# Some extra controlling
# displaying specified amount of ions, sorted by yield
if nions:
# sort by yield (greatest first)
sorted_indices = argsort(mydata.yield_data)[::-1][:nions]
ref_index = where(mydata.nuclei_names == ref_ion)[0]
sorted_indices = append(sorted_indices, ref_index)
mydata.nuclei_names = mydata.nuclei_names[sorted_indices]
if harmonics:
for harmonic in harmonics: # for each harmonic
name = f'{harmonic}'
mydata.simulated_data_dict[name] = mydata.simulated_data_dict[name][sorted_indices]
if nions: display_nions(nions, mydata.yield_data, mydata.nuclei_names, mydata.simulated_data_dict, ref_ion, harmonics)

mycanvas = CreateGUI(ref_ion, mydata.nuclei_names, ndivs, amplitude, show)
mycanvas._view(mydata.experimental_data, mydata.simulated_data_dict, filename = data_file, out = out)

log.debug(f'Plotted labels = {mycanvas.labels},{mycanvas.ref_ion}')
log.info(f'Program has ended. I hope you have found what you were looking for. :)')

def display_nions(nions, yield_data, nuclei_names, simulated_data_dict, ref_ion, harmonics):
sorted_indices = argsort(yield_data)[::-1][:nions]
ref_index = where(nuclei_names == ref_ion)[0]
if ref_index not in sorted_indices:
sorted_indices = append(sorted_indices, ref_index)
nuclei_names = nuclei_names[sorted_indices]

for harmonic in harmonics: # for each harmonic
name = f'{harmonic}'
simulated_data_dict[name] = simulated_data_dict[name][sorted_indices]

def controller2(data_file, particles_to_simulate, alphap, ref_ion, ndivs, amplitude, show, brho = None, fref = None, ke = None, out = None, harmonics = None, gam = None, correct = None, ods = False, nions = None):

log.debug(f'Tracking of variables introduced:\n {data_file} = data_file, {particles_to_simulate} = particles_to_simulate, {harmonics} = harmonics, {alphap} = alphap, {ref_ion} = ref_ion, {ndivs} = ndivs, {amplitude} = amplitude, {show} = show, {brho} = brho, {fref} = fref, {ke} = ke')
Expand All @@ -120,14 +120,14 @@ def controller2(data_file, particles_to_simulate, alphap, ref_ion, ndivs, amplit
mydata._calculate_moqs()
mydata._calculate_srrf(fref = fref, brho = brho, ke = ke, gam = gam, correct = correct)
mydata._simulated_data(harmonics = harmonics) # -> simulated frecs
#pyView

if nions: display_nions(nions, mydata.yield_data, mydata.nuclei_names, mydata.simulated_data_dict, ref_ion, harmonics)

#pyView
app = QApplication(sys.argv)
sa = CreatePyGUI(mydata.experimental_data, mydata.simulated_data_dict)
sa.show()
sys.exit(app.exec_())



def read_masterfile(master_filename):
# reads list filenames with experiment data. [:-1] to remove eol sequence.
Expand Down
13 changes: 12 additions & 1 deletion rionid/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ def setup_controls(self):
self.run_button.clicked.connect(self.run_script)

self.stop_button = QPushButton('Stop')
self.stop_button.setStyleSheet("""
QPushButton {
background-color: #d1cc01;
color: white;
border-radius: 5px;
}
QPushButton:hover {
background-color: #45a049;
}
""")
self.stop_button.clicked.connect(self.stop_script)
self.stop_button.setEnabled(False)

Expand Down Expand Up @@ -207,6 +217,7 @@ def actual_run_script(self):

args = argparse.Namespace(datafile=datafile, alphap=alphap, refion=refion, filep=filep, ndivs=ndivs, amplitude=amplitude, mode=mode, value=value)
controller(args)

except Exception as e:
QMessageBox.critical(self, 'Error', f'An error occurred: {str(e)}')
log.error(f"Failed to run script: {str(e)}")
Expand All @@ -219,7 +230,6 @@ def __init__(self, function):
super().__init__()
self.function = function
self._stop_requested = False
#self.signalError.connect(self.handle_error)

def run(self):
try:
Expand All @@ -233,6 +243,7 @@ def requestStop(self):

def controller(datafile=None, alphap=None, refion=None, filep=None, ndivs=None, amplitude=None, mode=None, value=None):
print('HELLO!')

if __name__ == '__main__':
app = QApplication(sys.argv)
window = RionID_GUI()
Expand Down

0 comments on commit 8e43188

Please sign in to comment.