stella.adapter
Class FocussingMoments

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by stella.adapter.AdapterUnit
                  extended by stella.adapter.FocussingUnit
                      extended by stella.adapter.FocussingMoments
All Implemented Interfaces:
Cloneable, Abortable, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying
Direct Known Subclasses:
LinearPrimeFocus, MirrorFocus

public abstract class FocussingMoments
extends FocussingUnit
implements Abortable

This class uses maximization of ADU moments to obtain a best focus. Its mechanism of offsetting the focus are unspecified, but a CCD must be present in order to obtain images from which ADU statistics can be drawn. Additionally, a method must be present that allows a crude estimate of the focus position. This can be done with a temperature model, but any other mechanism is allowed, as long as it adheres to crudeFocus().


Nested Class Summary
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private  boolean abort
          Abort ongoing focus sequence.
private static double DEFA4ERROR
          Default A4 error (2011-10-14).
private static double DEFA4SLOPE
          Default A4 slope (2011-10-14).
private static Dimension DEFADUSIZE
          The default size around the bright spot.
private static Dimension DEFBLOBSIZE
          The default blob size.
private static boolean DEFDOSAVE
          If true we save the indivdual images during focus.
private static boolean DEFDOSEARCH
          If temperature model is accurate enough, we can skip the search.
private static double DEFERRORZERNIKE
          Default always do sequence.
private static double DEFEXPOSEFOCUS
          The default S/N on acquire.
private static Dimension DEFFOCUSBINNING
          The default binning on acquire.
private static int DEFFOCUSORDER
          The moment during fine focus.
private static double DEFHIGHSKYSIGMA
          Per default we do not do ADU rejection, thus this is zero.
private static double DEFLOWSKYSIGMA
          Per default we do not do ADU rejection, thus this is zero.
private static boolean DEFMEDIANSKY
          Default we use median for sky-level determination.
private static String DEFMOMENTS
          Default focus temperature parameter name.
private static int DEFSEARCHORDER
          The moment during coarse focus.
private static int DEFSEARCHSTEPS
          Default half-number of search steps.
private static int DEFSKYFRAME
          The defautl sky frame size.
private static double DEFZERNIKESTEP
          Default no extra Zernike images.
private static double DEFZEXPOSE
          Default no extra increase in exposure time on Zernikes.
private  long expt
          The exposure time in ms calculated once per focus sequence.
static String EXTRAFOCAL
          Extension for extrafocal image in Zernike coefficient determination.
static String INTRAFOCAL
          Extension for intrafocal image in Zernike coefficient determination.
static String KEY_A4ERROR
          This is the error estimate for A4 slope.
static String KEY_A4SLOPE
          This is the slope of A4 versus steps.
static String KEY_ADUSIZE
          The box to scan for A4.
static String KEY_BLOBSIZE
          The default blob size.
static String KEY_DOSAVE
          Save the focus sequence images.
static String KEY_DOSEARCH
          Once the temperature model is accurate enough, we do not search.
static String KEY_ERRORZERNIKE
          If the zernike error is below this, we spare the sequence.
static String KEY_EXPOSEFOCUS
          The S/N for focus.
static String KEY_FOCUSBINNING
          The binnning for focus images.
static String KEY_FOCUSFRAME
          The frame for focus images.
static String KEY_FOCUSOFFSET
          The offset from the optimal focus for image 1&2.
static String KEY_FOCUSORDER
          The moment during fine focus.
static String KEY_HIGHSKYSIGMA
          If greather than zero, the high bound sigma for background rejection.
static String KEY_LOWSKYSIGMA
          If greather than zero, the low-bound sigma for background rejection.
static String KEY_MAXFOCUSEXPOSE
          If the exposure time required for moments exceed this, do T only.
static String KEY_MEDIANSKY
          If true, use median in background frame.
static String KEY_MOMENTS
          The name of the fits moments to use.
static String KEY_MOMENTSFRAME
          The frame for focus moments, smaller than image frame.
