MCPcopy
hub / github.com/mne-tools/mne-python / write_named_matrix

Function write_named_matrix

mne/_fiff/matrix.py:97–137  ·  view source on GitHub ↗

Write named matrix from the given node. Parameters ---------- fid : file The opened file descriptor. kind : int The kind of the matrix. matkind : int The type of matrix.

(fid, kind, mat)

Source from the content-addressed store, hash-verified

95
96
97def write_named_matrix(fid, kind, mat):
98 """Write named matrix from the given node.
99
100 Parameters
101 ----------
102 fid : file
103 The opened file descriptor.
104 kind : int
105 The kind of the matrix.
106 matkind : int
107 The type of matrix.
108 """
109 # let's save ourselves from disaster
110 n_tot = mat["nrow"] * mat["ncol"]
111 if mat["data"].size != n_tot:
112 ratio = n_tot / float(mat["data"].size)
113 if n_tot < mat["data"].size and ratio > 0:
114 ratio = 1 / ratio
115 raise ValueError(
116 f"Cannot write matrix: row ({mat['nrow']}) and column ({mat['ncol']}) "
117 f"total element ({n_tot}) mismatch with data size ({mat['data'].size}), "
118 f"appears to be off by a factor of {ratio:g}x"
119 )
120 start_block(fid, FIFF.FIFFB_MNE_NAMED_MATRIX)
121 write_int(fid, FIFF.FIFF_MNE_NROW, mat["nrow"])
122 write_int(fid, FIFF.FIFF_MNE_NCOL, mat["ncol"])
123
124 if len(mat["row_names"]) > 0:
125 # let's prevent unintentional stupidity
126 if len(mat["row_names"]) != mat["nrow"]:
127 raise ValueError('len(mat["row_names"]) != mat["nrow"]')
128 write_name_list(fid, FIFF.FIFF_MNE_ROW_NAMES, mat["row_names"])
129
130 if len(mat["col_names"]) > 0:
131 # let's prevent unintentional stupidity
132 if len(mat["col_names"]) != mat["ncol"]:
133 raise ValueError('len(mat["col_names"]) != mat["ncol"]')
134 write_name_list(fid, FIFF.FIFF_MNE_COL_NAMES, mat["col_names"])
135
136 write_float_matrix(fid, kind, mat["data"])
137 end_block(fid, FIFF.FIFFB_MNE_NAMED_MATRIX)

Callers 3

_write_forward_solutionFunction · 0.85
write_ctf_compFunction · 0.85
_write_inverse_operatorFunction · 0.85

Calls 5

start_blockFunction · 0.85
write_intFunction · 0.85
write_name_listFunction · 0.85
write_float_matrixFunction · 0.85
end_blockFunction · 0.85

Tested by

no test coverage detected