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 First, a jython translation of the SlaveMode.java: __________________________________________ # -*- coding: utf-8 -*- ''' /* Copyright 2002-2010 CS Communication & Systèmes * Licensed to CS Communication & Systèmes (CS) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * CS licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Translated from SlaveMode.java to jython by Petrus Hyvönen 2011-05-04 ''' # orekit.jar,orekit-data.zip and commons-maths in CLASSPATH through eclipse project import java, os from org.orekit.errors import OrekitException from org.orekit.frames import Frame from org.orekit.frames import FramesFactory from org.orekit.orbits import KeplerianOrbit from org.orekit.orbits import Orbit from org.orekit.propagation import SpacecraftState from org.orekit.propagation.analytical import KeplerianPropagator from org.orekit.data import DataProvidersManager from org.orekit.data import ZipJarCrawler from org.orekit.time import AbsoluteDate from org.orekit.time import TimeScalesFactory from math import radians # Configure Orekit. The file orekit-data.zip must be in current dir DM = DataProvidersManager.getInstance() crawler=ZipJarCrawler("orekit-data.zip") DM.clearProviders() DM.addProvider(crawler) #Initial orbit parameters a = 24396159 # semi major axis in meters e = 0.72831215 # eccentricity i = radians(7.0)# inclination omega = radians(180) # perigee argument raan = radians(261) #right ascension of ascending node lM = 0.0 # mean anomaly #Inertial frame inertialFrame = FramesFactory.getEME2000() #Initial date in UTC time scale utc = TimeScalesFactory.getUTC(); initialDate = AbsoluteDate(2004, 01, 01, 23, 30, 00.000, utc) #gravitation coefficient mu = 3.986004415e+14 #Orbit construction as Keplerian initialOrbit = KeplerianOrbit(a, e, i, omega, raan, lM, KeplerianOrbit.MEAN_ANOMALY, inertialFrame, initialDate, mu) #Simple extrapolation with Keplerian motion kepler = KeplerianPropagator(initialOrbit) #Set the propagator to slave mode (could be omitted as it is the default mode) kepler.setSlaveMode() #Overall duration in seconds for extrapolation duration = 90*60.0 #Stop date finalDate = AbsoluteDate(initialDate, duration, utc) #Step duration in seconds stepT = 30.0 #Extrapolation loop cpt = 1 extrapDate = initialDate while extrapDate.compareTo(finalDate) <= 0: currentState = kepler.propagate(extrapDate) print "step %d: time %s %s" % (cpt, currentState.getDate(), currentState.getOrbit()) extrapDate = AbsoluteDate(extrapDate, stepT, utc) cpt=cpt+1 ____________________________ _____________________________ # -*- coding: utf-8 -*- ''' /* Copyright 2002-2010 CS Communication & Syst?mes * Licensed to CS Communication & Syst?mes (CS) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * CS licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Translated from SlaveMode.java to jython by Petrus Hyv?nen 2011-05-04 ''' # orekit and common maths in CLASSPATH through eclipse project import java, os from org.orekit.data import DataProvidersManager from org.orekit.data import ZipJarCrawler from org.apache.commons.math.geometry import Vector3D from org.orekit.bodies import BodyShape from org.orekit.bodies import GeodeticPoint from org.orekit.bodies import OneAxisEllipsoid from org.orekit.errors import OrekitException; from org.orekit.frames import Frame from org.orekit.frames import FramesFactory from org.orekit.frames import TopocentricFrame from org.orekit.orbits import KeplerianOrbit from org.orekit.orbits import Orbit from org.orekit.propagation import Propagator from org.orekit.propagation import SpacecraftState from org.orekit.propagation.analytical import KeplerianPropagator from org.orekit.propagation.events import ElevationDetector from org.orekit.propagation.events import EventDetector from org.orekit.time import AbsoluteDate from org.orekit.time import TimeScalesFactory from org.orekit.utils import PVCoordinates from math import degrees, radians, pi # Configure Orekit DM = DataProvidersManager.getInstance() crawler=ZipJarCrawler("orekit-data.zip") DM.clearProviders() DM.addProvider(crawler) # Initial state definition: date, orbit initialDate = AbsoluteDate(2004, 01, 01, 23, 30, 00.000, TimeScalesFactory.getUTC()) mu = 3.986004415e+14 inertialFrame = FramesFactory.getEME2000() # inertial frame for orbit definition position = Vector3D(-6142438.668, 3492467.560, -25767.25680) velocity = Vector3D(505.8479685, 942.7809215, 7435.922231) pvCoordinates = PVCoordinates(position, velocity) initialOrbit = KeplerianOrbit(pvCoordinates, inertialFrame, initialDate, mu) # Propagator : consider a simple keplerian motion (could be more elaborate) kepler = KeplerianPropagator(initialOrbit) #Earth and frame ae = 6378137.0 # // equatorial radius in meter f = 1.0 / 298.257223563 #; // flattening ITRF2005 = FramesFactory.getITRF2005() #; // terrestrial frame at an arbitrary date earth = OneAxisEllipsoid(ae, f, ITRF2005) # Station longitude = radians(45.0) latitude = radians(25.0) altitude = 0.0 station1 = GeodeticPoint(latitude, longitude, altitude) sta1Frame = TopocentricFrame(earth, station1, "station1") # Event definition maxcheck = 1.0 elevation = radians(5.0) class VisibilityDetector(ElevationDetector): # Class for handling the eventOccured java. Example of subclassing # a java class in jython def __init__(self, maxCheck, elevation, topo): ElevationDetector.__init__(self,maxCheck, elevation, topo) def eventOccurred(self, s, increasing): if (increasing): print "Visibility on", self.topocentricFrame.getName(),"begins at" , s.getDate() else: print "Visibility on", self.topocentricFrame.getName(), "ends at" , s.getDate() return self.CONTINUE sta1Visi = VisibilityDetector(maxcheck, elevation, sta1Frame) #Add event to be detected kepler.addEventDetector(sta1Visi) #Propagate from the initial date to the first raising or for the fixed duration finalState = kepler.propagate(initialDate.shiftedBy(1500.0)) print "Final state : " , finalState.getDate().durationFrom(initialDate) _________________________________ |