static String KEY_SEARCHOFFSET
          The step width, if focus model is bad.
static String KEY_SEARCHORDER
          The moment during coarse focus.
static String KEY_SEARCHSTEPS
          The number of search steps in either direction.
static String KEY_SKYFRAME
          The default sky frame size.
static String KEY_ZERNIKESTEP
          If this multiplier to searchsteps is greater 0, we do Zernikes.
static String KEY_ZEXPOSE
          Multiplier to nominal exposure time for extra/intra focal Zernike.
private  FitsMoments moments
          The fits-moments parameter.
static String SEARCH
          If the mode quals search, we always do an extensive search.
 
Fields inherited from class stella.adapter.FocussingUnit
increase
 
Fields inherited from class stella.adapter.AdapterUnit
ACQUIRETYPE, GUIDERTYPE, PYRAMIDTYPE
 
Fields inherited from class util.PropertyBundles
KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_RESOURCEBUNDLES
 
Fields inherited from class util.PropertyResources
KEY_NOINITONCREATE, localurl, locate, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_URL, urlset
 
Fields inherited from class util.PropertyContainer
KEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Fields inherited from interface util.PropertySupplying
CONFIG, KEY_CLASS
 
Constructor Summary
protected FocussingMoments(Map<String,String> prop)
          Constructor chaining.
 
Method Summary
private  double coarseFocus()
          In the coarse focus, we do a temperature model, even if very inaccurate, then procced to in and out with #KEY_SEARCH step, doing a image on the small frame along the offsets.
protected abstract  double crudeFocus()
          This method makes a first crude focus and returns the current focus position in arbitrary units, which my be millimeters or steps or even non-linear units.
protected  ErrorEvent doFocusTask(String mode)
          Task of this unit is to auto focus after a successful acquire.
private  double doZernikes(double zernike, double pos0)
          Does Zernike focussing using A4.
private  double getA4Focus(nom.tam.fits.Fits extra, double fext, nom.tam.fits.Fits intra, double fint)
          From an extra and an intra focal image, done at considerable offset from the estimated focus, we calculate the second image moment and derive the focus with the pre-measured slope of A4 vs.
private  double getA4Focus(nom.tam.fits.Fits extra, double fext, nom.tam.fits.Fits intra, double fint, int use)
          From an extra and an intra focal image, done at considerable offset from the estimated focus, we calculate the second image moment and derive the focus with the pre-measured slope of A4 vs.
abstract  double getMaximumFocus()
          Returns the maximum focus position to avoid focus underruns.
abstract  double getMinimumFocus()
          Returns the minimum focus position to avoid focus underruns.
private  Double getMomentAt(double step, int order, String fext)
          We position the linear stage at the indicated step, take an image with the CCD camera on the #KEY_FOCSUFRAME and calculate the moments of this image.
protected  boolean isValid()
          We are valid only if we have the linear drive and the moments.
private  double scanA4(nom.tam.fits.Fits ff, int use)
          We calculate the A4 parameter from second image moments following Equation 5 in PASP118, 1165, but without pixel scaling.
 void setAbort(boolean to)
          Allows the sub-device to abort as soone as possible.
protected  void setMaster(AdapterMaster chef)
          From the master, we query the driver for the linear stage and grab the temperature and the fits moments parameter.
private  nom.tam.fits.Fits takeSingleImage(CcdDriver ccd, long ms, Dimension bin, String uu)
          Takes a single image, stores it, resets the driver.
 
Methods inherited from class stella.adapter.FocussingUnit
setFocus, setFocusOffset, setIncrease
 
Methods inherited from class stella.adapter.AdapterUnit
doUnitTask, getGuider, getMaster, getTelescope, getUnitType, isManual, resetUnit, setGuider, setManual, setTelescope
 
Methods inherited from class util.PropertyBundles
clone, getLocalized, getLocalized, getLocalizedString, getLocalizedString, loadResource
 
