Orientations#

class Orientations(translations, rotations, scores=None, details=None, metadata=<factory>, optics=<factory>)[source]#

Bases: object

Handle template matching orientations and conversion between formats.

Parameters:
translations: array_like

Array with translations of each orientations (n, d).

rotations: array_like

Array with euler angles of each orientation in zxy convention (n, d).

scores: array_like, optional

Array with the score of each orientation (n, ). When provided, stored in metadata["_pytmeScore"] and overrides any preexisting value there.

details: array_like, optional

Array with additional orientation details (n, ). When provided, stored in metadata["_rlnClassNumber"] and overrides any preexisting value there.

metadata: dict, optional

Per-particle metadata. Array values whose first dimension matches the number of orientations are sliced by __getitem__().

optics: dict, optional

File-level optics-group metadata (Relion-style).

Examples

The following achieves the minimal definition of an Orientations instance

>>> import numpy as np
>>> from tme import Orientations
>>> translations = np.random.randint(low = 0, high = 100, size = (100,3))
>>> rotations = np.random.rand(100, 3)
>>> orientations = Orientations(
>>>     translations=translations,
>>>     rotations=rotations,
>>> )

The created orientations object can be written to disk in a range of formats. See Orientations.to_file() for available formats. The following creates a STAR file

>>> orientations.to_file("test.star")

Orientations.from_file() can create Orientations instances from a range of formats, to enable conversion between formats

>>> orientations_star = Orientations.from_file("test.star")
>>> np.all(orientations.translations == orientations_star.translations)
True

Attributes and underlying data#

Serialization#

Orientations.to_file(filename[, file_format])

Save the current class instance to a file in the specified format.

Orientations.from_file(filename[, file_format])

Create an instance of Orientations from a file.

Subsetting#

Orientations.get_extraction_slices(...[, ...])

Calculate slices for extracting regions of interest within a larger array.