astro.fits
Class Overscan

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by astro.fits.Overscan
All Implemented Interfaces:
Cloneable, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying

public class Overscan
extends PropertyBundles

Class to model an overscan region and to subtract it from an image hdu. Mainly for column-overscan .


Nested Class Summary
static class Overscan.Column
          Fits a column and prints out the row-average, stddev and the fit.
static class Overscan.Corner
          Prints the corner pixel of the overscan region in the first imagehdu
static class Overscan.Extract
          Extracts the smoothened column overscan from a wifsip image for the stated extension.
static class Overscan.Solver
           
static class Overscan.Wifsip
          Subtracts a wifsip overscan.
static class Overscan.WifsipBias
          Subtracts a wifsip overscan.
static class Overscan.WifsipOverscan
          A non-linear model for fitting the exponentially glow in WiFSIP data.
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private static double DEFADDOFFSET
          Default additional offset.
private static int DEFFITOVERLAP
          Default half overlap.
private static int DEFFITREGIONMAX
          Default fit region.
private static int DEFFITREGIONMIN
          Default fit region.
private static Dimension DEFMASTERCLIP
          The default master clip.
private static int DEFORDER
          Default fit order.
private static Rectangle DEFOVERSCAN
          Default overscan region.
private static double DEFRMSINCREASE
          Default additional offset.
private static Rectangle DEFROWOVERSCAN
          Default overscan region.
private static int DEFRUNNINGAVERAGE
          Default running average half-size.
static String KEY_ADDOFFSET
          Artificial raise of level.
static String KEY_FITOVERLAP
          The overlap region around fitmin where we match Legendre and exp.
static String KEY_FITREGIONMAX
          The region where we use an overscan fit, outside median.
static String KEY_FITREGIONMIN
          The region where we use an overscan fit, outside median.
static String KEY_MASTERCLIP
          Key that denotes the active window per quadrant.
static String KEY_ORDER
          The legendre order to which we fit in the region.
static String KEY_OVERSCAN
          The rectangle where we have the column overscan region.
static String KEY_RMSINCREASE
          Maximum factorial increase in RMS from linear to exponential fit.
static String KEY_ROWOVERSCAN
          The rectangle where we have the row overscan region.
static String KEY_RUNNINGAVERAGE
          If no fit is found, use an running average of this size.
static String OSAV
          The key that states the overscan model RMS.
static String OSAVREM
          The comment to the overscan rms header entry.
static String OSRMS
          The key that states the overscan model RMS.
static String OSRMSREM
          The comment to the overscan rms header entry.
private  double[][] scan
          The extracted overscan region.
 
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
Overscan(Map<String,String> prop)
          Defaults the overscan region.
 
Method Summary
static double[] averageOverscan(double[][] adu, int window)
          From a rectangluar overscan, we first smooth along the minor axis, then calculating a running average of given length on the smoothened overscan.
private static double[] averageOverscan(Vector2D[] smooth, int window)
          From a rectangluar overscan, we first smooth along the minor axis, then calculating a running average of given length on the smoothened overscan.
 nom.tam.fits.ImageHDU correct(nom.tam.fits.ImageHDU image, boolean expf)
          In the object version, do the entire fit.
 double[][] extractOverscan(nom.tam.fits.ImageHDU image)
          Extracts the overscan as a two-dimensional double array.
static double[][] extractOverscan(nom.tam.fits.ImageHDU image, Rectangle reg)
          Extracts the overscan as a two-dimensional double array.
static Legendre fitRegion(int order, int min, int max, double[][] adu)
          Fits the input array with a legendre polynom of the defined order.
private static Legendre fitRegion(int order, int min, int max, double[][] adu, Vector1D nn)
          Fits the input array with a legendre polynom of the defined order.
private static Legendre fitRegion(int order, int min, int max, Vector2D[] smooth, Vector1D nn)
          Fits the input array with a legendre polynom of the defined order.
