Table of Contents Previous Chapter ACIS

42.0 FEP Timed Exposure Bias Calibration (36-53226 02)

42.1 Purpose

The fepTimedBias module, executing in the FEP, calibrates the bias map for subsequent timed-exposure science processing. It is called from fepCtl with a single argument, fp, a pointer to the fepParm structure. Before invoking fepTimedBias, the FEP must be commanded to load a timed-exposure FEPparmBlock into fp->tp.

42.2 Uses

The fepTimedBias function operates in one of the following modes, according to the value of fp->tp.type:

  1. Calculate bias using a "whole-frame" algorithm.

  2. Calculate bias thresholds using a "strip" algorithm.

FIGURE 175. fepTimedBias Structure in "Whole-Frame" Mode


FIGURE 176. fepTimedBias Structure in "Strip" Mode


42.3 Organization

All interactions with the BEP and with FEP hardware are made through fepio library functions described in Section 38.0. The commands that are passed between FEP and BEP are defined in that document and in Section 4.10. fepTimedBias makes use of the following functions which call each other in the manner shown in Figure 175 ("whole-frame" mode) or in Figure 176 ("strip" mode), depending on the value of fp->tp.btype (see Table 45):

42.4 Global Variables

The following FEPparm fields, defined in fepCtl.h and fepBep.h, and is invariably 
addressed by the fp pointer parameter, are used by all timed exposure bias modes:
bepCmd
latest command received from BEP
br
pointer to bias calibration parameters
bias0[4]
average overclocks for first bias frame
biassum
sum of the 4 bias0 values
ex
current
FEPexpRec record
d0clk[4]
change in average overclock since last exposure
expnum
current exposure number
timestamp
microsecond timer value at start of expnum
expcount
number of bias frames processed
fepStatus
FEP status reported to BEP
biasflag
=1 if bias has been computed
flags
flag bits:
FP_SUSPEND
BEP has sent BEP_FEP_CMD_SUSPEND
FP_PAST_EOR
FEP hardware has finished with the current frame
FP_TERMINATE
BEP has sent BEP_FEP_CMD_STOP
FP_DONE
BEP is terminating normally
image
pointer to start of current image row
nextexpnum
the next exposure index that the FEP is to process
parity
pointer to 4096-element bias parity table
quadrants
the number of DEA output nodes being sampled
tp
exposure parameter block (see Table 45)
bparm[5]
mode-dependent parameters
btype
type of bias calibration desired
ncols
number of CCD columns clocked
noclk
number of overclocks per node per row
nrows
number of CCD rows clocked
nskip
2-exposure alternation factor
quadcode
output node clocking mode

42.5 Scenarios

The following paragraphs describe the basic functions performed by fepTimedBias during timed exposure bias calibrations, which are determined by the fields in the parameter block, fp->tp shown in Table 45.

TABLE 45. Parameters used by fepTimedBias

----------------------------------------------------------------------------------
 Field Type   Field Name        "Whole-Frame" Mode               "Strip" Mode         
----------------------------------------------------------------------------------
unsigned     nrows       Number of bias rows to be calibrated.                      
unsigned     ncols       Number of pixels per output node per row                   
fepQuadCode  quadcode    Output node configuration, i.e., ABCD, AC, or BD.          
unsigned     noclk       Number of overclocks per row per output node               
fepBiasType  btype       FEP_BIAS_1                    FEP_BIAS_2                   
int          bparm[0]    Number of conditioning        Number of exposures per      
                         exposures (PHASE2)            pixel                        
int          bparm[1]    Number of approxima           =0 to use mean               
                         tion-to-mean exposures        =1 to use fractile           
                         (PHASE3)                                                   
int          bparm[2]    Rejection threshold for       For mean, specifies s        
                         low-pixel elimination         rejection criterion. For     
                         (immediately prior to         fractile, index of sorted    
                         PHASE3)                       pixel array.                 
int          bparm[3]    Threshold for event rejec     Ignored                      
                         tion (PHASE3)                                              
int          bparm[4]    Rejection threshold for       Ignored                      
                         approximation-to-mean                                      
unsigned     nskip       Exposure skip factor; if non-zero, don't use those with    
                         "non-standard" exposure times for bias calibration.        
----------------------------------------------------------------------------------

