def extract_semi_major(en): shape = (ens.nbod-1,ens.nsys) value = numpy.empty(shape) for sysid, sys in enumerate(en): star = sys[0] center = (star.pos,star.vel,star.mass) for bodid in range(1,en.nbod): bod = sys[bodid] planet = (bod.pos,bod.vel,bod.mass) orbital_elements = swarmng.keplerian_for_cartesian(planet,center) value[bodid-1,sysid] = orbital_elements.a return value
# * planet number 0 to nbod-1 # * orbital element number : 0 to 5 # * system id # import numpy shape = (ens.nbod-1, 6, ens.nsys) value = numpy.empty(shape) for sysid, sys in enumerate(ens): star = sys[0] center = (star.pos,star.vel,star.mass) for bodid in range(1,ens.nbod): bod = sys[bodid] planet = (bod.pos,bod.vel,bod.mass) orbital_elements = swarmng.keplerian_for_cartesian(planet,center) value[bodid-1, :,sysid] = orbital_elements # @section pr Write the information to standard output # Now iterate through the 3-dimensional array # and calculate the average and standard deviation # of each orbital element value for each body, then # print it to the output. # print("Body number, Semi-major axis, Eccentricity, Inclination, Longtitude of the ascending node, Argument of periapsis, Mean anomaly") for bodid in range(1,ens.nbod): orbital_elements = [0,0,0,0,0] o = "{0}".format(bodid) for i in range(0,6): o += ", {0}±{1}".format(numpy.average(value[bodid-1,i,:]),numpy.std(value[bodid-1,i,:])) print(o)