Methods inherited from class util.PropertyResources
createFrom, createFrom, createFrom, getApplet, getAsResources, getLocalClassLoader, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, init, keyCreate, keyCreate, reload, setApplet
 
Methods inherited from class util.PropertyContainer
augment, augment, augment, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, isNew, parseObject, reload, removeProperty, rescanned, setObject, setProperties, setProperty, stringProperties, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface util.ResourceSupplying
getResource, getResourceAsStream, getResources
 
Methods inherited from interface util.PropertySupplying
defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, parseObject, removeProperty, setObject, setProperty, stringProperties
 
Methods inherited from interface util.Initializable
init
 

Field Detail

EXTRAFOCAL

public static final String EXTRAFOCAL
Extension for extrafocal image in Zernike coefficient determination.

See Also:
Constant Field Values

INTRAFOCAL

public static final String INTRAFOCAL
Extension for intrafocal image in Zernike coefficient determination.

See Also:
Constant Field Values

SEARCH

public static final String SEARCH
If the mode quals search, we always do an extensive search.

See Also:
Constant Field Values

KEY_MOMENTS

public static final String KEY_MOMENTS
The name of the fits moments to use.

See Also:
Constant Field Values

KEY_FOCUSOFFSET

public static final String KEY_FOCUSOFFSET
The offset from the optimal focus for image 1&2.

See Also:
Constant Field Values

KEY_FOCUSORDER

public static final String KEY_FOCUSORDER
The moment during fine focus.

See Also:
Constant Field Values

KEY_SEARCHSTEPS

public static final String KEY_SEARCHSTEPS
The number of search steps in either direction.

See Also:
Constant Field Values

KEY_SEARCHOFFSET

public static final String KEY_SEARCHOFFSET
The step width, if focus model is bad.

See Also:
Constant Field Values

KEY_SEARCHORDER

public static final String KEY_SEARCHORDER
The moment during coarse focus.

See Also:
Constant Field Values

KEY_DOSEARCH

public static final String KEY_DOSEARCH
Once the temperature model is accurate enough, we do not search.

See Also:
Constant Field Values

KEY_DOSAVE

public static final String KEY_DOSAVE
Save the focus sequence images. Always done with String-type ccds.

See Also:
Constant Field Values

KEY_FOCUSFRAME

public static final String KEY_FOCUSFRAME
The frame for focus images.

See Also:
Constant Field Values

KEY_MOMENTSFRAME

public static final String KEY_MOMENTSFRAME
The frame for focus moments, smaller than image frame.

See Also:
Constant Field Values

KEY_FOCUSBINNING

public static final String KEY_FOCUSBINNING
The binnning for focus images.

See Also:
Constant Field Values

KEY_EXPOSEFOCUS

public static final String KEY_EXPOSEFOCUS
The S/N for focus.

See Also:
Constant Field Values

KEY_MAXFOCUSEXPOSE

public static final String KEY_MAXFOCUSEXPOSE
If the exposure time required for moments exceed this, do T only.

See Also:
Constant Field Values

KEY_ZERNIKESTEP

public static final String KEY_ZERNIKESTEP
If this multiplier to searchsteps is greater 0, we do Zernikes.

See Also:
Constant Field Values

KEY_ZEXPOSE

public static final String KEY_ZEXPOSE
Multiplier to nominal exposure time for extra/intra focal Zernike.

See Also:
Constant Field Values

KEY_A4SLOPE

public static final String KEY_A4SLOPE
This is the slope of A4 versus steps.

See Also:
Constant Field Values

KEY_A4ERROR

public static final String KEY_A4ERROR
This is the error estimate for A4 slope.

See Also:
Constant Field Values

KEY_BLOBSIZE

public static final String KEY_BLOBSIZE
The default blob size.

See Also:
Constant Field Values

KEY_ADUSIZE

public static final String KEY_ADUSIZE
The box to scan for A4.

See Also:
Constant Field Values

KEY_SKYFRAME

public static final String KEY_SKYFRAME
The default sky frame size.

