[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Orekit Users] orekit and Jython



I am also a fan of using the orekit libraries for scripting.  As a proof-of-concept, I have developed some wrapper classes (in Java) based on the orekit classes which help to simplify and streamline scripting.  As sample jython script is below.  I use the package name "orescript", and have left out some initialization:

#
#   Create a spacecraft.
#

from org.orekit.time import AbsoluteDate
from orescript import Spacecraft, TimeScale, ReferenceFrame

iss = Spacecraft(

    AbsoluteDate(2010, 5, 28, 12, 0, 00.000, TimeScale.UTC),
    [  3198022.67,  2901879.73,  5142928.95],
    [-6129.640631, 4489.647187, 1284.511245],
    ReferenceFrame.J2000
       
)

iss.cd   = 2.0
iss.mass = 370220.0
iss.area = 1299.99967

#
#  Select a propagator.
#

from orescript.propagators import CowellPropagator
iss.propagator = CowellPropagator()

#
#  Add nonspherical Earth gravity.
#

from orescript.forces.gravity import EGMGravity
iss.propagator.addForceModel(EGMGravity(40,40))

#
#  Add drag force modeling.
#

from orescript.bodies import Earth
from orescript.forces.drag import ExponentialAtmosphere
from orescript.forces.drag import DragForce

earth = Earth()
earth.atmosphere = ExponentialAtmosphere()

iss.propagator.addForceModel(DragForce(earth.atmosphere))

#
#  Add third-body gravity.
#

from orescript.bodies import Moon, Sun
from org.orekit.forces.gravity import ThirdBodyAttraction

moon = Moon()
sun  = Sun()

iss.propagator.addForceModel(ThirdBodyAttraction(moon))
iss.propagator.addForceModel(ThirdBodyAttraction(sun))

#
#  Add solar radiation pressure.
#

from orescript.forces.radiation import RadiationPressure
iss.propagator.addForceModel(RadiationPressure(sun))

#
#  Let's see the initial state
#

print "Initial state"
print "CB       = ", iss.cb.name
print "Epoch    = ", iss.epoch
print "Position = ", iss.pv.position
print "Velocity = ", iss.pv.velocity
print "Frame    = ", iss.orbit.frame
print "Radius   = ", iss.pv.position.norm

#
#  Let's see the propagator information
#

print "\nPropagation settings"
print "Integrator : ", iss.propagator.integrator.name
print "Forces     : "

for force in iss.propagator.forceModels:
    print "   %s" % force

#
#  Propagate.
#

iss.propagate(86400)

#
#  Let's see the final state.
#

print "\n"
print "Final state"
print "Epoch    = ", iss.epoch
print "Position = ", iss.pv.position, "meters"
print "Velocity = ", iss.pv.velocity, "meters/sec"
print "Frame    = ", iss.orbit.frame
print "Radius   = ", iss.pv.position.norm, "meters"


This yields the output:

Initial state
CB       =  Earth
Epoch    =  2010-05-28T12:00:00.000
Position =  {3,198,022.67; 2,901,879.73; 5,142,928.95}
Velocity =  {-6,129.64; 4,489.65; 1,284.51}
Frame    =  EME2000
Radius   =  6715502.44955

Propagation settings
Integrator :  classical Runge-Kutta
Forces     :
   EGMGravity (40x40)
   org.orekit.forces.drag.DragForce@29d65b
   org.orekit.forces.gravity.ThirdBodyAttraction@b8176d
   org.orekit.forces.gravity.ThirdBodyAttraction@a1d7b
   org.orekit.forces.radiation.SolarRadiationPressure@127461b


Final state
Epoch    =  2010-05-29T12:00:00.000
Position =  {5,149,764.12; -4,232,662.2; -841,421.8} meters
Velocity =  {3,638.83; 3,252.03; 5,966.86} meters/sec
Frame    =  EME2000
Radius   =  6718890.56326 meters

To me, encapsulating the complexity of the low-level API makes the scripting easier and perhaps more accessible to casual users.  Java can be ugly and tedious, but python is so clean.  I'm looking forward to future orekit releases!

Steven

--- On Mon, 5/16/11, Petrus Hyvönen <petrus.hyvonen@gmail.com> wrote:

From: Petrus Hyvönen <petrus.hyvonen@gmail.com>
Subject: [Orekit Users] orekit and Jython
To: orekit-users@orekit.org
Date: Monday, May 16, 2011, 2:02 PM

Hi all,

I was playing around with the idea of using Python for mission design, and found Jython and the orekit library. As new to both Python and Java, I had some initial troubles of getting things to work, primary the access to orekit-data, what was current dir and javapaths etc. I am now using Eclipse with pydev extension, and can add the orekit jars and orekit-data to the eclipse project. 

As an exercise I took the liberty to translate a few of the orekit examples from java to jython, and copy them below as it could be of interest for others. I have been exploring scipy before (based on regular python) and it contains very good plotting and array routines, which is not available in jython. So next step would be to find a suitable java plotting and arrays library to be able to represent the results.

Regards
/Petrus