|
33 | 33 | logger = logging.getLogger(__name__) |
34 | 34 |
|
35 | 35 |
|
36 | | -class ProgressPlot: # pragma: no cover |
37 | | - def __init__(self, ncol, width, title=None): |
38 | | - plt.ion() |
39 | | - |
40 | | - fig, (ax1, ax2, ax3) = plt.subplots(ncols=3) |
41 | | - |
42 | | - plot_title = "Curvature in each order" |
43 | | - if title is not None: |
44 | | - plot_title = f"{title}\n{plot_title}" |
45 | | - fig.suptitle(plot_title) |
46 | | - |
47 | | - (line1,) = ax1.plot(np.arange(ncol) + 1) |
48 | | - (line2,) = ax1.plot(0, 0, "d") |
49 | | - ax1.set_yscale("log") |
50 | | - |
51 | | - self.ncol = ncol |
52 | | - self.width = width * 2 + 1 |
53 | | - |
54 | | - self.fig = fig |
55 | | - self.ax1 = ax1 |
56 | | - self.ax2 = ax2 |
57 | | - self.ax3 = ax3 |
58 | | - self.line1 = line1 |
59 | | - self.line2 = line2 |
60 | | - |
61 | | - def update_plot1(self, vector, peaks, offset=0): |
62 | | - data = np.ones(self.ncol) |
63 | | - data[offset : len(vector) + offset] = np.clip(vector, 1, None) |
64 | | - self.line1.set_ydata(data) |
65 | | - peaks = np.atleast_1d(peaks) |
66 | | - self.line2.set_xdata(peaks) |
67 | | - self.line2.set_ydata(data[peaks]) |
68 | | - self.ax1.set_ylim((data.min(), data.max())) |
69 | | - self.fig.canvas.draw() |
70 | | - self.fig.canvas.flush_events() |
71 | | - |
72 | | - def update_plot2(self, img, model, p1, p2, peak): |
73 | | - self.ax2.clear() |
74 | | - self.ax3.clear() |
75 | | - |
76 | | - self.ax2.imshow(img) |
77 | | - self.ax3.imshow(model) |
78 | | - |
79 | | - nrows, _ = img.shape |
80 | | - middle = nrows // 2 |
81 | | - y = np.arange(-middle, -middle + nrows) |
82 | | - x = peak + (p1 + p2 * y) * y |
83 | | - y += middle |
84 | | - |
85 | | - self.ax2.plot(x, y, "r") |
86 | | - self.ax3.plot(x, y, "r") |
87 | | - |
88 | | - self.fig.canvas.draw() |
89 | | - self.fig.canvas.flush_events() |
90 | | - |
91 | | - def close(self): |
92 | | - plt.close() |
93 | | - plt.ioff() |
94 | | - |
95 | | - |
96 | 36 | class Curvature: |
97 | 37 | def __init__( |
98 | 38 | self, |
@@ -499,10 +439,6 @@ def _determine_curvature_all_lines(self, original): |
499 | 439 | # Fit curvature from peak positions |
500 | 440 | p1, p2 = self._fit_curvature_from_positions(peaks, positions, offsets) |
501 | 441 |
|
502 | | - if self.plot >= 2: # pragma: no cover |
503 | | - for peak in peaks: |
504 | | - self.progress.update_plot1(vec, peak, cr[0]) |
505 | | - |
506 | 442 | all_peaks.append(peaks) |
507 | 443 | all_p1.append(p1) |
508 | 444 | all_p2.append(p2) |
@@ -699,16 +635,10 @@ def execute(self, original): |
699 | 635 |
|
700 | 636 | self._fix_inputs(original) |
701 | 637 |
|
702 | | - if self.plot >= 2: # pragma: no cover |
703 | | - self.progress = ProgressPlot(ncol, self.window_width, title=self.plot_title) |
704 | | - |
705 | 638 | peaks, p1, p2, vec = self._determine_curvature_all_lines(original) |
706 | 639 |
|
707 | 640 | coef_p1, coef_p2 = self.fit(peaks, p1, p2) |
708 | 641 |
|
709 | | - if self.plot >= 2: # pragma: no cover |
710 | | - self.progress.close() |
711 | | - |
712 | 642 | if self.plot: # pragma: no cover |
713 | 643 | self.plot_results(ncol, peaks, vec, p1, p2, coef_p1, coef_p2) |
714 | 644 |
|
|
0 commit comments