def extract_DF_F(Y, A, C, i=None):
"""Extract DF/F values from spatial/temporal components and background
Parameters
-----------
Y: np.ndarray
input data (d x T)
A: sparse matrix of np.ndarray
Set of spatial including spatial background (d x K)
C: matrix
Set of temporal components including background (K x T)
Returns
-----------
C_df: matrix
temporal components in the DF/F domain
Df: np.ndarray
vector with baseline values for each trace
"""
A2 = A.copy()
A2.data **= 2
nA2 = np.squeeze(np.array(A2.sum(axis=0)))
A = A * diags(1 / nA2, 0)
C = diags(nA2, 0) * C
# if i is None:
# i = np.argmin(np.max(A,axis=0))
Y = np.matrix(Y)
Yf = A.transpose() * (Y - A * C) # + A[:,i]*C[i,:])
Df = np.median(np.array(Yf), axis=1)
C_df = diags(1 / Df, 0) * C
return C_df, Df
评论列表
文章目录