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)
mounttree.yaml
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:
  • universeCoordinateUniverse in 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 rotation and t is position.

If the reference system provides any local rotation frame != 1, R is defined as:

R = R_thisframe * R_locrot
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 cls as baseclass for the frame. Otherwise CoordinateFrame is used.
getTransformation(source, target)[source]

Get the transformation from one frame into another.

Parameters:
  • source – Source coordinate frame (can be name or frame object)
  • target – Target coordinate frame (can be name or frame object)
exception runmacs.geometry.coordinateframes.NotFound[source]
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.SphericalFrame(universe, name)[source]
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 universe of both coordinate frames must be the same.

R

Current rotation matrix of the transformation

applyDirection(direction)[source]

Apply transformation to a direction vector.

Parameters:directionnumpy array of size 3 or Nx3 representing one or many direction vectors in the source coordinate frame.
Returns:numpy array of the same shape as direction representing the same directions in the target coordinate frame.
applyPoint(point)[source]

Apply transformation to a point vector.

Parameters:pointnumpy array of size 3 or Nx3 representing one or many point vectors in the source coordinate frame.
Returns:numpy array of the same shape as point representing 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.

apply(t)[source]

Applies time correction.

apply_dt(t)[source]

Applies time correction for datetime64 object.

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

list of all sensors defined by the tree.

sensorsById

dict of all sensors defined by the tree with sensorId as keys.

availableSensors

Returns a set of all sensorIds defined in the mounttree.

coordinateframes

Returns a dict of coordinate frames defined in the mounttree.

classmethod fromDict(mtDict)[source]

Constructs a MountTree from a dictionary.

Parameters:mtDictdict describing the mounttree.
requiredSensors

Returns a set of all sensorIds which provide data for the mounttree orientation.

class runmacs.geometry.mounttree.NullTimeCorrection[source]

Dummy applicator for no time correction.

apply(t)[source]

Applies time correction (in this case, returns t as it is).

apply_dt(t)[source]

Applies time correction (in this case, returns t as it is) for datetime64 object.

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 dt1 and dt2 between the reference times t1 and t2.

apply(t)[source]

Applies time correction.

apply_dt(t)[source]

Applies time correction for datetime64 object.

runmacs.geometry.mounttree.parseRotation(r)[source]

Parses a rotation, either as a list of euler angles or like parseRotationPrimitives().

runmacs.geometry.mounttree.parseRotationPrimitives(r)[source]

Parses a rotation string, given as multiplication of rotations about x,y or z axes.

Parameters:x – String like Rx(5deg)*Ry(-7.2rad)

Units (deg or rad) are optional, rad is default.