Skip to content
Snippets Groups Projects
Commit c9a10f13 authored by Petrus Hyvönen's avatar Petrus Hyvönen
Browse files

Started on better intro

parent ad38b9a9
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# Orekit in Python - The basics
# Orekit in Python - The Basics
%% Cell type:markdown id: tags:
Orekit is an open-source library for a number of space related calculations such as:
Orekit is an open-source library for astrodynamical calculations such as:
* Orbit Propagation
* Coordinate system transformations
* Time systems
* Orbit Determination
The orekit webpage can be accessed at http://www.orekit.org.
And much more..
The orekit webpage can be accessed at http://www.orekit.org.
%% Cell type:markdown id: tags:
## The java - pyhon bridge
## The Java - Python bridge - "orekit python wrapper"
%% Cell type:markdown id: tags:
The orekit library is written in java. For interactive work a bridge to Python has been made, which will be used in this tutorial.
The orekit library is written and executing in java. However for interactive work a bridge to Python has been made, the "orekit python wrapper" which will be used in this tutorial.
%% Cell type:markdown id: tags:
The orekit java library has been wrapped using the open source JCC tool, that enables interaction with java objects from the Python ecosystem. Python has quick and high quality routines for plotting and a easily read code.
The orekit java library has been wrapped using the open source JCC tool, that enables interaction with java objects from the Python ecosystem.
<embed src="files/images/integration.svg" type="image/svg+xml" />
%% Cell type:markdown id: tags:
## Initiating orekit in python
# Installation
%% Cell type:markdown id: tags:
### Install Anaconda
%% Cell type:markdown id: tags:
Orekit needs to be initiated before used, partly setting up the Python - both the Java gateway and partly setting up access to the data needed for different orekit functions, such as the shape of the earth, leap time seconds etc.
The recommended way to install the orekit python wrapper is through the pre-built packages for the Anaconda python distribution.
The Anaconda python distribution can be downloaded at:
https://www.anaconda.com/distribution/
%% Cell type:markdown id: tags:
First we need to intitilize the iPython notebook, that we want to use the inline pylab functionality and how large defalt plots should be. This is not orekit specific.
### Install Orekit Python Wrapper Conda package
%% Cell type:markdown id: tags:
A pre-built orekit package for conda is created in the conda-forge channel, and can be installed in the conda environment by:
conda install orekit -c conda-forge
This should download and install the orekit package into the currently activated conda environment, and install the dependenies (openjdk).
For some usages it is useful to install conda-wrappers, for example if using an IDE like PyCharm. The conda-wrappers are installed in the same way:
conda install conda-wrappers -c conda-forge
%% Cell type:markdown id: tags:
### Getting the orekit-data.zip file
%% Cell type:markdown id: tags:
Some fundamental parameters are not included in the orekit package, and should be provided separately. Such files are earth orientation parameters, time standards etc. An example collection of such parameters are available on the orekit page (no guaratees, this data should be maintained by the user for any professional usage).
The datafile is default accessed in current orekit directory or a path can be supplied. The file can be downloaded from https://gitlab.orekit.org/orekit/orekit-data
A convenience function to download this file is included in the orekit package.
%% Cell type:code id: tags:
``` python
%pylab inline
figsize(15,15)
from orekit.pyhelpers import download_orekit_data_curdir
# download_orekit_data_curdir()
```
%% Output
%% Cell type:markdown id: tags:
Populating the interactive namespace from numpy and matplotlib
# Initiating Orekit in Python
%% Cell type:markdown id: tags:
To start up the orekit JVM:
Orekit needs to be initiated before used, this starts up the java engine and exposes the orekit classes in python.
%% Cell type:markdown id: tags:
To start up orekit use the initVM() function:
%% Cell type:code id: tags:
``` python
import orekit
vm = orekit.initVM()
print ('Java version:',vm.java_version)
print ('Orekit version:', orekit.VERSION)
```
%% Output
Java version: 1.8.0_92
Java version: 1.8.0_152-release
Orekit version: 10.0
%% Cell type:markdown id: tags:
The orekit library needs a data file with various information on time and earth rotation parameters. This file, called orekit-data.zip is loaded from current dir. A basic version of this file can be downloaded from the orekit [webpage](https://www.orekit.org/forge/projects/orekit/files).
The orekit library needs a data file with various information on time and earth rotation parameters. This file, called orekit-data.zip is loaded from current dir as default.
This routine is commonly used in the notebooks, so a python specific function is created for this, setup_orekit_curdir()
This routine of setting up these parameters is commonly used in the notebooks, so a python specific function is created for this, setup_orekit_curdir()
%% Cell type:code id: tags:
``` python
from orekit.pyhelpers import setup_orekit_curdir
setup_orekit_curdir()
```
%% Cell type:markdown id: tags:
Now we are set up to import and use objects from the orekit library.
Now we are set up to import and use objects from the orekit library. With the proper initialization, all objects in the orekit java library is exposed to Python and can be imported using normal Python syntax.
%% Cell type:code id: tags:
``` python
from org.orekit.utils import Constants
```
%% Cell type:code id: tags:
``` python
print (Constants.WGS84_EARTH_EQUATORIAL_RADIUS)
```
%% Output
6378137.0
%% Cell type:markdown id: tags:
SI base units are used in the library, such as seconds, meter, m/s
%% Cell type:markdown id: tags:
*Petrus Hyvönen, SSC, 2014*
# Documentation
%% Cell type:markdown id: tags:
One of the best sources of knowledge about orekit and the Python wrapper is on the orekit forum, https://forum.orekit.org/
%% Cell type:markdown id: tags:
## Orekit API
%% Cell type:markdown id: tags:
The Python version of orekit is very closely matching the java version and the API documentation from Java can be used. This documentation is available at https://www.orekit.org/site-orekit-10.1/apidocs/index.html
%% Cell type:markdown id: tags:
In addition to the API documentation there are a number of architecture descriptions, based on the Java syntax but highly applicable to the Python side. See https://www.orekit.org/doc-maven.html
%% Cell type:markdown id: tags:
# Specifics for the Python version of Orekit
%% Cell type:markdown id: tags:
For many users there will be no or little differnce in the usage of Orekit between Java and Python. The following chapter provides additional information for more advanced usage.
%% Cell type:markdown id: tags:
The Python version, or correctly stated the Python Wrapper (it is a pure java orekit that runs in background) has a few areas where there are specific ways to do things, limitations and some quirks. The wrapper is created with a tool called JCC (https://lucene.apache.org/pylucene/jcc/), which is providing most of these features and the documentation for that is relevant.
%% Cell type:markdown id: tags:
### Casting of classes
%% Cell type:markdown id: tags:
Java is a more strongly typed language than Python and is indirectly casting classes as part of the syntax. In most cases the Python user does not need to consider this when using orekit in Python, but in some cases it may be neccessary to specify which type or interface of a particular object that is refered to.
%% Cell type:markdown id: tags:
Example:
%% Cell type:code id: tags:
``` python
from org.orekit.bodies import CelestialBodyFactory
from org.orekit.utils import PVCoordinatesProvider
from org.orekit.time import AbsoluteDate, TimeScalesFactory
from org.orekit.frames import FramesFactory
sun = CelestialBodyFactory.getSun() # Here we get it as an CelestialBody
sun = PVCoordinatesProvider.cast_(sun) # But we want the PVCoord interface
# Get the position of the sun in the Earth centered coordinate system EME2000
date = AbsoluteDate(2020, 2, 28, 23, 30, 0.0, TimeScalesFactory.getUTC())
sun.getPVCoordinates(date, FramesFactory.getEME2000()).getPosition()
```
%% Output
<Vector3D: {138,869,605,874.96655; -47,461,924,824.28846; -20,575,480,674.707344}>
%% Cell type:markdown id: tags:
### Usage of parametric types
%% Cell type:markdown id: tags:
The Java language has a feature of parametric class definitions and orekit uses this in some areas. These can be managed in Python with the _of(Class) method that sets this.
%% Cell type:markdown id: tags:
Example:
%% Cell type:code id: tags:
``` python
```
%% Cell type:markdown id: tags:
### Subclassing Java classes in Python
%% Cell type:markdown id: tags:
In some use cases it is relevant to subclass a java class for an own implementation. For the standard orekit classes this is not possible, but a work-around has been implemented for selected classes that allows Python subclassing. These classes are labeled as their corresponding java classes but with a "Python" prefix.
%% Cell type:markdown id: tags:
Example:
%% Cell type:markdown id: tags:
### Implementation of Java Interfaces in Python
%% Cell type:markdown id: tags:
The implementation of orekit interfaces in Python is performed in the same way as subclassing, where all interfaces has a corresponding "Python" prefixed version that can be subclassed in python in order to implement that interface.
%% Cell type:markdown id: tags:
Example:
%% Cell type:code id: tags:
``` python
```
%% Cell type:markdown id: tags:
Note: It is not possible to implement several interfaces to a Python class
%% Cell type:markdown id: tags:
*Petrus Hyvönen, SSC, 2020*
%% Cell type:code id: tags:
``` python
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment