Skip to content

Commit

Permalink
Aggregate at the end in -m timestat
Browse files Browse the repository at this point in the history
Previously, the aggregator was applied separately on each member, and
then averaged. This isn't what is desired for -a std for example, where
aggregation should be done across all members and gridpoints.
  • Loading branch information
tnipen committed Apr 24, 2017
1 parent 0d44110 commit 6cae1b9
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions wxgen/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,18 +573,25 @@ def plot(self, sims, truth):
L = sim.length
else:
L = self.timemod
values = np.zeros([L])
counts = np.zeros([L])

"""
Take values from all gridpoints, leadtimes, and members and then aggregate at the end.
This could potentially require a large memory footprint, but since the aggregation isn't
always just a sum, we have to load all data first, then aggregate (instead of
iteratively summing up values, without keeping all values in memory at once),
"""
values = [np.zeros([0])]*L
for m in range(sim.num):
traj = sim.get(m)
q = sim.extract_grid(traj)
for i in range(L):
I = range(i, q.shape[0], L)
values[i] += self.aggregator(self.transform(q[I, :, :, Ivar]))
counts[i] += 1
values = values / counts
values[i] = np.append(values[i], self.transform(q[I, :, :, Ivar]).flatten())
values_agg = np.zeros(L)
for i in range(L):
values_agg[i] = self.aggregator(values[i])
col = self._get_color(s, len(sims))
mpl.plot(range(L), values, '-o', color=col, label=sim.name)
mpl.plot(range(L), values_agg, '-o', color=col, label=sim.name)
mpl.xlabel("Lead time (days)")
mpl.ylabel("%s" % (self.aggregator.name().capitalize()))
mpl.legend(loc="best")
Expand Down

0 comments on commit 6cae1b9

Please sign in to comment.