[Kst] extragear/graphics/kst/src/datasources/fitsimage

Ted Kisner tskisner.public at gmail.com
Mon Dec 4 21:20:48 CET 2006


SVN commit 610649 by tskisner:

Some FITS images contain floating point data and were created without calling the fits_write_pixnull function.  This function sets null pixels to NaN in the image.  In such files, the BLANK keyword is often used to indicate the null pixel value.  This keyword is technically only for use with integer arrays.  This patch manually looks for the BLANK keyword and sets pixels with this value to NaN in the output matrix (so that they are not plotted).  Is it ok if I also commit this to the 1.3 branch?

 M  +20 -1     fitsimage.cpp  


--- trunk/extragear/graphics/kst/src/datasources/fitsimage/fitsimage.cpp #610648:610649
@@ -20,7 +20,9 @@
 
 #include <stdio.h>
 #include <math.h>
+#include <ksdebug.h>
 
+
 FitsimageSource::FitsimageSource(KConfig *cfg, const QString& filename, const QString& type)
 : KstDataSource(cfg, filename, type) {
   _fptr = 0L;
@@ -108,7 +110,8 @@
                                      int yStart, int xNumSteps,
                                      int yNumSteps) {
   long n_axes[2],  fpixel[2] = {1, 1};
-  double nullval = 0;
+  double nullval = NAN;
+  double blank = 0.0;
   long n_elements;
   int i,  px, py,  anynull,  ni;
   int y0, y1, x0, x1;
@@ -129,6 +132,22 @@
 
   fits_read_pix( _fptr,  TDOUBLE, fpixel, n_elements,
                  &nullval, buffer, &anynull,  &status );
+  
+  // Check to see if the file is using the BLANK keyword
+  // to indicate the NULL value for the image.  This is
+  // not correct useage for floating point images, but 
+  // it is used frequently nonetheless... 
+  fits_read_key(_fptr, TDOUBLE, "BLANK", &blank, NULL, &status );
+  if (status) { //keyword does not exist, ignore it
+    status = 0;
+  } else { //keyword is used, replace pixels with this value
+    double epsilon = fabs(1e-4 * blank);
+    for (long j = 0; j < n_elements; j++) {
+      if (fabs(buffer[j]-blank) < epsilon) {
+        buffer[j] = NAN;
+      }
+    }
+  }
 
   y0 = yStart;
   y1 = yStart+yNumSteps;


More information about the Kst mailing list