geometry¶
The geometry module allows to define multiple coordinate systems as a tree of nested coordinate systems which can be moved and rotated against each other. Points and directions can be converted between different coordinate systems. The coordinate system trees can be stored e.g. as YAML files on disk.
Example¶
Taking the sample mounttree.yaml from below, a MountTree instance can be constructed using:
>>> from runmacs.geometry.mounttree import MountTree
>>> import yaml
>>> mounttree = MountTree.fromDict(yaml.load(open('mounttree.yaml')))
A transformation from a direction in SWIR coordinates to the VNIR camera system which is independent of the dynamic corrdinates (== aircraft position data) can now be performed using:
>>> import numpy as np
>>> transformation = mounttree.universe.getTransformation('SWIR', 'VNIR')
>>> in_swir_coordinates = np.array((0.5, 0.1, 1.0))
>>> in_vnir_coordinates = transformation.applyDirection(in_swir_coordinates)
To transform to earth based coordinates, the position of the aircraft has to be set:
>>> mounttree.update(lat=-40., lon=-3., height=5000., roll=0.1, pitch=0.1, yaw=0.5)
>>> transformation = mounttree.universe.getTransformation('VNIR', 'EARTH')
>>> in_earth_coordinates = transformation.applyDirection(in_swir_coordinates)
type: mount tree
description:
name: Flight AC 17
valid:
from: 2014-09-27T00:00:00+00:00
until: 2014-09-27T23:59:59+00:00
mounttree:
framename: EARTH
framespec: WGS-84
subframes:
- framename: HALO
position: [lat, lon, height]
rotation: [roll, pitch, yaw]
axesConvention: NED
sensors:
- name: BAHAMAS
sensorId: BAHAMAS
provides: [lat, lon, height, roll, pitch, yaw]
subframes:
- framename: VNIR
position: [0, 0, 0]
rotation: Ry(-85deg)*Rz(-90deg)
sensors:
- name: VNIR
sensorId: "550008"
tofs:
method: twopoint
params: {dt1: 0.42, dt2: 1.43, t1: 1409657184.0, t2: 1409681114.8}
- framename: SWIR
position: [0, 0, 0]
rotation: Ry(-85deg)*Rz(-90deg)
sensors:
- name: SWIR
sensorId: "410043"
tofs:
method: twopoint
params: {dt1: 0.42, dt2: 1.43, t1: 1409657184.0, t2: 1409681114.8}
Module documentation¶
coordinateframes¶
-
class
runmacs.geometry.coordinateframes.CoordinateFrame(universe, name)[source]¶ A coordinate frame.
Parameters: - universe –
CoordinateUniversein which the frame should be registered. - name – Name of the frame.
-
position¶ The origin of this frame in coordinates of the
referenceSystem.
-
rotation¶ The rotation of this coordinate frame
The rotation is defined such that a point in the referece system x_r is related to a point in this system x_s as follows:
x_r = R^-1 x_s + t
Where R is
rotationandtis position.If the reference system provides any local rotation frame != 1, R is defined as:
R = R_thisframe * R_locrot
- universe –
-
class
runmacs.geometry.coordinateframes.CoordinateUniverse[source]¶ A set of coordinate frames is called a
CoordinateUniverse.-
coordLib(spec, name)[source]¶ Get a coordinate frame from the coordinate library.
Parameters: - spec – Specification of the coordinate system.
- name – Name of the newly created coordinate frame.
Currently the following specifications are implemented:
- GRS-80
- WGS-84
-
getCoordinateFrame(name, cls=None)[source]¶ Get the coordinate frame to a given name.
If the given coordinate frame does not exist, create it.
Parameters: - name – Name of the coordinate frame
- cls – If set, use
clsas baseclass for the frame. OtherwiseCoordinateFrameis used.
-
-
class
runmacs.geometry.coordinateframes.OblateEllipsoidFrame(universe, name)[source]¶ -
axes¶ length of axes (unit: meters)
Returns: (longer, shorter) axes == (xy axes, z axis)
-
-
class
runmacs.geometry.coordinateframes.Transformation(sourceFrame, targetFrame)[source]¶ Represents a coordinate transformation from one frame into another.
Parameters: - sourceFrame – Source coordinate frame
- targetFrame – Target coordinate frame
If the position or orientation of any relavant coordinate frame is changed, the transformation will automatically be updated the next time it is used.
Note
The
universeof both coordinate frames must be the same.-
R¶ Current rotation matrix of the transformation
-
applyDirection(direction)[source]¶ Apply transformation to a direction vector.
Parameters: direction – numpyarray of size3orNx3representing one or many direction vectors in the source coordinate frame.Returns: numpyarray of the same shape asdirectionrepresenting the same directions in the target coordinate frame.
-
applyPoint(point)[source]¶ Apply transformation to a point vector.
Parameters: point – numpyarray of size3orNx3representing one or many point vectors in the source coordinate frame.Returns: numpyarray of the same shape aspointrepresenting the same points in the target coordinate frame.
-
t¶ Current translation vector of the transformation
mounttree¶
handling of mount tree files
-
class
runmacs.geometry.mounttree.ConstantTimeCorrection(dt)[source]¶ Applicator for constant time correction.
Parameters: dt – time offset (in seconds) Performs a constant time correction.
-
class
runmacs.geometry.mounttree.MountTree[source]¶ mounttree representation
-
name¶ The name of the mounttree.
-
validFrom¶ Start of validity period.
-
validUntil¶ End of validity period.
-
update(**kwargs)¶ Updates the dynamic variables of the mounttree.
All named variables from the mount tree can be given as keyword arguments.
-
universe¶ The coordinate universe defined by the mounttree
-
sensors¶ listof all sensors defined by the tree.
-
sensorsById¶ dictof all sensors defined by the tree withsensorIdas keys.
-
availableSensors¶ Returns a
setof all sensorIds defined in the mounttree.
-
coordinateframes¶ Returns a
dictof coordinate frames defined in the mounttree.
-
classmethod
fromDict(mtDict)[source]¶ Constructs a MountTree from a dictionary.
Parameters: mtDict – dictdescribing the mounttree.
-
requiredSensors¶ Returns a
setof all sensorIds which provide data for the mounttree orientation.
-
-
class
runmacs.geometry.mounttree.NullTimeCorrection[source]¶ Dummy applicator for no time correction.
-
class
runmacs.geometry.mounttree.TwopointTimeCorrection(t1, t2, dt1, dt2)[source]¶ Applicator for two point time correction.
Parameters: - t1 – reference time 1 (as unix timestamp)
- t2 – reference time 2 (as unix timestamp)
- dt1 – time offset at
t1(in seconds) - dt2 – time offset at
t2(in seconds)
Performs a time correction by a linear interpolation (and extrapolation) of the time offsets
dt1anddt2between the reference timest1andt2.
-
runmacs.geometry.mounttree.parseRotation(r)[source]¶ Parses a rotation, either as a list of euler angles or like
parseRotationPrimitives().