Shape gradients

Analytical gradients of the chi-squared with respect to shape parameters (radii, inclination, position angle). Enables joint optimization of the surface map and stellar geometry.

Rotation matrix

FunctionDescription
rotation_matrix(psi, inc, PA)3x3 rotation matrix R(psi, inc, PA), all angles in radians. Same as rot_vertex in geometry.jl
dR_dinc(psi, inc, PA)Derivative of R w.r.t. inclination
dR_dPA(psi, inc, PA)Derivative of R w.r.t. position angle

Convention: xyz = su * R (right-multiply), where su are the scaled unit-sphere vertices.

Rapid rotator derivative

FunctionDescription
f_rapid_rot_and_deriv(x)Returns (f(x), f'(x)) where f(x) = 3*cos((pi+acos(x))/3)/x. Near x=0, returns (1, 0)

Projected vertices and derivatives

FunctionDescription
projected_vertices_and_derivs(tessels, star_params, t; nparams)Compute projected vertices and their analytical derivatives w.r.t. shape parameters

Returns (proj_west, proj_north, dproj_west_dtheta, dproj_north_dtheta, normals_z, dnz_dtheta):

OutputShapeDescription
proj_west, proj_north(npix, 4)Projected quad vertex coordinates
dproj_west_dtheta, dproj_north_dtheta(npix, 4, nparams)Vertex derivatives w.r.t. shape parameters
normals_z(npix,)Normalized z-component of face normals
dnz_dtheta(npix, nparams)Normal z-component derivatives

The derivative computation is surface-type-specific:

SurfaceParameterDerivative
Sphereradiusd(su)/d(r) = unit_xyz
Ellipsoidrx, ry, rzd(su_j)/d(r_j) = unit_xyz_j (axis-aligned)
Rapid rotatorrpoled(su)/d(rpole) = su / rpole
Rapid rotatoromegad(r)/d(omega) = rpole * f'(omega*sin(theta)) * sin(theta)
Allincd(xyz)/d(inc) = su * dR_dinc
AllPAd(xyz)/d(PA) = su * dR_dPA

Shape chi2 + gradient

FunctionDescription
shape_chi2_fg!(grad_θ, grad_xmap, xmap, θ, data, tessels, star_params_base, tepochs; κ, verbose)Chi2 and gradients w.r.t. both shape and map parameters

The gradient chain has three components:

  1. Vertex positions: d(chi2)/d(theta) = sum_p sum_v (d(chi2)/d(proj_west) * d(proj_west)/d(theta) + ...)
  2. Flux normalization: shoelace area derivatives for the flux correction term
  3. Soft visibility: d(chi2)/d(theta) += d(chi2)/d(w) * d(sigmoid)/d(kappa*nz) * kappa * d(nz)/d(theta)

Shape parameter vector layout

Surface typetheta vectornparams
0 (Sphere)[radius, inclination, PA]3
1 (Ellipsoid)[rx, ry, rz, inclination, PA]5
2 (Rapid Rotator)[rpole, omega, inclination, PA]4

Inclination and PA are in degrees (converted internally).

Joint reconstruction

FunctionDescription
joint_reconstruct_oi(xmap, θ, data, tessels, star_params, tepochs; kwargs...)Alternating optimization of map and shape parameters

Keywords

KeywordDefaultDescription
maxiter_xmap200Max iterations for map optimization
maxiter_θ50Max iterations for shape optimization
nouter5Number of alternating cycles
reg_weight1e-5TV2 regularization weight for map step
κ50.0Sigmoid sharpness for soft visibility
θ_lowernothingLower bounds on shape parameters
θ_uppernothingUpper bounds on shape parameters
verbosetruePrint diagnostics