The bias calibration algorithms themselves are presented in some detail in the ACIS report entitled "CCD Bias Level Determination" by Rita Somigliana and Peter Ford, ACIS part #36--56012--02, MIT CSR, Revision 2, May 30, 1995.

42.5.1 Use 1: Calculate Bias using a Whole-Frame Algorithm

fepTimedBias calls FEPtimedBiasInit to check the fp->tp parameter block, to initialize the parity table (fp->parity), and set the hardware registers. It then loops, waiting for the next exposure to be received from the DEA. Subsequent processing occurs in three distinct phases, with an optional 2a phase invoked in special circumstances.

(EQ 1)

(EQ 2)

(EQ 3)

(EQ 4)

(EQ 5)

Before processing each line of image pixels, FIOgetNextCmd is called. If it returns TRUE, fepHandleCmd is called to process a single BEP command.

After the last exposure has been processed, FEPtimedBiasParity is called to construct a bias parity buffer that contains a single parity bit for each pixel in the bias map. This will be used by the FEP hardware to detect single-bit flips in the bias map during subsequent timed exposure science runs.

Finally, fepTimedBias exits with writes to the image map disabled. It returns to its command mode and waits for more BEP commands.

42.5.2 Use 2: Calculate Bias using a Strip Algorithm

fepTimedBias calls FEPtimedBiasInit to check the fp->tp parameter block, to initialize the parity table (fp->parity), and set the hardware registers. It then loops over calls to FIOgetExpInfo, waiting for the next exposure to be received from the DEA.

The algorithms require each image pixel to be exposed several times, and its values after each exposure must be available simultaneously. Since there is insufficient memory available to store more than a single copy of the image map, the pixels must be processed a few at a time. On each exposure, the FEP hardware is therefore commanded to write only a strip of CCD image pixels to the image map. On subsequent exposures, the registers are adjusted so that each strip is written into a different part of the image map, as shown in Figure 177.

FIGURE 177. The Relation between CCD strips, Image strips, and exposures


The choice of strip size is determined by the number of exposures desired (the value of fp->tp.bparm[0]), i.e. its size in rows is the smallest integer that does not exceed 1024 divided by the number of exposures. Once the image map is filled with strips, the program copies the corresponding pixel value in each strip to an array in D-cache for faster access. It then operates on the array values and uses either their truncated mean or their fractile as the bias value, which it stores in the bias map.

42.5.2.1 The Iterated Mean Algorithm

This algorithm, described in Section 3.2.4 of 36--56012--02, is implemented by the function mean (see Section 42.6.11). It takes the N pixel values pi, i=0,N--1, and computes their mean value p and variance s2:

(EQ 6)

(EQ 7)

If the value of BPARM[2] is zero, mean returns p as the bias value. Otherwise, it inspects the pi and removes any that do not satisfy the condition

(EQ 8)

Finally, it recomputes p from the remaining pi using Eq. 6, and returns that as the bias value.

42.5.2.2 The Fractile Algorithm

This algorithm, which is a generalization of the Median method described in Section 3.2.5 of 36--56012--02, is implemented in the function fractile (see Section 42.6.12). It takes the N pixel values pi, i=0,N--1, sorts them into ascending order, and returns the value indexed by the value of bparm[2]. For instance, if N were 11 (it is usually 1024), and bparm[2] were 5, and the pixel values pi were,

212 216 205 1041 208 217 211 214 215 206 210

their bias value would be 212, since, when the values are sorted into ascending order,

205 206 208 210 211 212 214 215 216 217 1041

that is the value of the element p5.

42.6 Specification


This section describes the functions that are local to the fepTimedBias unit. The only external is fepTimedBias itself which is called from fepCtl. The FEPparm structure is defined in fepCtl.h and fepBep.h, along with several pixel access macros. The interface to the FEP I/O library is described in Section 38.0, and data and messages exchanged between FEP and BEP are described in Section 4.10.

42.6.1 fepTimedBias()

