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)
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( sm.capsule_corp(im, t, t_exp=i + 1, i=i, zero=zero + i, path=img_dir)) ensemble = pc.ImageEnsemble(filenames) S_hat_stack, S_stack, S_hat, S, R_hat = ensemble.calculate_R(n_procs=4, debug=True) S_inv = pc._ifftwn(S_hat) d = S - S_inv
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' t = Time(now) filenames.append( simtools.capsule_corp(frame, t, t_exp=1,
for theta in [0, 45, 105, 150]: N = 512 # side X_FWHM = 5 + 2.5*theta/180 Y_FWHM = 5 t_exp = 1 max_fw = max(X_FWHM, Y_FWHM) test_dir = os.path.abspath('./test/test_images/psf_basis_kl_gs') x = np.random.randint(low=6*max_fw, high=N-6*max_fw, size=80) 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()
FWHM = 10 test_dir = os.path.abspath('./test/test_images/one_star') x = np.linspace(5 * FWHM, N - 5 * FWHM, 10) y = np.linspace(5 * FWHM, N - 5 * FWHM, 10) xy = simtools.cartesian_product([x, y]) now = '2016-05-17T00:00:00.1234567' 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)