powspec_fitsio.cc

00001 /*
00002  *  This file is part of Healpix_cxx.
00003  *
00004  *  Healpix_cxx is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  Healpix_cxx is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with Healpix_cxx; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017  *
00018  *  For more information about HEALPix, see http://healpix.sourceforge.net
00019  */
00020 
00021 /*
00022  *  Healpix_cxx is being developed at the Max-Planck-Institut fuer Astrophysik
00023  *  and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
00024  *  (DLR).
00025  */
00026 
00027 /*
00028  *  Copyright (C) 2003-2013 Max-Planck-Society
00029  *  Author: Martin Reinecke
00030  */
00031 
00032 #include "powspec_fitsio.h"
00033 #include "powspec.h"
00034 #include "fitshandle.h"
00035 
00036 using namespace std;
00037 
00038 void read_powspec_from_fits (fitshandle &inp, PowSpec &powspec, int nspecs,
00039   int lmax)
00040   {
00041   planck_assert ((nspecs==1)||(nspecs==4)||(nspecs==6),
00042     "wrong number of spectra");
00043 
00044   arr<double> tt(lmax+1,0),gg(lmax+1,0),cc(lmax+1,0),tg(lmax+1,0),
00045               tc(lmax+1,0),gc(lmax+1,0);
00046 
00047   int lmax_file = safe_cast<int>(inp.nelems(1)-1);
00048   if (lmax_file<lmax)
00049     cerr << "warning: lmax in file smaller than expected; padding with 0."
00050           << endl;
00051   int lmax_read = min (lmax,lmax_file);
00052   inp.read_column_raw (1,&tt[0],lmax_read+1);
00053   if (nspecs>=4)
00054     {
00055     inp.read_column_raw (2,&gg[0],lmax_read+1);
00056     inp.read_column_raw (3,&cc[0],lmax_read+1);
00057     inp.read_column_raw (4,&tg[0],lmax_read+1);
00058     }
00059   if (nspecs==6)
00060     {
00061     inp.read_column_raw (5,&tc[0],lmax_read+1);
00062     inp.read_column_raw (6,&gc[0],lmax_read+1);
00063     }
00064 
00065   if (nspecs==1) powspec.Set(tt);
00066   if (nspecs==4) powspec.Set(tt,gg,cc,tg);
00067   if (nspecs==6) powspec.Set(tt,gg,cc,tg,tc,gc);
00068   }
00069 
00070 void read_powspec_from_fits (const string &infile, PowSpec &powspec,
00071   int nspecs, int lmax, int hdunum)
00072   {
00073   fitshandle inp;
00074   inp.open(infile);
00075   inp.goto_hdu(hdunum);
00076 
00077   read_powspec_from_fits (inp,powspec,nspecs,lmax);
00078   }
00079 
00080 void write_powspec_to_fits (fitshandle &out,
00081   const PowSpec &powspec, int nspecs)
00082   {
00083   planck_assert ((nspecs==1)||(nspecs==4)||(nspecs==6),
00084     "incorrect number of spectra");
00085   vector<fitscolumn> cols;
00086   cols.push_back(fitscolumn("Temperature C_l","unknown",1,PLANCK_FLOAT64));
00087   if (nspecs>1)
00088     {
00089     cols.push_back(fitscolumn("E-mode C_l","unknown",1,PLANCK_FLOAT64));
00090     cols.push_back(fitscolumn("B-mode C_l","unknown",1,PLANCK_FLOAT64));
00091     cols.push_back(fitscolumn("T-E cross-corr.","unknown",1,
00092       PLANCK_FLOAT64));
00093     }
00094   if (nspecs>4)
00095     {
00096     cols.push_back(fitscolumn("T-B cross-corr.","unknown",1,PLANCK_FLOAT64));
00097     cols.push_back(fitscolumn("E-B cross-corr.","unknown",1,PLANCK_FLOAT64));
00098     }
00099   out.insert_bintab(cols);
00100   out.write_column(1,powspec.tt());
00101   if (nspecs>1)
00102     {
00103     out.write_column(2,powspec.gg());
00104     out.write_column(3,powspec.cc());
00105     out.write_column(4,powspec.tg());
00106     }
00107   if (nspecs>4)
00108     {
00109     out.write_column(5,powspec.tc());
00110     out.write_column(6,powspec.gc());
00111     }
00112   }
00113 
00114 void write_powspec_to_fits (const string &outfile,
00115   const PowSpec &powspec, int nspecs)
00116   {
00117   fitshandle out;
00118   out.create(outfile);
00119   write_powspec_to_fits(out,powspec,nspecs);
00120   }

Generated on Thu Oct 8 14:48:52 2015 for Healpix C++