Healpix C++  3.83
healpix_data_io.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, 2005, 2009 Max-Planck-Society
29  * Author: Martin Reinecke
30  */
31 
32 #include "healpix_data_io.h"
33 #include "arr.h"
34 #include "fitshandle.h"
35 #include "paramfile.h"
36 #include "string_utils.h"
37 
38 using namespace std;
39 
40 namespace {
41 
42 void read_wring (const string &weightfile, int nside, arr<double> &weight)
43  {
44  fitshandle inp;
45  inp.open(weightfile);
46  inp.goto_hdu(2);
47  planck_assert(nside==inp.get_key<int>("NSIDE"),"incorrect Nside parameter");
48  inp.read_entire_column(1,weight);
49  planck_assert(weight.size()==size_t(2*nside),
50  "incorrect number of weights in ring weight file");
51  }
52 
53 } // unnamed namespace
54 
55 void read_weight_ring (const string &dir, int nside, arr<double> &weight)
56  {
57  read_wring(dir+"/weight_ring_n"+intToString(nside,5)+".fits", nside, weight);
58  }
59 
60 void get_ring_weights (paramfile &params, int nside, arr<double> &weight)
61  {
62  string weightfile = params.find<string>("ringweights","");
63  weight.alloc (2*nside);
64  if (weightfile!="")
65  {
66  read_wring (weightfile, nside, weight);
67  for (tsize m=0; m<weight.size(); ++m) weight[m]+=1;
68  }
69  else
70  weight.fill(1);
71  }
72 
73 vector<double> read_fullweights_from_fits(const std::string &weightfile,
74  int nside)
75  {
76  fitshandle inp;
77  inp.open(weightfile);
78  inp.goto_hdu(2);
79  planck_assert(inp.colname(1)=="COMPRESSED PIXEL WEIGHTS","wrong column name");
80  planck_assert(inp.get_key<int>("NSIDE")==nside,"incorrect NSIDE parameter");
81  vector<double> res;
82  inp.read_entire_column(1,res);
83  return res;
84  }
85 
86 void read_pixwin (const string &file, arr<double> &temp)
87  {
88  fitshandle inp;
89  inp.open(file);
90  inp.goto_hdu(2);
91  if (temp.size()==0)
92  inp.read_entire_column(1,temp);
93  else
94  inp.read_column(1,temp);
95  }
96 void read_pixwin (const string &file, arr<double> &temp, arr<double> &pol)
97  {
98  fitshandle inp;
99  inp.open(file);
100  inp.goto_hdu(2);
101  if (temp.size()==0)
102  inp.read_entire_column(1,temp);
103  else
104  inp.read_column(1,temp);
105  if (pol.size()==0)
106  inp.read_entire_column(2,pol);
107  else
108  inp.read_column(2,pol);
109  }
110 
111 void get_pixwin (paramfile &params, int lmax, arr<double> &pixwin)
112  {
113  string windowfile = params.find<string>("windowfile","");
114  pixwin.alloc(lmax+1);
115  pixwin.fill(1);
116  if (windowfile!="")
117  read_pixwin (windowfile,pixwin);
118  }
119 void get_pixwin (paramfile &params, int lmax, arr<double> &pixwin,
120  arr<double> &pixwin_pol)
121  {
122  string windowfile = params.find<string>("windowfile","");
123  pixwin.alloc(lmax+1);
124  pixwin.fill(1);
125  pixwin_pol.alloc(lmax+1);
126  pixwin_pol.fill(1);
127  if (windowfile!="")
128  read_pixwin (windowfile,pixwin,pixwin_pol);
129  }

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