def derivatives(self, x, y, sigma0, Ra, Rs, e1, e2, center_x=0, center_y=0): """ returns df/dx and df/dy of the function (integral of NFW) """ phi_G, q = param_util.ellipticity2phi_q(e1, e2) x_, y_ = param_util.transform_e1e2_square_average( x, y, e1, e2, center_x, center_y) e = param_util.q2e(q) cos_phi = np.cos(phi_G) sin_phi = np.sin(phi_G) f_x_prim, f_y_prim = self.spherical.derivatives(x_, y_, sigma0, Ra, Rs, center_x=0, center_y=0) f_x_prim *= np.sqrt(1 - e) f_y_prim *= np.sqrt(1 + e) f_x = cos_phi * f_x_prim - sin_phi * f_y_prim f_y = sin_phi * f_x_prim + cos_phi * f_y_prim return f_x, f_y
def derivatives(self, x, y, Rs, alpha_Rs, e1, e2, center_x=0, center_y=0): """ returns df/dx and df/dy of the function, calculated as an elliptically distorted deflection angle of the spherical NFW profile :param x: angular position (normally in units of arc seconds) :param y: angular position (normally in units of arc seconds) :param Rs: turn over point in the slope of the NFW profile in angular unit :param alpha_Rs: deflection (angular units) at projected Rs :param e1: eccentricity component in x-direction :param e2: eccentricity component in y-direction :param center_x: center of halo (in angular units) :param center_y: center of halo (in angular units) :return: deflection in x-direction, deflection in y-direction """ x_, y_ = param_util.transform_e1e2_square_average( x, y, e1, e2, center_x, center_y) phi_G, q = param_util.ellipticity2phi_q(e1, e2) cos_phi = np.cos(phi_G) sin_phi = np.sin(phi_G) e = abs(1 - q) R_ = np.sqrt(x_**2 + y_**2) rho0_input = self.nfw.alpha2rho0(alpha_Rs=alpha_Rs, Rs=Rs) if Rs < 0.0000001: Rs = 0.0000001 f_x_prim, f_y_prim = self.nfw.nfwAlpha(R_, Rs, rho0_input, x_, y_) f_x_prim *= np.sqrt(1 - e) f_y_prim *= np.sqrt(1 + e) f_x = cos_phi * f_x_prim - sin_phi * f_y_prim f_y = sin_phi * f_x_prim + cos_phi * f_y_prim return f_x, f_y
def function(self, x, y, sigma0, Rs, e1, e2, center_x=0, center_y=0): """ returns double integral of NFW profile """ x_, y_ = param_util.transform_e1e2_square_average(x, y, e1, e2, center_x, center_y) f_ = self.spherical.function(x_, y_, sigma0, Rs) return f_
def function(self, x, y, Rs, alpha_Rs, r_trunc, e1, e2, center_x=0, center_y=0): """ returns elliptically distorted NFW lensing potential :param x: angular position (normally in units of arc seconds) :param y: angular position (normally in units of arc seconds) :param Rs: turn over point in the slope of the NFW profile in angular unit :param alpha_Rs: deflection (angular units) at projected Rs :param r_trunc: truncation radius :param e1: eccentricity component in x-direction :param e2: eccentricity component in y-direction :param center_x: center of halo (in angular units) :param center_y: center of halo (in angular units) :return: lensing potential """ x_, y_ = param_util.transform_e1e2_square_average( x, y, e1, e2, center_x, center_y) R_ = np.sqrt(x_**2 + y_**2) rho0_input = self.tnfw.alpha2rho0(alpha_Rs=alpha_Rs, Rs=Rs) Rs = np.maximum(Rs, 0.0000001) #if Rs < 0.0000001: # Rs = 0.0000001 f_ = self.tnfw.nfwPot(R_, Rs, rho0_input, r_trunc) return f_
def function(self, x, y, n_sersic, R_sersic, k_eff, e1, e2, center_x=0, center_y=0): """ returns Gaussian """ # phi_G, q = param_util.ellipticity2phi_q(e1, e2) x_, y_ = param_util.transform_e1e2_square_average(x, y, e1, e2, center_x, center_y) # x_, y_ = self._coord_transf(x, y, q, phi_G, center_x, center_y) f_ = self.sersic.function(x_, y_, n_sersic, R_sersic, k_eff) return f_
def function(self, x, y, amp, Ra, Rs, e1, e2, center_x=0, center_y=0): """ :param x: :param y: :param amp: :param Ra: :param Rs: :param center_x: :param center_y: :return: """ x_, y_ = param_util.transform_e1e2_square_average(x, y, e1, e2, center_x, center_y) return self.spherical.function(x_, y_, amp, Ra, Rs)
def test_transform_e1e2_square_average(): x, y = np.array([1, 0]), np.array([0, 1]) e1 = 0.1 e2 = 0 center_x, center_y = 0, 0 x_, y_ = param_util.transform_e1e2_square_average(x, y, e1, e2, center_x=center_x, center_y=center_y) npt.assert_almost_equal(np.sum(x**2 + y**2), np.sum(x_**2 + y_**2), decimal=8)
def derivatives(self, x, y, n_sersic, R_sersic, k_eff, e1, e2, center_x=0, center_y=0): """ returns df/dx and df/dy of the function """ phi_G, q = param_util.ellipticity2phi_q(e1, e2) e = param_util.q2e(q) # e = abs(1. - q) cos_phi = np.cos(phi_G) sin_phi = np.sin(phi_G) x_, y_ = param_util.transform_e1e2_square_average(x, y, e1, e2, center_x, center_y) # x_, y_ = self._coord_transf(x, y, q, phi_G, center_x, center_y) f_x_prim, f_y_prim = self.sersic.derivatives(x_, y_, n_sersic, R_sersic, k_eff) f_x_prim *= np.sqrt(1 - e) f_y_prim *= np.sqrt(1 + e) f_x = cos_phi*f_x_prim-sin_phi*f_y_prim f_y = sin_phi*f_x_prim+cos_phi*f_y_prim return f_x, f_y
def derivatives(self, x, y, sigma0, Rs, e1, e2, center_x=0, center_y=0): """ returns df/dx and df/dy of the function (integral of NFW) """ x_, y_ = param_util.transform_e1e2_square_average(x, y, e1, e2, center_x, 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) e = abs(1 - q) #x_ = (cos_phi*x_shift+sin_phi*y_shift)*np.sqrt(1 - e) #y_ = (-sin_phi*x_shift+cos_phi*y_shift)*np.sqrt(1 + e) f_x_prim, f_y_prim = self.spherical.derivatives(x_, y_, sigma0, Rs) f_x_prim *= np.sqrt(1 - e) f_y_prim *= np.sqrt(1 + e) f_x = cos_phi*f_x_prim-sin_phi*f_y_prim f_y = sin_phi*f_x_prim+cos_phi*f_y_prim return f_x, f_y