private static double[] getBestOverscanModel(int s0, Vector2D[] ovscn, double[] exp, Function legendre, double[] average, int window, int min, int overlap, int max, double rms)
          From the exponential and the Legendre fit on one hand, and from the running average on the other hand, we decide which fit is best to model the overscan.
static double[] nonlinearFit(Class<? extends AbstractGradientModel> wifsip, int s0, int max, double[][] adu, VectorG start, VectorG len, double maxrms)
          Tries to fit outside the region.
static double[] nonlinearFit(Class<? extends AbstractGradientModel> wifsip, Map<String,String> prop, int s0, int max, double[][] adu, VectorG start, VectorG len, double maxrms)
          Tries to fit outside the region.
static double[] nonlinearFit(Class<? extends AbstractGradientModel> wifsip, Map<String,String> prop, int s0, int max, Vector2D[] adu, VectorG start, VectorG len, double maxrms)
          Tries to fit outside the region.
private static double[] pumpUp(double[] post, int s0)
           
private static int searchCrossing(int row, int width, Function legendre, double[] expsolve, double rms)
          Starting from the row given, we scan at most overlap rows to the top and bottom, searching for the index where the exponential fit and the Legendre fit cross.
static GeneralLinearRegression setupFit(Function[] legendre, int min, int max, Vector2D[] adu)
          Converts an adu with the fit axis on the first index plus the fitting functions into a general linear regression.
private static GradientModel setupModel(Class<? extends AbstractGradientModel> wifsip, Map<String,String> prop, int s0, int max, Vector2D[] adu)
          Converts an adu-array into a data model of the given class type.
static Vector2D[] smoothOverscan(double[][] adu)
          From a rectangluar overscan we calculate the average across the minor axis, leaving out the lowest and highest value.
private static VectorG solveFor(Overscan.Solver s, GradientModel exp, VectorG start, VectorG len)
          Takes a differtiable model of the non-linear gradient region and fits it with one of the specified solvers.
static nom.tam.fits.ImageHDU subtractOverscanColumn(nom.tam.fits.ImageHDU image, double[] overscan, double addoff, Rectangle os, Dimension thick, double modrms)
          Corrects an image hdu by subtracting the overscan fit in the fitting region or by subtracting the exponential not-to-fit region.
 
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

OSAV

public static final String OSAV
The key that states the overscan model RMS.

See Also:
Constant Field Values

OSAVREM

public static final String OSAVREM
The comment to the overscan rms header entry.

See Also:
Constant Field Values

OSRMS

public static final String OSRMS
The key that states the overscan model RMS.

See Also:
Constant Field Values

OSRMSREM

public static final String OSRMSREM
The comment to the overscan rms header entry.

See Also:
Constant Field Values

KEY_OVERSCAN

public static final String KEY_OVERSCAN
The rectangle where we have the column overscan region.

See Also:
Constant Field Values

KEY_ROWOVERSCAN

public static final String KEY_ROWOVERSCAN
The rectangle where we have the row overscan region.

See Also:
Constant Field Values

KEY_FITREGIONMIN

public static final String KEY_FITREGIONMIN
The region where we use an overscan fit, outside median.

See Also:
Constant Field Values

KEY_FITOVERLAP

public static final String KEY_FITOVERLAP
The overlap region around fitmin where we match Legendre and exp. fit

See Also:
Constant Field Values

KEY_FITREGIONMAX

public static final String KEY_FITREGIONMAX
The region where we use an overscan fit, outside median.

See Also:
Constant Field Values

KEY_ORDER

public static final String KEY_ORDER
The legendre order to which we fit in the region.

See Also:
Constant Field Values

KEY_ADDOFFSET

public static final String KEY_ADDOFFSET
Artificial raise of level.

See Also:
Constant Field Values

KEY_RMSINCREASE

public static final String KEY_RMSINCREASE
Maximum factorial increase in RMS from linear to exponential fit.

See Also:
Constant Field Values

KEY_RUNNINGAVERAGE

public static final String KEY_RUNNINGAVERAGE
If no fit is found, use an running average of this size.

See Also:
Constant Field Values

KEY_MASTERCLIP

