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

Ted Kisner tskisner.public at gmail.com
Tue Oct 25 22:54:53 CEST 2005


SVN commit 474259 by tskisner:

Enable healpix autoscaling by default.  Still need a config widget...

 M  +83 -25    healpix.cpp  
 M  +9 -0      healpix_source.h  


--- trunk/extragear/graphics/kst/kst/datasources/healpix/healpix.cpp #474258:474259
@@ -47,12 +47,11 @@
     if (ret) {
       _valid = true;
       _mapNpix = 12 * _mapNside * _mapNside;
-      _nX = 640;
-      _nY = 480;
-      _phiMin = HEALPIX_PI+0.01;
-      _thetaMin = 0.0;
-      _phiMax = HEALPIX_PI-0.01;
-      _thetaMax = HEALPIX_PI;
+      _nX = 800;
+      _nY = 600;
+      _autoTheta = true;
+      _autoPhi = true;
+      _autoMag = true;
       
       // populate the metadata
       QString metaVal;
@@ -293,25 +292,6 @@
       
     }
     
-    // copy sphere data to matrix.
-    
-    //data->xMin = _phiMin;
-    //data->yMin = _thetaMax;
-    //FIXME
-    // temporarily return data in bastardized RA/DEC, 
-    // since kst cannot yet handle max < min.  Change this
-    // once kst2drenderer is implemented
-    if (_phiMin > _phiMax) {
-      data->xMin = -((2.0*HEALPIX_PI - _phiMin)/HEALPIX_PI) * 180.0;
-      data->xStepSize = ((_phiMax + (2.0*HEALPIX_PI-_phiMin))/HEALPIX_PI) * 180.0/(double)_nX;
-    } else {
-      data->xMin = (_phiMin/HEALPIX_PI) * 180.0;
-      data->xStepSize = ((_phiMax - _phiMin)/HEALPIX_PI) * 180.0/(double)_nX;
-    }
-    data->yMin = 90.0 - (_thetaMax/HEALPIX_PI) * 180.0;
-    data->yStepSize = ((_thetaMax - _thetaMin)/HEALPIX_PI) * 180.0/(double)_nY;
-    
-    
     double theta, phi;
     size_t ppix;
     
@@ -320,6 +300,68 @@
       data->z[i] = NAN;
     }
     
+    // compute autorange parameters
+    _mapMinTheta = HEALPIX_PI;
+    _mapMaxTheta = 0.0;
+    _mapMinPhi = 2.0*HEALPIX_PI;
+    _mapMaxPhi = 0.0;
+    
+    for (size_t i = 0; i < _mapNpix; i++) {
+      if (!healpix_is_fnull(mapdata[i])) {
+        if (_mapOrder == HEALPIX_RING) {
+          healpix_pix2ang_ring(_mapNside, i, &theta, &phi);
+        } else {
+          healpix_pix2ang_nest(_mapNside, i, &theta, &phi);
+        }
+        if (theta < _mapMinTheta) {
+          _mapMinTheta = theta;
+        }
+        if (theta > _mapMaxTheta) {
+          _mapMaxTheta = theta;
+        }
+        if (phi < _mapMinPhi) {
+          _mapMinPhi = phi;
+        }
+        if (phi > _mapMaxPhi) {
+          _mapMaxPhi = phi;
+        }
+      }
+    }
+    if (_mapMaxTheta < _mapMinTheta) { // no valid data in map
+      _mapMaxTheta = HEALPIX_PI;
+      _mapMinTheta = 0.0;
+      _mapMaxPhi = 2.0*HEALPIX_PI;
+      _mapMinPhi = 0.0;
+    } else { // add 3% buffers to the range
+      _mapMaxTheta *= 1.03;
+      if (_mapMaxTheta > HEALPIX_PI) {
+        _mapMaxTheta = HEALPIX_PI;
+      }
+      _mapMinTheta *= 0.97;
+      if (_mapMinTheta < 0.0) {
+        _mapMinTheta = 0.0;
+      }
+      //autoscaling in phi only supports min < max
+      _mapMaxPhi *= 1.03;
+      if (_mapMaxPhi > 2.0*HEALPIX_PI) {
+        _mapMaxPhi = 2.0*HEALPIX_PI;
+      }
+      _mapMinPhi *= 0.97;
+      if (_mapMinPhi < 0.0) {
+        _mapMinPhi = 0.0;
+      }
+    }
+    if (_autoTheta) {
+      _thetaMin = _mapMinTheta;
+      _thetaMax = _mapMaxTheta;
+    }
+    if (_autoPhi) {
+      _phiMin = _mapMinPhi;
+      _phiMax = _mapMaxPhi;
+    }
+    
+    // copy sphere data to matrix.
+    
     for (int i = xStart; i < nxread; i++) {
       for (int j = yStart; j < nyread; j++) {
         healpix_proj_rev_car(_thetaMin, _thetaMax, _phiMin, _phiMax, (double)_nX, (double)_nY, (double)i, (double)j, &theta, &phi);
@@ -336,6 +378,22 @@
       }
     }
     
+    //data->xMin = _phiMin;
+    //data->yMin = _thetaMax;
+    //FIXME
+    // temporarily return data in bastardized RA/DEC, 
+    // since kst cannot yet handle max < min.  Change this
+    // once kst2drenderer is implemented
+    if (_phiMin > _phiMax) {
+      data->xMin = -((2.0*HEALPIX_PI - _phiMin)/HEALPIX_PI) * 180.0;
+      data->xStepSize = ((_phiMax + (2.0*HEALPIX_PI-_phiMin))/HEALPIX_PI) * 180.0/(double)_nX;
+    } else {
+      data->xMin = (_phiMin/HEALPIX_PI) * 180.0;
+      data->xStepSize = ((_phiMax - _phiMin)/HEALPIX_PI) * 180.0/(double)_nX;
+    }
+    data->yMin = 90.0 - (_thetaMax/HEALPIX_PI) * 180.0;
+    data->yStepSize = ((_thetaMax - _thetaMin)/HEALPIX_PI) * 180.0/(double)_nY;
+    
     free(mapdata);
     fits_close_file(fp, &ret);
         
--- trunk/extragear/graphics/kst/kst/datasources/healpix/healpix_source.h #474258:474259
@@ -71,11 +71,20 @@
     double _phiMin;
     double _thetaMax;
     double _phiMax;
+    bool _autoTheta;
+    bool _autoPhi;
+    double _mapMinTheta;
+    double _mapMaxTheta;
+    double _mapMinPhi;
+    double _mapMaxPhi;
     
     /* vector field */
     int _vecDegrade;
     int _vecComp1;
     int _vecComp2;
+    bool _autoMag;
+    double _maxMag;
+    double _vecMax;
     
 };
 


More information about the Kst mailing list