From 2113db425c50470ebb3496f34c4612a31bc1d109 Mon Sep 17 00:00:00 2001 From: "Mads M. Pedersen" <mmpe@dtu.dk> Date: Tue, 24 Apr 2018 11:32:09 +0200 Subject: [PATCH] plotting parameters updated --- topfarm/cost_models/dummy.py | 4 ++-- topfarm/plotting.py | 32 ++++++++++++++------------------ 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/topfarm/cost_models/dummy.py b/topfarm/cost_models/dummy.py index 55f8db8b..caa9fe69 100644 --- a/topfarm/cost_models/dummy.py +++ b/topfarm/cost_models/dummy.py @@ -57,8 +57,8 @@ class DummyCost(ExplicitComponent): J['cost', 'turbineY'] = (2 * y - 2 * np.array(self.optimal)[:, 1]) class DummyCostPlotComp(PlotComp): - def __init__(self, optimal): - super().__init__() + def __init__(self, optimal, memory=10): + super().__init__(memory) self.optimal = optimal def init_plot(self, boundary): diff --git a/topfarm/plotting.py b/topfarm/plotting.py index fbe71655..a5981293 100644 --- a/topfarm/plotting.py +++ b/topfarm/plotting.py @@ -9,10 +9,9 @@ class PlotComp(ExplicitComponent): """ colors = ['b', 'r', 'm', 'c', 'g', 'y', 'orange', 'indigo', 'grey'] * 100 - def __init__(self, memory=10, plot_every=5): + def __init__(self, memory=10): ExplicitComponent.__init__(self) self.memory = memory - self.plot_every = plot_every self.history = [] self.counter = 0 @@ -47,20 +46,17 @@ class PlotComp(ExplicitComponent): x = inputs['turbineX'] y = inputs['turbineY'] cost = inputs['cost'] - if self.history: - self.history = [(x.copy(), y.copy())] + self.history[:self.memory] - else: - self.history = [(x.copy(), y.copy())] - if self.counter % self.plot_every == 0: - boundary = inputs['boundary'] - self.init_plot(boundary) - plt.title(cost) - - history_arr = np.array(self.history) - for i, c, x_, y_ in zip(range(len(x)), self.colors, x, y): - plt.plot(history_arr[:, 0, i], history_arr[:, 1, i], '.-', color=c, lw=1) - plt.plot(x_, y_, 'o', color=c, ms=5) - plt.plot(x_, y_, 'x' + 'k', ms=4) - - plt.pause(.01) + self.history = [(x.copy(), y.copy())] + self.history[:self.memory] + + boundary = inputs['boundary'] + self.init_plot(boundary) + plt.title(cost) + + history_arr = np.array(self.history) + for i, c, x_, y_ in zip(range(len(x)), self.colors, x, y): + plt.plot(history_arr[:, 0, i], history_arr[:, 1, i], '.-', color=c, lw=1) + plt.plot(x_, y_, 'o', color=c, ms=5) + plt.plot(x_, y_, 'x' + 'k', ms=4) + + plt.pause(.01) self.counter += 1 -- GitLab