Exemplo n.º 1
0
 def test_make_sugrid(self):
     ra_sub, dec_sub = self.system1.get_subgrid(subgrid_res=2)
     ra_sub = util.array2image(ra_sub)
     ra, dec = self.system1.get_cutout_coords
     cos_dec = np.cos(self.system1.dec / 360 * 2 * np.pi)
     ra = util.array2image(ra*cos_dec)
     ra_resized = util.averaging(ra_sub, len(ra_sub), len(ra_sub)/2)
     assert ra[0][0] == ra_resized[0][0]
     assert ra[9][7] == ra_resized[9][7]
Exemplo n.º 2
0
 def get_psf_errors(self, kernel, sigma_bkg, star_list):
     """
     returns a error map of sigma prop Intensity for a stacked psf estimation
     :param psf_kwargs:
     :param star_list:
     :return:
     """
     psf_size = len(kernel)
     kernel_mean = util.image2array(kernel)
     weights = np.zeros(len(star_list))
     cov_i = np.zeros((psf_size**2, psf_size**2))
     num_stars = len(star_list)
     for i in range(0, num_stars):
         star_list_i = star_list[i].copy()
         star = util.cut_edges(star_list_i, psf_size)
         weights[i] = np.sum(star)
         rel_array = np.array(
             [util.image2array(star) / weights[i] - kernel_mean])
         a = (rel_array.T).dot(rel_array)
         cov_i += a
     factor = 1. / (num_stars)
     #weights_sum = sum(weights)
     sigma2_stack = factor * util.array2image(np.diag(cov_i))
     psf_stack = copy.deepcopy(kernel)
     sigma2_stack_new = sigma2_stack  # - (data_kwargs['sigma_background']**2/weights_sum)
     sigma2_stack_new[np.where(sigma2_stack_new < 0)] = 0
     psf_stack[np.where(psf_stack < sigma_bkg)] = sigma_bkg
     error_map = sigma2_stack_new / (psf_stack)**2
     #error_map[np.where(error_map < psf_stack**2/data_kwargs['reduced_noise'])] = 0
     # n = len(error_map)
     #error_map[(n-1)/2-1:(n-1)/2+2,(n-1)/2-1:(n-1)/2+2] += 0
     #error_map = filters.gaussian_filter(error_map, sigma=0.5)
     return error_map
Exemplo n.º 3
0
 def test_cutout(self):
     """
     tests the cutout routine and whether the header is also changed accordingly
     """
     xw = 50  # number of pixel to be cutout in x-axis
     yw = 50  # number of pixel to be cutout in y-axis
     img, head, exp_map, ra_coords, dec_coords = self.system1._cutout(self.fits_filename, self.ra, self.dec, xw, yw)
     ra_coords = util.array2image(ra_coords)
     dec_coords = util.array2image(dec_coords)
     assert head['NAXIS1'] == 2*xw
     assert head['NAXIS2'] == 2*yw
     assert len(img) == 2*yw
     assert len(img[0]) == 2*xw
     assert len(ra_coords) == yw*2
     assert len(ra_coords[0]) == xw*2
     cos_dec = np.cos(self.system1.dec / 360 * 2 * np.pi)
     print(cos_dec)
     print(np.sqrt((ra_coords[yw, xw]*cos_dec)**2 + dec_coords[yw, xw]**2))
     ra, dec = self.system1.map_pix2coord(xw, yw)
     npt.assert_almost_equal(ra_coords[yw, xw]*cos_dec, ra, decimal=5)
     npt.assert_almost_equal(dec_coords[yw, xw], dec, decimal=5)
Exemplo n.º 4
0
                                       x,
                                       y,
                                       n_max,
                                       beta,
                                       1.,
                                       center_x=0,
                                       center_y=0)
# reconstruct M31 with the shapelet coefficients
image_reconstructed = shapeletSet.function(x,
                                           y,
                                           param_list,
                                           n_max,
                                           beta,
                                           center_x=0,
                                           center_y=0)
image_reconstructed_2d = util.array2image(
    image_reconstructed)  # map 1d data vector in 2d image
plt.matshow(np.log10(image_reconstructed_2d),
            origin='lower')  #,vmin=-5, vmax=1)
plt.colorbar()
plt.show()
pyfits.PrimaryHDU(image_reconstructed_2d).writeto(
    'shapelet/{0}_shapelet.fits'.format(name), overwrite=True)

import pickle
output = open('shapelet/{0}.pkl'.format(name), 'wb')
passvar = {
    'n_max': n_max,
    'beta': beta,
    'param_list': param_list,
    'numPix_large': len(data)
}