AstroPy - flatten.py


Description

Performs masking and flat-fielding of image using mask, intercept, and slope images to invert an affine detector response. Result is = (data - intercept) / slope where the mask is 1, and 0 otherwise. The output is then clipped to zero and rescaled so that the average is 1000.0. All pixels are converted to floating-point values, and the input and output images are displayed. This program implicitly reads files called 'mask.fits', 'intercept.fits', and 'slope.fits' in a folder supplied on the command line. The program can be used on a single file to plot results, or on a folder fo files without graphics in batch mode.

Usage

flatten.py flatFolder fits-file, or
flatten.py flatFolder imageFolder outputFolder [min-fits-file max-fits-file]

Examples

Single file mode:

> flatten.py 072407/intermediates 072407/raw/im0215.a.fits
reading 072407/intermediates/mask.fits
reading 072407/intermediates/intercept.fits
reading 072407/intermediates/slope.fits

> flatten.py 090807/intermediates 090807/raw/im1902.a.fits
reading 090807/intermediates/mask.fits
reading 090807/intermediates/intercept.fits
reading 090807/intermediates/slope.fits

While flattening doesn't necessarily improve the image quality, it does remove the row noise and many of the detector abberations.

Batch mode:

> flatten.py 072407/intermediates 072407/raw 072407/flattened im0171.a.fits im0276.a.fits
072407/flattened/im0171.a.fits
072407/flattened/im0172.a.fits
072407/flattened/im0173.a.fits
072407/flattened/im0174.a.fits
072407/flattened/im0175.a.fits
072407/flattened/im0176.a.fits
072407/flattened/im0177.a.fits
072407/flattened/im0178.a.fits
072407/flattened/im0179.a.fits
072407/flattened/im0180.a.fits
...
072407/flattened/im0267.a.fits
072407/flattened/im0268.a.fits
072407/flattened/im0269.a.fits
072407/flattened/im0270.a.fits
072407/flattened/im0271.a.fits
072407/flattened/im0272.a.fits
072407/flattened/im0273.a.fits
072407/flattened/im0274.a.fits
072407/flattened/im0275.a.fits
072407/flattened/im0276.a.fits

> flatten.py 090807/intermediates 090807/raw 090807/flattened im0492.a.fits im0891.a.fits
090807/flattened/im0492.a.fits
090807/flattened/im0493.a.fits
090807/flattened/im0494.a.fits
090807/flattened/im0495.a.fits
090807/flattened/im0496.a.fits
090807/flattened/im0497.a.fits
090807/flattened/im0498.a.fits
090807/flattened/im0499.a.fits
090807/flattened/im0500.a.fits
090807/flattened/im0501.a.fits
...
090807/flattened/im0882.a.fits
090807/flattened/im0883.a.fits
090807/flattened/im0884.a.fits
090807/flattened/im0885.a.fits
090807/flattened/im0886.a.fits
090807/flattened/im0887.a.fits
090807/flattened/im0888.a.fits
090807/flattened/im0889.a.fits
090807/flattened/im0890.a.fits
090807/flattened/im0891.a.fits

NOTE: You may want to make 2 changes to your pyfits code (located in your Python site-packages folder):

  1. Comment out line 4798 of NP_pyfits.py to eliminate new sigint binding, so you can use control-c to abort the program.
  2. Comment out line 4946 of NP_pyfits.py to eliminate overwrite message.


©Sky Coyote 2007