Example #1
0
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
Example #2
0
Aprior = pf.open('./Simu_2744/Estimated_A.fits')[0].data


##param
mom = 'mom'
positivity =False
reweighting ='none'
pca = 'PCA'
wmode = 'add'
soft = False
npca = 32
n = 800
#[145,255]

S,A = MC.mMCA(cube, Aprior, 5,n,threshmode = mom,  PCA=[2,11], harder =0, alpha = [142,256], npca = npca, pos = positivity,mode=pca)


pen = reweighting
hdus = pf.PrimaryHDU(S)
lists = pf.HDUList([hdus])
lists.writeto('Simu_2744/Sources_'+str(n)+'_'+pen+'.fits', clobber=True)

hdus = pf.PrimaryHDU(A)
lists = pf.HDUList([hdus])
lists.writeto('Simu_2744/Estimated_A.fits', clobber=True)

cs.make_colour_sub('Simu_2744/Sources_'+str(n)+'_'+pen+'.fits',
                   'Simu_2744/Estimated_A.fits',
                   './Simu_2744/All_real.fits','big_'+str(n)+'_'+pen, cuts = ['0','0.25','0','0.15','0','0.02','0','0.1','0','0.1'], prefix = './Simu_2744/')
Example #3
0
## Openning data cube
cube = pf.open('Simu_big/Cube.fits')[0].data
num,n1,n2 = np.shape(cube)

## A for toy model
Aprior = pf.open('Simu_simple/Simu_A.fits')[0].data

## Input parameters
pca = 'PCA'     #Estimation of the mixing coefficients from PCA. If different from PCA it will use the array provided in Aprior
n = 100         #Number of iterations
nsig = 5        #Threshold in units of noise standard deviation
ns = 2          #Number of sources
angle = 5      #Resolution angle for the PCA colour estimation (start with 15 then adjust empirically)

## Running MuSCADeT
S,A = MCA.mMCA(cube, Aprior.T, nsig,n, PCA=[ns,angle], mode=pca)

hdus = pf.PrimaryHDU(S)
lists = pf.HDUList([hdus])
lists.writeto('Simu_big/Sources_'+str(n)+'.fits', clobber=True)

hdus = pf.PrimaryHDU(A)
lists = pf.HDUList([hdus])
lists.writeto('Simu_big/Estimated_A.fits', clobber=True)

cs.make_colour_sub('Simu_big/Sources_'+str(n)+'.fits',
                   'Simu_big/Estimated_A.fits',
                   './Simu_big/Cube.fits',
                   'big_'+str(n),
                   prefix = './Simu_big/',
                   cuts = ['-0.1','0.6','-0.05','0.3','-0.02','0.1'])
Example #4
0
num,n,n = np.shape(cube)

## If A is unknown, set it to zero.
Aprior = 0 #pf.open('Simu_simple/Simu_A.fits')[0].data

## Input parameters
pca = 'PCA'     #Estimation of the mixing coefficients from PCA. If different from PCA it will use the array provided in Aprior
n = 100        #Number of iterations: increase if the separation is not good enough!
nsig = 5        #Threshold in units of noise standard deviation: Can be lowered down to 3 but 5 should be fine.
ns = 2          #Number of sources:
angle = 10      #Resolution angle for the PCA colour estimation (start with 15 then adjust empirically)
alpha = [0,0]   #If automated estimation of PCA coefficients fails, chose adequate alphas. See readme for more details
plot = False     #option to plot the PCA coefficients of the SEDs in the image. This option is usefull if one wants to make sure that SEDs have been correctly estimated. In automated mode, keep this option at False. In case the SEDs have to be refined, set plot to True, identify the features (alignements) on the plot that stand for different SEDs and use this to give values for alpha. (see readme.)

## Running MuSCADeT
S,A = MCA.mMCA(cube, Aprior, nsig,n, PCA=[ns,angle], mode=pca, alpha = [0,0])

## MuSCADeT estimates ns source, which means, variable S contains ns images
## Saves the sources in a fits file
hdus = pf.PrimaryHDU(S)
lists = pf.HDUList([hdus])
lists.writeto('Simu_For_User/Sources_'+str(n)+'.fits', clobber=True)

## Saves the estimated mixing matrix, A, in a fits file
hdus = pf.PrimaryHDU(A)
lists = pf.HDUList([hdus])
lists.writeto('Simu_For_User/Estimated_A.fits', clobber=True)

## This command shows the result of the separation in various formats:
## The command needs : A fits file with the extracted source and mixing coefficients (MuSCADeT's outputs)
##                     A fits file with the original data
Example #5
0
## Openning data cube
cube = pf.open('./Simu_Refsdal_big/Cube.fits')[0].data
num,n,n = np.shape(cube)

## A for toy model
Aprior =pf.open('Simu_Refsdal_big/Estimated_A_PCA.fits')[0].data

## Input parameters
pca = 'noPCA'   #Estimation of the mixing coefficients from PCA. If different from PCA it will use the array provided in Aprior
n = 2000        #Number of iterations
nsig = 5        #Threshold in units of noise standard deviation
ns = 2          #Number of sources
angle = 50      #Resolution angle for the PCA colour estimation (start with 15 then adjust empirically)

## Running MuSCADeT
S,A = MCA.mMCA(cube, Aprior, nsig,n, PCA=[ns,angle], mode=pca, harder = 1)


for i in [1]:
    hdus = pf.PrimaryHDU(S)
    lists = pf.HDUList([hdus])
    lists.writeto('Simu_Refsdal_big/Sources_'+str(n)+'.fits', clobber=True)

    hdus = pf.PrimaryHDU(A)
    lists = pf.HDUList([hdus])
    lists.writeto('Simu_Refsdal_big/Estimated_A.fits', clobber=True)

    cs.make_colour_sub('Simu_Refsdal_big/Sources_'+str(n)+'.fits',
                       'Simu_Refsdal_big/Estimated_A.fits',
                       './Simu_Refsdal_big/Cube.fits',
                       'Refsdal_big_'+str(n),