''' Main script to run simulator from a single point.
.. todo::
Why you have to specify PAX and SAX for this?
I wander if they can be removed.
'''
from argparse import ArgumentParser
import numpy as np
import matplotlib.pyplot as plt
from . import simulator
from . import observer
from . import f2j
def main(scpos, scvel, fovvec, ena_velocity, tlist, primary_axis=None, secondary_axis=None, output=None, iophase=0.):
'''Main script, to compare with previous plot.'''
rj = 71492.
scpos = np.array(scpos) * rj
scvel = np.array(scvel)
fovvec = np.array(fovvec)
tlist = np.array(tlist)
if secondary_axis == None and (scvel ** 2).sum() == 0:
raise ValueError('Velocity is 0, so that secondary_axis should be specified')
sim = simulator.SimulatorCore()
obsrvr = observer.VirtualObserver(
observer.VirtualSpacecraft(scpos, scvel,
primary_axis=primary_axis,
secondary_axis=secondary_axis),
observer.VirtualSensor(fovvec, ena_velocity))
sim.set_observer(obsrvr)
sim.set_tlist(tlist)
sim.set_iophase(iophase)
if output == None:
mpl = False
mpl_prefix = None
else:
mpl = True
mpl_prefix = output
f, j = sim.run(mpl=mpl, mpl_prefix=mpl_prefix)
if output != None:
fp = open(output + '.info', 'w')
else:
fp = sys.stdout
print('xyz = %f %f %f km' % (scpos[0], scpos[1], scpos[2]), file=fp)
print('Vxyz = %f %f %f km/s' % (scvel[0], scvel[1], scvel[2]), file=fp)
print('FOV = %f %f %f' % (fovvec[0], fovvec[1], fovvec[2]), file=fp)
print('ENA = %f km/s' % ena_velocity, file=fp)
print('Tlimit = %f' % tlist[-1], file=fp)
print('N = %d' % len(tlist), file=fp)
if primary_axis != None:
print('PAX = %f %f %f' % (primary_axis[0], primary_axis[1], primary_axis[2]), file=fp)
else:
print('PAX = nan nan nan', file=fp)
if secondary_axis != None:
print('SAX = %f %f %f' % (secondary_axis[0], secondary_axis[1], secondary_axis[2]), file=fp)
else:
print('SAX = nan nan nan', file=fp)
print('f = %e s^3/m^6' % f, file=fp)
print('j = %e /cm2 sr eV s' % j, file=fp)
def parse():
desc = "Run a single simulation of IO ENA emission"
parser = ArgumentParser(description=desc)
parser.add_argument("-o", "--output", dest="output",
help="Output file name prefix")
parser.add_argument('-x', '--position', dest='scpos', default=[0, 15., 0],
nargs=3, type=float, help='Spacecraft position vector in Rj',
metavar=('X', 'Y', 'Z')
)
parser.add_argument('-v', '--velocity', dest='scvel', default=[-1, 0, 0],
nargs=3, type=float, help='Spacecraft velocity vector in km/s',
metavar=('Vx', 'Vy', 'Vz'))
parser.add_argument('-f', '--fov', dest='fov', default=[0, -1, 0],
nargs=3, type=float, help='Sensor FOV vector',
metavar=('FOVx', 'FOVy', 'FOVz'))
parser.add_argument('-s', '--ena-speed', dest='enaspeed', default=100.,
type=float, help='ENA velocity to be measured in km/s')
parser.add_argument('-t', '--tlimit', dest='tlimit', default=-40000,
type=float, help='Max time to calculate in sec (usually negative)',
)
parser.add_argument('-n', '--ndiv', dest='ndiv', default=4000,
type=float, help='Number of separation of time for calculation')
parser.add_argument('--primary-axis', dest='pax', default=None,
nargs=3, type=float, help='Primary axis vector',
metavar=('Px', 'Py', 'Pz'))
parser.add_argument('--secondary-axis', dest='sax', default=None,
nargs=3, type=float, help='Secondary axis vector',
metavar=('Sx', 'Sy', 'Sz'))
parser.add_argument('-i', '--io-phase', dest='iophase', default=0,
type=float, help="Io's phase in degrees at t=0")
args = parser.parse_args()
return args
if __name__ == "__main__":
args = parse()
main(args.scpos, args.scvel, args.fov, args.enaspeed,
np.linspace(0, args.tlimit, args.ndiv), output=args.output,
primary_axis=args.pax, secondary_axis=args.sax,
iophase=args.iophase
)