See Also:
Constant Field Values

KEY_MEDIANSKY

public static final String KEY_MEDIANSKY
If true, use median in background frame.

See Also:
Constant Field Values

KEY_LOWSKYSIGMA

public static final String KEY_LOWSKYSIGMA
If greather than zero, the low-bound sigma for background rejection.

See Also:
Constant Field Values

KEY_HIGHSKYSIGMA

public static final String KEY_HIGHSKYSIGMA
If greather than zero, the high bound sigma for background rejection.

See Also:
Constant Field Values

KEY_ERRORZERNIKE

public static final String KEY_ERRORZERNIKE
If the zernike error is below this, we spare the sequence.

See Also:
Constant Field Values

DEFMOMENTS

private static final String DEFMOMENTS
Default focus temperature parameter name.

See Also:
Constant Field Values

DEFSEARCHSTEPS

private static final int DEFSEARCHSTEPS
Default half-number of search steps.

See Also:
Constant Field Values

DEFDOSEARCH

private static final boolean DEFDOSEARCH
If temperature model is accurate enough, we can skip the search.

See Also:
Constant Field Values

DEFDOSAVE

private static final boolean DEFDOSAVE
If true we save the indivdual images during focus.

See Also:
Constant Field Values

DEFEXPOSEFOCUS

private static final double DEFEXPOSEFOCUS
The default S/N on acquire.

See Also:
Constant Field Values

DEFSEARCHORDER

private static final int DEFSEARCHORDER
The moment during coarse focus.

See Also:
Constant Field Values

DEFFOCUSORDER

private static final int DEFFOCUSORDER
The moment during fine focus.

See Also:
Constant Field Values

DEFFOCUSBINNING

private static final Dimension DEFFOCUSBINNING
The default binning on acquire.


DEFZERNIKESTEP

private static final double DEFZERNIKESTEP
Default no extra Zernike images.

See Also:
Constant Field Values

DEFZEXPOSE

private static final double DEFZEXPOSE
Default no extra increase in exposure time on Zernikes.

See Also:
Constant Field Values

DEFA4SLOPE

private static final double DEFA4SLOPE
Default A4 slope (2011-10-14).

See Also:
Constant Field Values

DEFA4ERROR

private static final double DEFA4ERROR
Default A4 error (2011-10-14).

See Also:
Constant Field Values

DEFBLOBSIZE

private static final Dimension DEFBLOBSIZE
The default blob size.


DEFADUSIZE

private static final Dimension DEFADUSIZE
The default size around the bright spot.


DEFSKYFRAME

private static final int DEFSKYFRAME
The defautl sky frame size.

See Also:
Constant Field Values

DEFMEDIANSKY

private static final boolean DEFMEDIANSKY
Default we use median for sky-level determination.

See Also:
Constant Field Values

DEFLOWSKYSIGMA

private static final double DEFLOWSKYSIGMA
Per default we do not do ADU rejection, thus this is zero.

See Also:
Constant Field Values

DEFHIGHSKYSIGMA

private static final double DEFHIGHSKYSIGMA
Per default we do not do ADU rejection, thus this is zero.

See Also:
Constant Field Values

DEFERRORZERNIKE

private static final double DEFERRORZERNIKE
Default always do sequence.

See Also:
Constant Field Values

moments

private FitsMoments moments
The fits-moments parameter.


expt

private long expt
The exposure time in ms calculated once per focus sequence.


abort

private boolean abort
Abort ongoing focus sequence.

Constructor Detail

FocussingMoments

protected FocussingMoments(Map<String,String> prop)
Constructor chaining.

Method Detail

getMinimumFocus

public abstract double getMinimumFocus()
Returns the minimum focus position to avoid focus underruns.


getMaximumFocus

public abstract double getMaximumFocus()
Returns the maximum focus position to avoid focus underruns.


crudeFocus

protected abstract double crudeFocus()
This method makes a first crude focus and returns the current focus position in arbitrary units, which my be millimeters or steps or even non-linear units.


