Ejemplo n.º 1
0
 def test_raise(self):
     with self.assertRaises(ValueError):
         array = np.ones(5)
         util.array2image(array)
     with self.assertRaises(ValueError):
         array = np.ones((2, 2))
         util.array2cube(array, 2, 2)
     with self.assertRaises(ValueError):
         x, y = np.ones(6), np.ones(6)
         util.get_axes(x, y)
     with self.assertRaises(ValueError):
         util.selectBest(array=np.ones(6),
                         criteria=np.ones(5),
                         numSelect=1,
                         highest=True)
     with self.assertRaises(ValueError):
         util.select_best(array=np.ones(6),
                          criteria=np.ones(5),
                          num_select=1,
                          highest=True)
     with self.assertRaises(ValueError):
         util.convert_bool_list(n=2, k=[3, 7])
     with self.assertRaises(ValueError):
         util.convert_bool_list(n=3, k=[True, True])
     with self.assertRaises(ValueError):
         util.convert_bool_list(n=2, k=[0.1, True])
Ejemplo n.º 2
0
def test_cube2array2cube():
    cube = np.zeros((2, 10, 10))
    ns, nx, ny = np.shape(cube)
    assert nx == ny  # condition required
    nxy = nx * ny
    cube[1, 2, 2] = 1
    array = util.cube2array(cube)
    cube_new = util.array2cube(array, ns, nxy)
    assert cube_new[1, 2, 2] == cube[1, 2, 2]
Ejemplo n.º 3
0
    def function(self, x, y, amp=None, n_scales=None, n_pixels=None, scale=1, center_x=0, center_y=0):
        """
        1D inverse starlet transform from starlet coefficients stored in coeffs
        Follows lenstronomy conventions for light profiles.

        :param amp: decomposition coefficients ('amp' to follow conventions in other light profile)
         This is an ndarray with shape (n_scales, sqrt(n_pixels), sqrt(n_pixels)) or (n_scales*n_pixels,)
        :param n_scales: number of decomposition scales
        :param n_pixels: number of pixels in a single scale
        :return: reconstructed signal as 1D array of shape (n_pixels,)
        """
        if len(amp.shape) == 1:
            coeffs = util.array2cube(amp, n_scales, n_pixels)
        elif len(amp.shape) == 3:
            coeffs = amp
        else:
            raise ValueError("Starlets 'amp' has not the right shape (1D or 3D arrays are supported)")
        image = self.function_2d(coeffs, n_scales, n_pixels)
        image = self.interpol.function(x, y, image=image, scale=scale,
                                       center_x=center_x, center_y=center_y,
                                       amp=1, phi_G=0)
        return image
Ejemplo n.º 4
0
def test_array2cube():
    array = np.linspace(1, 200, 200)
    image = util.array2cube(array, 2, 100)
    assert image[0][9][9] == 100
    assert image[1][0][9] == 110