''' Produce a bunch of mass spectra from an output file (DataFileV1 format).
'''
#import math
import numpy as np
import matplotlib.pyplot as plt
import os
import logging
from matplotlib import cm
import datetime
from irfpy.util import irfpyrc
from irfpy.util import exception
import irfpy.util.julday
import irfpy.util.utc
from irfpy.moon import moon_map as _moon_map
import irfpy.cy1orb.terminator
import irfpy.cy1orb.subsolar
#import irfpy.util.v3ang
import irfpy.cy1orb.pvat2 as pvat
import math
def _v3ang(v):
r = math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2])
t = math.acos(v[2] / r) * 180 / math.pi
p = math.atan2(v[1], v[0]) * 180 / math.pi
return (r, t, p)
[docs]def axis_cy1_me_at(times, fmt='+', **args):
''' Make a map of the Moon overlaying the positions of the spacecraft at the specified times.
:param times: List of the time to be plotted.
:type times: ``Array-like of datetime.datetime``
:keyword fmt: Format specifier for ``matplotlib.pyplot.plot`` function.
:keyword ``**args``: Argument to be given to :func:`axis_cy1_me`.
This is a simple example of plotting ME position at a specified time
Prepare the time, for 1 hour with 1 min resolution.
::
import datetime
tlist = datetime.datetime(2009, 1, 25, 3) + arange(60) * datetime.timedelta(seconds=60)
Plot them.
::
axis_cy1_me.axis_cy1_me_at(tlist)
.. note::
If you connect data points by "line", fake lines may be plotted at the poles.
Because this is not a priority issues (not so simple to refine),
I have no plan to fix them so far.
Idea to remove is to plot data points as points (as in the default value for fmt keyword)
or plot by line first, save them by vector format like ``eps`` file, and
remove the segment manually.
'''
lons = []
lats = []
for t in times:
posme = pvat.getmepos(t)
while posme[0] > 180:
posme[0] -= 360
while posme[0] < -180:
posme[0] += 360
lons.append(posme[0])
lats.append(posme[1])
return axis_cy1_me(lons, lats, fmt=fmt, **args)
[docs]def axis_cy1_me(lons, lats, fmt='-', rect=None, terminator=None, **args):
''' Make a map of the Moon together with plotting the positions of the spacecraft.
:param lons: List of longitude. Longitude should be in a range of (-180, 180)
:param lats: List of latitude.
:keyword fmt: Format specifier for ``matplotlib.pyplot.plot`` function.
:keyword rect: *rect* keyword to be given to axes() method. [left, bottom, width, height].
:keyword terminator: None or ``datetime`` for calculating terminator and the subsolar point.
:keyword ``**args``: Argument to be given to ``matplotlib.pyplot.plot`` function.
Sample code is here::
from irfpy.cy1orb.plot import axis_cy1_me
axis_cy1_me.axis_cy1_me([-120, -80, 0, 80, 120], [45, -20, -35, -5, 60], fmt='-*')
'''
ax, img = axis_map_me(rect=rect, terminator=terminator)
ax.plot(lons, lats, fmt, **args)
return ax, img
[docs]def axis_map_me(rect=None, terminator=None):
''' Make a map of the Moon and return as axis and image instances.
:keyword rect: *rect* keyword to given to axes() method. [left, bottom, width, height].
:keyword terminator: Specify the time for calculating terminator and the subsolar point.
:type terminator: ``datetime.datetime``
:returns: Axis and image instance.
A sample::
from irfpy.cy1orb.plot import axis_cy1_me
ax, im = axis_cy1_me.axis_map_me()
will show a moon map.
To plot a position of the spacecraft, do like::
ax.plot([-100, -50, 0, 50, 100], [-50, -40, 0, 40, 50])
The x coordinate is longitude and y coordinate is latitude.
Longitude ranges from -180 and 180.
'''
logger = logging.getLogger('axis_cy1_me')
logger.setLevel(logging.DEBUG)
if rect:
ax = plt.axes(rect)
else:
ax = plt.axes()
moon = _moon_map.MoonMapSmall().image
im = ax.imshow(moon, cmap=cm.gray, origin='lower', extent=[-180, 180, -90, 90])
if terminator:
jd = irfpy.util.utc.convert(terminator, irfpy.util.julday.Julday)
tvec = irfpy.cy1orb.terminator.terminator(jd)
tme = np.array([_v3ang(p) for p in tvec])
tlat = 90 - tme[:, 1]
tlon = tme[:, 2]
ax.plot(tlon, tlat, 'k:')
sme = irfpy.cy1orb.subsolar.subsolar_asdegrees(jd)
ax.plot([sme[0]], [sme[1]], 'r*')
ax.set_axis_off()
return ax, im