Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common/lib/deflectometry: Test docs #197

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading