Differences between revisions 8 and 9
 ⇤ ← Revision 8 as of 2010-01-08 21:25:49 → Size: 2561 Editor: penczek Comment: ← Revision 9 as of 2010-01-08 21:29:05 → ⇥ Size: 2340 Editor: penczek Comment: Deletions are marked like this. Additions are marked like this. Line 10: Line 10: Creating just rotations: def get_params2D(ima, xform = "xform.align2d"): """   retrieve 2D alignment parameters from the header   alpha tx ty mirror scale """ t = ima.get_attr(xform) d = t.get_params("2D") return d["alpha"],d["tx"],d["ty"],d["mirror"],d["scale"] Line 12: Line 19: . RA=Transform3D(0,0,25); # Default is the ZXZ convention . RA=Transform3D(EULER_SPIDER,0,0,25); # This is the typical ZYZ convention . RA=Transform3D(m11,m12,m13,m21,m22,m23,m31,m32,m33) # create the transformation by entering . componentsCreating more complicated transformations using set : def set_params2D(ima, p, xform = "xform.align2d"): """   set 2D alignment parameters in the header   alpha tx ty mirror scale """ t = Transform({"type":"2D","alpha":p,"tx":p,"ty":p,"mirror":p,"scale":p}) ima.set_attr(xform, t) Line 18: Line 27: def get_params3D(ima, xform = "xform.align3d"): """   retrieve 3D alignment parameters from the header   phi theta psi tx ty tz mirror scale """ t = ima.get_attr(xform) d = t.get_params("spider") return d["phi"],d["theta"],d["psi"],d["tx"],d["ty"],d["tz"],d["mirror"],d["scale"] Line 19: Line 36: . RA = Transform3D(); # this creates the 3D identity matrix . RA.set_rotation(0,0,25); # creates a matrix that will rotate 2D images by 25 degrees . RA.set_posttrans(Vec3f(1,0,0)); # the matrix will now also shift 1 pixel in the x-direction . RA.set_scale(1); # Occaisionally one will wish to rescale. . def set_params3D(ima, p, xform = "xform.align3d"): """   set 3D alignment parameters in the header   phi theta psi tx ty tz mirror scale """ t = Transform({"type":"spider","phi":p,"theta":p,"psi":p,"tx":p,"ty":p,"tz":p,"mirror":p,"scale":p}) ima.set_attr(xform, t) Line 25: Line 44: The following code will multiple (combine) two sets of Eulerian angles: def get_params_proj(ima, xform = "xform.projection"): """   retrieve projection alignment parameters from the header   phi theta psi s2x s2y """ t = ima.get_attr(xform) d = t.get_params("spider") return d["phi"],d["theta"],d["psi"],-d["tx"],-d["ty"] Line 27: Line 53: . a=even_angles(2.,symmetry='d4',method="P",phiEqpsi = "Zero") . R2 = Transform3D(EULER_SPIDER,90.,0.,0.) . for i in xrange(len(a)):  . R1 = Transform3D(EULER_SPIDER,a[i],a[i],a[i])  . R3=R1*R2  . compeuler = R3.get_rotation(EULER_SPIDER)  . compphi = compeuler["phi"] ; compphi = (compphi +360.0)%360.0  . comptheta = compeuler["theta"]; comptheta = (comptheta+360.0)%360.0  . comppsi = compeuler["psi"]; comppsi = (comppsi +360.0)%360.0  . print a[i]  . print compphi,comptheta,comppsi def set_params_proj(ima, p, xform = "xform.projection"): """   set projection alignment parameters in the header   phi theta psi s2x s2y """ t = Transform({"type":"spider","phi":p,"theta":p,"psi":p}) t.set_trans(Vec2f(-p, -p)) ima.set_attr(xform, t) Line 44: Line 65: . b) There is also a set_rotation via a dictionary object, which we will explain at length soon. . c) The first two lines of the second block of commands, could have been written as the second line of the first block of commands. This command sets RA to a rotation that rotates a 2D image by 25 degrees around the Z-axis. . d) There are corresponding "get" calls to extract the information from the transformation matrices. SPARX has some of its own, that are wrappers for these get calls. More later. Line 52: Line 71: P. R. Baldwin P.A. Penczek

Transform Class

# Usage

## Examples

All angles are in degrees

def get_params2D(ima, xform = "xform.align2d"):

• """
• retrieve 2D alignment parameters from the header alpha tx ty mirror scale
""" t = ima.get_attr(xform) d = t.get_params("2D") return d["alpha"],d["tx"],d["ty"],d["mirror"],d["scale"]

def set_params2D(ima, p, xform = "xform.align2d"):

• """
• set 2D alignment parameters in the header alpha tx ty mirror scale
""" t = Transform({"type":"2D","alpha":p,"tx":p,"ty":p,"mirror":p,"scale":p}) ima.set_attr(xform, t)

def get_params3D(ima, xform = "xform.align3d"):

• """
• retrieve 3D alignment parameters from the header phi theta psi tx ty tz mirror scale
""" t = ima.get_attr(xform) d = t.get_params("spider") return d["phi"],d["theta"],d["psi"],d["tx"],d["ty"],d["tz"],d["mirror"],d["scale"]

def set_params3D(ima, p, xform = "xform.align3d"):

• """
• set 3D alignment parameters in the header phi theta psi tx ty tz mirror scale
""" t = Transform({"type":"spider","phi":p,"theta":p,"psi":p,"tx":p,"ty":p,"tz":p,"mirror":p,"scale":p}) ima.set_attr(xform, t)

def get_params_proj(ima, xform = "xform.projection"):

• """
• retrieve projection alignment parameters from the header phi theta psi s2x s2y
""" t = ima.get_attr(xform) d = t.get_params("spider") return d["phi"],d["theta"],d["psi"],-d["tx"],-d["ty"]

def set_params_proj(ima, p, xform = "xform.projection"):

• """
• set projection alignment parameters in the header phi theta psi s2x s2y
""" t = Transform({"type":"spider","phi":p,"theta":p,"psi":p}) t.set_trans(Vec2f(-p, -p)) ima.set_attr(xform, t)

Notes:

• a) We could have used EMAN, IMAGIC, SPIN, QUATERNION, SGIROT, MRC, XYZ, MATRIX instead of the SPIDER of EULER_SPIDER above.

# Description

Purpose: to apply rotation/shift/scaling operations for 2D or 3D images via a variety of methods.

P.A. Penczek

P. R. Baldwin

category 1
FUNDAMENTALS

libEM