facedetection - catch warning if doesnt tend towards a fit
This commit is contained in:
@@ -2,7 +2,8 @@ import json
|
||||
import time
|
||||
from typing import Tuple, Dict, List, Optional
|
||||
import numpy as np
|
||||
from scipy.optimize import curve_fit
|
||||
from scipy.optimize import curve_fit, OptimizeWarning
|
||||
import warnings
|
||||
import statistics
|
||||
import math
|
||||
from aare.common.logger_config import setup_logger
|
||||
@@ -86,7 +87,11 @@ def fit_cosine(samples: List[Tuple[float, float]]) -> dict:
|
||||
bounds = ([-np.inf, 0.0, -math.pi, -np.inf], [np.inf, B_max, math.pi, np.inf])
|
||||
|
||||
try:
|
||||
popt, _ = curve_fit(cos_model, degs, ys, p0=[A0, B0, phi0, C0], bounds=bounds, maxfev=10000)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter("always", OptimizeWarning)
|
||||
popt, _ = curve_fit(cos_model, degs, ys, p0=[A0, B0, phi0, C0], bounds=bounds, maxfev=10000)
|
||||
if w:
|
||||
logger.debug(f"curve_fit OptimizeWarning: {w[-1].message}")
|
||||
logger.info(f"fit cosine: {popt}")
|
||||
A, B, phi, C = map(float, popt)
|
||||
B = max(0.0, B)
|
||||
|
||||
Reference in New Issue
Block a user