#include fepCtl.h
Scope: Science
Return type: void
Arguments
FEPparm *fp
Description:
fepTimedBias is called from fepCtl with a single argument: the pointer fp to the 
fepParm structure. It is responsible for all FEP actions associated with a timed 
exposure bias calibration. It performs the following actions:
Copies the address of the par array in its D-cache stack, to fp->parity, where it will be initialized within FEPtimedBiasInit and used within FEPtimedBiasParity.
Calls FEPtimedBiasInit to initialize various fepParm fields and hardware registers. If FEPtimedBiasInit returns FEP_CMD_NOERR, fepTimedBias calls fepAckCmd and continues. Otherwise, it calls fepNackCmd to pass the error code to the BEP, indicating that the command has failed, and fepTimedBias then returns to fepCtl
Loops over exposures until either the FP_DONE or the FP_TERMINATE flag is set in fp->flags.
--
When the bias type (fp->tp.btype) is "strip" mode (FEP_BIAS_2), sets the mode parameter to BIAS2. Otherwise, this is "whole-frame" mode and the mode parameter is set according to the number of fully-processed exposures (fp->expcount) and the fp->tp.bparm values. The first exposure will be processed as BIAS1_PHASE1, the next
fp->tp.bparm[0] exposures will be processed as BIAS1_PHASE2, and the final fp->tp.bparm[1] exposures will be processed as BIAS1_PHASE3.
--
Calls fioWriteImPulseReg, to set the IPULSE_ARMNXTACQ bit in the FEP's image pulse register.
--
Loops over calls to FIOgetExpInfo until the exposure number changes, i.e. until the hardware begins to write pixels from the next exposure into the image map. During this loop, calls are made to FIOgetNextCmd to intercept and process commands from the BEP, and FIOtouchWatchdog to keep the watchdog timer alive.
--
Calls FEPtimedBiasExec to process the exposure. NOTE: when the CCDs are clocked with two exposure times (i.e. non-zero fp->tp.nskip), FEPtimedBiasExec will not be called for those exposures with the initial (i.e. less frequent) exposure time.
In "whole-frame" mode, calls FEPtimedBiasParity to initialize the bias parity buffer.
Marks the bias map as "good" by setting fp->biasmode to TRUE and
fp->br.biassum to the sum of the 4 elements in the fp->br.bias0 array.

42.6.2 FEPtimedBiasExec()

#include fepCtl.h
Scope: Science
Return type: void
Arguments
FEPparm *fp
BiasMode   mode
Description:
This function is called from fepTimedBias to process a single frame. mode selects 
either a phase of the "whole-frame" algorithm: BIAS1_PHASE1, 
BIAS1_PHASE2, or BIAS1_PHASE3, or the "strip" algorithm, BIAS2.
In the "whole-frame" algorithm, the routine loops over image frame rows, calling 
FIOgetNextCmd once per row to catch incoming commands from the BEP and, 
when detected, fepHandleCmd is called to process them. FEPtimedBiasExec then 
sums the overclocks and calls a subroutine to process the image pixels, depending 
on the mode value:
BIAS1_PHASE1---FEPtimedBias1Copy copies a row of image pixels to the bias 
map without any change.
BIAS1_PHASE2---FEPtimedBias1Cond reads a row of image pixels and uses 
them to replace the corresponding bias map values when the latter are larger than 
the former. The result of performing this operation over several consecutive expo
sures is to "condition" the bias map values, removing any contamination from 
CCD events.
BIAS1_PHASE3---first, FEPtimedBias1ZapEvent is called to mark all image 
map pixels that may contain events, followed by FEPtimedBias1Mean to use the 
unmarked pixels to update the bias values.
In the "strip" algorithm, when mode has the value FEP_BIAS_2, FEPtimedBia
sExec does very little until the last of a set of strips has been written to the image 
map. It merely adjusts the hardware pointers via calls to FIOsetImageMapRow
Start and FIOsetImageMapRowLength to march the strips down the image map, 
and to FIOsetCcdRowStart to select different rows of the CCD. After the image 
map is full of strips, FEPtimedBiasExec sums the overclocks of the last frame and 
then calls FEPtimedBias2Proc to update the bias map.


42.6.3 FEPtimedBiasInit()

#include fepCtl.h
Scope: Science
Return type: fepCmdRetCode
Arguments
FEPparm *fp
Description:
This function is called from fepTimedBias to verify the contents of the 
FEPparmBlock, fp->tp, and to perform the following initializations:
fp->quadrants to 2 or 4, depending on the value of
fp->tp.quadcode.
fp->parity[0] through fp->parity[4095] to either PARITY_EVEN or PARITY_ODD (defined in fepCtl.h) according to the bit parity of the binary integers 0--4095.
FEP hardware registers, by calls to FIOsetCcdRowStart, FIOsetImageMapRowStart, and FIOsetImageMapRowLength.
If an error is detected, FEPtimedBiasInit returns a fepCmdRetCode value as defined in fepBep.h; otherwise it returns FEP_CMD_NOERR.

