Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid crashes in plotting, do not plot residuals of mask or bad times #127

Merged
merged 3 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions xija/component/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ def plot_resid__time(self, fig, ax):
resids = self.resids
if self.mask:
resids[~self.mask.mask] = np.nan
for i0, i1 in self.model.mask_times_indices:
resids[i0:i1] = np.nan

if not lines:
plot_cxctime(self.model.times, resids, ls='-', color='#386cb0', fig=fig, ax=ax)
Expand All @@ -312,12 +314,16 @@ def plot_resid__time(self, fig, ax):
ax.set_ylabel('Temperature (%s)' % self.units)
else:
lines[0].set_ydata(resids)
ax.relim()
ax.autoscale()

def plot_resid__data(self, fig, ax):
lines = ax.get_lines()
resids = self.resids
if self.mask:
resids[~self.mask.mask] = np.nan
for i0, i1 in self.model.mask_times_indices:
resids[i0:i1] = np.nan

if not lines:
ax.plot(self.dvals + self.randx, resids, 'o',
Expand All @@ -328,6 +334,8 @@ def plot_resid__data(self, fig, ax):
ax.set_ylabel('Temperature (%s)' % self.units)
else:
lines[0].set_ydata(resids)
ax.relim()
ax.autoscale()


class Coupling(ModelComponent):
Expand Down
26 changes: 13 additions & 13 deletions xija/gui_fit/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def __init__(self, model, hist_msids):
self.emin_entry = QtWidgets.QLineEdit()
self.emin_entry.setText(f"{self.errorlimits[0]}")
self.emin_entry.returnPressed.connect(self.emin_edited)

self.emax_entry = QtWidgets.QLineEdit()
self.emax_entry.setText(f"{self.errorlimits[1]}")
self.emax_entry.returnPressed.connect(self.emax_edited)
Expand All @@ -284,18 +284,17 @@ def __init__(self, model, hist_msids):
self.max_limit = -1000
self.min_limit = 1000

self.canvas = canvas
self.ax1 = self.fig.add_subplot(1, 2, 1)
self.ax2 = self.fig.add_subplot(1, 2, 2)
self.plot_dict = {}
self.rz_mask
self.fmt1_mask
self.make_plots()

@property
def errorlimits(self):
return self._errorlimits

@errorlimits.setter
def errorlimits(self, lims):
self._errorlimits = lims
Expand Down Expand Up @@ -390,7 +389,7 @@ def update_plots(self):
mask &= self.rz_mask
if self.fmt1_masked:
mask &= self.fmt1_mask
for i0, i1 in self.model.bad_times_indices:
for i0, i1 in self.model.mask_times_indices:
mask[i0:i1] = False
resids = self.comp.resids[mask]
dvals = self.comp.dvals[mask]
Expand Down Expand Up @@ -505,7 +504,8 @@ def update_plots(self):
xpos_max, ystart, 'Maximum Error',
ha="left", va="center", rotation=90, clip_on=True)

self.canvas.draw_idle()
self.fig.canvas.draw_idle()
self.fig.canvas.flush_events()


class PlotBox(QtWidgets.QVBoxLayout):
Expand Down Expand Up @@ -541,11 +541,10 @@ def __init__(self, plot_name, plots_box):
self.ax = self.fig.add_subplot(111, sharex=plots_box.default_ax)
self.ax.autoscale(enable=False, axis='x')

self.canvas = canvas
self.plots_box = plots_box
self.main_window = self.plots_box.main_window
self.selecter = self.canvas.mpl_connect("button_press_event", self.select)
self.releaser = self.canvas.mpl_connect("button_release_event", self.release)
self.selecter = self.fig.canvas.mpl_connect("button_press_event", self.select)
self.releaser = self.fig.canvas.mpl_connect("button_release_event", self.release)

self.ly = None
self.limits = None
Expand All @@ -556,7 +555,7 @@ def select(self, event):
grab = event.inaxes and self.main_window.show_line and \
not self.ax.get_navigate_mode()
if grab:
self.mover = self.canvas.mpl_connect('motion_notify_event', self.on_mouse_move)
self.mover = self.fig.canvas.mpl_connect('motion_notify_event', self.on_mouse_move)
self.plots_box.xline = event.xdata
self.plots_box.update_xline()
else:
Expand All @@ -571,12 +570,12 @@ def on_mouse_move(self, event):

def release(self, event):
if hasattr(self, "mover"):
self.canvas.mpl_disconnect(self.mover)
self.fig.canvas.mpl_disconnect(self.mover)

def update_xline(self):
if self.plot_name.endswith("time") and self.ly is not None:
self.ly.set_xdata(self.plots_box.xline)
self.canvas.draw_idle()
self.fig.canvas.draw_idle()

_rz_times = None

Expand Down Expand Up @@ -657,7 +656,8 @@ def update(self, first=False):
self.add_annotation("line")
if mw.show_limits:
self.add_annotation("limits")
self.canvas.draw_idle()
self.fig.canvas.draw_idle()
self.fig.canvas.flush_events()


class PlotsBox(QtWidgets.QVBoxLayout):
Expand Down