def test_displace_eccentricity(): #x, y = np.array([1, 0]), np.array([0, 1]) x, y = util.make_grid(numPix=10, deltapix=1) e1 = 0.1 #.1 e2 = -0 #.1 center_x, center_y = 0, 0 x_, y_ = param_util.transform_e1e2(x, y, e1, e2, center_x=center_x, center_y=center_y) phi_G, q = param_util.ellipticity2phi_q(e1, e2) x_shift = x - center_x y_shift = y - center_y cos_phi = np.cos(phi_G) sin_phi = np.sin(phi_G) print(cos_phi, sin_phi) xt1 = cos_phi * x_shift + sin_phi * y_shift xt2 = -sin_phi * x_shift + cos_phi * y_shift xt1 *= np.sqrt(q) xt2 /= np.sqrt(q) npt.assert_almost_equal(x_, xt1, decimal=8) npt.assert_almost_equal(y_, xt2, decimal=8) x, y = util.make_grid(numPix=10, deltapix=1) x, y = np.array([1, 0]), np.array([0, 1]) e1 = 0.1 #.1#.1 e2 = 0 center_x, center_y = 0, 0 x_, y_ = param_util.transform_e1e2(x, y, e1, e2, center_x=center_x, center_y=center_y) phi_G, q = param_util.ellipticity2phi_q(e1, e2) x_shift = x - center_x y_shift = y - center_y cos_phi = np.cos(phi_G) sin_phi = np.sin(phi_G) print(cos_phi, sin_phi) xt1 = cos_phi * x_shift + sin_phi * y_shift xt2 = -sin_phi * x_shift + cos_phi * y_shift xt1 *= np.sqrt(q) xt2 /= np.sqrt(q) npt.assert_almost_equal(x_, xt1, decimal=8) npt.assert_almost_equal(y_, xt2, decimal=8)
def function_split(self, x, y, amp, sigma, e1, e2, center_x=0, center_y=0): x_, y_ = param_util.transform_e1e2(x, y, e1, e2) f_list = [] for i in range(len(amp)): f_list.append( self.gaussian.function(x_, y_, amp[i], sigma[i], sigma[i], center_x, center_y)) return f_list
def test_transform_e1e2(): e1 = 0.01 e2 = 0. x = 0. y = 1. x_, y_ = param_util.transform_e1e2(x, y, e1, e2) x_new = (1 - e1) * x - e2 * y y_new = -e2 * x + (1 + e1) * y det = np.sqrt((1 - e1) * (1 + e1) + e2**2) npt.assert_almost_equal(x_, x_new / det, decimal=5) npt.assert_almost_equal(y_, y_new / det, decimal=5)
def function(self, x, y, amp, sigma, e1, e2, center_x=0, center_y=0): """ :param x: :param y: :param sigma0: :param a: :param s: :param center_x: :param center_y: :return: """ x_, y_ = param_util.transform_e1e2(x, y, e1, e2, center_x, center_y) return self.gaussian.function(x_, y_, amp, sigma, center_x=0, center_y=0)
def function(self, x, y, amp, sigma, e1, e2, center_x=0, center_y=0): """ :param x: :param y: :param sigma0: :param a: :param s: :param center_x: :param center_y: :return: """ x_, y_ = param_util.transform_e1e2(x, y, e1, e2, center_x, center_y) f_ = np.zeros_like(x) for i in range(len(amp)): f_ += self.gaussian.function(x_, y_, amp[i], sigma[i], center_x=0, center_y=0) return f_
def function(self, x, y, amp, radius, e1, e2, center_x, center_y): """ :param x: :param y: :param amp: :param radius: :param e1: :param e2: :param center_x: :param center_y: :return: """ x_, y_ = param_util.transform_e1e2(x, y, e1, e2, center_x, center_y) r2 = x_**2 + y_**2 flux = np.zeros_like(x) flux[r2 <= radius**2] = 1 A = np.pi * radius ** 2 return amp / A * flux
def multi_gaussian_lens_light(self, kwargs_lens_light, model_bool_list=None, e1=0, e2=0, n_comp=20, deltaPix=None, numPix=None): """ multi-gaussian decomposition of the lens light profile (in 1-dimension) :param kwargs_lens_light: :param n_comp: :return: """ if 'center_x' in kwargs_lens_light[0]: center_x = kwargs_lens_light[0]['center_x'] center_y = kwargs_lens_light[0]['center_y'] else: center_x, center_y = 0, 0 r_h = self.half_light_radius_lens(kwargs_lens_light, center_x=center_x, center_y=center_y, model_bool_list=model_bool_list, deltaPix=deltaPix, numPix=numPix) r_array = np.logspace(-3, 2, 200) * r_h * 2 x_coords, y_coords = param_util.transform_e1e2(r_array, np.zeros_like(r_array), e1=-e1, e2=-e2) x_coords += center_x y_coords += center_y #r_array = np.logspace(-2, 1, 50) * r_h flux_r = self._lens_light_internal(x_coords, y_coords, kwargs_lens_light, model_bool_list=model_bool_list) amplitudes, sigmas, norm = mge.mge_1d(r_array, flux_r, N=n_comp) return amplitudes, sigmas, center_x, center_y
def multi_gaussian_lens(self, kwargs_lens, model_bool_list=None, e1=0, e2=0, n_comp=20): """ multi-gaussian lens model in convergence space :param kwargs_lens: :param n_comp: :return: """ if 'center_x' in kwargs_lens[0]: center_x = kwargs_lens[0]['center_x'] center_y = kwargs_lens[0]['center_y'] else: raise ValueError('no keyword center_x defined!') theta_E = self._lensModelExtensions.effective_einstein_radius( kwargs_lens) r_array = np.logspace(-4, 2, 200) * theta_E x_coords, y_coords = param_util.transform_e1e2(r_array, np.zeros_like(r_array), e1=-e1, e2=-e2) x_coords += center_x y_coords += center_y #r_array = np.logspace(-2, 1, 50) * theta_E if model_bool_list is None: model_bool_list = [True] * len(kwargs_lens) kappa_s = np.zeros_like(r_array) for i in range(len(kwargs_lens)): if model_bool_list[i] is True: kappa_s += self.LensModel.kappa(x_coords, y_coords, kwargs_lens, k=i) amplitudes, sigmas, norm = mge.mge_1d(r_array, kappa_s, N=n_comp) return amplitudes, sigmas, center_x, center_y
def function(self, x, y, amp, gamma, e1, e2, center_x=0, center_y=0): """ :param x: ra-coordinate :param y: dec-coordinate :param gamma: projected power-law slope :param e1: ellipticity :param e2: ellipticity :param center_x: center :param center_y: center :return: projected flux """ x_, y_ = param_util.transform_e1e2(x, y, e1, e2, center_x, center_y) P2 = x_ ** 2 + y_ ** 2 if isinstance(P2, int) or isinstance(P2, float): a = max(0.00000001, P2) else: a = np.empty_like(P2) p2 = P2[P2 > 0] # in the SIS regime a[P2 == 0] = 0.00000001 a[P2 > 0] = p2 sigma = amp * a ** ((1. - gamma)/2.) return sigma