check background
This commit is contained in:
@ -170,6 +170,30 @@ def resolve_visible_aux_curves(aux_curves: SweepAuxCurves, enabled: bool) -> Swe
|
||||
return aux_1_arr, aux_2_arr
|
||||
|
||||
|
||||
def compute_background_subtracted_bscan_levels(
|
||||
disp_fft_lin: np.ndarray,
|
||||
disp_fft: np.ndarray,
|
||||
) -> Optional[Tuple[float, float]]:
|
||||
"""Pick robust color levels from positive residuals after background subtraction."""
|
||||
if disp_fft_lin.size == 0 or disp_fft.size == 0:
|
||||
return None
|
||||
positive_mask = np.isfinite(disp_fft_lin) & (disp_fft_lin > 0.0)
|
||||
if np.count_nonzero(positive_mask) < 2:
|
||||
return None
|
||||
vals = np.asarray(disp_fft[positive_mask], dtype=np.float64).reshape(-1)
|
||||
vals = vals[np.isfinite(vals)]
|
||||
if vals.size < 2:
|
||||
return None
|
||||
try:
|
||||
vmin = float(np.nanpercentile(vals, 15.0))
|
||||
vmax = float(np.nanpercentile(vals, 99.7))
|
||||
except Exception:
|
||||
return None
|
||||
if not (np.isfinite(vmin) and np.isfinite(vmax)) or vmin >= vmax:
|
||||
return None
|
||||
return (vmin, vmax)
|
||||
|
||||
|
||||
def run_pyqtgraph(args) -> None:
|
||||
"""Start the PyQtGraph GUI."""
|
||||
peak_calibrate_mode = bool(getattr(args, "calibrate", False))
|
||||
@ -1330,15 +1354,8 @@ def run_pyqtgraph(args) -> None:
|
||||
|
||||
levels = None
|
||||
if active_background is not None:
|
||||
try:
|
||||
p5 = float(np.nanpercentile(disp_fft, 5))
|
||||
p95 = float(np.nanpercentile(disp_fft, 95))
|
||||
span = max(abs(p5), abs(p95))
|
||||
if np.isfinite(span) and span > 0.0:
|
||||
levels = (-span, span)
|
||||
except Exception:
|
||||
levels = None
|
||||
else:
|
||||
levels = compute_background_subtracted_bscan_levels(disp_fft_lin, disp_fft)
|
||||
if levels is None:
|
||||
try:
|
||||
mean_spec = np.nanmean(disp_fft, axis=1)
|
||||
vmin_v = float(np.nanmin(mean_spec))
|
||||
|
||||
Reference in New Issue
Block a user