next up previous 530
Next: Removing bad pixels
Up: Masking, Bad Values, and Quality
Previous: Special Filters for Inserting Bad Values


Quality Masking

All the NDF  tasks in KAPPA use quality yet there is no obvious sign in individual applications how particular values of quality are selected. What gives? The meanings attached to the quality bits will inevitably be quite specific for specialist software packages, but KAPPA tasks aim to be general purpose. To circumvent this conflict there is an NDF component called the bad-bits mask that forms part of the quality information. Like a QUALITY value, the bad-bits mask is an unsigned byte. Its purpose is to convert the eight quality flags into a single logical value for each pixel, which can then be processed just like a bad pixel.

When data are read from the NDF by mapping into memory, the quality of each pixel is combined with the bad-bits mask; if a result of this quality masking is FALSE, that pixel is assigned the bad value for processing. This does not change the original values stored in the NDF; it only affects the mapped data.

So how do the quality and bad-bits mask combine to form a logical value? They form the bit-wise `AND' and test it for equality for 0. None the wiser? Regard each bit in the bad-bits mask as a switch to activate detection of the corresponding bit in a pixel's quality. The switch is on if it has value 1, and is off if it has value 0. Thus if the pixel is flagged only if one or more of the 8 bits has both quality and the corresponding bad-bit set to 1. Here are some examples:

QUALITY: 10000001 10000001
Bad-bits: 01000100 01000101
Bits on:   ^
Result: TRUE FALSE

The application SETBB allows you to modify the bad-bits mask in an NDF. It allows you to specify the bit pattern in a number of ways including decimal and binary as illustrated below.

     % setbb RO950124 5
     % setbb RO950124 b101

These both set the bad-bits mask to 00000101 for the NDF RO950124. SETBB also allows you to combine an existing NDF bad-bits mask with another mask using the operators AND and OR. OR lets you switch on additional bits without affecting those already on; AND lets you turn off selected bits leaving the rest unchanged.

     % setbb RO950124 b00010001 or
     % setbb RO950124 b11101110 and

The first example sets bits 1 and 5 but leaves the other bits of the mask unaltered, whereas the second switches off the same bits.

Now remembering which bit corresponds to which could be a strain on the memory. It would be better if some meaning was attached to each bit through a name. There are four general tasks that address this. SETQUAL sets quality values and names; SHOWQUAL lists the named qualities; REMQUAL removes named qualities; and QUALTOBAD uses a logical expression containing the named quality properties to create a copy of your NDF in which pixels satisfying the quality expression are set bad. See ``Using Quality Names'' for more information about using these tasks. Once you have defined quality names, you can set the bad-bits mask with SETBB to mask pixels with those named quality attributes.

     % setbb RO950124 spike
     % setbb RO950124 '"spike,back"'

The first example might set the bad-bits mask to exclude spike artefacts. The second could mask both spikes and background pixels. Thus it might be used to select the spectral lines not affected by noise spikes in a spectral cube. Other logical combinations are possible using the AND and OR operators.



next up previous 530
Next: Removing bad pixels
Up: Masking, Bad Values, and Quality
Previous: Special Filters for Inserting Bad Values

KAPPA --- Kernel Application Package
Starlink User Note 95
Malcolm J. Currie & David S. Berry
2013 February 14
E-mail:starlink@jiscmail.ac.uk

Copyright © 2013 Science and Technology Facilities Council