Example #1
0
    y = np.random.randint(low=6*max_fw, high=N-6*max_fw, size=80)
    xy = [(x[i], y[i]) for i in range(80)]

    SN =  5. # SN para poder medir psf
    weights = list(np.linspace(10, 1000., len(xy)))
    m = simtools.delta_point(N, center=False, xy=xy, weights=weights)
    im = simtools.image(m, N, t_exp, X_FWHM, Y_FWHM=Y_FWHM, theta=theta,
                        SN=SN, bkg_pdf='poisson')
    frames.append(im+100.)

frame = np.zeros((1024, 1024))
for j in range(2):
    for i in range(2):
        frame[i*512:(i+1)*512, j*512:(j+1)*512] = frames[i+2*j]



with si.SingleImage(frame) as sim:
    a_fields, psf_basis = sim.get_variable_psf(inf_loss=0.025)
    x, y = sim.get_afield_domain()

plt.imshow(np.log(frame), interpolation='none')
plt.colorbar()
plt.savefig(os.path.join(test_dir, 'test_frame.png'))
plt.close()

plot.plot_psfbasis(psf_basis, path=os.path.join(test_dir, 'psf_basis.png'))
plot.plot_afields(a_fields, x, y, path=os.path.join(test_dir, 'a_fields.png'))


Example #2
0
frame = os.path.join(datapath, 'NGC_6544-010.fit')

d = fits.getdata(frame)

plot.plot_S(d, path='./test/test_images/real_image_test/frame.png')

# =============================================================================
#    PSF spatially variant
# =============================================================================

with si.SingleImage(frame) as sim:
    a_f, psf_b = sim.get_variable_psf(inf_loss=0.1)
    x, y = sim.get_afield_domain()
    normal_image = sim.normal_image
    interp = sim.interped
    print((sim.n_sources))
    S = sim.s_component

plot.plot_psfbasis(psf_b,
                   path='./test/test_images/real_image_test/psf_basis.png')

plot.plot_afields(a_f,
                  x,
                  y,
                  path='./test/test_images/real_image_test/a_fields.png')

plot.plot_S(S, path='./test/test_images/real_image_test/S.png')
plot.plot_S(interp, path='./test/test_images/real_image_test/interped.png')
plot.plot_S(normal_image, path='./test/test_images/real_image_test/norm.png')
Example #3
0
def main():
    imgsdir = '/home/bruno/Documentos/Data/SNiPTF/imgs'
    imgsdir = '/home/bruno/Data/SNiPTF/imgs'

    imgsdir = '/home/bruno/Data/LIGO_O2/Jan04/20171119/PGC073926/calibrated'
    dest_dir = './test/test_images/test_sniptf'
    imgs = glob.glob(imgsdir + '/aligned_PGC073926-*.fits')
    mask = glob.glob(imgsdir + '/*mask*.fits')

    imgs.sort()
    mask.sort()

    #~ print imgs
    #~ print mask

    #~ for animg in imgs:
    #~ img = fits.open(animg, 'update')
    #~ img[0].data = img[0].data[:495, :495]
    #~ img[0].header['NAXIS1'] = 495
    #~ img[0].header['NAXIS2'] = 495

    #~ img.flush()
    #~ img.close()

    #images = [s.SingleImage(animg, mask=amask) for animg, amask in zip(imgs, mask)]

    images = [s.SingleImage(animg) for animg in imgs]

    for j, an_img in enumerate(images):
        an_img.inf_loss = 0.18
        plot.plot_psfbasis(an_img.kl_basis,
                           path=os.path.join(dest_dir,
                                             'psf_basis_{}.png'.format(j)),
                           nbook=False)
        x, y = an_img.get_afield_domain()
        plot.plot_afields(an_img.kl_afields,
                          x,
                          y,
                          path=os.path.join(dest_dir,
                                            'afields_{}.png'.format(j)),
                          nbook=False,
                          size=4)
        fits.writeto(os.path.join(dest_dir, 'mask_{}.fits'.format(j)),
                     an_img.mask.astype('uint8'),
                     overwrite=True)
        fits.writeto(os.path.join(dest_dir, 'S_comp_{}.fits'.format(j)),
                     an_img.s_component,
                     overwrite=True)
        fits.writeto(os.path.join(dest_dir, 'interped_{}.fits'.format(j)),
                     an_img.interped,
                     overwrite=True)
        plot.plt.imshow(an_img.psf_hat_sqnorm().real)
        plot.plt.colorbar()
        plot.plt.savefig(
            os.path.join(dest_dir, 'psf_hat_sqnorm_{}.png'.format(j)))
        plot.plt.close()

    R, P_r = pc.stack_R(images, align=False, n_procs=4, inf_loss=0.25)

    fits.writeto(os.path.join(dest_dir, 'R.fits'), R.real, overwrite=True)
    fits.writeto(os.path.join(dest_dir, 'P.fits'), P_r.real, overwrite=True)

    for an_img in images:
        an_img._clean()

    return