00001 #ifndef SKYMAP_HPP 00002 #define SKYMAP_HPP 00003 /* ============================================================================ 00004 'skymap.h' defines the pixel and skymap classes. Non-inline methods and space 00005 for static class members are defined in 'skymap.cpp'. 00006 00007 Written by Nicholas Phillips, December 2006 00008 Adapted for WMAP. FITS and copy operator added. Michael R. Greason, ADNET, 00009 27 December 2006. 00010 ============================================================================ */ 00011 #include <fitsio.h> 00012 #include <QString> 00013 #include <string> 00014 #include "pixel.h" 00015 //#include "fileprogress.h" 00016 00017 class ControlDialog; 00018 /* ============================================================================= 00019 The Skymap class defines a collection of pixels to represent a sky map. 00020 This version allows for dynamically selecting how much information is stored 00021 for each pixel. Can be as simple as just the temperature or up to temperature, 00022 polarization and number of observations. This class has no knowledge of the 00023 pixel formatting; it is up to child classes to provide this information. 00024 00025 When set() is called, memory is allocated for the type of pixel requested. 00026 The address is stored in the appropiate data points (tpix, tppix, etc) and 00027 the member function pointer returnfct is set to point to the corresponding 00028 indexing method (returnTpix, etc). Now when the indexing operator[] is called, 00029 this is inlined de-referenced to the correct index method. In turn, this method 00030 is just an inlined index into the corresponding data array. 00031 00032 A bunch of inlined syntax sugar so we can write 00033 map2[i].T() = map1[j].T() 00034 00035 There are four functions that are used to read and write the FITS headers. The 00036 two write routines exist to add keywords to the default headers. These versions 00037 do nothing; child classes should overload them as needed. 00038 ============================================================================= */ 00039 class Skymap 00040 { 00041 public: 00042 // The possible data that can be stored per pixel 00043 enum Type { 00044 none, // No type set 00045 TPix, // Only temperature 00046 PPix, // Temperature and Polarization, i.e. Stoke's parameters 00047 TnobsPix, // Temperature and Number of observations 00048 TPnobsPix // Temperature, Polarization and Number of observations 00049 }; 00050 00051 protected: 00052 Type type_; // The current data Type 00053 unsigned int n_; // The current number of pixels 00054 TPixel *tpix; // When TPix, where to store data 00055 TPPixel *tppix; // When PPix, where to store data 00056 TnobsPixel *tnobspix; // When TnobsPix, where to store data 00057 TPnobsPixel *tpnobspix; // When TPnobsPix, where to store data 00058 00059 TPnobsPixel minpix; // Minimum pixel values. 00060 TPnobsPixel maxpix; // Maximum pixel values. 00061 TPnobsPixel avgpix; // Mean pixel value. 00062 TPnobsPixel stdpix; // Std. dev. of the mean. 00063 00064 // Dummy variable needed for completeness of returnnone() 00065 static BasePixel basedummy; 00066 00067 // Set to zero size and no type 00068 virtual void init(); 00069 // Allocate pixel memory. 00070 virtual void allocPixMemory(unsigned int n_in, Type type_in); 00071 // Free all heap memory. 00072 virtual void freeMemory(); 00073 00074 //------------------------------------------------------------------------ 00075 // Versions of base indexing function to return a reference into this map 00076 // Used when the contents of the map are to be modified 00077 00078 // method to call to return a refernece to an indexed pixel 00079 BasePixel& (Skymap::*returnfct)(unsigned int); 00080 00081 // Index look-up method for when no data is allocated 00082 BasePixel& returnnone(unsigned int i); 00083 // Index look-up method for when type = TPix 00084 BasePixel& returnTpix(unsigned int i); 00085 // Index look-up method for when type = PPix 00086 BasePixel& returnTPpix(unsigned int i); 00087 // Index look-up method for when type = TnobsPix 00088 BasePixel& returnTnobspix(unsigned int i); 00089 // Index look-up method for when type = TPnobsPix 00090 BasePixel& returnTPnobspix(unsigned int i); 00091 00092 00093 // Functions to read/write the FITS headers. 00094 void writeHdrDate (fitsfile *fptr); 00095 virtual void readFITSPrimaryHeader (fitsfile *fptr); 00096 virtual void writeFITSPrimaryHeader (fitsfile *fptr); 00097 virtual void readFITSExtensionHeader (fitsfile *fptr); 00098 virtual void writeFITSExtensionHeader (fitsfile *fptr); 00099 public: 00100 // Create with no data and Type 00101 Skymap(); 00102 00103 // Create with a selected size and Type 00104 Skymap(unsigned int n_in, Type type_in); 00105 00106 // Done, call freeMemory() 00107 virtual ~Skymap(); 00108 00109 // Fundamental method to set size and type of data 00110 virtual void set(unsigned int n_in, Type type_in); 00111 00112 // Clear stored memory and reset state 00113 virtual void clear() { set(0,none); } 00114 00115 // Copy another map into this one. 00116 void copy (Skymap &imap); 00117 00118 // Return the number of pixels 00119 unsigned int size() const { return n_; } 00120 00121 // Return the number of pixels 00122 unsigned int n() const { return n_; } 00123 00124 // Return the type of data stored at each pixel 00125 Type type() const { return type_; } 00126 bool has_Temperature (void) const; 00127 bool has_Polarization (void) const; 00128 bool has_Nobs (void) const; 00129 00130 // Basic function to access a pixel 00131 BasePixel& operator[](unsigned int i); 00132 00133 // Copy operator. 00134 Skymap& operator= (Skymap &imap); 00135 00136 // Compute the polarization magnitude and angle for each pixel. 00137 virtual void computePolar (void); 00138 00139 // Compute and return statistics on the map. 00140 virtual void calcStats (void); 00141 00142 double getMeanT() const; 00143 double getStdDevT() const; 00144 double getMinT() const; 00145 double getMaxT() const; 00146 00147 double getMeanQ() const; 00148 double getStdDevQ() const; 00149 double getMinQ() const; 00150 double getMaxQ() const; 00151 00152 double getMeanU() const; 00153 double getStdDevU() const; 00154 double getMinU() const; 00155 double getMaxU() const; 00156 00157 double getMeanNobs() const; 00158 double getStdDevNobs() const; 00159 double getMinNobs() const; 00160 double getMaxNobs() const; 00161 00162 double getMeanPmag() const; 00163 double getStdDevPmag() const; 00164 double getMinPmag() const; 00165 double getMaxPmag() const; 00166 00167 double getMeanPang() const; 00168 double getStdDevPang() const; 00169 double getMinPang() const; 00170 double getMaxPang() const; 00171 00172 // Read a map from a FITS file. 00173 /* 00174 virtual void readFITS (const char* filename, fileProgress *progwin = NULL); 00175 virtual void readFITS (std::string filename, fileProgress *progwin = NULL); 00176 virtual void readFITS (QString filename, fileProgress *progwin = NULL); 00177 */ 00178 // Read a map from a FITS file. 00179 virtual void readFITS (const char* filename, ControlDialog *progwin = NULL); 00180 virtual void readFITS (std::string filename, ControlDialog *progwin = NULL); 00181 virtual void readFITS (QString filename, ControlDialog *progwin = NULL); 00182 00183 // Write a map to a FITS file. 00184 virtual void writeFITS (const char* filename, char* tabname = NULL); 00185 virtual void writeFITS (std::string filename, char* tabname = NULL); 00186 virtual void writeFITS (QString filename, char* tabname = NULL); 00187 }; 00188 //---------------------------------------------------------------------------------- 00189 inline BasePixel& Skymap::returnTpix(unsigned int i) { return tpix[i]; } 00190 inline BasePixel& Skymap::returnTPpix(unsigned int i) { return tppix[i]; } 00191 inline BasePixel& Skymap::returnTnobspix(unsigned int i) { return tnobspix[i]; } 00192 inline BasePixel& Skymap::returnTPnobspix(unsigned int i) { return tpnobspix[i]; } 00193 /* ---------------------------------------------------------------------------- 00194 'has_Temperature' returns true if the map contains Stokes I/temperature data. 00195 00196 Arguments: 00197 None. 00198 00199 Returned: 00200 true if the map contains the desired data. 00201 ---------------------------------------------------------------------------- */ 00202 inline bool Skymap::has_Temperature (void) const 00203 { 00204 return (type() != none); 00205 } 00206 /* ---------------------------------------------------------------------------- 00207 'has_Polarization' returns true if the map contains Stokes Q and U data. 00208 00209 Arguments: 00210 None. 00211 00212 Returned: 00213 true if the map contains the desired data. 00214 ---------------------------------------------------------------------------- */ 00215 inline bool Skymap::has_Polarization (void) const 00216 { 00217 return ((type() == PPix) || (type() == TPnobsPix)); 00218 } 00219 /* ---------------------------------------------------------------------------- 00220 'has_Nobs' returns true if the map contains N_obs data. 00221 00222 Arguments: 00223 None. 00224 00225 Returned: 00226 true if the map contains the desired data. 00227 ---------------------------------------------------------------------------- */ 00228 inline bool Skymap::has_Nobs (void) const 00229 { 00230 return ((type() == TnobsPix) || (type() == TPnobsPix)); 00231 } 00232 /* ---------------------------------------------------------------------------- 00233 'operator[]' allows the sky map to be indexed as an array. 00234 00235 Arguments: 00236 i - The index into the map. 00237 00238 Returned: 00239 A reference to the pixel is returned. An exception is thrown if the index is out of 00240 bounds. 00241 ---------------------------------------------------------------------------- */ 00242 inline BasePixel& Skymap::operator[](unsigned int i) 00243 { 00244 if (i >= n_) throw MapException(MapException::Bounds); 00245 return (this->*returnfct)(i); 00246 } 00247 /* ---------------------------------------------------------------------------- 00248 'operator=' copies another map into this one using the assignment operator. 00249 00250 Arguments: 00251 imap - The source map. 00252 00253 Returned: 00254 A reference to this map. 00255 ---------------------------------------------------------------------------- */ 00256 inline Skymap& Skymap::operator= (Skymap &imap) 00257 { 00258 copy(imap); 00259 return *this; 00260 } 00261 /* ---------------------------------------------------------------------------- 00262 'getMeanT' returns the average temperature/Stokes I map value. 'calcStats' 00263 should have been called since the last change to the map before trying to use 00264 this routine. 00265 00266 Arguments: 00267 None.. 00268 00269 Returned: 00270 double - The mean value. 00271 ---------------------------------------------------------------------------- */ 00272 inline double Skymap::getMeanT(void) const 00273 { 00274 if (! has_Temperature()) throw MapException(MapException::InvalidType); 00275 return avgpix.T(); 00276 } 00277 /* ---------------------------------------------------------------------------- 00278 'getStdDevT' returns the standard deviation of the mean temperature/Stokes I 00279 map value. 'calcStats' should have been called since the last change to the 00280 map before trying to use this routine. 00281 00282 Arguments: 00283 None.. 00284 00285 Returned: 00286 double - The standard deviation. 00287 ---------------------------------------------------------------------------- */ 00288 inline double Skymap::getStdDevT(void) const 00289 { 00290 if (! has_Temperature()) throw MapException(MapException::InvalidType); 00291 return stdpix.T(); 00292 } 00293 /* ---------------------------------------------------------------------------- 00294 'getMinT' returns the minimum temperature/Stokes I map value. 'calcStats' 00295 should have been called since the last change to the map before trying to use 00296 this routine. 00297 00298 Arguments: 00299 None.. 00300 00301 Returned: 00302 double - The minimum value. 00303 ---------------------------------------------------------------------------- */ 00304 inline double Skymap::getMinT(void) const 00305 { 00306 if (! has_Temperature()) throw MapException(MapException::InvalidType); 00307 return minpix.T(); 00308 } 00309 /* ---------------------------------------------------------------------------- 00310 'getMaxT' returns the maximum temperature/Stokes I map value. 'calcStats' 00311 should have been called since the last change to the map before trying to use 00312 this routine. 00313 00314 Arguments: 00315 None.. 00316 00317 Returned: 00318 double - The maximum value. 00319 ---------------------------------------------------------------------------- */ 00320 inline double Skymap::getMaxT(void) const 00321 { 00322 if (! has_Temperature()) throw MapException(MapException::InvalidType); 00323 return maxpix.T(); 00324 } 00325 /* ---------------------------------------------------------------------------- 00326 'getMeanQ' returns the average Stokes Q map value. 'calcStats' should have 00327 been called since the last change to the map before trying to use this routine. 00328 00329 Arguments: 00330 None.. 00331 00332 Returned: 00333 double - The mean value. 00334 ---------------------------------------------------------------------------- */ 00335 inline double Skymap::getMeanQ(void) const 00336 { 00337 if (! has_Polarization()) throw MapException(MapException::InvalidType); 00338 return avgpix.Q(); 00339 } 00340 /* ---------------------------------------------------------------------------- 00341 'getStdDevQ' returns the standard deviation of the Stokes Q map value. 00342 'calcStats' should have been called since the last change to the map before 00343 trying to use this routine. 00344 00345 Arguments: 00346 None.. 00347 00348 Returned: 00349 double - The standard deviation. 00350 ---------------------------------------------------------------------------- */ 00351 inline double Skymap::getStdDevQ(void) const 00352 { 00353 if (! has_Polarization()) throw MapException(MapException::InvalidType); 00354 return stdpix.Q(); 00355 } 00356 /* ---------------------------------------------------------------------------- 00357 'getMinQ' returns the minimum Stokes Q map value. 'calcStats' should have 00358 been called since the last change to the map before trying to use this routine. 00359 00360 Arguments: 00361 None.. 00362 00363 Returned: 00364 double - The minimum value. 00365 ---------------------------------------------------------------------------- */ 00366 inline double Skymap::getMinQ(void) const 00367 { 00368 if (! has_Polarization()) throw MapException(MapException::InvalidType); 00369 return minpix.Q(); 00370 } 00371 /* ---------------------------------------------------------------------------- 00372 'getMaxQ' returns the maximum Stokes Q map value. 'calcStats' should have 00373 been called since the last change to the map before trying to use this routine. 00374 00375 Arguments: 00376 None.. 00377 00378 Returned: 00379 double - The maximum value. 00380 ---------------------------------------------------------------------------- */ 00381 inline double Skymap::getMaxQ(void) const 00382 { 00383 if (! has_Polarization()) throw MapException(MapException::InvalidType); 00384 return maxpix.Q(); 00385 } 00386 /* ---------------------------------------------------------------------------- 00387 'getMeanU' returns the average Stokes U map value. 'calcStats' should have 00388 been called since the last change to the map before trying to use this routine. 00389 00390 Arguments: 00391 None.. 00392 00393 Returned: 00394 double - The mean value. 00395 ---------------------------------------------------------------------------- */ 00396 inline double Skymap::getMeanU(void) const 00397 { 00398 if (! has_Polarization()) throw MapException(MapException::InvalidType); 00399 return avgpix.U(); 00400 } 00401 /* ---------------------------------------------------------------------------- 00402 'getStdDevU' returns the standard deviation of the Stokes U map value. 00403 'calcStats' should have been called since the last change to the map before 00404 trying to use this routine. 00405 00406 Arguments: 00407 None.. 00408 00409 Returned: 00410 double - The standard deviation. 00411 ---------------------------------------------------------------------------- */ 00412 inline double Skymap::getStdDevU(void) const 00413 { 00414 if (! has_Polarization()) throw MapException(MapException::InvalidType); 00415 return stdpix.U(); 00416 } 00417 /* ---------------------------------------------------------------------------- 00418 'getMinU' returns the minimum Stokes U map value. 'calcStats' should have 00419 been called since the last change to the map before trying to use this routine. 00420 00421 Arguments: 00422 None.. 00423 00424 Returned: 00425 double - The minimum value. 00426 ---------------------------------------------------------------------------- */ 00427 inline double Skymap::getMinU(void) const 00428 { 00429 if (! has_Polarization()) throw MapException(MapException::InvalidType); 00430 return minpix.U(); 00431 } 00432 /* ---------------------------------------------------------------------------- 00433 'getMaxU' returns the maximum Stokes U map value. 'calcStats' should have 00434 been called since the last change to the map before trying to use this routine. 00435 00436 Arguments: 00437 None.. 00438 00439 Returned: 00440 double - The maximum value. 00441 ---------------------------------------------------------------------------- */ 00442 inline double Skymap::getMaxU(void) const 00443 { 00444 if (! has_Polarization()) throw MapException(MapException::InvalidType); 00445 return maxpix.U(); 00446 } 00447 /* ---------------------------------------------------------------------------- 00448 'getMeanNobs' returns the average Nobs map value. 'calcStats' should have 00449 been called since the last change to the map before trying to use this routine. 00450 00451 Arguments: 00452 None.. 00453 00454 Returned: 00455 double - The mean value. 00456 ---------------------------------------------------------------------------- */ 00457 inline double Skymap::getMeanNobs(void) const 00458 { 00459 if (! has_Nobs()) throw MapException(MapException::InvalidType); 00460 return avgpix.Nobs(); 00461 } 00462 /* ---------------------------------------------------------------------------- 00463 'getStdDevNobs' returns the standard deviation of the Nobs map value. 00464 'calcStats' should have been called since the last change to the map before 00465 trying to use this routine. 00466 00467 Arguments: 00468 None.. 00469 00470 Returned: 00471 double - The standard deviation. 00472 ---------------------------------------------------------------------------- */ 00473 inline double Skymap::getStdDevNobs(void) const 00474 { 00475 if (! has_Nobs()) throw MapException(MapException::InvalidType); 00476 return stdpix.Nobs(); 00477 } 00478 /* ---------------------------------------------------------------------------- 00479 'getMinNobs' returns the minimum Nobs map value. 'calcStats' should have 00480 been called since the last change to the map before trying to use this routine. 00481 00482 Arguments: 00483 None.. 00484 00485 Returned: 00486 double - The minimum value. 00487 ---------------------------------------------------------------------------- */ 00488 inline double Skymap::getMinNobs(void) const 00489 { 00490 if (! has_Nobs()) throw MapException(MapException::InvalidType); 00491 return minpix.Nobs(); 00492 } 00493 /* ---------------------------------------------------------------------------- 00494 'getMaxNobs' returns the maximum Nobs map value. 'calcStats' should have 00495 been called since the last change to the map before trying to use this routine. 00496 00497 Arguments: 00498 None.. 00499 00500 Returned: 00501 double - The maximum value. 00502 ---------------------------------------------------------------------------- */ 00503 inline double Skymap::getMaxNobs(void) const 00504 { 00505 if (! has_Nobs()) throw MapException(MapException::InvalidType); 00506 return maxpix.Nobs(); 00507 } 00508 /* ---------------------------------------------------------------------------- 00509 'getMeanPmag' returns the average polarization magnitude map value. 00510 00511 'computePolar' and 'calcStats' should have been called since the last change 00512 to the map before trying to use this routine. 00513 00514 Arguments: 00515 None.. 00516 00517 Returned: 00518 double - The mean value. 00519 ---------------------------------------------------------------------------- */ 00520 inline double Skymap::getMeanPmag(void) const 00521 { 00522 if (! has_Polarization()) throw MapException(MapException::InvalidType); 00523 return avgpix.Pmag(); 00524 } 00525 /* ---------------------------------------------------------------------------- 00526 'getStdDevPmag' returns the standard deviation of the polarization magnitude 00527 map value. 00528 00529 'computePolar' and 'calcStats' should have been called since the last change 00530 to the map before trying to use this routine. 00531 00532 Arguments: 00533 None.. 00534 00535 Returned: 00536 double - The standard deviation. 00537 ---------------------------------------------------------------------------- */ 00538 inline double Skymap::getStdDevPmag(void) const 00539 { 00540 if (! has_Polarization()) throw MapException(MapException::InvalidType); 00541 return stdpix.Pmag(); 00542 } 00543 /* ---------------------------------------------------------------------------- 00544 'getMinPmag' returns the minimum polarization magnitude map value. 00545 00546 'computePolar' and 'calcStats' should have been called since the last change 00547 to the map before trying to use this routine. 00548 00549 Arguments: 00550 None.. 00551 00552 Returned: 00553 double - The minimum value. 00554 ---------------------------------------------------------------------------- */ 00555 inline double Skymap::getMinPmag(void) const 00556 { 00557 if (! has_Polarization()) throw MapException(MapException::InvalidType); 00558 return minpix.Pmag(); 00559 } 00560 /* ---------------------------------------------------------------------------- 00561 'getMaxPmag' returns the maximum polarization magnitude map value. 00562 00563 'computePolar' and 'calcStats' should have been called since the last change 00564 to the map before trying to use this routine. 00565 00566 Arguments: 00567 None.. 00568 00569 Returned: 00570 double - The maximum value. 00571 ---------------------------------------------------------------------------- */ 00572 inline double Skymap::getMaxPmag(void) const 00573 { 00574 if (! has_Polarization()) throw MapException(MapException::InvalidType); 00575 return maxpix.Pmag(); 00576 } 00577 /* ---------------------------------------------------------------------------- 00578 'getMeanPang' returns the average polarization angle map value. 00579 00580 'computePolar' and 'calcStats' should have been called since the last change 00581 to the map before trying to use this routine. 00582 00583 Arguments: 00584 None.. 00585 00586 Returned: 00587 double - The mean value. 00588 ---------------------------------------------------------------------------- */ 00589 inline double Skymap::getMeanPang(void) const 00590 { 00591 if (! has_Polarization()) throw MapException(MapException::InvalidType); 00592 return avgpix.Pang(); 00593 } 00594 /* ---------------------------------------------------------------------------- 00595 'getStdDevPang' returns the standard deviation of the polarization angle 00596 map value. 00597 00598 'computePolar' and 'calcStats' should have been called since the last change 00599 to the map before trying to use this routine. 00600 00601 Arguments: 00602 None.. 00603 00604 Returned: 00605 double - The standard deviation. 00606 ---------------------------------------------------------------------------- */ 00607 inline double Skymap::getStdDevPang(void) const 00608 { 00609 if (! has_Polarization()) throw MapException(MapException::InvalidType); 00610 return stdpix.Pang(); 00611 } 00612 /* ---------------------------------------------------------------------------- 00613 'getMinPang' returns the minimum polarization angle map value. 00614 00615 'computePolar' and 'calcStats' should have been called since the last change 00616 to the map before trying to use this routine. 00617 00618 Arguments: 00619 None.. 00620 00621 Returned: 00622 double - The minimum value. 00623 ---------------------------------------------------------------------------- */ 00624 inline double Skymap::getMinPang(void) const 00625 { 00626 if (! has_Polarization()) throw MapException(MapException::InvalidType); 00627 return minpix.Pang(); 00628 } 00629 /* ---------------------------------------------------------------------------- 00630 'getMaxPang' returns the maximum polarization angle map value. 00631 00632 'computePolar' and 'calcStats' should have been called since the last change 00633 to the map before trying to use this routine. 00634 00635 Arguments: 00636 None.. 00637 00638 Returned: 00639 double - The maximum value. 00640 ---------------------------------------------------------------------------- */ 00641 inline double Skymap::getMaxPang(void) const 00642 { 00643 if (! has_Polarization()) throw MapException(MapException::InvalidType); 00644 return maxpix.Pang(); 00645 } 00646 #endif