public static final String KEY_MASTERCLIP
Key that denotes the active window per quadrant.

See Also:
Constant Field Values

DEFRMSINCREASE

private static final double DEFRMSINCREASE
Default additional offset.

See Also:
Constant Field Values

DEFADDOFFSET

private static final double DEFADDOFFSET
Default additional offset.

See Also:
Constant Field Values

DEFORDER

private static final int DEFORDER
Default fit order.

See Also:
Constant Field Values

DEFFITOVERLAP

private static final int DEFFITOVERLAP
Default half overlap.

See Also:
Constant Field Values

DEFFITREGIONMIN

private static final int DEFFITREGIONMIN
Default fit region.

See Also:
Constant Field Values

DEFFITREGIONMAX

private static final int DEFFITREGIONMAX
Default fit region.

See Also:
Constant Field Values

DEFRUNNINGAVERAGE

private static final int DEFRUNNINGAVERAGE
Default running average half-size.

See Also:
Constant Field Values

DEFROWOVERSCAN

private static final Rectangle DEFROWOVERSCAN
Default overscan region.


DEFOVERSCAN

private static final Rectangle DEFOVERSCAN
Default overscan region.


DEFMASTERCLIP

private static final Dimension DEFMASTERCLIP
The default master clip.


scan

private double[][] scan
The extracted overscan region.

Constructor Detail

Overscan

public Overscan(Map<String,String> prop)
Defaults the overscan region.

Method Detail

correct

public nom.tam.fits.ImageHDU correct(nom.tam.fits.ImageHDU image,
                                     boolean expf)
                              throws nom.tam.fits.FitsException
In the object version, do the entire fit. If the image geometry does not fit to the specified rectangle, we try to guess the correct location of the over

Parameters:
expf - If true, also do the exponential fit.
Throws:
nom.tam.fits.FitsException

getBestOverscanModel

private static double[] getBestOverscanModel(int s0,
                                             Vector2D[] ovscn,
                                             double[] exp,
                                             Function legendre,
                                             double[] average,
                                             int window,
                                             int min,
                                             int overlap,
                                             int max,
                                             double rms)
From the exponential and the Legendre fit on one hand, and from the running average on the other hand, we decide which fit is best to model the overscan. This is basically done by calculating the chi-2 of the modelled data and returning the better fit. If the exponential solution did not converge, the running average is used throughout the entire region.


extractOverscan

public double[][] extractOverscan(nom.tam.fits.ImageHDU image)
                           throws nom.tam.fits.FitsException
Extracts the overscan as a two-dimensional double array.

Throws:
nom.tam.fits.FitsException

fitRegion

public static Legendre fitRegion(int order,
                                 int min,
                                 int max,
                                 double[][] adu)
Fits the input array with a legendre polynom of the defined order.


fitRegion

private static Legendre fitRegion(int order,
                                  int min,
                                  int max,
                                  double[][] adu,
                                  Vector1D nn)
Fits the input array with a legendre polynom of the defined order.


fitRegion

private static Legendre fitRegion(int order,
                                  int min,
                                  int max,
                                  Vector2D[] smooth,
                                  Vector1D nn)
Fits the input array with a legendre polynom of the defined order.


nonlinearFit

public static double[] nonlinearFit(Class<? extends AbstractGradientModel> wifsip,
                                    int s0,
                                    int max,
                                    double[][] adu,
                                    VectorG start,
                                    VectorG len,
                                    double maxrms)
Tries to fit outside the region. This is tricky, and is only tested for STELLA-1 WiFSIP CCD. This shows a double-exponential overscan in the region 0-350, which is fitted here with a wifsip data model.


nonlinearFit

public static double[] nonlinearFit(Class<? extends AbstractGradientModel> wifsip,
                                    Map<String,String> prop,
                                    int s0,
                                    int max,
                                    double[][] adu,
                                    VectorG start,
                                    VectorG len,
                                    double maxrms)
Tries to fit outside the region. This is tricky, and is only tested for STELLA-1 WiFSIP CCD. This shows a double-exponential overscan in the region 0-350, which is fitted here with a wifsip data model.


