-
Notifications
You must be signed in to change notification settings - Fork 4
/
skymap.h
646 lines (546 loc) · 21.7 KB
/
skymap.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
#ifndef SKYMAP_HPP
#define SKYMAP_HPP
/* ============================================================================
'skymap.h' defines the pixel and skymap classes. Non-inline methods and space
for static class members are defined in 'skymap.cpp'.
Written by Nicholas Phillips, December 2006
Adapted for WMAP. FITS and copy operator added. Michael R. Greason, ADNET,
27 December 2006.
============================================================================ */
#include <fitsio.h>
#include <QString>
#include <string>
#include "pixel.h"
//#include "fileprogress.h"
class ControlDialog;
/* =============================================================================
The Skymap class defines a collection of pixels to represent a sky map.
This version allows for dynamically selecting how much information is stored
for each pixel. Can be as simple as just the temperature or up to temperature,
polarization and number of observations. This class has no knowledge of the
pixel formatting; it is up to child classes to provide this information.
When set() is called, memory is allocated for the type of pixel requested.
The address is stored in the appropiate data points (tpix, tppix, etc) and
the member function pointer returnfct is set to point to the corresponding
indexing method (returnTpix, etc). Now when the indexing operator[] is called,
this is inlined de-referenced to the correct index method. In turn, this method
is just an inlined index into the corresponding data array.
A bunch of inlined syntax sugar so we can write
map2[i].T() = map1[j].T()
There are four functions that are used to read and write the FITS headers. The
two write routines exist to add keywords to the default headers. These versions
do nothing; child classes should overload them as needed.
============================================================================= */
class Skymap
{
public:
// The possible data that can be stored per pixel
enum Type {
none, // No type set
TPix, // Only temperature
PPix, // Temperature and Polarization, i.e. Stoke's parameters
TnobsPix, // Temperature and Number of observations
TPnobsPix // Temperature, Polarization and Number of observations
};
protected:
Type type_; // The current data Type
unsigned int n_; // The current number of pixels
TPixel *tpix; // When TPix, where to store data
TPPixel *tppix; // When PPix, where to store data
TnobsPixel *tnobspix; // When TnobsPix, where to store data
TPnobsPixel *tpnobspix; // When TPnobsPix, where to store data
TPnobsPixel minpix; // Minimum pixel values.
TPnobsPixel maxpix; // Maximum pixel values.
TPnobsPixel avgpix; // Mean pixel value.
TPnobsPixel stdpix; // Std. dev. of the mean.
// Dummy variable needed for completeness of returnnone()
static BasePixel basedummy;
// Set to zero size and no type
virtual void init();
// Allocate pixel memory.
virtual void allocPixMemory(unsigned int n_in, Type type_in);
// Free all heap memory.
virtual void freeMemory();
//------------------------------------------------------------------------
// Versions of base indexing function to return a reference into this map
// Used when the contents of the map are to be modified
// method to call to return a refernece to an indexed pixel
BasePixel& (Skymap::*returnfct)(unsigned int);
// Index look-up method for when no data is allocated
BasePixel& returnnone(unsigned int i);
// Index look-up method for when type = TPix
BasePixel& returnTpix(unsigned int i);
// Index look-up method for when type = PPix
BasePixel& returnTPpix(unsigned int i);
// Index look-up method for when type = TnobsPix
BasePixel& returnTnobspix(unsigned int i);
// Index look-up method for when type = TPnobsPix
BasePixel& returnTPnobspix(unsigned int i);
// Functions to read/write the FITS headers.
void writeHdrDate (fitsfile *fptr);
virtual void readFITSPrimaryHeader (fitsfile *fptr);
virtual void writeFITSPrimaryHeader (fitsfile *fptr);
virtual void readFITSExtensionHeader (fitsfile *fptr);
virtual void writeFITSExtensionHeader (fitsfile *fptr);
public:
// Create with no data and Type
Skymap();
// Create with a selected size and Type
Skymap(unsigned int n_in, Type type_in);
// Done, call freeMemory()
virtual ~Skymap();
// Fundamental method to set size and type of data
virtual void set(unsigned int n_in, Type type_in);
// Clear stored memory and reset state
virtual void clear() { set(0,none); }
// Copy another map into this one.
void copy (Skymap &imap);
// Return the number of pixels
unsigned int size() const { return n_; }
// Return the number of pixels
unsigned int n() const { return n_; }
// Return the type of data stored at each pixel
Type type() const { return type_; }
bool has_Temperature (void) const;
bool has_Polarization (void) const;
bool has_Nobs (void) const;
// Basic function to access a pixel
BasePixel& operator[](unsigned int i);
// Copy operator.
Skymap& operator= (Skymap &imap);
// Compute the polarization magnitude and angle for each pixel.
virtual void computePolar (void);
// Compute and return statistics on the map.
virtual void calcStats (void);
double getMeanT() const;
double getStdDevT() const;
double getMinT() const;
double getMaxT() const;
double getMeanQ() const;
double getStdDevQ() const;
double getMinQ() const;
double getMaxQ() const;
double getMeanU() const;
double getStdDevU() const;
double getMinU() const;
double getMaxU() const;
double getMeanNobs() const;
double getStdDevNobs() const;
double getMinNobs() const;
double getMaxNobs() const;
double getMeanPmag() const;
double getStdDevPmag() const;
double getMinPmag() const;
double getMaxPmag() const;
double getMeanPang() const;
double getStdDevPang() const;
double getMinPang() const;
double getMaxPang() const;
// Read a map from a FITS file.
/*
virtual void readFITS (const char* filename, fileProgress *progwin = NULL);
virtual void readFITS (std::string filename, fileProgress *progwin = NULL);
virtual void readFITS (QString filename, fileProgress *progwin = NULL);
*/
// Read a map from a FITS file.
virtual void readFITS (const char* filename, ControlDialog *progwin = NULL);
virtual void readFITS (std::string filename, ControlDialog *progwin = NULL);
virtual void readFITS (QString filename, ControlDialog *progwin = NULL);
// Write a map to a FITS file.
virtual void writeFITS (const char* filename, char* tabname = NULL);
virtual void writeFITS (std::string filename, char* tabname = NULL);
virtual void writeFITS (QString filename, char* tabname = NULL);
};
//----------------------------------------------------------------------------------
inline BasePixel& Skymap::returnTpix(unsigned int i) { return tpix[i]; }
inline BasePixel& Skymap::returnTPpix(unsigned int i) { return tppix[i]; }
inline BasePixel& Skymap::returnTnobspix(unsigned int i) { return tnobspix[i]; }
inline BasePixel& Skymap::returnTPnobspix(unsigned int i) { return tpnobspix[i]; }
/* ----------------------------------------------------------------------------
'has_Temperature' returns true if the map contains Stokes I/temperature data.
Arguments:
None.
Returned:
true if the map contains the desired data.
---------------------------------------------------------------------------- */
inline bool Skymap::has_Temperature (void) const
{
return (type() != none);
}
/* ----------------------------------------------------------------------------
'has_Polarization' returns true if the map contains Stokes Q and U data.
Arguments:
None.
Returned:
true if the map contains the desired data.
---------------------------------------------------------------------------- */
inline bool Skymap::has_Polarization (void) const
{
return ((type() == PPix) || (type() == TPnobsPix));
}
/* ----------------------------------------------------------------------------
'has_Nobs' returns true if the map contains N_obs data.
Arguments:
None.
Returned:
true if the map contains the desired data.
---------------------------------------------------------------------------- */
inline bool Skymap::has_Nobs (void) const
{
return ((type() == TnobsPix) || (type() == TPnobsPix));
}
/* ----------------------------------------------------------------------------
'operator[]' allows the sky map to be indexed as an array.
Arguments:
i - The index into the map.
Returned:
A reference to the pixel is returned. An exception is thrown if the index is out of
bounds.
---------------------------------------------------------------------------- */
inline BasePixel& Skymap::operator[](unsigned int i)
{
if (i >= n_) throw MapException(MapException::Bounds);
return (this->*returnfct)(i);
}
/* ----------------------------------------------------------------------------
'operator=' copies another map into this one using the assignment operator.
Arguments:
imap - The source map.
Returned:
A reference to this map.
---------------------------------------------------------------------------- */
inline Skymap& Skymap::operator= (Skymap &imap)
{
copy(imap);
return *this;
}
/* ----------------------------------------------------------------------------
'getMeanT' returns the average temperature/Stokes I map value. 'calcStats'
should have been called since the last change to the map before trying to use
this routine.
Arguments:
None..
Returned:
double - The mean value.
---------------------------------------------------------------------------- */
inline double Skymap::getMeanT(void) const
{
if (! has_Temperature()) throw MapException(MapException::InvalidType);
return avgpix.T();
}
/* ----------------------------------------------------------------------------
'getStdDevT' returns the standard deviation of the mean temperature/Stokes I
map value. 'calcStats' should have been called since the last change to the
map before trying to use this routine.
Arguments:
None..
Returned:
double - The standard deviation.
---------------------------------------------------------------------------- */
inline double Skymap::getStdDevT(void) const
{
if (! has_Temperature()) throw MapException(MapException::InvalidType);
return stdpix.T();
}
/* ----------------------------------------------------------------------------
'getMinT' returns the minimum temperature/Stokes I map value. 'calcStats'
should have been called since the last change to the map before trying to use
this routine.
Arguments:
None..
Returned:
double - The minimum value.
---------------------------------------------------------------------------- */
inline double Skymap::getMinT(void) const
{
if (! has_Temperature()) throw MapException(MapException::InvalidType);
return minpix.T();
}
/* ----------------------------------------------------------------------------
'getMaxT' returns the maximum temperature/Stokes I map value. 'calcStats'
should have been called since the last change to the map before trying to use
this routine.
Arguments:
None..
Returned:
double - The maximum value.
---------------------------------------------------------------------------- */
inline double Skymap::getMaxT(void) const
{
if (! has_Temperature()) throw MapException(MapException::InvalidType);
return maxpix.T();
}
/* ----------------------------------------------------------------------------
'getMeanQ' returns the average Stokes Q map value. 'calcStats' should have
been called since the last change to the map before trying to use this routine.
Arguments:
None..
Returned:
double - The mean value.
---------------------------------------------------------------------------- */
inline double Skymap::getMeanQ(void) const
{
if (! has_Polarization()) throw MapException(MapException::InvalidType);
return avgpix.Q();
}
/* ----------------------------------------------------------------------------
'getStdDevQ' returns the standard deviation of the Stokes Q map value.
'calcStats' should have been called since the last change to the map before
trying to use this routine.
Arguments:
None..
Returned:
double - The standard deviation.
---------------------------------------------------------------------------- */
inline double Skymap::getStdDevQ(void) const
{
if (! has_Polarization()) throw MapException(MapException::InvalidType);
return stdpix.Q();
}
/* ----------------------------------------------------------------------------
'getMinQ' returns the minimum Stokes Q map value. 'calcStats' should have
been called since the last change to the map before trying to use this routine.
Arguments:
None..
Returned:
double - The minimum value.
---------------------------------------------------------------------------- */
inline double Skymap::getMinQ(void) const
{
if (! has_Polarization()) throw MapException(MapException::InvalidType);
return minpix.Q();
}
/* ----------------------------------------------------------------------------
'getMaxQ' returns the maximum Stokes Q map value. 'calcStats' should have
been called since the last change to the map before trying to use this routine.
Arguments:
None..
Returned:
double - The maximum value.
---------------------------------------------------------------------------- */
inline double Skymap::getMaxQ(void) const
{
if (! has_Polarization()) throw MapException(MapException::InvalidType);
return maxpix.Q();
}
/* ----------------------------------------------------------------------------
'getMeanU' returns the average Stokes U map value. 'calcStats' should have
been called since the last change to the map before trying to use this routine.
Arguments:
None..
Returned:
double - The mean value.
---------------------------------------------------------------------------- */
inline double Skymap::getMeanU(void) const
{
if (! has_Polarization()) throw MapException(MapException::InvalidType);
return avgpix.U();
}
/* ----------------------------------------------------------------------------
'getStdDevU' returns the standard deviation of the Stokes U map value.
'calcStats' should have been called since the last change to the map before
trying to use this routine.
Arguments:
None..
Returned:
double - The standard deviation.
---------------------------------------------------------------------------- */
inline double Skymap::getStdDevU(void) const
{
if (! has_Polarization()) throw MapException(MapException::InvalidType);
return stdpix.U();
}
/* ----------------------------------------------------------------------------
'getMinU' returns the minimum Stokes U map value. 'calcStats' should have
been called since the last change to the map before trying to use this routine.
Arguments:
None..
Returned:
double - The minimum value.
---------------------------------------------------------------------------- */
inline double Skymap::getMinU(void) const
{
if (! has_Polarization()) throw MapException(MapException::InvalidType);
return minpix.U();
}
/* ----------------------------------------------------------------------------
'getMaxU' returns the maximum Stokes U map value. 'calcStats' should have
been called since the last change to the map before trying to use this routine.
Arguments:
None..
Returned:
double - The maximum value.
---------------------------------------------------------------------------- */
inline double Skymap::getMaxU(void) const
{
if (! has_Polarization()) throw MapException(MapException::InvalidType);
return maxpix.U();
}
/* ----------------------------------------------------------------------------
'getMeanNobs' returns the average Nobs map value. 'calcStats' should have
been called since the last change to the map before trying to use this routine.
Arguments:
None..
Returned:
double - The mean value.
---------------------------------------------------------------------------- */
inline double Skymap::getMeanNobs(void) const
{
if (! has_Nobs()) throw MapException(MapException::InvalidType);
return avgpix.Nobs();
}
/* ----------------------------------------------------------------------------
'getStdDevNobs' returns the standard deviation of the Nobs map value.
'calcStats' should have been called since the last change to the map before
trying to use this routine.
Arguments:
None..
Returned:
double - The standard deviation.
---------------------------------------------------------------------------- */
inline double Skymap::getStdDevNobs(void) const
{
if (! has_Nobs()) throw MapException(MapException::InvalidType);
return stdpix.Nobs();
}
/* ----------------------------------------------------------------------------
'getMinNobs' returns the minimum Nobs map value. 'calcStats' should have
been called since the last change to the map before trying to use this routine.
Arguments:
None..
Returned:
double - The minimum value.
---------------------------------------------------------------------------- */
inline double Skymap::getMinNobs(void) const
{
if (! has_Nobs()) throw MapException(MapException::InvalidType);
return minpix.Nobs();
}
/* ----------------------------------------------------------------------------
'getMaxNobs' returns the maximum Nobs map value. 'calcStats' should have
been called since the last change to the map before trying to use this routine.
Arguments:
None..
Returned:
double - The maximum value.
---------------------------------------------------------------------------- */
inline double Skymap::getMaxNobs(void) const
{
if (! has_Nobs()) throw MapException(MapException::InvalidType);
return maxpix.Nobs();
}
/* ----------------------------------------------------------------------------
'getMeanPmag' returns the average polarization magnitude map value.
'computePolar' and 'calcStats' should have been called since the last change
to the map before trying to use this routine.
Arguments:
None..
Returned:
double - The mean value.
---------------------------------------------------------------------------- */
inline double Skymap::getMeanPmag(void) const
{
if (! has_Polarization()) throw MapException(MapException::InvalidType);
return avgpix.Pmag();
}
/* ----------------------------------------------------------------------------
'getStdDevPmag' returns the standard deviation of the polarization magnitude
map value.
'computePolar' and 'calcStats' should have been called since the last change
to the map before trying to use this routine.
Arguments:
None..
Returned:
double - The standard deviation.
---------------------------------------------------------------------------- */
inline double Skymap::getStdDevPmag(void) const
{
if (! has_Polarization()) throw MapException(MapException::InvalidType);
return stdpix.Pmag();
}
/* ----------------------------------------------------------------------------
'getMinPmag' returns the minimum polarization magnitude map value.
'computePolar' and 'calcStats' should have been called since the last change
to the map before trying to use this routine.
Arguments:
None..
Returned:
double - The minimum value.
---------------------------------------------------------------------------- */
inline double Skymap::getMinPmag(void) const
{
if (! has_Polarization()) throw MapException(MapException::InvalidType);
return minpix.Pmag();
}
/* ----------------------------------------------------------------------------
'getMaxPmag' returns the maximum polarization magnitude map value.
'computePolar' and 'calcStats' should have been called since the last change
to the map before trying to use this routine.
Arguments:
None..
Returned:
double - The maximum value.
---------------------------------------------------------------------------- */
inline double Skymap::getMaxPmag(void) const
{
if (! has_Polarization()) throw MapException(MapException::InvalidType);
return maxpix.Pmag();
}
/* ----------------------------------------------------------------------------
'getMeanPang' returns the average polarization angle map value.
'computePolar' and 'calcStats' should have been called since the last change
to the map before trying to use this routine.
Arguments:
None..
Returned:
double - The mean value.
---------------------------------------------------------------------------- */
inline double Skymap::getMeanPang(void) const
{
if (! has_Polarization()) throw MapException(MapException::InvalidType);
return avgpix.Pang();
}
/* ----------------------------------------------------------------------------
'getStdDevPang' returns the standard deviation of the polarization angle
map value.
'computePolar' and 'calcStats' should have been called since the last change
to the map before trying to use this routine.
Arguments:
None..
Returned:
double - The standard deviation.
---------------------------------------------------------------------------- */
inline double Skymap::getStdDevPang(void) const
{
if (! has_Polarization()) throw MapException(MapException::InvalidType);
return stdpix.Pang();
}
/* ----------------------------------------------------------------------------
'getMinPang' returns the minimum polarization angle map value.
'computePolar' and 'calcStats' should have been called since the last change
to the map before trying to use this routine.
Arguments:
None..
Returned:
double - The minimum value.
---------------------------------------------------------------------------- */
inline double Skymap::getMinPang(void) const
{
if (! has_Polarization()) throw MapException(MapException::InvalidType);
return minpix.Pang();
}
/* ----------------------------------------------------------------------------
'getMaxPang' returns the maximum polarization angle map value.
'computePolar' and 'calcStats' should have been called since the last change
to the map before trying to use this routine.
Arguments:
None..
Returned:
double - The maximum value.
---------------------------------------------------------------------------- */
inline double Skymap::getMaxPang(void) const
{
if (! has_Polarization()) throw MapException(MapException::InvalidType);
return maxpix.Pang();
}
#endif