Skip to content

Commit

Permalink
opencsp/common/lib/deflectormetry: test docs
Browse files Browse the repository at this point in the history
  • Loading branch information
e10harvey committed Nov 11, 2024
1 parent 3388720 commit f118981
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 3 deletions.
2 changes: 2 additions & 0 deletions opencsp/common/lib/deflectometry/ParamsSlopeSolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@


class ParamsSlopeSolver(ABC):
"""Abstract ParamsSlopeSolver class"""

pass
2 changes: 2 additions & 0 deletions opencsp/common/lib/deflectometry/Surface2DParabolic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions opencsp/common/lib/deflectometry/Surface2DPlano.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
51 changes: 49 additions & 2 deletions opencsp/common/lib/deflectometry/slope_fitting_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)

Expand Down
24 changes: 23 additions & 1 deletion opencsp/test/test_DocStringsExist.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
import opencsp.common.lib.camera.ImageAcquisition_MSMF as ImageAcquisition_MSMF
import opencsp.common.lib.camera.UCamera as UCamera
import opencsp.common.lib.cv.SpotAnalysis as SpotAnalysis
import opencsp.common.lib.deflectometry.ImageProjectionSetupGUI as ImageProjectionSetupGUI
import opencsp.common.lib.deflectometry.ParamsSlopeSolver as ParamsSlopeSolver
import opencsp.common.lib.deflectometry.ParamsSlopeSolverAbstract as ParamsSlopeSolverAbstract
import opencsp.common.lib.deflectometry.ParamsSlopeSolverParaboloid as ParamsSlopeSolverParaboloid
import opencsp.common.lib.deflectometry.ParamsSlopeSolverPlano as ParamsSlopeSolverPlano


def test_docstrings_exist_for_methods():
Expand Down Expand Up @@ -147,7 +152,24 @@ def test_docstrings_exist_for_methods():
opencsp.common.lib.cv.image_reshapers,
]

common_class_list = camera_class_list + csp_class_list + cv_class_list
deflectometry_class_list = [
opencsp.common.lib.deflectometry.CalibrationCameraPosition,
opencsp.common.lib.deflectometry.ImageProjection,
opencsp.common.lib.deflectometry.ImageProjectionSetupGUI,
opencsp.common.lib.deflectometry.ParamsSlopeSolver,
opencsp.common.lib.deflectometry.ParamsSlopeSolverAbstract,
opencsp.common.lib.deflectometry.ParamsSlopeSolverParaboloid,
opencsp.common.lib.deflectometry.ParamsSlopeSolverPlano,
opencsp.common.lib.deflectometry.SlopeSolver,
opencsp.common.lib.deflectometry.SlopeSolverData,
opencsp.common.lib.deflectometry.SlopeSolverDataDebug,
opencsp.common.lib.deflectometry.Surface2DAbstract,
opencsp.common.lib.deflectometry.Surface2DParabolic,
opencsp.common.lib.deflectometry.Surface2DPlano,
opencsp.common.lib.deflectometry.slope_fitting_2d,
]

common_class_list = camera_class_list + csp_class_list + cv_class_list + deflectometry_class_list

class_list = app_class_list + common_class_list

Expand Down

0 comments on commit f118981

Please sign in to comment.