forked from jfnavarro/st_analysis
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathalignment.py
More file actions
44 lines (43 loc) · 1.59 KB
/
Copy pathalignment.py
File metadata and controls
44 lines (43 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""
Alignment functions for the ST Analysis packages.
Aligment refers to the matrix that transforms
spots in array coordinates to image pixel coordinates.
"""
import numpy as np
import os
def parseAlignmentMatrix(alignment_file):
"""
Takes a file as input that contains
the values of a 3x3 affine matrix in one line
as :
a11 a12 a13 a21 a22 a23 a31 a32 a33
and returns a 3x3 matrix with the parsed elements
:param alignment_file: a file containing the 9 elements of a 3x3 matrix
:return: a 3x3 matrix (default identify if error happens)
"""
alignment_matrix = np.zeros((3,3), dtype=np.float)
alignment_matrix[0,0] = 1
alignment_matrix[0,1] = 0
alignment_matrix[0,2] = 0
alignment_matrix[1,0] = 0
alignment_matrix[1,1] = 1
alignment_matrix[1,2] = 0
alignment_matrix[2,0] = 0
alignment_matrix[2,1] = 0
alignment_matrix[2,2] = 1
if alignment_file is None or not os.path.isfile(alignment_file):
return alignment_matrix
with open(alignment_file, "r") as filehandler:
line = filehandler.readline()
tokens = line.split()
assert(len(tokens) == 9)
alignment_matrix[0,0] = float(tokens[0])
alignment_matrix[0,1] = float(tokens[1])
alignment_matrix[0,2] = float(tokens[2])
alignment_matrix[1,0] = float(tokens[3])
alignment_matrix[1,1] = float(tokens[4])
alignment_matrix[1,2] = float(tokens[5])
alignment_matrix[2,0] = float(tokens[6])
alignment_matrix[2,1] = float(tokens[7])
alignment_matrix[2,2] = float(tokens[8])
return alignment_matrix