def setUp(self): print("setting up") self.tempdir = tempfile.mkdtemp() now = "2020-05-17T00:00:00.1234567" t = sm.Time(now) N = 1024 SN = 15.0 theta = 0 xfwhm = 4 yfwhm = 3 weights = np.random.random(100) * 20000 + 10 zero = 10 # for zero in [5, 10, 25]: filenames = [] x = np.random.randint(low=30, high=900, size=100) y = np.random.randint(low=30, high=900, size=100) xy = [(x[i], y[i]) for i in range(100)] m = sm.delta_point(N, center=False, xy=xy, weights=weights) img_dir = os.path.join(self.tempdir, "zp_{}".format(zero)) os.makedirs(img_dir) for i in range(4): im = sm.image( m, N, t_exp=2 * i + 1, X_FWHM=xfwhm, Y_FWHM=yfwhm, theta=theta, SN=SN, bkg_pdf="gaussian", ) filenames.append( sm.capsule_corp(im, t, t_exp=i + 1, i=i, zero=zero + i, path=img_dir)) self.filenames = filenames self.img = im self.img_masked = np.ma.MaskedArray(im, mask=np.zeros(im.shape))
def random_4psf_simage(): frames = [] for theta in [0, 45, 105, 150]: image_seed = int(random.rand() * 1000) N = 512 # side X_FWHM = 5 + 5.5 * theta / 180 Y_FWHM = 5 t_exp = 5 max_fw = max(X_FWHM, Y_FWHM) x = random.randint(low=6 * max_fw, high=N - 6 * max_fw, size=80) y = random.randint(low=6 * max_fw, high=N - 6 * max_fw, size=80) xy = [(x[i], y[i]) for i in range(80)] SN = 30.0 # SN para poder medir psf weights = list(np.linspace(10, 1000.0, 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="gaussian", seed=image_seed, ) frames.append(im + 100.0) 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 ] return s.SingleImage(frame)
now = '2016-05-17T00:00:00.1234567' t = Time(now) SN = 5. theta = 0 xfwhm = 4 yfwhm = 3 weights = np.random.random(25) * 20000 + 10 zero = 10 #for zero in [5, 10, 25]: filenames = [] x = np.random.randint(low=30, high=900, size=25) y = np.random.randint(low=30, high=900, size=25) xy = [(x[i], y[i]) for i in range(25)] m = sm.delta_point(N, center=False, xy=xy, weights=weights) img_dir = os.path.join(test_dir, 'zp={}'.format(zero)) if not os.path.exists(img_dir): os.makedirs(img_dir) for i in range(40): im = sm.image(m, N, t_exp=i + 1, X_FWHM=xfwhm, Y_FWHM=yfwhm, theta=theta, SN=SN, bkg_pdf='poisson') filenames.append(
for k in range(10): frames = [] for theta in [0, 45, 105, 150]: N = 512 # side X_FWHM = 2 + 2.5 * theta / 180 Y_FWHM = 2.8 t_exp = 1 max_fw = max(X_FWHM, Y_FWHM) x = np.linspace(6 * max_fw, N - 6 * max_fw, 6) y = np.linspace(6 * max_fw, N - 6 * max_fw, 6) xy = simtools.cartesian_product([x, y]) SN = 30. # SN para poder medir psf weights = list(np.linspace(1000, 3000, 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='gaussian') frames.append(im) frame = np.zeros((2 * N, 2 * N)) for j in range(2): for i in range(2): frame[i * N:(i + 1) * N, j * N:(j + 1) * N] = frames[i + 2 * j] now = '2016-05-17T00:00:00.1234567'
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] weights = 100000. * cat['flux'] / max(cat['flux']) m = simtools.delta_point(N * 2, center=False, xy=xy) #, weights=weights) x, y = np.mgrid[:frame.shape[0], :frame.shape[1]] rebuild = np.zeros_like(frame) for i in range(len(psf_basis)): psf = psf_basis[i] a = a_fields[i] rebuild += a(x, y) * simtools.convol_gal_psf_fft(m, psf) rebuild += 1000. plt.imshow(np.log10(rebuild), interpolation='none') plt.colorbar() plt.tight_layout() plt.savefig(os.path.join(test_dir, 'frame_rebuild.png')) plt.close()