Healpix C++  3.83
powspec_fitsio.cc
1 /*
2  * This file is part of Healpix_cxx.
3  *
4  * Healpix_cxx is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * Healpix_cxx is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Healpix_cxx; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * For more information about HEALPix, see http://healpix.sourceforge.net
19  */
20 
21 /*
22  * Healpix_cxx is being developed at the Max-Planck-Institut fuer Astrophysik
23  * and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
24  * (DLR).
25  */
26 
27 /*
28  * Copyright (C) 2003-2017 Max-Planck-Society
29  * Author: Martin Reinecke
30  */
31 
32 #include "powspec_fitsio.h"
33 #include "powspec.h"
34 #include "fitshandle.h"
35 
36 using namespace std;
37 
38 void read_powspec_from_fits (fitshandle &inp, PowSpec &powspec, int nspecs,
39  int lmax)
40  {
41  planck_assert ((nspecs==1)||(nspecs==4)||(nspecs==6),
42  "wrong number of spectra");
43 
44  arr<double> tt(lmax+1,0),gg(lmax+1,0),cc(lmax+1,0),tg(lmax+1,0),
45  tc(lmax+1,0),gc(lmax+1,0);
46 
47  int lmax_file = safe_cast<int>(inp.nelems(1)-1);
48  if (lmax_file<lmax)
49  cerr << "warning: lmax in file smaller than expected; padding with 0."
50  << endl;
51  int lmax_read = min (lmax,lmax_file);
52  inp.read_column_raw (1,&tt[0],lmax_read+1);
53  if (nspecs>=4)
54  {
55  inp.read_column_raw (2,&gg[0],lmax_read+1);
56  inp.read_column_raw (3,&cc[0],lmax_read+1);
57  inp.read_column_raw (4,&tg[0],lmax_read+1);
58  }
59  if (nspecs==6)
60  {
61  inp.read_column_raw (5,&tc[0],lmax_read+1);
62  inp.read_column_raw (6,&gc[0],lmax_read+1);
63  }
64 
65  if (nspecs==1) powspec.Set(tt);
66  if (nspecs==4) powspec.Set(tt,gg,cc,tg);
67  if (nspecs==6) powspec.Set(tt,gg,cc,tg,tc,gc);
68  }
69 
70 PowSpec read_powspec_from_fits (fitshandle &inp, int nspecs, int lmax)
71  {
72  PowSpec res;
73  read_powspec_from_fits (inp, res, nspecs, lmax);
74  return res;
75  }
76 
77 void read_powspec_from_fits (const string &infile, PowSpec &powspec,
78  int nspecs, int lmax, int hdunum)
79  {
80  fitshandle inp;
81  inp.open(infile);
82  inp.goto_hdu(hdunum);
83 
84  read_powspec_from_fits (inp,powspec,nspecs,lmax);
85  }
86 
87 PowSpec read_powspec_from_fits (const string &infile,
88  int nspecs, int lmax, int hdunum)
89  {
90  PowSpec res;
91  read_powspec_from_fits (infile, nspecs, lmax, hdunum);
92  return res;
93  }
94 
95 void write_powspec_to_fits (fitshandle &out,
96  const PowSpec &powspec, int nspecs)
97  {
98  planck_assert ((nspecs==1)||(nspecs==4)||(nspecs==6),
99  "incorrect number of spectra");
100  vector<fitscolumn> cols;
101  cols.push_back(fitscolumn("Temperature C_l","unknown",1,PLANCK_FLOAT64));
102  if (nspecs>1)
103  {
104  cols.push_back(fitscolumn("E-mode C_l","unknown",1,PLANCK_FLOAT64));
105  cols.push_back(fitscolumn("B-mode C_l","unknown",1,PLANCK_FLOAT64));
106  cols.push_back(fitscolumn("T-E cross-corr.","unknown",1,
107  PLANCK_FLOAT64));
108  }
109  if (nspecs>4)
110  {
111  cols.push_back(fitscolumn("T-B cross-corr.","unknown",1,PLANCK_FLOAT64));
112  cols.push_back(fitscolumn("E-B cross-corr.","unknown",1,PLANCK_FLOAT64));
113  }
114  out.insert_bintab(cols);
115  out.write_column(1,powspec.tt());
116  if (nspecs>1)
117  {
118  out.write_column(2,powspec.gg());
119  out.write_column(3,powspec.cc());
120  out.write_column(4,powspec.tg());
121  }
122  if (nspecs>4)
123  {
124  out.write_column(5,powspec.tc());
125  out.write_column(6,powspec.gc());
126  }
127  }
128 
129 void write_powspec_to_fits (const string &outfile,
130  const PowSpec &powspec, int nspecs)
131  {
132  fitshandle out;
133  out.create(outfile);
134  write_powspec_to_fits(out,powspec,nspecs);
135  }
void Set(int nspec, int lmax)
Definition: powspec.cc:92
const arr< double > & gg() const
Definition: powspec.h:71
const arr< double > & tc() const
Definition: powspec.h:77
const arr< double > & tt() const
Definition: powspec.h:69
const arr< double > & tg() const
Definition: powspec.h:75
const arr< double > & cc() const
Definition: powspec.h:73
void read_powspec_from_fits(fitshandle &inp, PowSpec &powspec, int nspecs, int lmax)
const arr< double > & gc() const
Definition: powspec.h:79
void write_powspec_to_fits(fitshandle &out, const PowSpec &powspec, int nspecs)

Generated on Wed Nov 13 2024 12:18:30 for Healpix C++