-
Notifications
You must be signed in to change notification settings - Fork 0
/
movie_magnetic_field.py
95 lines (61 loc) · 2.29 KB
/
movie_magnetic_field.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
'''
Created on Apr 06, 2012
@author: Michael Kraus ([email protected])
'''
import matplotlib
#matplotlib.use('Cairo')
matplotlib.use('AGG')
#matplotlib.use('PDF')
#import StringIO
import argparse
#import os
#import numpy as np
#import h5py
from imhd.diagnostics import Diagnostics
class movie(object):
'''
'''
def __init__(self, hdf5_file, nPlot=1, ntMax=0, write=False):
'''
Constructor
'''
self.diagnostics = Diagnostics(hdf5_file)
if ntMax > 0 and ntMax < self.diagnostics.nt:
self.nt = ntMax
else:
self.nt = self.diagnostics.nt
self.nPlot = nPlot
self.plot = PlotMHD2D(self.diagnostics, self.diagnostics.nt, self.nt, nPlot, write)
self.init()
def init(self):
self.update(0)
def update(self, itime, final=False):
self.diagnostics.read_from_hdf5(itime)
self.diagnostics.update_invariants(itime)
return self.plot.update(itime, final=final)
def run(self, write=False):
for itime in range(1, self.nt+1):
print("it = %4i" % (itime))
self.update(itime, final=(itime == self.nt))
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Vlasov-Poisson Solver in 1D')
parser.add_argument('hdf5_file', metavar='<run.hdf5>', type=str,
help='Run HDF5 File')
parser.add_argument('-np', metavar='i', type=int, default=1,
help='plot every i\'th frame')
parser.add_argument('-ntmax', metavar='i', type=int, default=0,
help='limit to i points in time')
parser.add_argument('-o', metavar='<run.mp4>', type=str, default=None,
help='output video file')
parser.add_argument('-fps', metavar='i', type=int, default=1,
help='frames per second')
args = parser.parse_args()
from imhd.plots.movie_plot_magnetic_field import PlotMHD2D
print
print("Replay run with " + args.hdf5_file)
print
pyvp = movie(args.hdf5_file, ntMax=args.ntmax, nPlot=args.np, write=True)
pyvp.run()
print
print("Replay finished.")
print