def derivatives(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_x, f_y """ 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_d_theta = self._d_phi_theta(theta, dphi_) * self._phi_r(r, d_r) 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_) f_x = d_phi_dr * dr_dx + d_phi_d_theta * d_theta_dx f_y = d_phi_dr * dr_dy + d_phi_d_theta * d_theta_dy return f_x * coeff, f_y * coeff
def test_d_phi_dxx(self): x, y = util.make_grid(numPix=10, deltapix=0.1) delta = 0.00001 d_phi_dx = calc_util.d_phi_dx(x, y) d_phi_dx_delta = calc_util.d_phi_dx(x + delta, y) d_phi_dy = calc_util.d_phi_dy(x, y) d_phi_dxx = calc_util.d_phi_dxx(x, y) d_phi_dxx_num = (d_phi_dx_delta - d_phi_dx) / delta npt.assert_almost_equal(d_phi_dxx_num, d_phi_dxx, decimal=1) d_phi_dy_delta = calc_util.d_phi_dy(x, y + delta) d_phi_dyy = calc_util.d_phi_dyy(x, y) d_phi_dyy_num = (d_phi_dy_delta - d_phi_dy) / delta npt.assert_almost_equal(d_phi_dyy_num, d_phi_dyy, decimal=1) d_phi_dx_delta_y = calc_util.d_phi_dx(x, y + delta) d_phi_dxy = calc_util.d_phi_dxy(x, y) d_phi_dxy_num = (d_phi_dx_delta_y - d_phi_dx) / delta npt.assert_almost_equal(d_phi_dxy_num, d_phi_dxy, decimal=1)
def test_d_phi_dx(self): x, y = np.array([1., 0., -1.]), np.array([1., 1., -1.]) dx, dy = 0.0001, 0.0001 r, phi = param_util.cart2polar(x, y, center_x=0, center_y=0) d_phi_dx = calc_util.d_phi_dx(x, y) d_phi_dy = calc_util.d_phi_dy(x, y) r_dx, phi_dx = param_util.cart2polar(x + dx, y, center_x=0, center_y=0) r_dy, phi_dy = param_util.cart2polar(x, y + dy, center_x=0, center_y=0) d_phi_dx_num = (phi_dx - phi) / dx d_phi_dy_num = (phi_dy - phi) / dy npt.assert_almost_equal(d_phi_dx, d_phi_dx_num, decimal=4) npt.assert_almost_equal(d_phi_dy, d_phi_dy_num, decimal=4)
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