''' Energy time diagram
'''
import os
import sys
import datetime
import dateutil.parser
import logging
logging.basicConfig()
import numpy as np
import pyana.juice.jspice as js
js.init()
import pyana.util.timeseries
from . import f2j
from . import imager
def main(m=16., overwrite=True):
'''Main script'''
t0 = dateutil.parser.parse('2031-05-04T00:00:00')
t1 = dateutil.parser.parse('2031-05-14T00:00:00')
dt = datetime.timedelta(minutes=10)
tlist = pyana.util.timeseries.dtrange(t0, t1, dt)
estep = [10 * 1.5 ** i for i in range(16)]
# estep = estep[::2]
print(estep)
vstep = f2j.vel(estep, m)
print(vstep)
dfarray = []
tarray = []
xlist = np.linspace(-30, 0, 21)
ylist = np.linspace(-3, 3, 5)
ntobedone = len(tlist) * len(estep)
ndone = 0
import time
t0 = time.time()
for t in tlist:
for idx, vena_sc in enumerate(vstep):
output = 'etdiagram/%s-m%02d-%03d.txt' % (t.strftime('%FT%T'), m, idx)
if not overwrite and os.path.exists(output):
print('File %s exists. Skip calculation.' % output, file=sys.stderr)
continue
imgr = imager.singlepointimager_juice_at(t, vena_sc, mass=m)
imgr.do_calculation(xlist, ylist, output=output)
ndone += 1
print('Done %d/%d. Ellapsed=%f, Expected=%f' % (ndone, ntobedone, time.time() - t0, (time.time() - t0) / ndone * ntobedone), file=sys.stderr)
if __name__ == "__main__":
main(m=float(sys.argv[1]), overwrite=False)