Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
fun_plot_reconstruction.py
Go to the documentation of this file.
1from cycler import cycler
2import argparse
3import matplotlib.animation as animation
4import matplotlib.pyplot as plt
5import matplotlib.mlab as mlab
6import numpy as np
7
8def plot_reconstruction(step,scale='linear'):
9
10 #parser = argparse.ArgumentParser(description='Plot 1d reconstructions')
11 #parser.add_argument('--step', metavar = 'N', type=int, nargs=1,
12 # default=[0], help='Step to plot')
13 #args = parser.parse_args()
14
15 #fname = 'reconstruction_100'
16 fname = 'reconstruction_{:05d}'.format(step)
17
18 #dat = loadtxt('reconstructions_010.dat')
19 dat = np.loadtxt('reconstructions_{:05d}.dat'.format(step))
20 plt.figure(1,figsize=(8,6),dpi = 100)
21 plt.clf()
22 T = 5e5
23 m_p = 1.67262158e-27
24 k_B = 1.3806503e-23
25
26 r0 = -2e5
27 dr = 500
28
29 r = dat[:,0] - (r0 + step * dr)
30 f = 1.0e18 * (m_p / (2.0 * np.pi * k_B * T)) ** 1.5 * np.exp(-m_p * r ** 2 / (2.0 * k_B * T))
31 #f = 1.0e6 * (m_p / (2.0 * pi * k_B * T)) ** 1.5 * (
32 # exp(-m_p * dat[:,0] ** 2 / (2.0 * k_B * T)) +
33 # exp(-m_p * (dat[:,0] + 2e5) ** 2 / (2.0 * k_B * T)))
34 plt.rc('axes', prop_cycle = cycler('color', ['c','m','y','k']))
35 plt.plot(dat[:,0],f , '-', lw = 2, label = 'Analytic Function')
36 plt.plot(dat[:,0],dat[:,1], '-', lw = 2, label = 'Volume Average')
37 plt.plot(dat[:,0],dat[:,2], '-', lw = 2, label = 'Reconstruction')
38 plt.grid(True)
39 plt.legend(loc=0)
40
41 if scale is 'log':
42 plt.ylim(1e-16,1e3)
43 plt.xlim(-1e6,1e6)
44 else:
45 pass
46 plt.xlim(-0.6e6,0.6e6)
47
48 ax = plt.gca()
49 ax.set_yscale(scale)
50 plt.savefig(fname+'.png')
51 #plt.savefig(fname+'.eps')
52
53 #show(block=False)
54 #print(sum(dat[:,2]))
55 #print(np.trapz(dat[:,2],dat[:,0]),max(dat[:,2]))
56 print(sum(np.gradient(dat[:,0]) * dat[:,2]),max(dat[:,2]))
57 return sum(np.gradient(dat[:,0]) * dat[:,2]),max(dat[:,2])
58
59 #return dat
static ARCH_HOSTDEV VecSimple< T > max(VecSimple< T > const &l, VecSimple< T > const &r)