nonlinearFit

public static double[] nonlinearFit(Class<? extends AbstractGradientModel> wifsip,
                                    Map<String,String> prop,
                                    int s0,
                                    int max,
                                    Vector2D[] adu,
                                    VectorG start,
                                    VectorG len,
                                    double maxrms)
Tries to fit outside the region. This is tricky, and is only tested for STELLA-1 WiFSIP CCD. This shows a double-exponential overscan in the region 0-350, which is fitted here with a wifsip data model.


pumpUp

private static final double[] pumpUp(double[] post,
                                     int s0)

solveFor

private static VectorG solveFor(Overscan.Solver s,
                                GradientModel exp,
                                VectorG start,
                                VectorG len)
Takes a differtiable model of the non-linear gradient region and fits it with one of the specified solvers.


subtractOverscanColumn

public static nom.tam.fits.ImageHDU subtractOverscanColumn(nom.tam.fits.ImageHDU image,
                                                           double[] overscan,
                                                           double addoff,
                                                           Rectangle os,
                                                           Dimension thick,
                                                           double modrms)
                                                    throws nom.tam.fits.FitsException
Corrects an image hdu by subtracting the overscan fit in the fitting region or by subtracting the exponential not-to-fit region.

Throws:
nom.tam.fits.FitsException

searchCrossing

private static int searchCrossing(int row,
                                  int width,
                                  Function legendre,
                                  double[] expsolve,
                                  double rms)
Starting from the row given, we scan at most overlap rows to the top and bottom, searching for the index where the exponential fit and the Legendre fit cross. If this index is found, we return it, otherwise we return -1.


extractOverscan

public static double[][] extractOverscan(nom.tam.fits.ImageHDU image,
                                         Rectangle reg)
                                  throws nom.tam.fits.FitsException
Extracts the overscan as a two-dimensional double array. We always extract such that the long axis is the first index, i.e. a column overscan is then d[y][x], a row overscan d[x][y]. If the image is smaller than the requested overscan size, we fill with zero, assuming that the image is always centered.

Throws:
nom.tam.fits.FitsException

setupModel

private static GradientModel setupModel(Class<? extends AbstractGradientModel> wifsip,
                                        Map<String,String> prop,
                                        int s0,
                                        int max,
                                        Vector2D[] adu)
Converts an adu-array into a data model of the given class type. In almost any case, this should be a Overscan.WifsipOverscan, i.e. a double-exponential drop.


setupFit

public static GeneralLinearRegression setupFit(Function[] legendre,
                                               int min,
                                               int max,
                                               Vector2D[] adu)
Converts an adu with the fit axis on the first index plus the fitting functions into a general linear regression. From the input adu, only those with index i: min <= i < max are considered. Within this fitting region, the adu value is the average over the second index, but excluding the minimum and maximum value. The error to this value is estimated by the standard deviation of the original column, including min/max.


smoothOverscan

public static Vector2D[] smoothOverscan(double[][] adu)
From a rectangluar overscan we calculate the average across the minor axis, leaving out the lowest and highest value. The standard deviation of all ADUs (including min max) is returned as the error estimate. The returned VectorG array is the index along the major axis, the 2d-Vector carries the average at index zero and the stddev in index 1.

Parameters:
adu - Overscan region, major axis on first index.
column - If true, CCD column is the major axis.
See Also:
extractOverscan

averageOverscan

public static double[] averageOverscan(double[][] adu,
                                       int window)
From a rectangluar overscan, we first smooth along the minor axis, then calculating a running average of given length on the smoothened overscan. Data outside the average window is replaced with the value on that index, thus the returned array size is of the same length as the overscan major axis.


averageOverscan

private static double[] averageOverscan(Vector2D[] smooth,
                                        int window)
From a rectangluar overscan, we first smooth along the minor axis, then calculating a running average of given length on the smoothened overscan. Data outside the average window is replaced with the best non-centered average on that index, thus the returned array size is of the same length as the overscan major axis.