@@ -1317,6 +1317,9 @@ def focus_from_scale(self, scale, scale_err, mode, rotator, hdr=None):
13171317
13181318 raw .rotate (angle = - (self .rotation - rotator ))
13191319 zv = raw - self .reference_aberrations (mode , hdr = hdr )
1320+ # only defocus is measured. the subtraction leaves the reference's other terms (sign-flipped) and ~0 tilts,
1321+ # which would read as measured aberrations, so keep Z04 alone.
1322+ zv = ZernikeVector (Z04 = zv ["Z04" ].value , errorbars = {"Z04" : zv .errorbars ["Z04" ].value }, units = zv .units )
13201323
13211324 focus = self .m2_gain_periodicity * self .calculate_focus (zv .copy ())
13221325 fmax = self .periodicity_focus_max .to_value (u .um )
@@ -1349,8 +1352,18 @@ def periodicity_focus(self, data, mode, center, rotator, hdr=None, plot=True):
13491352 grid ["center" ] = tuple (center )
13501353
13511354 zv , focus = self .focus_from_scale (grid ["scale" ], grid ["scale_err" ], mode , rotator , hdr = hdr )
1355+ # the Z04 error bar through the same gains as the correction, before the (1 - frac_error) down-weighting
1356+ zd = zv .copy ()
1357+ zd .denormalize ()
1358+ focus_err = np .abs (self .m2_gain_periodicity * self .m2_gain * zd .errorbars ["Z04" ] / self .secondary .focus_trans )
13521359 fig = plot_periodicity (meas ) if plot else None
1353- return {"grid" : grid , "zernike" : zv , "pending_focus" : focus , "figure" : fig }
1360+ return {
1361+ "grid" : grid ,
1362+ "zernike" : zv ,
1363+ "pending_focus" : focus ,
1364+ "focus_err" : focus_err .to (u .um ).round (2 ),
1365+ "figure" : fig ,
1366+ }
13541367
13551368 def process_image (self , fitsfile ):
13561369 """
@@ -1505,15 +1518,17 @@ def measure_slopes(
15051518 fallback = None
15061519 if fallback is not None :
15071520 grid = fallback ["grid" ]
1508- log .warning (
1509- f"Using focus-only periodicity fallback: scale = { grid ['scale' ]:.5f} +/- "
1510- f"{ grid ['scale_err' ]:.5f} , SNR = { grid ['snr' ].min ():.0f} , focus = { fallback ['pending_focus' ]} "
1511- )
1521+ # one value per line so the focus correction isn't lost off the right edge of a log window
1522+ log .warning ("Using focus-only periodicity fallback:" )
1523+ log .warning (f" grid scale = { grid ['scale' ]:.5f} +/- { grid ['scale_err' ]:.5f} " )
1524+ log .warning (f" SNR = { grid ['snr' ].min ():.0f} " )
1525+ log .warning (f" focus = { fallback ['pending_focus' ]} +/- { fallback ['focus_err' ]} " )
15121526 results ["focus_only" ] = True
15131527 results ["method" ] = "periodicity"
15141528 results ["grid" ] = grid
15151529 results ["zernike" ] = fallback ["zernike" ]
15161530 results ["pending_focus" ] = fallback ["pending_focus" ]
1531+ results ["focus_err" ] = fallback ["focus_err" ]
15171532 results ["figures" ]["periodicity" ] = fallback ["figure" ]
15181533 return results
15191534 except Exception as e :
0 commit comments