42.6.4 FEPtimedBiasParity()

#include fepCtl.h
Scope: Science
Return type: void
Arguments
FEPparm *fp
unsigned rowstart
unsigned nrows
Description:
In "strip" mode, this function is called from FEPtimedBias2Proc to update 
nrows in the bias parity buffer, starting at row rowstart, from the correspond
ing values in the bias map. In "full-frame mode", it is called from FEPtimedBias 
to compute the entire parity buffer at the end of the bias calibration run. Each 12-
bit bias map value is used as an index into the fp->parity array, whose ele
ments are either PARITY_EVEN or PARITY_ODD, according to the parity of the 
index. For instance, the number fifteen is represented by the bit pattern 01111, 
which contains an even number of `1's. Its parity is therefore even, so 

fp->parity[15] = PARITY_EVEN.
Precondition:
fp->parity must point to an array of 4096 32-bit values, which have been ini
tialized to PARITY_EVEN if the index number possesses even parity, or to 
PARITY_ODD if odd. 


42.6.5 FEPtimedBias1Copy()

#include fepCtl.h
Scope: Science
Return type: void
Arguments
FEPparm *fp
Description:
This function is called from FEPtimedBiasExec in BIAS1_PHASE1 to copy a 
single row of pixels from the image map (located at fp->image) to the bias map 
(located at fp->image + BIAS_OFFSET).
Since this routine is only called for the first exposure of the bias calibration se
quence, no overclock correction factor need be applied.


42.6.6 FEPtimedBias1Cond()

#include fepCtl.h
Scope: Science
Return type: void
Arguments
FEPparm *fp
Description:
This function is called from FEPtimedBiasExec in BIAS1_PHASE2 to inspect a 
single row of pixels from the image map (located at fp->image) and update the 
corresponding values in the bias map (located at fp->image + BIAS_OFFSET) 
when the former are smaller than the latter.
Before making the comparison with the bias pixel, each image pixel is corrected 
for any change in average overclock by subtracting the fp->ex.dOclk element 
appropriate to the pixel's output node. Since the correction factor is based on the 
average overclocks from the previous exposure, this can only compensate for slow 
changes in the analog system.


42.6.7 FEPtimedBias1Mean()

#include fepCtl.h
Scope: Science
Return type: void
Arguments
FEPparm *fp
Description:
This function is called from FEPtimedBiasExec in BIAS1_PHASE3 to read a sin
gle row of image pixels (located in fp->image - PIXEL_STRIDE) and update 
the corresponding bias values (located in fp->image + BIAS_OFFSET - 
PIXEL_STRIDE). Image pixels with the PIXEL_BAD value are skipped since 
they have been identified in a prior call to FEPtimedBias1ZapEvents as possibly 
containing events.
Before making the comparison with the bias pixel, each image pixel is corrected 
for any change in average overclock by subtracting the fp->ex.dOclk element 
appropriate to the pixel's output node. Since the correction factor is based on the 
average overclocks from the previously processed exposure, this can only compen
sate for slow changes in the analog system.
When the pixel value p exceeds the corresponding bias value b by not more than 
fp->bparm[4], b is replaced by (n*b+p)/(n+1), where n is the exposure count, 
i.e. n=1 for the first exposure of BIAS1_PHASE3, 2 for the second, etc.
Since FEPtimedBias1Mean is called immediately after FEPtimedBias1Cond, 
and the latter is capable of nullifying pixels in the preceding row, 
FEPtimedBias1Mean must also work on that row, whose first pixel is located at 
fp->image - PIXEL_STRIDE, rather than on the current row, pointed to by 
fp->image.


42.6.8 FEPtimedBias1Median()

#include fepCtl.h
Scope: Science
Return type: void
Arguments
FEPparm *fp
Description:
This function is called from fepTimedBias at the end of BIAS1_PHASE2 to iden
tify anomalously low valued pixels in the bias map. It does this by comparing each 
bias value with those of its 8 neighbors. If the central value is smaller than all but 
one of its neighbors by more than fp->tp.bparm[2], FEPtimedBias1Median 
replaces the central value by the median of the neighbors.
This function is only invoked if fp->tp.bparm[2] is non-zero. It should only 
be used if it has been found from a study of previous bias maps that some anoma
lously low image pixel values will be encountered, since these would otherwise 
dominate the bias map that is constructed during BIAS1_PHASE2. 


42.6.9 FEPtimedBias1ZapEvent()

#include fepCtl.h
Scope: Science
Return type: void
Arguments
FEPparm *fp
unsigned irow
Description:
This function is called from FEPtimedBiasExec in BIAS1_PHASE3 to identify 
image pixel values (at location fp->image) in row irow that are larger than their 
corresponding bias values (at location fp->image + BIAS_OFFSET) by more 
than a constant fp->tp.bparm[3]. 
Before making the comparison, each image pixel is corrected for any change in av
erage overclock by subtracting the fp->ex.dOclk element appropriate to the 
pixel's output node. Since the correction factor is based on the average overclocks 
from the previous exposure, this can only compensate for slow changes in the an
alog system.
Once identified, the image pixels and their immediate neighbors (8 pixels, or less 
if the identified pixel is on the edge of the CCD) are reset to PIXEL_BAD so that 
they can be identified in the FEPtimedBias1Mean routine.


42.6.10 FEPtimedBias2Proc()

#include fepCtl.h
Scope: Science
Return type: void
Arguments
FEPparm *fp
Description:
This function is called from FEPtimedBiasExec in the BIAS2 mode ("strip" pro
cessing) when the image map is filled with a series of strips of pixels from the same 
group of CCD rows from fp->tp.bparm[0] consecutive exposures.
Each image pixel is corrected for any change in average overclock by subtracting 
the fp->ex.dOclk element appropriate to the pixel's output node. Since the cor
rection factor is based on the average overclocks from the previous exposure, this 
can only compensate for slow changes in the analog system.
Each set of pixel values, one from each exposure, is copied to a buffer in D-cache, 
Data0 for pixels from even-indexed columns and Data1 for pixels from odd-in
dexed columns. The value to be stored in the bias map is determined by the value of 

fp->tp.bparm[1].
bparm[1] = 0:   mean is called to compute the mean of the pixel values. 
When fp->tp.bparm[2] is zero, this becomes the bias 
map value. When fp->tp.bparm[2] is non-zero, pixels 
with values that differ from the zeroth-order mean by more 
than fp->tp.bparm[2] times the RMS variance of the 
values are eliminated, and the mean of the remainder be
comes the bias map value.
bparm[1] = 1:  fractile is called to sort the pixel values into ascending or
der. The element in this sorted list indexed by

fp->tp.bparm[2] becomes the bias map value.
After processing the entire set of strips in the image map, FEPtimedBias2Proc 
calls FEPtimedBiasParity to compute parity flags for each of the new bias map 
pixel values and store the result in the appropriate section of the bias parity buffer.


42.6.11 mean()

#include fepCtl.h
Scope: Science
Return type: unsigned
Arguments
unsigned *vec
unsigned nvec
unsigned nsigma
Description:
This function returns the integer closest to the mean value of the nvec-element ar
ray vec[]. Half-integer values are rounded up. If nsigma is non-zero, the stan
dard deviation (s) of the elements is also calculated, and the mean is re-calculated 
from those elements of vec[] that differ from the original mean value by no more 
than nsigma C s. The algorithm is described in Section 42.5.2.1.

42.6.12 fractile()

#include fepCtl.h
Scope: Science
Return type: unsigned
Arguments
unsigned *vec
unsigned nvec
unsigned nrep
Description:
This function sorts the elements of the nvec-element array vec[] into ascending 
value, and returns the value of the nrep'th element, i.e. nrep=0 returns the min
imum, nrep=nvec/2 returns the median, etc. The routine uses Shell's method, 
which was chosen for its computational efficiency---nvec  ln(nvec)---and low 
start-up overhead. The algorithm is described in Section 42.5.2.2.

Footnotes

(1)
Care must be taken when observing a bright target during bias calibration that the pile-up in any single pixel doesn't violate this condition. At XRCF, bias calibration should probably be performed with the source turned off or with ACIS translated away from the focal axis.

Table of Contents Next Chapter