setMaster

protected void setMaster(AdapterMaster chef)
From the master, we query the driver for the linear stage and grab the temperature and the fits moments parameter.

Overrides:
setMaster in class AdapterUnit

isValid

protected boolean isValid()
We are valid only if we have the linear drive and the moments.

Overrides:
isValid in class AdapterUnit

setAbort

public void setAbort(boolean to)
Description copied from interface: Abortable
Allows the sub-device to abort as soone as possible. Does not necessarily block until the sub-device is ready again, but must ensure that the sub-device is ready to proceed with a new task, or, on starting the new task, is not doing the last task. As an example: On a focus sequence, an abort should mean that furhter stepping through the sequences is canceled. If the same CCD is used by an acquire task, a synchronization on the CCD fulfills the requirement above.

Specified by:
setAbort in interface Abortable

doFocusTask

protected ErrorEvent doFocusTask(String mode)
Task of this unit is to auto focus after a successful acquire. This is done in two steps


coarseFocus

private double coarseFocus()
In the coarse focus, we do a temperature model, even if very inaccurate, then procced to in and out with #KEY_SEARCH step, doing a image on the small frame along the offsets. For each image, the value of the KEY_SEARCHORDER moment is recorded, in this list the maximum is found. From this maximum and from its neighbouring values, a parabola is fit through this three points, the maximum is the new focus, which we also set. If the maximum value in the original sequence is at the edge, we return a value slightly inside, depending on the two inner points to the maximum.

Returns:
True on success.

doZernikes

private double doZernikes(double zernike,
                          double pos0)
Does Zernike focussing using A4.


getA4Focus

private double getA4Focus(nom.tam.fits.Fits extra,
                          double fext,
                          nom.tam.fits.Fits intra,
                          double fint)
From an extra and an intra focal image, done at considerable offset from the estimated focus, we calculate the second image moment and derive the focus with the pre-measured slope of A4 vs. focus. The error of this estimate is proportional to the missjudge of the thermal focus position model.


getA4Focus

private double getA4Focus(nom.tam.fits.Fits extra,
                          double fext,
                          nom.tam.fits.Fits intra,
                          double fint,
                          int use)
From an extra and an intra focal image, done at considerable offset from the estimated focus, we calculate the second image moment and derive the focus with the pre-measured slope of A4 vs. focus. The error of this estimate is proportional to the missjudge of the thermal focus position model.

Parameters:
use - The extension to use.

scanA4

private double scanA4(nom.tam.fits.Fits ff,
                      int use)
               throws nom.tam.fits.FitsException,
                      IOException
We calculate the A4 parameter from second image moments following Equation 5 in PASP118, 1165, but without pixel scaling.
       A4 = sqrt(Mx+My), with
Mx,y = Σ(x,y_ij-x,y_c)^2*ADU_ij/ΣADU_ij
Centered on the brightest pixel blob in the image, we use a rectangle of size KEY_ADUSIZE and around that a #SKYFRAME thick frame for background determination. The background is either the median or the mean of the ADUs in the sky frame, the RMS estimate is either the quartile-sigma or the standard deviation. The two values KEY_LOWSKYSIGMA and KEY_HIGHSKYSIGMA define which range of ADUs should be considered background. This background count is removed from the image prior to calculating the moments.

Throws:
nom.tam.fits.FitsException
IOException

getMomentAt

private Double getMomentAt(double step,
                           int order,
                           String fext)
We position the linear stage at the indicated step, take an image with the CCD camera on the #KEY_FOCSUFRAME and calculate the moments of this image. The value returned is the indicated central normalized moment, except for 1 that returns the average and 2 returns the square root of the variance. If the positioning fails (or if the requested position is out of range) null is returned.


takeSingleImage

private nom.tam.fits.Fits takeSingleImage(CcdDriver ccd,
                                          long ms,
                                          Dimension bin,
                                          String uu)
Takes a single image, stores it, resets the driver.