def pca_ring_spectrum(images, std=0): """ Decomposes a set of SEDs from multiband images into PCA and filters the less significant coefficients INPUTS: images: cube of muti-bandimages with size n1xn2xs where s is the number of bands and n1xn2, the size of each image OUTPUTS: alphas: PCA coefficients for each SED at each pixel location. basis: corresponding PCA basis. sig: noise as propagated into PCA space. EXAMPLE: """ pad = 0 images = images.T n1, n2, s = np.shape(images) res0 = images + 0 res = res0 + 0 res1 = res + 0. sigmamr = np.zeros(s) tr = res + 0 #For thresholded images support = np.zeros((n1, n2)) for j in range(s): sigmamr[j] = MCA.MAD(res0[:, :, j]) res[:, :, j] = res1[:, :, j] x, y = np.where(res[:, :, j] == 0) tr[x, y, j] = 0 tr[:, :, -1] = 1 support = np.prod(tr, 2) support[np.where(support == 0.0)] = 0 support[np.where(support != 0.0)] = 1 x00, y00 = np.where(support == 0) res[x00, y00, :] = 0 x, y = np.where(support == 1) support1d = np.reshape(support, (n1 * n2)) x1d = np.where(support1d == 1) spectrums = np.reshape(res[x, y, :], (np.size(x1d), s)) alphas = np.zeros((np.size(x), n1 * n2)) alpha, base = mk.mk_pca(spectrums.T) ##Noise propagation in PCA space noise = np.multiply(np.random.randn(100, s), std.T) alphanoise = np.dot(base.T, noise.T) sig = np.zeros(2) sig[0] = np.std(alphanoise[0, :]) sig[1] = np.std(alphanoise[1, :]) count = 0 for ind in np.reshape(x1d, np.size(x1d)): alphas[:, ind] = alpha[:, count] count = count + 1 return alphas, base, sig