diff --git a/opencsp/common/lib/deflectometry/ParamsSlopeSolver.py b/opencsp/common/lib/deflectometry/ParamsSlopeSolver.py index f75e8512..625a274f 100644 --- a/opencsp/common/lib/deflectometry/ParamsSlopeSolver.py +++ b/opencsp/common/lib/deflectometry/ParamsSlopeSolver.py @@ -2,4 +2,6 @@ class ParamsSlopeSolver(ABC): + """Abstract ParamsSlopeSolver class""" + pass diff --git a/opencsp/common/lib/deflectometry/Surface2DParabolic.py b/opencsp/common/lib/deflectometry/Surface2DParabolic.py index 778a743d..4786f92c 100644 --- a/opencsp/common/lib/deflectometry/Surface2DParabolic.py +++ b/opencsp/common/lib/deflectometry/Surface2DParabolic.py @@ -9,6 +9,8 @@ class Surface2DParabolic(Surface2DAbstract): + """Representation of 2D fit parabolic surface.""" + def __init__(self, initial_focal_lengths_xy: tuple[float, float], robust_least_squares: bool, downsample: int): """ Representation of 2D fit parabolic surface. diff --git a/opencsp/common/lib/deflectometry/Surface2DPlano.py b/opencsp/common/lib/deflectometry/Surface2DPlano.py index 000c9709..cbd10e19 100644 --- a/opencsp/common/lib/deflectometry/Surface2DPlano.py +++ b/opencsp/common/lib/deflectometry/Surface2DPlano.py @@ -9,6 +9,8 @@ class Surface2DPlano(Surface2DAbstract): + """Representation of 2D plano surface.""" + def __init__(self, robust_least_squares: bool, downsample: int): """ Representation of 2D plano surface. diff --git a/opencsp/common/lib/deflectometry/slope_fitting_2d.py b/opencsp/common/lib/deflectometry/slope_fitting_2d.py index 7197a902..cb389248 100644 --- a/opencsp/common/lib/deflectometry/slope_fitting_2d.py +++ b/opencsp/common/lib/deflectometry/slope_fitting_2d.py @@ -74,6 +74,36 @@ def calc_slopes(v_surf_int_pts_optic: Vxyz, v_optic_cam_optic: Vxyz, v_screen_po def fit_slope_robust_ls( slope_fit_poly_order: int, slope: np.ndarray, weights: np.ndarray, v_surf_int_pts_optic: Vxyz ) -> np.ndarray: + """ + Fits a slope using robust least squares fitting with weighted residuals. + + This function performs a robust least squares fit to the provided slope data, + adjusting weights iteratively based on the residuals to minimize the influence + of outliers. + + Parameters + ---------- + slope_fit_poly_order : int + The order of the polynomial used for fitting the slope. + slope : np.ndarray + A 1D array of slope measurements. + weights : np.ndarray + A 1D array of weights corresponding to the slope measurements. + v_surf_int_pts_optic : Vxyz + An object containing the x and y coordinates of the surface intersection points. + + Returns + ------- + np.ndarray + The coefficients of the fitted slope. + + Raises + ------ + ValueError + If the lengths of the input arrays do not match or if the fitting process does not converge + within the maximum number of iterations. + """ + # "ChatGPT 4o" assisted with generating this docstring. # Check lengths match if slope.size != weights.size or slope.size != len(v_surf_int_pts_optic): raise ValueError( @@ -129,9 +159,26 @@ def fit_slope_robust_ls( def fit_slope_ls(slope_fit_poly_order: int, slope: np.ndarray, v_surf_int_pts_optic: Vxyz) -> np.ndarray: """ - Returns best fit slope coefficients to measured slope points using least - squared fitting. + Fits a slope using ordinary least squares fitting. + + This function computes the best fit slope coefficients for the provided slope data + using the least squares method. + + Parameters + ---------- + slope_fit_poly_order : int + The order of the polynomial used for fitting the slope. + slope : np.ndarray + A 1D array of slope measurements. + v_surf_int_pts_optic : Vxyz + An object containing the x and y coordinates of the surface intersection points. + + Returns + ------- + np.ndarray + The coefficients of the fitted slope. """ + # "ChatGPT 4o" assisted with generating this docstring. # Create terms terms = poly_terms(slope_fit_poly_order, v_surf_int_pts_optic.x, v_surf_int_pts_optic.y)