MaxScoreOverRotations#
- class MaxScoreOverRotations(shape=None, scores=None, rotations=None, offset=None, score_threshold=0, shared_memory_handler=None, use_memmap=False, thread_safe=True, only_unique_rotations=False, **kwargs)[source]#
Bases:
object
Determine the rotation maximizing the score of all given translations.
- Attributes:
- shapetuple of ints.
Shape of
scores
and rotations.- scoresBackendArray
Array mapping translations to scores.
- rotationsBackendArray
Array mapping translations to rotation indices.
- rotation_mappingDict
Mapping of rotation matrix bytestrings to rotation indices.
- offsetBackendArray, optional
Coordinate origin considered during merging, zero by default
- use_memmapbool, optional
Memmap scores and rotations arrays, False by default.
- thread_safe: bool, optional
Allow class to be modified by multiple processes, True by default.
- only_unique_rotationsbool, optional
Whether each rotation will be shown only once, False by default.
- Raises:
- ValueError
If the data shape cannot be determined from the parameters.
Examples
The following achieves the minimal definition of a
MaxScoreOverRotations
instance>>> from tme.analyzer import MaxScoreOverRotations >>> analyzer = MaxScoreOverRotations(shape = (50, 50))
The following simulates a template matching run by creating random data for a range of rotations and sending it to
analyzer
via its __call__ method>>> for rotation_number in range(10): >>> scores = np.random.rand(50,50) >>> rotation = np.random.rand(scores.ndim, scores.ndim) >>> analyzer(scores = scores, rotation_matrix = rotation)
The aggregated scores can be extracted by invoking the __iter__ method of
analyzer
>>> results = tuple(analyzer)
The
results
tuple contains (1) the maximum scores for each translation, (2) an offset which is relevant when merging results from split template matching usingMaxScoreOverRotations.merge()
, (3) the rotation used to obtain a score for a given translation, (4) a dictionary mapping rotation matrices to the indices used in (2).We can extract the
optimal_score
,optimal_translation
andoptimal_rotation
as follows>>> optimal_score = results[0].max() >>> optimal_translation = np.where(results[0] == results[0].max()) >>> optimal_rotation_index = results[2][optimal_translation] >>> for key, value in results[3].items(): >>> if value != optimal_rotation_index: >>> continue >>> optimal_rotation = np.frombuffer(key, rotation.dtype) >>> optimal_rotation = optimal_rotation.reshape(scores.ndim, scores.ndim)
The outlined procedure is a trivial method to identify high scoring peaks. Alternatively,
PeakCaller
offers a range of more elaborate approaches that can be used.Attributes
Methods
MaxScoreOverRotations.merge
(param_stores, ...)Merges multiple instances of
MaxScoreOverRotations
.