class Plot(object): ''' ''' def __init__(self, hdf5_file, nPlot=1, ntMax=0): ''' Constructor ''' self.diagnostics = Diagnostics(hdf5_file) if ntMax > 0 and ntMax < self.diagnostics.nt: self.nt = ntMax else: self.nt = self.diagnostics.nt self.plot = PlotMHD2D(self.diagnostics, args.hdf5_file.replace(".hdf5", ""), self.nt, nPlot) def update(self, itime): self.diagnostics.read_from_hdf5(itime) self.diagnostics.update_invariants(itime) if itime > 0: self.plot.add_timepoint() self.plot.update() def run(self): for itime in range(1, self.nt + 1): print("it = %4i" % (itime)) self.update(itime)
class replay(object): ''' ''' def __init__(self, hdf5_file, nPlot=1, write=False): ''' Constructor ''' self.diagnostics = Diagnostics(hdf5_file) self.nPlot = nPlot self.plot = PlotMHD2D(self.diagnostics, self.diagnostics.nt, nPlot, write) def init(self): self.update(0) def update(self, itime, final=False): self.diagnostics.read_from_hdf5(itime) self.diagnostics.update_invariants(itime) if itime > 0: self.plot.add_timepoint() return self.plot.update(final=final) def run(self): for itime in range(1, self.diagnostics.nt + 1): print("it = %4i" % (itime)) self.update(itime, final=(itime == self.diagnostics.nt))
class replay(object): ''' ''' def __init__(self, hdf5_file, nPlot=1, output=0): ''' Constructor ''' self.diagnostics = Diagnostics(hdf5_file) self.nPlot = nPlot self.plot = PlotMHD2D(self.diagnostics, self.diagnostics.nt, nPlot, output) def init(self): self.update(0) def update(self, itime): print(itime) self.diagnostics.read_from_hdf5(itime) self.diagnostics.update_invariants(itime) if itime > 0: self.plot.add_timepoint() self.plot.update() def run(self): for itime in range(1, self.diagnostics.nt + 1): self.update(itime)
class replay(object): ''' ''' def __init__(self, hdf5_file, nPlot=1): ''' Constructor ''' self.diagnostics = Diagnostics(hdf5_file) self.nPlot = nPlot self.plot = PlotMHD2D(self.diagnostics, self.diagnostics.nt, nPlot) def init(self): self.update(0) def update(self, itime, final=False): self.diagnostics.read_from_hdf5(itime) self.diagnostics.update_invariants(itime) if itime > 0: self.plot.add_timepoint() return self.plot.update(final=final) def run(self): for itime in range(1, self.diagnostics.nt + 1): self.update(itime, final=(itime == self.diagnostics.nt)) def movie(self, outfile, fps=1): self.plot.nPlot = 1 ani = animation.FuncAnimation(self.plot.figure, self.update, np.arange(1, self.diagnostics.nt + 1), init_func=self.init, repeat=False, blit=True) ani.save(outfile, fps=fps)