def test_d_x_diffr_dx(self): x = 1 y = 0 out = calc_util.d_x_diffr_dx(x, y) assert out == 0 x = 0 y = 1 out = calc_util.d_x_diffr_dx(x, y) assert out == 1
def hessian(self, x, y, sigma0, r_core, center_x=0, center_y=0): """ :param x: x-coordinate in angular units :param y: y-coordinate in angular units :param sigma0: convergence in the core :param r_core: core radius :param center_x: center of the profile :param center_y: center of the profile :return: Hessian df/dxdx, df/dxdy, df/dydx, df/dydy at position (x, y) """ x_ = x - center_x y_ = y - center_y r = np.sqrt(x_**2 + y_**2) r = np.maximum(r, self._s) d_alpha_dr = self.d_alpha_dr(r, sigma0, r_core) alpha = self.alpha_r(r, sigma0, r_core) dr_dx = calc_util.d_r_dx(x_, y_) dr_dy = calc_util.d_r_dy(x_, y_) f_xx = d_alpha_dr * dr_dx * x_ / r + alpha * calc_util.d_x_diffr_dx( x_, y_) f_yy = d_alpha_dr * dr_dy * y_ / r + alpha * calc_util.d_y_diffr_dy( x_, y_) f_xy = d_alpha_dr * dr_dy * x_ / r + alpha * calc_util.d_x_diffr_dy( x_, y_) return f_xx, f_xy, f_xy, f_yy
def hessian(self, x, y, coeff, d_r, d_phi, center_x, center_y): """ :param x: x-coordinate :param y: y-coordinate :param coeff: float, amplitude of basis :param d_r: period of radial sinusoidal in units of angle :param d_phi: period of tangential sinusoidal in radian :param center_x: center of rotation for tangential basis :param center_y: center of rotation for tangential basis :return: f_xx, f_yy, f_xy """ r, theta = param_util.cart2polar(x, y, center_x=center_x, center_y=center_y) dphi_ = d_phi / self._2_pi d_phi_dr = self._d_phi_r(r, d_r) * self._phi_theta(theta, dphi_) d_phi_dr2 = self._d_phi_r2(r, d_r) * self._phi_theta(theta, dphi_) d_phi_d_theta = self._d_phi_theta(theta, dphi_) * self._phi_r(r, d_r) d_phi_d_theta2 = self._d_phi_theta2(theta, dphi_) * self._phi_r(r, d_r) d_phi_dr_dtheta = self._d_phi_r(r, d_r) * self._d_phi_theta( theta, dphi_) x_ = x - center_x y_ = y - center_y dr_dx = derivative_util.d_r_dx(x_, y_) dr_dy = derivative_util.d_r_dy(x_, y_) d_theta_dx = derivative_util.d_phi_dx(x_, y_) d_theta_dy = derivative_util.d_phi_dy(x_, y_) dr_dxx = derivative_util.d_x_diffr_dx(x_, y_) dr_dxy = derivative_util.d_x_diffr_dy(x_, y_) dr_dyy = derivative_util.d_y_diffr_dy(x_, y_) d_theta_dxx = derivative_util.d_phi_dxx(x_, y_) d_theta_dyy = derivative_util.d_phi_dyy(x_, y_) d_theta_dxy = derivative_util.d_phi_dxy(x_, y_) f_xx = d_phi_dr2 * dr_dx**2 + d_phi_dr * dr_dxx + d_phi_d_theta2 * d_theta_dx**2 + d_phi_d_theta * d_theta_dxx + 2 * d_phi_dr_dtheta * dr_dx * d_theta_dx f_yy = d_phi_dr2 * dr_dy**2 + d_phi_dr * dr_dyy + d_phi_d_theta2 * d_theta_dy**2 + d_phi_d_theta * d_theta_dyy + 2 * d_phi_dr_dtheta * dr_dy * d_theta_dy f_xy = d_phi_dr2 * dr_dx * dr_dy + d_phi_dr * dr_dxy + d_phi_d_theta2 * d_theta_dx * d_theta_dy + d_phi_d_theta * d_theta_dxy + d_phi_dr_dtheta * dr_dx * d_theta_dy + d_phi_dr_dtheta * dr_dy * d_theta_dx return f_xx * coeff, f_xy * coeff, f_xy * coeff, f_yy * coeff
def test_differentails(self): x_, y_ = 1., 1 n_sersic = 2. R_sersic = 1. k_eff = 0.2 r = np.sqrt(x_**2 + y_**2) d_alpha_dr = self.sersic.d_alpha_dr(x_, y_, n_sersic, R_sersic, k_eff) alpha = self.sersic.alpha_abs(x_, y_, n_sersic, R_sersic, k_eff) f_xx_ = d_alpha_dr * calc_util.d_r_dx( x_, y_) * x_ / r + alpha * calc_util.d_x_diffr_dx(x_, y_) f_yy_ = d_alpha_dr * calc_util.d_r_dy( x_, y_) * y_ / r + alpha * calc_util.d_y_diffr_dy(x_, y_) f_xy_ = d_alpha_dr * calc_util.d_r_dy( x_, y_) * x_ / r + alpha * calc_util.d_x_diffr_dy(x_, y_) f_xx = (d_alpha_dr / r - alpha / r**2) * y_**2 / r + alpha / r f_yy = (d_alpha_dr / r - alpha / r**2) * x_**2 / r + alpha / r f_xy = (d_alpha_dr / r - alpha / r**2) * x_ * y_ / r npt.assert_almost_equal(f_xx, f_xx_, decimal=10) npt.assert_almost_equal(f_yy, f_yy_, decimal=10) npt.assert_almost_equal(f_xy, f_xy_, decimal=10)