cena_energy_time_sum
¶
A script to plot CENA energy time spectra (summed over)
USAGE: python cena_energy_time_sum.py [opts] start_time stop_time
#!/usr/bin/env python
''' A script to plot CENA energy time spectra (summed over)
USAGE: python cena_energy_time_sum.py [opts] start_time stop_time
'''
import sys
from pylab import *
import numpy as np
import numpy.ma as ma
from optparse import OptionParser
import datetime
import dateutil.parser
import logging
logging.basicConfig()
try:
import irfpy.cena.cena_mass2 as cenam
except IOError as e:
logging.error('Failed to load CENA module. ' +
'Most probable reason of this failure is ' +
'"CENA database or orbit number file not found." ' +
'Check the ~/.irfpyrc settings and the corresponding database location.')
sys.exit(-3)
from irfpy.cena import energy
from irfpy.util import utc
from irfpy.util import bipower
import irfpy.cena.cena_mass2
import irfpy.cena.plot.axis_cena
clr = ['b', 'g', 'r', 'c', 'm', 'y', 'k']
def main(t0, t1, *args, **kwds):
''' A script to plot CENA energy time diagram.
:param t0: Start of the time of accumulation
:type t0: ``datetime.datetime`` is recommended.
:param t1: End of the time of accumulation
:type t1: ``datetime.datetime`` is recommended.
:keyword validation: You can set 'full' for full validation.
:type type: ``string``
:keyword vrange: Range of the value, ``[vmin, vmax]``.
:keyword output: Output file name. PNG is recommended.
Default is ``None``.
If ``None`` is given, no output graphic is produced (only X output).
:return: TBD
'''
fig = figure(figsize=(12, 7))
type = kwds.get('validation', 'none')
print('!!!!!!!!!! ', type)
if type.lower() == 'full':
vld = [irfpy.cena.cena_mass2.invalid_mask.high_heavy_mask,
irfpy.cena.cena_mass2.invalid_mask.high_count_mask]
else:
vld = []
vrange = kwds.get('vrange', [0, 100])
output = kwds.get('output', None)
logging.getLogger('cena_mass2.invalid_mask').debug('Use validation = %s' % type)
ax = irfpy.cena.plot.axis_cena.getSimpleEnergyTime(t0, t1,
vmin=vrange[0], vmax=vrange[1], validation=vld)
if output == None:
show()
else:
plt.savefig(output)
def mainexec():
usage = "USAGE: %prog [options] start_time stop_time"
parser = OptionParser(usage=usage)
parser.add_option('-v', action='store_true', dest='verbose',
default=False)
parser.add_option('-f', action='store_true', dest='full_validation',
default=False,
help='Enable full validation (heavy-light ratio and count rate)')
parser.add_option('-l', action='store', type='float', dest='vmin',
default=0)
parser.add_option('-u', action='store', type='float', dest='vmax',
default=10)
parser.add_option('-o', '--output', action='store', dest='filename',
default=None, help='Plot errorbar as well.')
options, args = parser.parse_args()
if len(args) != 2:
logging.error('!!!! Illegal number of argument. t0 and t1 should be specified.')
parser.print_help()
sys.exit(-5)
t0 = dateutil.parser.parse(args[0])
t1 = dateutil.parser.parse(args[1])
if options.verbose:
# logging.getLogger().setLevel(logging.DEBUG)
logging.getLogger('cena_mass2.invalid_mask').setLevel(logging.DEBUG)
logging.getLogger('cenamass2.getdataE16').setLevel(logging.DEBUG)
if options.full_validation:
validation = 'full'
else:
validation = 'none'
logging.debug('Start = %s' % t0)
logging.debug('End = %s' % t1)
cena_data = main(t0, t1, validation=validation, vrange=[options.vmin, options.vmax])
if __name__ == '__main__':
mainexec()