From 6bd2a716b1fcd618779f97270eba934e5c3957ca Mon Sep 17 00:00:00 2001 From: Stuart Sim Date: Thu, 13 Jul 2017 11:43:58 +0100 Subject: [PATCH 1/5] Attempt to fix up the GUI to work again. Much of the work here done by Mark Magee, some by Stuart Sim. Beware: pragmatism and empirical approaches used in several places: functionality may appear to be restored but some minor alterations may have occurred. --- tardis/analysis.py | 14 +++++----- tardis/gui/widgets.py | 64 +++++++++++++++++++++---------------------- tardis/util.py | 2 +- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/tardis/analysis.py b/tardis/analysis.py index e6e4d5b33c4..2ed27a855e0 100644 --- a/tardis/analysis.py +++ b/tardis/analysis.py @@ -12,15 +12,15 @@ class LastLineInteraction(object): @classmethod def from_model(cls, model): - return cls(model.last_line_interaction_in_id, model.last_line_interaction_out_id, - model.last_line_interaction_shell_id, model.last_line_interaction_angstrom, model.atom_data.lines) + return cls(model.runner.last_line_interaction_in_id, model.runner.last_line_interaction_out_id, + model.runner.last_line_interaction_shell_id, model.runner.last_interaction_in_nu, model.plasma.atomic_data.lines) def __init__(self, last_line_interaction_in_id, last_line_interaction_out_id, last_line_interaction_shell_id, - last_line_interaction_angstrom, lines, packet_filter_mode='packet_nu'): + last_interaction_in_nu, lines, packet_filter_mode='packet_nu'): self.last_line_interaction_in_id = last_line_interaction_in_id self.last_line_interaction_out_id = last_line_interaction_out_id self.last_line_interaction_shell_id = last_line_interaction_shell_id - self.last_line_interaction_angstrom = last_line_interaction_angstrom + self.last_line_interaction_angstrom = (last_interaction_in_nu * u.Hz).to(u.Angstrom, equivalencies=u.spectral()) self.lines = lines self._wavelength_start = 0 * u.angstrom @@ -77,13 +77,13 @@ def update_last_interaction_filter(self): packet_filter = (self.last_line_interaction_angstrom > self.wavelength_start) & \ (self.last_line_interaction_angstrom < self.wavelength_end) elif self.packet_filter_mode == 'line_in_nu': - line_in_nu = self.lines.wavelength.ix[self.last_line_interaction_in_id].values + line_in_nu = self.lines.wavelength.iloc[self.last_line_interaction_in_id].values packet_filter = (line_in_nu > self.wavelength_start.to(u.angstrom).value) & \ (line_in_nu < self.wavelength_end.to(u.angstrom).value) - self.last_line_in = self.lines.ix[self.last_line_interaction_in_id[packet_filter]] - self.last_line_out = self.lines.ix[self.last_line_interaction_out_id[packet_filter]] + self.last_line_in = self.lines.iloc[self.last_line_interaction_in_id[packet_filter]] + self.last_line_out = self.lines.iloc[self.last_line_interaction_out_id[packet_filter]] if self.atomic_number is not None: self.last_line_in = self.last_line_in[self.last_line_in.atomic_number == self.atomic_number] diff --git a/tardis/gui/widgets.py b/tardis/gui/widgets.py index 3407670df6e..5adbed691cc 100644 --- a/tardis/gui/widgets.py +++ b/tardis/gui/widgets.py @@ -470,15 +470,15 @@ def fill_output_label(self): Model converged : {}
Simulation Time : {} s
\ Inner Temperature : {} K
Number of packets : {}
\ Inner Luminosity : {}'\ - .format(self.model.iterations_max_requested, + .format(self.model.iterations, self.model.iterations_executed, 'True' if self.model.converged else 'False', - self.model.time_of_simulation.value, - self.model.t_inner.value, - self.model.current_no_of_packets, - self.model.luminosity_inner) + self.model.runner.time_of_simulation.value, + self.model.model.t_inner.value, + self.model.last_no_of_packets, + self.model.runner.calculate_luminosity_inner(self.model.model)) self.outputLabel.setText(labeltext) def make_shell_widget(self): @@ -566,8 +566,8 @@ def change_model(self, model): """Reset the model set in the GUI.""" self.model = model self.tablemodel.arraydata = [] - self.tablemodel.add_data(model.t_rad.value.tolist()) - self.tablemodel.add_data(model.ws.tolist()) + self.tablemodel.add_data(model.model.t_rad.value.tolist()) + self.tablemodel.add_data(model.model.w.tolist()) def change_spectrum_to_spec_virtual_flux_angstrom(self): """Change the spectrum data to the virtual spectrum.""" @@ -622,11 +622,11 @@ def plot_spectrum(self): def change_graph_to_ws(self): """Change the shell plot to show dilution factor.""" - self.change_graph(self.model.ws, 'Ws', '') + self.change_graph(self.model.model.w, 'Ws', '') def change_graph_to_t_rads(self): """Change the graph back to radiation Temperature.""" - self.change_graph(self.model.t_rad.value, 't_rad', '(K)') + self.change_graph(self.model.model.t_rad.value, 't_rad', '(K)') def change_graph(self, data, name, unit): """Called to change the shell plot by the two methods above.""" @@ -659,7 +659,7 @@ def plot_model(self): self.graph.ax1.set_ylabel('Rad. Temp (K)') self.graph.ax1.yaxis.get_major_formatter().set_powerlimits((0, 1)) self.graph.dataplot = self.graph.ax1.plot( - range(len(self.model.t_rad.value)), self.model.t_rad.value) + range(len(self.model.model.t_rad.value)), self.model.model.t_rad.value) self.graph.ax2.clear() self.graph.ax2.set_title('Shell View') self.graph.ax2.set_xticklabels([]) @@ -667,38 +667,38 @@ def plot_model(self): self.graph.ax2.grid = True self.shells = [] - t_rad_normalizer = colors.Normalize(vmin=self.model.t_rad.value.min(), - vmax=self.model.t_rad.value.max()) + t_rad_normalizer = colors.Normalize(vmin=self.model.model.t_rad.value.min(), + vmax=self.model.model.t_rad.value.max()) t_rad_color_map = plt.cm.ScalarMappable(norm=t_rad_normalizer, cmap=plt.cm.jet) - t_rad_color_map.set_array(self.model.t_rad.value) + t_rad_color_map.set_array(self.model.model.t_rad.value) if self.graph.cb: - self.graph.cb.set_clim(vmin=self.model.t_rad.value.min(), - vmax=self.model.t_rad.value.max()) + self.graph.cb.set_clim(vmin=self.model.model.t_rad.value.min(), + vmax=self.model.model.t_rad.value.max()) self.graph.cb.update_normal(t_rad_color_map) else: self.graph.cb = self.graph.figure.colorbar(t_rad_color_map) self.graph.cb.set_label('T (K)') self.graph.normalizing_factor = 0.2 * ( - self.model.tardis_config.structure.r_outer.value[-1] - - self.model.tardis_config.structure.r_inner.value[0]) / ( - self.model.tardis_config.structure.r_inner.value[0]) + self.model.model.r_outer.value[-1] - + self.model.model.r_inner.value[0]) / ( + self.model.model.r_inner.value[0]) #self.graph.normalizing_factor = 8e-16 - for i, t_rad in enumerate(self.model.t_rad.value): - r_inner = (self.model.tardis_config.structure.r_inner.value[i] * + for i, t_rad in enumerate(self.model.model.t_rad.value): + r_inner = (self.model.model.r_inner.value[i] * self.graph.normalizing_factor) - r_outer = (self.model.tardis_config.structure.r_outer.value[i] * + r_outer = (self.model.model.r_outer.value[i] * self.graph.normalizing_factor) self.shells.append(Shell(i, (0,0), r_inner, r_outer, facecolor=t_rad_color_map.to_rgba(t_rad), picker=self.graph.shell_picker)) self.graph.ax2.add_patch(self.shells[i]) self.graph.ax2.set_xlim(0, - self.model.tardis_config.structure.r_outer.value[-1] * + self.model.model.r_outer.value[-1] * self.graph.normalizing_factor) self.graph.ax2.set_ylim(0, - self.model.tardis_config.structure.r_outer.value[-1] * + self.model.model.r_outer.value[-1] * self.graph.normalizing_factor) self.graph.figure.tight_layout() self.graph.draw() @@ -727,7 +727,7 @@ def __init__(self, index, tablecreator, parent=None): self.on_atom_header_double_clicked) - self.table1_data = self.parent.model.tardis_config.abundances[ + self.table1_data = self.parent.model.plasma.abundance[ self.shell_index] self.atomsdata = self.createTable([['Z = '], ['Count (Shell %d)' % ( self.shell_index + 1)]], iterate_header=(2, 0), @@ -759,7 +759,7 @@ def on_atom_header_double_clicked(self, index): normalized_data = [] for item in self.table2_data.values: normalized_data.append(float(item / - self.parent.model.tardis_config.number_densities[self.shell_index] + self.parent.model.plasma.number_density[self.shell_index] .ix[self.current_atom_index])) @@ -832,10 +832,10 @@ def __init__(self, parent, wavelength_start, wavelength_end, tablecreator): self.layout.addWidget(LineInteractionTables(packet_nu_line_interaction, - self.parent.model.atom_data, 'filtered by frequency of packet', + self.parent.model.plasma.atomic_data.atom_data, self.parent.model.plasma.lines, 'filtered by frequency of packet', self.createTable)) self.layout.addWidget(LineInteractionTables(line_in_nu_line_interaction, - self.parent.model.atom_data, + self.parent.model.plasma.atomic_data.atom_data, self.parent.model.plasma.lines, 'filtered by frequency of line interaction', self.createTable)) self.setLayout(self.layout) @@ -948,7 +948,7 @@ class LineInteractionTables(QtGui.QWidget): """ - def __init__(self, line_interaction_analysis, atom_data, description, + def __init__(self, line_interaction_analysis, atom_data, lines_data, description, tablecreator): """Create the widget and set data.""" super(LineInteractionTables, self).__init__() @@ -959,13 +959,13 @@ def __init__(self, line_interaction_analysis, atom_data, description, self.layout = QtGui.QHBoxLayout() self.line_interaction_analysis = line_interaction_analysis self.atom_data = atom_data + self.lines_data = lines_data line_interaction_species_group = \ line_interaction_analysis.last_line_in.groupby(['atomic_number', 'ion_number']) self.species_selected = sorted( line_interaction_species_group.groups.keys()) - species_symbols = [util.species_tuple_to_string(item, - atom_data) for item in self.species_selected] + species_symbols = [util.species_tuple_to_string(item) for item in self.species_selected] species_table_model = self.createTable([species_symbols, ['Species']]) species_abundances = ( line_interaction_species_group.wavelength.count().astype(float) / @@ -1006,8 +1006,8 @@ def on_species_clicked(self, index): exc_deexc_string = 'exc. %d-%d (%.2f A) de-exc. %d-%d (%.2f A)' for line_id, row in grouped_line_interactions.wavelength.count().iteritems(): - current_line_in = self.atom_data.lines.ix[line_id[0]] - current_line_out = self.atom_data.lines.ix[line_id[1]] + current_line_in = self.lines_data.ix[line_id[0]] + current_line_out = self.lines_data.ix[line_id[1]] last_line_in_string.append(exc_deexc_string % ( current_line_in['level_number_lower'], current_line_in['level_number_upper'], diff --git a/tardis/util.py b/tardis/util.py index 31dfbaa32b7..6047f0dc903 100644 --- a/tardis/util.py +++ b/tardis/util.py @@ -428,4 +428,4 @@ def quantity_linspace(start, stop, num, **kwargs): raise ValueError('Both start and stop need to be quantities with a ' 'unit attribute') - return np.linspace(start.value, stop.to(start.unit).value, num, **kwargs) * start.unit \ No newline at end of file + return np.linspace(start.value, stop.to(start.unit).value, num, **kwargs) * start.unit From 346d954c135400e3e420c8fe853e57425550f205 Mon Sep 17 00:00:00 2001 From: Stuart Sim Date: Thu, 13 Jul 2017 11:51:47 +0100 Subject: [PATCH 2/5] Minor fix for util --- tardis/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tardis/util.py b/tardis/util.py index 6047f0dc903..31dfbaa32b7 100644 --- a/tardis/util.py +++ b/tardis/util.py @@ -428,4 +428,4 @@ def quantity_linspace(start, stop, num, **kwargs): raise ValueError('Both start and stop need to be quantities with a ' 'unit attribute') - return np.linspace(start.value, stop.to(start.unit).value, num, **kwargs) * start.unit + return np.linspace(start.value, stop.to(start.unit).value, num, **kwargs) * start.unit \ No newline at end of file From 4e9604ed2a7081ae813f8707ff04323e31ac6b28 Mon Sep 17 00:00:00 2001 From: Ulrich Noebauer Date: Thu, 13 Jul 2017 15:22:19 +0200 Subject: [PATCH 3/5] Replace last_interaction_in_nu with output_nu --- tardis/analysis.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tardis/analysis.py b/tardis/analysis.py index 2ed27a855e0..d8f5c2ed273 100644 --- a/tardis/analysis.py +++ b/tardis/analysis.py @@ -13,14 +13,17 @@ class LastLineInteraction(object): @classmethod def from_model(cls, model): return cls(model.runner.last_line_interaction_in_id, model.runner.last_line_interaction_out_id, - model.runner.last_line_interaction_shell_id, model.runner.last_interaction_in_nu, model.plasma.atomic_data.lines) + model.runner.last_line_interaction_shell_id, model.runner.output_nu, model.plasma.atomic_data.lines) def __init__(self, last_line_interaction_in_id, last_line_interaction_out_id, last_line_interaction_shell_id, - last_interaction_in_nu, lines, packet_filter_mode='packet_nu'): - self.last_line_interaction_in_id = last_line_interaction_in_id - self.last_line_interaction_out_id = last_line_interaction_out_id - self.last_line_interaction_shell_id = last_line_interaction_shell_id - self.last_line_interaction_angstrom = (last_interaction_in_nu * u.Hz).to(u.Angstrom, equivalencies=u.spectral()) + output_nus, lines, packet_filter_mode='packet_nu'): + # mask out packets which did not perform a line interaction + # TODO mask out packets which do not escape to observer? + mask = last_line_interaction_out_id != 1 + self.last_line_interaction_in_id = last_line_interaction_in_id[mask] + self.last_line_interaction_out_id = last_line_interaction_out_id[mask] + self.last_line_interaction_shell_id = last_line_interaction_shell_id[mask] + self.last_line_interaction_angstrom = (output_nu * u.Hz).to(u.Angstrom, equivalencies=u.spectral())[mask] self.lines = lines self._wavelength_start = 0 * u.angstrom @@ -81,7 +84,7 @@ def update_last_interaction_filter(self): packet_filter = (line_in_nu > self.wavelength_start.to(u.angstrom).value) & \ (line_in_nu < self.wavelength_end.to(u.angstrom).value) - + self.last_line_in = self.lines.iloc[self.last_line_interaction_in_id[packet_filter]] self.last_line_out = self.lines.iloc[self.last_line_interaction_out_id[packet_filter]] From a5e89bb1f90a4b75b74b3bbb9f01861cd7fd285b Mon Sep 17 00:00:00 2001 From: Ulrich Noebauer Date: Thu, 13 Jul 2017 15:39:48 +0200 Subject: [PATCH 4/5] Replace ilocs with ix --- tardis/analysis.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tardis/analysis.py b/tardis/analysis.py index d8f5c2ed273..294a6ab6ad5 100644 --- a/tardis/analysis.py +++ b/tardis/analysis.py @@ -80,13 +80,13 @@ def update_last_interaction_filter(self): packet_filter = (self.last_line_interaction_angstrom > self.wavelength_start) & \ (self.last_line_interaction_angstrom < self.wavelength_end) elif self.packet_filter_mode == 'line_in_nu': - line_in_nu = self.lines.wavelength.iloc[self.last_line_interaction_in_id].values + line_in_nu = self.lines.wavelength.ix[self.last_line_interaction_in_id].values packet_filter = (line_in_nu > self.wavelength_start.to(u.angstrom).value) & \ (line_in_nu < self.wavelength_end.to(u.angstrom).value) - self.last_line_in = self.lines.iloc[self.last_line_interaction_in_id[packet_filter]] - self.last_line_out = self.lines.iloc[self.last_line_interaction_out_id[packet_filter]] + self.last_line_in = self.lines.ix[self.last_line_interaction_in_id[packet_filter]] + self.last_line_out = self.lines.ix[self.last_line_interaction_out_id[packet_filter]] if self.atomic_number is not None: self.last_line_in = self.last_line_in[self.last_line_in.atomic_number == self.atomic_number] From a24c41aba9a4649cdd8c7399c8611516ab54ab2a Mon Sep 17 00:00:00 2001 From: Ulrich Noebauer Date: Thu, 13 Jul 2017 15:46:26 +0200 Subject: [PATCH 5/5] Fix typo, fix units error, fix masking error, revert to iloc --- tardis/analysis.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tardis/analysis.py b/tardis/analysis.py index 294a6ab6ad5..32653b6429c 100644 --- a/tardis/analysis.py +++ b/tardis/analysis.py @@ -16,14 +16,14 @@ def from_model(cls, model): model.runner.last_line_interaction_shell_id, model.runner.output_nu, model.plasma.atomic_data.lines) def __init__(self, last_line_interaction_in_id, last_line_interaction_out_id, last_line_interaction_shell_id, - output_nus, lines, packet_filter_mode='packet_nu'): + output_nu, lines, packet_filter_mode='packet_nu'): # mask out packets which did not perform a line interaction # TODO mask out packets which do not escape to observer? - mask = last_line_interaction_out_id != 1 + mask = last_line_interaction_out_id != -1 self.last_line_interaction_in_id = last_line_interaction_in_id[mask] self.last_line_interaction_out_id = last_line_interaction_out_id[mask] self.last_line_interaction_shell_id = last_line_interaction_shell_id[mask] - self.last_line_interaction_angstrom = (output_nu * u.Hz).to(u.Angstrom, equivalencies=u.spectral())[mask] + self.last_line_interaction_angstrom = output_nu.to(u.Angstrom, equivalencies=u.spectral())[mask] self.lines = lines self._wavelength_start = 0 * u.angstrom @@ -80,13 +80,13 @@ def update_last_interaction_filter(self): packet_filter = (self.last_line_interaction_angstrom > self.wavelength_start) & \ (self.last_line_interaction_angstrom < self.wavelength_end) elif self.packet_filter_mode == 'line_in_nu': - line_in_nu = self.lines.wavelength.ix[self.last_line_interaction_in_id].values + line_in_nu = self.lines.wavelength.iloc[self.last_line_interaction_in_id].values packet_filter = (line_in_nu > self.wavelength_start.to(u.angstrom).value) & \ (line_in_nu < self.wavelength_end.to(u.angstrom).value) - self.last_line_in = self.lines.ix[self.last_line_interaction_in_id[packet_filter]] - self.last_line_out = self.lines.ix[self.last_line_interaction_out_id[packet_filter]] + self.last_line_in = self.lines.iloc[self.last_line_interaction_in_id[packet_filter]] + self.last_line_out = self.lines.iloc[self.last_line_interaction_out_id[packet_filter]] if self.atomic_number is not None: self.last_line_in = self.last_line_in[self.last_line_in.atomic_number == self.atomic_number]