Subject: Re: ST-6 Image: FITS format

From: dwells at fits.CV.NRAO.EDU (Don Wells)
Date: Mon, 3 Jan 1994 18:33:17 GMT

[I have added sci.astro.fits to the Newsgroups line -DCW]

In article <CJ26DF.B5I at space.physics.uiowa.edu>
    rlm at astro.physics.uiowa.edu (Robert Mutel) writes:

 RM> .. an ambiguity with [all] 16-bit integer FITS files, viz that
 RM> the most  significant bit (MSB) is either treated as a sign bit
 RM> or a magnitude bit. ..

There is no ambiguity in the definition of FITS for BITPIX=16: FITS
readers should always construe 16-bit pixels as 2-s complement signed
integers. FITS readers should also obey the BSCALE and BZERO keywords
when they are present (and should default to BSCALE=1 and BZERO=0 when
they are absent).  The formula which FITS readers should use to
interpret FITS pixels is

    physical_value = BZERO + BSCALE * array_value

(See Eq.5.3 in Sect.5.2.2.5 on p.19 of the NOST 100-1.0 version of the
FITS standard, or item III.D.1 on p.368 of the Basic FITS paper in
June 1981 A&A supplement Series, or Eq.3.2 in Sect.3.1.1.2 of the NOST
FITS User's Guide).  

 RM> The ST-6 uses the MSB as a mag. bit, so that FITS readers which
 RM> treat it as a sign bit will 'fold' all intensities i>32767 to
 RM> -65536+i. .. We have both ST-6 and HPC-1 cameras, both of which
 RM> use the MSB as a magnitude bit. ..

16-bit A-to-D converters produce unsigned integers; unsigned integers
are not supported by FITS.  When these pixels are being written to
FITS files with BITPIX=16 the camera software can utilize the optional
BZERO FITS keyword to shift the zero point of the number system in
order to give a 16-bit positive range instead of the default positive
and negative 15-bit range. The camera software should subtract 32768
from the pixels (or, equivalently, add 8000_hex) and set BZERO=32768
and BSCALE=1 in the header. If this is done, properly coded FITS
readers will construe the pixels correctly.
--

  Donald C. Wells         Associate Scientist         dwells at nrao.edu
                    http://fits.cv.nrao.edu/~dwells
  National Radio Astronomy Observatory                +1-804-296-0277
  520 Edgemont Road,   Charlottesville, Virginia       22903-2475 USA

---

From: bschlesinger at nssdca.gsfc.nasa.gov (BARRY M. SCHLESINGER)
Date: 3 Jan 1994 14:00 EDT

In article <CJ26DF.B5I at space.physics.uiowa.edu>, rlm at astro.physics.uiowa.edu writes...
>In article ck2 at canopus.cc.umanitoba.ca, youngs at cc.umanitoba.ca (Scott D. Young) writes:
>>
>>   Just a note to anyone who is using the ST-6 software: it does NOT support
>>   the FITS format. Yes, I know there is an option to save a file as a "FITS"
>>   but it does not work. They write the file incorrectly; something about
>>   flipping the high-order bit or something (I'm not sure of the details). 
>>   ... 
>This is not quite correct.  The exported FITS format of  ST-6 images is
>fine except for an ambiguity with [all] 16-bit integer FITS files, viz
>that the most  significant bit (MSB) is either treated as a sign bit or
>a magnitude bit. 

Sixteen-bit integers in FITS are signed. BITPIX=16 signifies that the 
data are two-byte signed integers.  FITS does not support a 16-bit 
unsigned integer data type.  BITPIX=8 represents unsigned, 8-bit 
integers.

>The ST-6 uses the MSB as a mag. bit, so that FITS
>readers which treat it as a sign bit will 'fold' all intensities
>i>32767 to -65536+i. 

This practice means that any files ST-6 produces are not in
conformance to standard FITS.  If they are otherwise going to be in
syntax similar to FITS, they should begin with SIMPLE=F, to indicate
this departure. 

> [...but a FITS expert can comment.] 

				Barry  Schlesinger
				NSSDC/NOST 	
				FITS Support Office