Index

QuadFit fit_quadratic(listof TrialPosition trials)

Fit a quadratic to the fluxes measured at various trial offset positions.

Arguments:
listof TrialPosition trials
The list of trial offset positions, their fluxes and the uncertainties of those fluxes.

Example:

  # Set up a list of trial focus position offsets, with initially zeroed fluxes

  listof TrialPosition trials = {
    {-10.0,  0, 0},                  # A -10mm focus position offset.
    { -5.0,  0, 0},                  # A  -5mm focus position offset.
    {  0.0,  0, 0},                  # A   0mm focus position offset.
    {  5.0,  0, 0},                  # A  +5mm focus position offset.
    { 10.0,  0, 0}		     # A +10mm focus position offset.
  }

  # Start moving to a suitable point source.

  track saturn
  until $acquired(source)                  # Wait to acquire the source.

  # Go to the focus position indicated by the focus curve.

  focus
  until $acquired(focus)

  # Lookup the acquired focus position.

  Double origin = $focus_position()

  # Measure the received power at each of the above trial focus
  # position offsets from the initial focus position.

  foreach(TrialPosition p) $trials {
    set_focus $origin + $p.offset    # Move to the latest focus position.
    until $acquired(focus)           # Wait to acquire the focus position.
    request_flux kuband, ant, 0:0:10 # Ask for a 10s integrated flux.
    until $acquired(flux)            # Wait for the flux to be returned.
    p.flux = $requested_flux().flux  # Record the flux in the list.
    p.sdev = $requested_flux().sdev  # Record the uncertainty in the list.
  }

  # Attempt to fit a quadratic curve through the above offset fluxes.

  QuadFit fit = $fit_quadratic($trials)

  # Display the results.

  print "Fit: Origin position of fit=", $origin, "mm rchisq=", $fit.rchisq
  print "Fit: a=", $fit.a, " b=", $fit.b, " c=", $fit.c
  if($fit.c < 0) {
    print "Fit: Focus maximum of ", $fit.mid_flux, "counts at ",
          $fit.mid_offset + $origin, " mm"
  } else if($fit.c > 0) {
    print "Fit: Focus minimum of ", $fit.mid_flux, "counts at ",
          $fit.mid_offset + $origin, " mm"
  } else {
    print "Fit: No focus minimum or maximum found."
  }
TBD.

Context:
This function is designed to be a building block within focusing procedures.

Martin Shepherd (24-Jul-2010)