7 from logdb
import IndexedLogDB, PKey
9 from logrecord
import LogRecord
10 from struct
import pack, unpack
11 from functools
import partial
13 from exceptions
import *
16 RAD2DEG = 180.0/math.pi
17 class Keplerian(object):
18 ASTROCENTRIC, BARYCENTRIC, JACOBI, ORIGIN = range(4)
19 choices = [
"astrocentric",
"barycentric",
"jacobi",
"origin" ]
20 def __init__(self,type):
21 if isinstance(type,str):
22 self.type = Keplerian.choices.index(type)
26 return "Keplerian(%s)" % Keplerian.choices[self.type]
30 TABLE, KEYS = range(2)
31 def print_record(print_mode, r, body_range):
33 if print_mode == TABLE :
36 if(body_range.contains(i)):
37 print "%10d %lg %6d %6d %9.2g %10.4g %10.4g %10.4g %10.5lg %10.5lg %10.5lg %d" % (l.msgid, l.time, l.sys, i, b.mass, b.position[0], b.position[1], b.position[2], b.velocity[0], b.velocity[1], b.velocity[2], l.state)
40 elif isinstance( print_mode , Keplerian ):
42 if tp == Keplerian.JACOBI:
43 body_orbits = l.bodies_in_keplerian_jacobi()
45 if tp == Keplerian.ASTROCENTRIC:
47 elif tp == Keplerian.BARYCENTRIC:
48 center = l.barycenter()
49 elif tp == Keplerian.ORIGIN:
52 raise ValueError(
"Wrong keplerian index")
53 body_orbits = l.bodies_in_keplerian(center)
55 for i, b, orbit
in body_orbits:
56 if(body_range.contains(i)):
57 print "%10d %lg %6d %6d %9.2g %9.5lg %9.5lg %9.5lg %9.5lg %9.5lg %9.5lg %d" % (l.msgid, l.time, l.sys, i, b.mass, orbit.a, orbit.e , orbit.i*RAD2DEG, orbit.O*RAD2DEG, orbit.w *RAD2DEG, orbit.M*RAD2DEG, l.state)
59 elif print_mode == KEYS :
62 print print_mode, type(print_mode)
65 def truncate(number,iterator):
66 for i
in range(0,number):
69 def run_with_args(args):
70 d = IndexedLogDB(args.database)
72 if args.keplerian !=
None:
73 print_mode = Keplerian(args.keplerian)
78 if args.initial_conditions :
79 q = d.initial_conditions(args.system_range)
80 elif args.final_conditions :
81 q = d.final_conditions(args.system_range)
83 q = d.query(args.time_range,args.system_range,args.evt_id)
85 for r
in truncate(args.max_records,q):
86 print_record(print_mode,r, args.body_range)