ace_oplot
ΒΆ
Ace Data Plotter and its module.
USAGE: ace_plot [-hv] start_time stop_time
Argument:
start_time Start time of the plot in the format as dateutil.parser.parse() can interpret.
stop_time Stop time of the plot in the format as dateutil.parser.parse() can interpret.
Options:
- -h
Help
- -v
Verbose mode
- -b baseurl
Use baseuri as a data file instead of the default.
'''Ace Data Plotter and its module.
USAGE: ace_plot [-hv] start_time stop_time
Argument:
start_time Start time of the plot in the format as dateutil.parser.parse()
can interpret.
stop_time Stop time of the plot in the format as dateutil.parser.parse()
can interpret.
Options:
-h Help
-v Verbose mode
-b baseurl Use baseuri as a data file instead of the default.
'''
#from pylab import *
import matplotlib.pyplot as plt
import sys
import getopt
import logging
from irfpy.swim.ace import AceData
from irfpy.util.utc import *
import dateutil.parser
def oplot(args, p_figure=None, p_subplot='111', param=(AceData.BX,AceData.BY,AceData.BZ)):
''' Plot ACE data.
Arguments:
:param args: args[0] is the start time.
args[1] is the stop time.
:keyword p_figure: is Figure object in matplotlib in which the data is plotted.
If it is None, figure() command is called to create Figure object.
:keyword p_subplot: is an argument when this program calles add_subplot() method.
:keyword param: is array-like which parameters are drawn. This parameter is
an enumerate defined in irfpy.swim.ace
'''
opts, arg = getopt.getopt(args, 'hvb:')
baseuri = AceData.DEFAULT_BROWSE_URI
for o,oa in opts:
if o in ('-h'):
usage()
return
if o in ('-v'):
logging.basicConfig(level=logging.DEBUG)
if o in ('-b'):
baseuri=oa
if len(arg) != 2:
usage()
return
t0dt = dateutil.parser.parse(arg[0])
t1dt = dateutil.parser.parse(arg[1])
ace=AceData()
ace.setFromUri(uri=baseuri)
dataset = ace.getTimeseries(t0dt, t1dt, value=list(range(12)))
jdlist = dataset.getJuldayList()
dtlist = [ jd2dt(jd) for jd in jdlist ]
logging.debug('Dataset size=%d'%dataset.size())
if p_figure == None:
p_figure=plt.figure()
p=p_figure.add_subplot(p_subplot)
for idx in param:
bxlist = [ dataset.getNeighbor(jd).getData()[idx] for jd in jdlist ]
p.plot(dtlist, bxlist, label=AceData.LABEL[idx])
p.legend()
return (p_figure, (p,))
def aceql(argv):
f=plt.figure(figsize=(8,10))
f,a1=oplot(argv, p_subplot='311',param=(AceData.BX,AceData.BY,AceData.BZ,AceData.B), p_figure=f)
f,a2=oplot(argv, p_subplot='312',param=(AceData.BT,AceData.BP), p_figure=f)
f,a3=oplot(argv, p_subplot='313',param=(AceData.NPROTON,), p_figure=f)
a1[0].set_ylim(-25,25)
a2[0].set_ylim(-90,360)
a2[0].yaxis.set_ticks([-90,0,90,180,270,360])
a3[0].set_yscale('log')
a3[0].set_ylim(0.01,100)
from matplotlib.dates import DateFormatter
a3[0].xaxis.set_major_formatter(DateFormatter('%F %T'))
f.autofmt_xdate()
return (f, (a1[0], a2[0], a3[0]))
def usage(fd=sys.stderr, exit=False):
print(__doc__, file=fd)
if __name__ == '__main__':
if len(sys.argv)==1:
usage()
sys.exit(-1)
argv=sys.argv[1:]
(f, a)=aceql(argv)
plt.show()