t = Time(now) filenames = [] for i in range(100): SN = 2. # + i weights = list(np.linspace(0.00001, 1, len(xy))) m = simtools.delta_point(N, center=False, xy=xy, weights=weights) im = simtools.image(m, N, t_exp=1, X_FWHM=FWHM, SN=SN, bkg_pdf='gaussian') filenames.append( simtools.capsule_corp(im, t, t_exp=1, i=i, zero=3.1415, path=test_dir)) S = np.zeros(shape=(N,N)) psf = simtools.Psf(N, FWHM) for afile in filenames: px = pc.SingleImage(afile) # Now I must combine this images, normalizing by the var(noise) var = px.meta['std'] conv = convolve_fft(px.imagedata, psf) S = S + conv/var**2. fits.writeto(data=S, filename='./test_images/S.fits', overwrite=True) swarp = shlex.split('swarp @test_images/one_star/imagelist.txt -c default.swarp') subprocess.call(swarp) plt.figure() plt.subplot(121) plt.imshow(S, interpolation='none') plt.title('Ofek') plt.subplot(122)
y = np.linspace(6 * max_fw, N - 6 * max_fw, 7) xy = simtools.cartesian_product([x, y]) SN = 1000. # SN para poder medir psf weights = list(np.linspace(10, 100, len(xy))) m = simtools.delta_point(N, center=False, xy=xy, weights=weights) im = simtools.image(m, N, t_exp, X_FWHM, SN, Y_FWHM=Y_FWHM, theta=theta, bkg_pdf='poisson') sim = pc.SingleImage(im, imagefile=False, sim=True) fitted_models = sim.fit_psf_sep() x_sds = [g.x_stddev for g in fitted_models] y_sds = [g.y_stddev for g in fitted_models] th = [g.theta * 180 / np.pi for g in fitted_models] amplitudes = [g.amplitude for g in fitted_models] fwhm_x = 2.335 * np.mean(x_sds) fwhm_y = 2.335 * np.mean(y_sds) mean_th = round(np.mean(th)) fwhm = max(fwhm_x, fwhm_y) print('X Fwhm = {}, Y Fwhm = {}, Mean Theta = {}'.format( fwhm_x, fwhm_y, mean_th))
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 pc.SingleImage(frame, sim=True, imagefile=False) as sim: a_fields, psf_basis = sim.get_variable_psf(pow_th=0.01) plt.imshow(np.log(frame), interpolation='none') plt.colorbar() plt.savefig(os.path.join(test_dir, 'test_frame.png')) plt.close() utils.plot_psfbasis(psf_basis, path=os.path.join(test_dir, 'psf_basis.png')) utils.plot_afields(a_fields, shape=(1024, 1024), path=os.path.join(test_dir, 'a_fields.png'))
import sep from astropy.io import fits from properimage.tests import simtools from properimage import propercoadd as pc from properimage import utils # ============================================================================= # PSF measure test by propercoadd # ============================================================================= N = 512 test_dir = os.path.abspath('./test/test_images/rebuild_psf2') frame = utils.sim_varpsf(400, test_dir, SN=5.) with pc.SingleImage(frame) as sim: a_fields, psf_basis = sim.get_variable_psf() utils.plot_afields(a_fields, frame.shape, os.path.join(test_dir, 'a_fields.png')) utils.plot_psfbasis(psf_basis, os.path.join(test_dir, 'psf_basis.png'), nbook=False) plt.imshow(np.log10(frame), interpolation='none') #plt.plot(cat['sources']['x'], cat['sources']['y'], '.k') plt.colorbar() plt.tight_layout() plt.savefig(os.path.join(test_dir, 'test_frame.png')) plt.close() cat = sep.extract(frame - sep.Background(frame), thresh=4.5*sep.Background(frame).globalrms) xy = [(int(row['y']), int(row['x'])) for row in cat]
reload(pc) # ============================================================================= # PSF measure test by propercoadd # ============================================================================= datapath = os.path.abspath('/home/bruno/Documentos/Data/ESO085-030') frame = os.path.join(datapath, 'eso085-030-030.fit') d = fits.getdata(frame) utils.plot_S(d, path='./test/test_images/real_image_test/frame.png') #fitted_models = sim.fit_psf_sep() # ============================================================================= # PSF spatially variant # ============================================================================= with pc.SingleImage(frame, imagefile=True) as sim: a_f, psf_b = sim.get_variable_psf(pow_th=0.01) S = sim.s_component utils.plot_psfbasis(psf_b, path='./test/test_images/real_image_test/psf_basis.png') utils.plot_afields(a_f, S.shape, path='./test/test_images/real_image_test/a_fields.png') utils.plot_S(S, path='./test/test_images/real_image_test/S.png')