plot_cy1_onmap
¶
Plot a CY1 position on map.
CY-1 position(s) plotter.
CY-1 positions are plotted according to the time (and interval) specification.
A simple sample is as follows.
% plot_cy1_onmap.py 2009-01-30T20:00:00
This will provide a plot of the CY-1 position at 20 o’clock on January 30, 2009.
Another sample is to specify the range of the time. It can be realized by specifying -e and -r as a sampling time and the number of repeat.
% plot_cy1_onmap.py -e 300 -r 12 2009-03-10T15:00:00
This will display a plot of 12 CY-1 positions every 5 minutes from 15:00 on 10 March 2009 (i.e. until 15:55).
If you want to save it to the file, you can use -o option.
% plot_cy1_onmap.py -e 300 -r 12 -o orbitplot.png 2009-03-10T15:00:00
The above figure is saved to orbitplot.png
.
#!/usr/bin/env python
''' Plot a CY1 position on map.
CY-1 position(s) plotter.
CY-1 positions are plotted according to the time (and interval) specification.
A simple sample is as follows.
.. code-block:: sh
% plot_cy1_onmap.py 2009-01-30T20:00:00
This will provide a plot of the CY-1 position at 20 o'clock on January 30, 2009.
Another sample is to specify the range of the time.
It can be realized by specifying -e and -r as a sampling time and the number of repeat.
.. code-block:: sh
% plot_cy1_onmap.py -e 300 -r 12 2009-03-10T15:00:00
This will display a plot of 12 CY-1 positions every 5 minutes from 15:00 on 10 March 2009
(i.e. until 15:55).
If you want to save it to the file, you can use -o option.
.. code-block:: sh
% plot_cy1_onmap.py -e 300 -r 12 -o orbitplot.png 2009-03-10T15:00:00
The above figure is saved to :file:`orbitplot.png`.
'''
import sys
from optparse import OptionParser
import matplotlib.pyplot as plt
import datetime
import dateutil.parser
import numpy as np
import logging
logging.basicConfig()
import irfpy.cy1orb.pvat2 as pvat
from irfpy.cy1orb.plot.axis_cy1_me import axis_cy1_me_at
def main(argv):
help = ''' USAGE: %prog options yyyy-mm-ddThh:mm:ss '''
parser = OptionParser(help)
parser.add_option('-v', action='store_true', dest='verbose',
default=False, help='Verbose mode')
parser.add_option('-e', action='store', dest='every',
default=60, help='Interval of the sample point every # s')
parser.add_option('-r', action='store', dest='repeat',
default=1, help='Number of sample point.')
parser.add_option('-o', action='store', dest='output',
default=None, help='Plot in a file instead of displaying')
(options, args) = parser.parse_args(argv[1:])
if len(args) != 1:
parser.print_help()
sys.exit(-5)
t0 = dateutil.parser.parse(args[0])
every = int(options.every)
repeat = int(options.repeat)
output = options.output
logger = logging.getLogger(__file__)
if options.verbose:
logger.setLevel(logging.DEBUG)
logger.info('Set logging level to DEBUG')
dt = datetime.timedelta(seconds=every)
tlist = t0 + dt * np.arange(repeat)
logger.debug('Time = %s' % str(tlist))
if len(tlist) >= 1:
t0 = tlist[0]
else:
t0 = None
if len(tlist) >= 2:
t1 = tlist[-1]
else:
t1 = None
fig = plt.figure(figsize=(10, 5))
ax, img = axis_cy1_me_at(tlist, terminator=t0, fmt='*')
if t0 != None:
posme = pvat.getmepos(t0)
while posme[0] > 180: posme[0] -= 360
while posme[0] < -180: posme[0] += 360
ax.text(posme[0], posme[1], t0.strftime('%FT%T'))
if t1 != None:
posme2 = pvat.getmepos(t1)
while posme2[0] > 180: posme2[0] -= 360
while posme2[0] < -180: posme2[0] += 360
ax.text(posme2[0], posme2[1], t1.strftime('%FT%T'))
ax.set_title('CY1 on Moon (%s - %s, every %d sec)' % (t0.strftime('%FT%T'), t1.strftime('%T'), every))
else:
ax.set_title('CY1 on Moon (%s)' % (t0.strftime('%FT%T')))
ax.set_xlim(-180, 180)
ax.set_ylim(-90, 90)
if output == None:
plt.show()
else:
logger.debug('.... Dumping to the file %s' % output)
fig.savefig(output)
if __name__ == '__main__':
main(sys.argv)