Table Of Contents

Previous topic


Next topic

Extracting and Pasting Images

IPLT command line

In this tutorial you will learn how to do basic things on the IPLT command line.

The Command Line Basics

The IPLT command line is built on top of Python. If you want to get more information on any object, function or class, the python help command may be useful.

#import classes from geom module
from ost.geom import *
# get list of methods of Rotation3
# get help for method GetPsi

Vector Math

IPLT has built-in support for vectors in 2,3 and 4 dimension. They are called Vec2, Vec3 and Vec4 respectively. You can use the vector classes like in a math formula: You can add them together, multiply them by scalar values or calculate the inner and outer product. This short code snippet gives an idea of how you can use vectors.

from ost.geom import *

# print the vectors
print a,b

# create a new vector by using components of both a and b.
# The components of a vector can be accessed by using the
# array subscript notation:
# print length of vector a and b
print Length(a), Length(b)

# calculate dot (inner) product
print Dot(a,b)

# do some fancy calculation
d = a+2*b
print '%s+2*%s is %s' % (a,b,d)

Linear Transforms

Linear transforms such as scaling, rotation of vectors can be achieved easily.


Rotations are usually carried out using quaternions or rotation matrices. There are several helper classes in IPLT that encapsulate the logic of rotation.The Rotation3 class represents a rotation in 3D space defined by 3 Euler angles.

import math
# define rotation around x axis by 180 degress (PI radians)
# rotate v by rot
print rot.GetRotationMatrix()*v

In two dimensions, the Rotate function can be used to rotate a vector by a certain amount

#rotate by 90 degrees (PI/2 radians)
print Rotate(Vec2(1,0),math.pi/2)


Uniform vector scaling can be accomplished by multiplication of the vector by a scalar factor. For non-uniform scaling you can use a 3x3 matrix with all but the main diagonal elements set to zero.


print scale*Vec3(1,1,1)

Short Example

While you are fitting a lattice to your diffraction pattern Fit lattice, you would like to set the angle between the first and second lattice vector to exactly 90 degrees. You decide to do it on the command line. Your a-vector is fitting perfectly, you only want to reorient the b-vector.

from ost.geom import *
from import LoadImage
import iplt.gui, math
# load the image and display it
# add lattice overlay

# get snapshot of lattice. note that all changes to lattice will not
# be reflected in the overlay. you need to call  lov.SetLattice(l)
l = lov.GetLattice()
new_b = Normalize(Rotate(l.GetFirst(),math.pi/2))*length_b