#!/usr/bin/env python
import matplotlib
matplotlib.use('Agg')
from pylab import *
import swim_mominteg
import datetime
import dateutil.parser
import numpy
import logging
logging.basicConfig()
logger = logging.getLogger('swim_mominteg_plot')
cmin = 1e-14
cmax = -8
def swim_fovplot(fv, prefix = 'SW', title = 'SW'):
''' Plot f(v). 16 panels.
'''
nfv = numpy.array(fv) # 16 x 360 x 180
x = numpy.arange(361)
y = numpy.arange(90, -91, -1)
X, Y = meshgrid(x, y)
for ie in range(16):
fig=figure(ie)
ax=fig.add_subplot(111)
fve = nfv[ie]
if fve.max() < 0:
continue
m = ma.masked_where(fve < 0, log10(fve+cmin))
pcl = ax.pcolor(X, Y, m.T, vmax=cmax)
ax.set_title('E=%2d %s' % (ie, title))
ax.set_xlim(0, 360)
ax.set_ylim(-90, 90)
fig.colorbar(pcl)
savefig(prefix + '%02d.png' % ie)
plt.close('all')
if __name__=='__main__':
''' Main routine to investigate the argument.
'''
import getopt
if len(sys.argv) != 3:
print('***\nUSAGE: %s t0 t1\n***' % (sys.argv[0]))
sys.exit(-1)
t0 = dateutil.parser.parse(sys.argv[1])
t1 = dateutil.parser.parse(sys.argv[2])
logger.info('Start %s' % t0)
logger.info('Stop %s' % t1)
# t0 = datetime.datetime(2009,1,25,13,50,0)
# t1 = datetime.datetime(2009,1,25,14,10,0)
# t0 = datetime.datetime(2009,1,25,14,00,0)
# t1 = datetime.datetime(2009,1,25,14,00,10)
# t0 = datetime.datetime(2009,1,25,14,50,0)
# t1 = datetime.datetime(2009,1,25,15,10,0)
import irfpy.swim.swim_start
obstime=irfpy.swim.swim_start.getobstime(timerange=[t0,t1])
# for t in obstime:
# swim_observation_table(t)
den, fv = swim_mominteg.swim_mominteg(t0, t1)
swim_fovplot(fv, prefix = 'SW-%s-%s-'%(t0.strftime('%FT%T'), t1.strftime('%FT%T')),
title = '%s - %s (n=%g/cc)'%(t0.strftime('%FT%T'), t1.strftime('%FT%T'), den/1e6))