[Kst] extragear/graphics/kst/kst/datasources/healpix

Ted Kisner tskisner.public at gmail.com
Sun Nov 6 22:57:12 CET 2005


SVN commit 478481 by tskisner:

Enable workaround for full-sphere FITS files that do not use 1024E wide columns like normal.  Some of the WMAP files are notably like this.  Also add checks for vectorfield degrade factor to make sure we cannot degrade past nside=1.

 M  +29 -3     healpix.cpp  
 M  +3 -0      healpix_source.h  
 M  +29 -13    healpix_tools_fits.cpp  


--- trunk/extragear/graphics/kst/kst/datasources/healpix/healpix.cpp #478480:478481
@@ -70,7 +70,7 @@
       _phiUnits = HPUNIT_RADEC;
       _vecUnits = HPUNIT_RADEC;
       _autoMag = true;
-      _vecDegrade = 1;
+      _vecDegrade = 0;
       _vecTheta = 0;
       _vecPhi = 0;
       _vecQU = false;
@@ -917,6 +917,7 @@
   double confThetaMax;
   double confPhiMin;
   double confPhiMax;
+  int tempdegrade;
   QDomNode n = e.firstChild();
   while (!n.isNull()) {
     QDomElement e = n.toElement();
@@ -959,7 +960,9 @@
           _autoMag = e.attribute("auto").toInt();
         }
         if (e.hasAttribute("degrade")) {
-          _vecDegrade = e.attribute("degrade").toInt();
+          tempdegrade = e.attribute("degrade").toInt();
+          checkDegrade(tempdegrade);
+          _vecDegrade = tempdegrade;
         }
         if (e.hasAttribute("theta")) {
           _vecTheta = e.attribute("theta").toInt();
@@ -1096,12 +1099,31 @@
   return;
 }
 
+void HealpixSource::checkDegrade(int& degrade) {
+  int nside = _mapNside;
+  if (!degrade) {
+    return;
+  }
+  if ((nside == 1) && (degrade != 0)) {
+    degrade = 0;
+    return;
+  }
+  for (int i = 0; i < degrade; i++) {
+    nside = (int)(nside/2);
+    if (nside == 1) {
+      degrade = i+1;
+      return;
+    }
+  }
+  return;
+}
 
 void HealpixSource::loadConfig(KConfig *cfg) {
   double confThetaMin;
   double confThetaMax;
   double confPhiMin;
   double confPhiMax;
+  int tempdegrade;
   
   cfg->setGroup("Healpix General");
   cfg->setGroup(fileName());
@@ -1117,11 +1139,15 @@
   confPhiMax = (cfg->readEntry("Phi Max", QString::null)).toDouble();
   _vecTheta = cfg->readNumEntry("Vector Theta", 0);
   _vecPhi = cfg->readNumEntry("Vector Phi", 0);
-  _vecDegrade = (int)cfg->readNumEntry("Vector Degrade Factor", 1);
+  tempdegrade = (int)cfg->readNumEntry("Vector Degrade Factor", 1);
   _autoMag = cfg->readBoolEntry("Vector Magnitude Autoscale", true);
   _maxMag = (cfg->readEntry("Vector Max Magnitude", QString::null)).toDouble();
   _vecQU = cfg->readBoolEntry("Vector is QU", false);
   
+  // check degrade factor
+  checkDegrade(tempdegrade);
+  _vecDegrade = tempdegrade;
+  
   // convert the entered range values into radians and 
   // force them to the correct range.
   theta2Internal(_thetaUnits, confThetaMin);
--- trunk/extragear/graphics/kst/kst/datasources/healpix/healpix_source.h #478480:478481
@@ -70,6 +70,9 @@
     void phi2Internal(int units, double& phi);
     void phi2External(int units, double& phi);
     
+    // degrade check
+    void checkDegrade(int& degrade);
+    
     // file parameters
     int _mapType;
     int _mapOrder;
--- trunk/extragear/graphics/kst/kst/datasources/healpix/healpix_tools_fits.cpp #478480:478481
@@ -427,15 +427,23 @@
   if ((*type) == HEALPIX_FITS_FULL) {
     (*nmaps) = tfields;
     if (inside > 8) {
-      if (nrows*1024 != (long)(12*inside*inside)){
+      // file *MAY* be written in 1024 wide columns
+      if (nrows*1024 == (long)(12*inside*inside)){
+        if (fits_read_col(fp, TFLOAT, 1, nrows-1, 1023, 1, &nullval, &testval, &nnull, &ret)) {
+          ret = 0;
+          fits_close_file(fp, &ret);
+          return 0;
+        }  
+      } else if (nrows == (long)(12*inside*inside)){
+        if (fits_read_col(fp, TFLOAT, 1, nrows-1, 1, 1, &nullval, &testval, &nnull, &ret)) {
+          ret = 0;
+          fits_close_file(fp, &ret);
+          return 0;
+        } 
+      } else {
         fits_close_file(fp, &ret);
         return 0;
       }
-      if (fits_read_col(fp, TFLOAT, 1, nrows-1, 1023, 1, &nullval, &testval, &nnull, &ret)) {
-        ret = 0;
-        fits_close_file(fp, &ret);
-        return 0;
-      }       
     } else {
       if (nrows != (long)(12*inside*inside)){
         fits_close_file(fp, &ret);
@@ -622,15 +630,23 @@
   if ((*type) == HEALPIX_FITS_FULL) {
     (*nmaps) = tfields;
     if (inside > 8) {
-      if (nrows*1024 != (long)(12*inside*inside)){
+      // file *MAY* be written in 1024 wide columns
+      if (nrows*1024 == (long)(12*inside*inside)){
+        if (fits_read_col(fp, TFLOAT, 1, nrows-1, 1023, 1, &nullval, &testval, &nnull, &ret)) {
+          ret = 0;
+          fits_close_file(fp, &ret);
+          return 0;
+        }  
+      } else if (nrows == (long)(12*inside*inside)){
+        if (fits_read_col(fp, TFLOAT, 1, nrows-1, 1, 1, &nullval, &testval, &nnull, &ret)) {
+          ret = 0;
+          fits_close_file(fp, &ret);
+          return 0;
+        } 
+      } else {
         fits_close_file(fp, &ret);
         return 0;
       }
-      if (fits_read_col(fp, TFLOAT, 1, nrows-1, 1023, 1, &nullval, &testval, &nnull, &ret)) {
-        ret = 0;
-        fits_close_file(fp, &ret);
-        return 0;
-      }       
     } else {
       if (nrows != (long)(12*inside*inside)){
         fits_close_file(fp, &ret);
@@ -641,7 +657,7 @@
         fits_close_file(fp, &ret);
         return 0;
       } 
-    }
+    }  
   } else {
     (*nmaps) = tfields - 3;
     if (fits_read_col(fp, TFLOAT, 2, nrows-1, 1, 1, &nullval, &testval, &nnull, &ret)) {


More information about the Kst mailing list