''' Time series of pitch angle coverage
.. image:: ../../../src/scripts/apps120820_joee/joee_pitchangle_mhd.png
:width: 90%
.. image:: ../../../src/scripts/apps120820_joee/joee_pitchangle_dipole.png
:width: 90%
'''
import datetime
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import pyana.pep.juice_spice1205 as spice
import pyana.joee.fov0 as fov
import pyana.joee.frame0 as frame
from pyana.pep.mhddata import MagneticField1201 as MF
import pyana.pep.pep_attitude
import pyana.pep.ganymede_magfield
def geo2pla(vecs_geo):
vecs_pla = np.ma.zeros(vecs_geo.shape)
vecs_pla[0] = -vecs_geo[1]
vecs_pla[1] = vecs_geo[0]
vecs_pla[2] = vecs_geo[2]
return vecs_pla
def main(model='mhd'):
t0 = datetime.datetime(2033, 4, 4, 18, 50)
t1 = t0 + datetime.timedelta(minutes=180)
dt = datetime.timedelta(seconds=30)
# dt = datetime.timedelta(seconds=180)
tlist = [t0]
while tlist[-1] < t1:
tlist.append(tlist[-1] + dt)
print(len(tlist))
if model == 'dipole':
mf = pyana.pep.ganymede_magfield.TiltedDipole()
else:
mf = MF(interpolate='trilin')
juice = spice.JuiceSpice.get_default_instance()
rg = 2634.1
sc = pyana.pep.pep_attitude.NadirLookingSc()
pitchangles = np.zeros([16, len(tlist)]) + np.nan
nadirangles = np.zeros_like(pitchangles) + np.nan
lons = np.zeros_like(tlist) + np.nan
lats = np.zeros_like(tlist) + np.nan
bs = np.zeros([3, len(tlist)]) + np.nan
for idx, t in enumerate(tlist):
print(idx)
# Position and velocity in plasma frame.
position = geo2pla(juice.get_position(t, relative_to="Ganymede", frame="IAU_GANYMEDE"))
velocity = geo2pla(juice.get_velocity(t, relative_to="Ganymede", frame="IAU_GANYMEDE"))
print('POS,VEL=', position, velocity)
h = np.sqrt((position ** 2).sum())
lon = np.arctan2(position[1] / h, position[0] / h) # In rad
lat = np.arcsin(position[2] / h) # In rad
lons[idx] = np.rad2deg(lon)
lats[idx] = np.rad2deg(lat)
pos = position / rg # In Rg
posnorm = position / h
mag = mf.interpolate3d(pos[0], pos[1], pos[2]) # In nT, (3,)
bs[:, idx] = mag
magmag = np.sqrt((mag ** 2).sum())
magnorm = mag / magmag
sc.set_posvel(position, velocity)
# Now start conversions
for ch in np.arange(16): # Each channel
sc.set_posvel(position, velocity)
lookdir_el = pyana.joee.fov0.elev_pix_center(ch)
lookdir_az = pyana.joee.fov0.azim_pix_center(ch)
vecjoee = pyana.joee.frame0.angles2joee(lookdir_el, lookdir_az)
vecnsc = pyana.joee.frame0.joee2nsc(vecjoee)
vecganpla = sc.convert_to_ref(vecnsc) # Looking direciton of the certain channel.
angle_from_nadir = np.arccos((-vecganpla * posnorm).sum()) * 180. / np.pi
angle_from_b = np.arccos((vecganpla * magnorm).sum()) * 180. / np.pi
pitchangles[ch, idx] = 180 - angle_from_b # Now the velocity vector with 180-
nadirangles[ch, idx] = angle_from_nadir
fig = plt.figure(figsize=(8, 14))
ax1 = fig.add_subplot(411)
ax2 = fig.add_subplot(412)
ax3 = fig.add_subplot(413)
ax4 = fig.add_subplot(414)
line=['b', 'g', 'r', 'c', 'm', 'y', 'k', 'pink']
for ch in np.arange(8):
ax1.plot(tlist, pitchangles[ch, :], line[ch], label='Ch%02d' % ch)
for ch in np.arange(8, 16):
ax2.plot(tlist, pitchangles[ch, :], line[ch % 8], label='Ch%02d' % ch)
ax3.plot(tlist, bs[0, :], label='Bx')
ax3.plot(tlist, bs[1, :], label='By')
ax3.plot(tlist, bs[2, :], label='Bz')
ax4.plot(tlist, lons, label='LON')
ax4.plot(tlist, lats, label='LAT')
ax1.set_title('NU/JoEE')
ax1.set_ylabel('Pitch angle')
ax1.yaxis.set_ticks([0, 45, 90, 135, 180])
ax2.set_title('ZU/JoEE')
ax2.set_ylabel('Pitch angle')
ax2.yaxis.set_ticks([0, 45, 90, 135, 180])
ax3.set_ylabel('B [nT] %s' % model)
ax4.yaxis.set_ticks(np.linspace(-180, 180, 9))
ax4.set_ylabel('S/C Position [deg]')
ax1.legend(loc='best', prop={'size': 7})
ax2.legend(loc='best', prop={'size': 7})
ax3.legend(loc='best', prop={'size': 7})
ax4.legend(loc='best', prop={'size': 7})
ax1.grid()
ax2.grid()
ax3.grid()
ax4.grid()
if __name__ == "__main__":
retval = main('mhd')
plt.savefig('joee_pitchangle_mhd.png')
retval = main('dipole')
plt.savefig('joee_pitchangle_dipole.png')