Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
vectorpotentialdipole_compare_with_data.py
Go to the documentation of this file.
1#!/usr/bin/env python import matplotlib.pyplot as plt
2
3# /*
4# * This file is part of Vlasiator.
5# * Copyright 2010-2016 Finnish Meteorological Institute
6# * Copyright 2017-2019 University of Helsinki
7# *
8# * For details of usage, see the COPYING file and read the "Rules of the Road"
9# * at http://www.physics.helsinki.fi/vlasiator/
10# *
11# * This program is free software; you can redistribute it and/or modify
12# * it under the terms of the GNU General Public License as published by
13# * the Free Software Foundation; either version 2 of the License, or
14# * (at your option) any later version.
15# *
16# * This program is distributed in the hope that it will be useful,
17# * but WITHOUT ANY WARRANTY; without even the implied warranty of
18# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# * GNU General Public License for more details.
20# *
21# * You should have received a copy of the GNU General Public License along
22# * with this program; if not, write to the Free Software Foundation, Inc.,
23# * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24# */
25import numpy as np
26import math
27import sys,os
28import pytools as pt
29import matplotlib.pyplot as plt
30import fieldmodels
31
32''' Testing routine for vector potential dipole
33
34run using "python vectorpotentialdipole_compare_with_data.py [ang]" where
35angle (given in degrees) is the polar angle of the line profile to plot.
36 Plots also Vlasiator BCH profiles at different times
37
38'''
39
40if len(sys.argv)!=1:
41 line_phi = float(sys.argv[1])
42else:
43 line_phi = 45.
44
45plt.switch_backend('Agg')
46
47outfilename = "./vecpotdip_compare_"+str(int(line_phi))+".png"
48
49inputLocation="/turso/group/spacephysics/vlasiator/data/L0/2D/BCH/bulk/"
50times = [0,10,50,100,200,500]
51colors = ['r','g','b','magenta','k']
52timefulls = [str(time).rjust(7, '0') for time in times]
53file_names = [inputLocation+"bulk."+timefull+".vlsv" for timefull in timefulls]
54
55vlsvobj = []
56for i in range(len(times)):
57 vlsvobj.append(pt.vlsvfile.VlsvReader(file_name=file_names[i]))
58
59RE=6371000.
60
61tilt_angle_phi = 0.
62tilt_angle_theta = 0.
63line_theta = 0. * math.pi/180.
64line_phi = line_phi * math.pi/180.
65line_start = np.array([0,0,0])
66
67step = 0.1
68linewidth=2
69linthresh=1.e-10
70fontsize=20
71
72
73#fieldmodels.dipole.set_dipole(centerx, centery, centerz, tilt_phi, tilt_theta, mult=1.0, radius_f=None, radius_z=None):
74dip = fieldmodels.dipole(0,0,0,tilt_angle_phi,tilt_angle_theta)
75mdip = fieldmodels.dipole(80*RE,0,0,tilt_angle_phi,180.-tilt_angle_theta)
76
77# Create figure
78fig = plt.figure()
79fig.set_size_inches(20,30)
80nsubplots=3
81for i in range(nsubplots):
82 fig.add_subplot(nsubplots,1,i+1)
83axes = fig.get_axes()
84
85radii = np.arange(0.1,45,step)*RE
86nr=len(radii)
87radiiRE = radii/RE
88
89fig.suptitle(r"Profiles with $\theta="+str(int(line_theta*180./math.pi))+"$, $\phi="+str(int(line_phi*180./math.pi))+"$ starting from ("+str(line_start[0])+","+str(line_start[1])+","+str(line_start[2])+") [RE] with dipole tilt $\Phi="+str(int(tilt_angle_phi*180./math.pi))+"$, $\Theta="+str(int(tilt_angle_theta*180./math.pi))+"$", fontsize=fontsize)
90
91xv = line_start[0]*RE + radii*np.sin(line_phi)*np.cos(line_theta)
92yv = line_start[1]*RE + radii*np.sin(line_phi)*np.sin(line_theta)
93zv = line_start[2]*RE + radii*np.cos(line_phi)
94
95B1 = np.zeros([nr,3])
96B2 = np.zeros([nr,3])
97B3 = np.zeros([nr,3])
98B4 = np.zeros([nr,3])
99
100for j in range(nr):
101 for k in range(3):
102 B1[j,k] = dip.get(xv[j],yv[j],zv[j],0,k,0)
103# B2[j,k] = dip.get_old(xv[j],yv[j],zv[j],0,k,0)
104# B3[j,k] = B2[j,k] + mdip.get_old(xv[j],yv[j],zv[j],0,k,0)
105# B4[j,k] = dip.get_ldp(xv[j],yv[j],zv[j],0,k,0)
106# B4[j,k] = B4[j,k] + mdip.get_ldp(xv[j],yv[j],zv[j],0,k,0)
107
108colors=['r','k','b']
109coords = ['x','y','z']
110
111for k in range(nsubplots):
112 ax = axes[k]
113 print("component "+coords[k])
114 ax.plot(radiiRE, B1[:,k], c=colors[-1], linestyle='-', linewidth=linewidth, label='vectorpot B'+coords[k], zorder=-10)
115 #ax.plot(radiiRE, B2[:,k], c=colors[k], linestyle='--', linewidth=linewidth, label='regular B'+coords[k])
116 #ax.plot(radiiRE, B3[:,k], c=colors[k], linestyle=':', linewidth=linewidth, label='reg+mirror B'+coords[k])
117 #if tilt_angle_phi==0:
118 # ax.plot(radiiRE, B4[:,k], c=colors[k], linestyle='-.', linewidth=linewidth, label='line+mirror B'+coords[k])
119
120 for i in range(len(times)):
121 vf=vlsvobj[i]
122 print('time t='+str(int(times[i]*0.5))+'s')
123 res = pt.calculations.cut_through_step(vf, [xv[0],0,zv[0]], [xv[-1],0,zv[-1]])
124 cut = res[0].data
125 pr_dist = res[1].data
126 pr_coords = res[2].data
127 pr_Re = np.array(pr_dist)/RE
128 pr_B = vf.read_variable("B", operator=coords[k],cellids=cut)
129 #ax.plot(pr_Re, np.array(pr_B), c=colors[i], linestyle='-', linewidth=linewidth, label='vlsv t='+str(int(times[i]*0.5))+'s',zorder=i)
130 ax.plot(pr_Re, np.array(pr_B), linestyle='-', linewidth=linewidth, label='vlsv t='+str(int(times[i]*0.5))+'s',zorder=i)
131
132 ax.set_xlabel(r"$r$ [$r_\mathrm{E}$]", fontsize=fontsize)
133 ax.set_xlim([0,70])
134 #ax.set_yscale('log', nonposy='clip')
135 ax.set_yscale('symlog', linthreshy=linthresh)
136 for item in ax.get_xticklabels():
137 item.set_fontsize(fontsize)
138 for item in ax.get_yticklabels():
139 item.set_fontsize(fontsize)
140
141 ylims = np.array(ax.get_ylim())
142 if ylims[0] < -1e-4:
143 ylims[0] = -1e-4
144 if ylims[1] > 1e-4:
145 ylims[1] = 1e-4
146 ax.set_ylim(ylims)
147
148 handles, labels = ax.get_legend_handles_labels()
149 ax.legend(handles, labels, fontsize=fontsize)
150
151fig.savefig(outfilename)
152plt.close()