**Description**

Subtracts a bracket-gamma composite image to reduce reflected glare on the night side of the planet, especially near the terminator. To reduce noise and artifacts which are amplified by subtracting near equal values, the input image is first blended with a copy of itself which has been slightly blurred via a gaussian filter of the form exp(-((r / width)**2)). The blending weights the blurred image more at higher image values according to the expression (im + blurred * (im / thresh)) / (1.0 + (im / thresh)) so that the darker areas of the planet (e.g. clouds) are less affected. A proportion of the bracket-gamma composite frame is subtracted from the blended input, and the result is rescaled so that two small regions in the background and the foreground of the input and result have the same average values. For a more detailed description and analysis of the overall process, see the following site.

**Usage**

subbrgm.py -g brgm-name -w fwidth -t bthresh -s sweight -b 'bgpt' -f 'fgpt' fits-file, or subbrgm.py -g brgm-name -w fwidth -t bthresh -s sweight -b 'bgpt' -f 'fgpt' dir [min-file max-file] brgm-name = the name of the bracket-gamma composite file (default 'brgm1.fits') fwidth = the width of the Gaussian blur filter (default 10.0) bthresh = the value at which the input image and its blur are blended 1:1 (default 1500) sweight = the proportion the brgm frame is multiplied by before subtraction (default 2.25) bgpt = the location of a background estimation point in quotes (default '49 449') fgpt = the location of a foreground estimation point in quotes (default '307 349')

**Examples**

Single file mode:

> subbrgm.py 072407/shifted/im0215.a.fits data: min= 0.000000, max= 8120.304629, mean= 979.306415, std= 1200.824910 brgm: min= 0.000000, max= 10842.000626, mean= 968.938120, std= 1412.002171 sub: min= -22250.431088, max= 1414.823334, mean= -1225.422090, std= 2728.726642 data: bg= 197.310711, fg= 1684.234697 sub: bg= -720.610030, fg= 172.932124 rescaling... sub: min= 0.000000, max= 3750.838743, mean= 597.735037, std= 594.289055 sub: bg= 197.310711, fg= 1684.234697

In multiple file mode, the subtracted images are implicitly written to a directory named 'subtracted', which must already exist:

> subbrgm.py 072407/shifted 072407/subtracted/im0188.a.fits 072407/subtracted/im0189.a.fits 072407/subtracted/im0190.a.fits 072407/subtracted/im0191.a.fits 072407/subtracted/im0192.a.fits 072407/subtracted/im0193.a.fits 072407/subtracted/im0194.a.fits 072407/subtracted/im0195.a.fits 072407/subtracted/im0196.a.fits 072407/subtracted/im0197.a.fits ... 072407/subtracted/im0267.a.fits 072407/subtracted/im0268.a.fits 072407/subtracted/im0269.a.fits 072407/subtracted/im0270.a.fits 072407/subtracted/im0271.a.fits 072407/subtracted/im0272.a.fits 072407/subtracted/im0273.a.fits 072407/subtracted/im0274.a.fits 072407/subtracted/im0275.a.fits 072407/subtracted/im0276.a.fits

©Sky Coyote 2007