10 #include "TObjString.h"
17 unsigned int healpix_repcount (tsize
npix)
19 if (npix<1024)
return 1;
20 if ((npix%1024)==0)
return 1024;
21 return isqrt (npix/12);
44 if(t1<0 || t1>180. || t2<0 || t2>180. || t2<t1) {
45 cout<<
"skymap(): invalid theta parameters"<<endl;
49 if(p1<0 || p1>360. || p2<0 || p2>360. || p2<p1) {
50 cout<<
"skymap(): invalid phi parameters"<<endl;
60 ntheta = 2*size_t((t2-t1)/sms/2.)+1;
61 d = ntheta>1 ? (t2-
t1)/(ntheta-1) : sms;
63 this->
index.reserve(ntheta);
64 this->
value.reserve(ntheta);
66 for(i=-ntheta/2; i<=ntheta/2; i++) {
67 c = cos(((t2+t1)/2.+i*d)*a);
68 s = sin(((t2+t1)/2.+i*d)*a);
69 c = s>0. ? (cos(sms*a)-c*
c)/s/s : 2.;
70 p = c>0&&c<1. ? acos(c)/a : 361.;
71 nphi = 2*size_t((p2-p1)/p/2.)+1;
73 std::vector<double>
v;
76 for(j=0; j<nphi; j++) v.push_back(0.);
77 index.push_back(nphi);
80 mIndex = mTheta = mPhi = -1;
102 healpix =
new Healpix_Map<double>();
103 read_Healpix_map_from_fits(ifile,*
healpix,1,2);
104 this->healpix_order =
healpix->Order();
107 for(i=0;i<=
healpix->Order();i++) ntheta=2*ntheta+1;
109 this->
index.reserve(ntheta);
110 this->
value.reserve(ntheta);
111 for(i=1; i<=ntheta; i++) {
113 int ring=
i;
int startpix;
int ringpix;
double costheta;
double sintheta;
bool shifted=
false;
114 healpix->get_ring_info(ring, startpix, ringpix, costheta, sintheta, shifted);
117 std::vector<double>
v;
120 for(j=0; j<nphi; j++) v.push_back(0.);
121 index.push_back(nphi);
124 mIndex = mTheta = mPhi = -1;
134 cout <<
"skymap::skymap(char* ifile) : not available - healpix not enabled" << endl;
152 for(i=0;i<=healpix_order;i++) ntheta=2*ntheta+1;
154 healpix =
new Healpix_Map<double>(healpix_order,RING);
156 this->healpix_order =
healpix->Order();
176 this->
index.reserve(ntheta);
177 this->
value.reserve(ntheta);
178 for(i=1; i<=ntheta; i++) {
180 int ring=
i;
int startpix;
int ringpix;
double costheta;
double sintheta;
bool shifted=
false;
181 healpix->get_ring_info(ring, startpix, ringpix, costheta, sintheta, shifted);
184 std::vector<double>
v;
187 for(j=0; j<nphi; j++) v.push_back(0.);
188 index.push_back(nphi);
191 mIndex = mTheta = mPhi = -1;
197 cout <<
"skymap::skymap(int healpix_order) : not available - healpix not enabled" << endl;
207 TFile *rfile = TFile::Open(ifile);
209 cout <<
"skymap::skymap - Error : No " << ifile.Data() <<
" file !!!" << endl;
213 if(rfile->Get(name)!=NULL) {
214 *
this = *(
skymap*)rfile->Get(name);
216 cout <<
"skymap::skymap - Error : skymap is not contained in root file " << ifile.Data() << endl;
245 this->healpix_order =
healpix->Order();
249 this->healpix_order = 0;
283 cout<<
"skymap::operator+ - incompatible skymaps"<<endl;
289 if(m != a.
value[i].size()) {
290 cout<<
"skymap::operator+ - incompatible skymaps"<<endl;
312 cout<<
"skymap::operator- - incompatible skymaps"<<endl;
318 if(m != a.
value[i].size()) {
319 cout<<
"skymap::operator- - incompatible skymaps"<<endl;
340 cout<<
"skymap::operator* - incompatible skymaps"<<endl;
346 if(m != a.
value[i].size()) {
347 cout<<
"skymap::operator* - incompatible skymaps"<<endl;
367 cout<<
"skymap::operator/ - incompatible skymaps"<<endl;
373 if(m != a.
value[i].size()) {
374 cout<<
"skymap::operator/ - incompatible skymaps"<<endl;
390 for(j=0; j<
m; j++) { this->
value[
i][
j] =
a; }
403 for(j=0; j<
m; j++) { this->
value[
i][
j] *=
a; }
415 for(j=0; j<
m; j++) { this->
value[
i][
j] +=
a; }
428 mTheta = mPhi = mIndex = -1;
434 if(x>a) { a=
x; mTheta=
i; mPhi=
j; mIndex=
k; }
449 mTheta = mPhi = mIndex = -1;
455 if(x<a) { a=
x; mTheta=
i; mPhi=
j; mIndex=
k; }
490 if(this->
value[i][j]>t) a += 1.;
503 (*this) += 1.-this->max();
514 if(a>0.) (*this) *= 1./
s;
522 size_t m = this->
size();
531 if(i&1) index.
data[
l] = 1;
532 if(j&1 && k==4) index.
data[
l] = 1;
541 void skymap::Dump2fits(
const char*
file,
double gps_obs,
const char* configur,
542 const char* TTYPE1,
const char* TUNIT1,
char coordsys)
551 if(fName.EndsWith(
".gz")) fName.Resize(fName.Sizeof()-4);
553 if(!fName.EndsWith(
".fits")) {
554 cout <<
"skymap::Dump2fits Error : wrong file extension" << endl;
555 cout <<
"fits file must ends with '.fits' or '.fits.gz'" << endl;
564 sprintf(cmd,
"rm %s",fName.Data());
566 int err=gSystem->Exec(cmd);
568 cout <<
"skymap::Dump2fits Error : failed to remove file" << endl;
575 out.create(fName.Data());
576 PDT datatype = PLANCK_FLOAT32;
579 arr<string> colname(1);
580 colname[0] = (
TString(TTYPE1)!=
"") ? TTYPE1 :
"unknown ";
581 string tunit1 = (
TString(TUNIT1)!=
"") ? TUNIT1 :
"unknown ";
582 vector<fitscolumn> cols;
583 int repcount = healpix_repcount (
healpix->Npix());
584 for (tsize
m=0;
m<colname.size(); ++
m)
585 cols.push_back (fitscolumn (colname[
m],tunit1,repcount, datatype));
586 out.insert_bintab(cols);
587 out.set_key (
"PIXTYPE",
string(
"HEALPIX"),
"HEALPIX pixelisation");
588 string ordering = (
healpix->Scheme()==RING) ?
"RING" :
"NESTED";
589 out.set_key (
"ORDERING",ordering,
"Pixel ordering scheme, either RING or NESTED");
590 out.set_key (
"NSIDE",
healpix->Nside(),
"Resolution parameter for HEALPIX");
591 out.set_key (
"FIRSTPIX",0,
"First pixel # (0 based)");
592 out.set_key (
"LASTPIX",
healpix->Npix()-1,
"Last pixel # (0 based)");
593 out.set_key (
"INDXSCHM",
string(
"IMPLICIT"),
"Indexing: IMPLICIT or EXPLICIT");
594 if(coordsys==
'c' || coordsys==
'C')
595 out.set_key (
"COORDSYS",
string(
"C "),
"Pixelisation coordinate system");
596 out.set_key (
"CREATOR",
string(
"CWB "),
"Program that created this file");
598 out.set_key (
"CONFIGUR",
string(configur),
"software configuration used to process the data");
603 TString sdate = date.GetDateString();
605 sdate.ReplaceAll(
" ",
"T");
607 sprintf(date_obs,
"%s.%d",sdate.Data(),
int(100*(date.GetNSec()/1000000000.)));
608 out.set_key (
"DATE-OBS",
string(date_obs),
"UTC date of the observation");
610 sprintf(mjd_obs,
"%.9f",date.GetModJulianDate());
611 out.set_key (
"MJD-OBS",
string(mjd_obs),
"modified Julian date of the observation");
616 TString sdate = date.GetDateString();
618 sdate.ReplaceAll(
" ",
"T");
620 sprintf(date_obs,
"%s.%d",sdate.Data(),
int(100*(date.GetNSec()/1000000000.)));
621 out.set_key (
"DATE",
string(date_obs),
"UTC date of file creation");
623 out.write_column(1,
healpix->Map());
628 if(
TString(file).EndsWith(
".gz")) {
630 sprintf(cmd,
"gzip -f %s",fName.Data());
632 int err=gSystem->Exec(cmd);
634 cout <<
"skymap::Dump2fits Error : gzip error" << endl;
642 cout <<
"skymap::Dump2fits Error : healpix not initialized" << endl;
651 TFile* rfile =
new TFile(file,
"RECREATE");
652 this->
Write(
"skymap");
693 return this->
value[mTheta][mPhi];
695 mTheta = mPhi = mIndex = -1;
715 g = (
value.size()-1)/(theta_2-theta_1);
717 if(th<theta_1) th = theta_1;
718 if(th>theta_2) th = theta_2;
719 mTheta =
int(g*(th-theta_1)+0.5);
723 g =
value[mTheta].size()/(phi_2-phi_1);
724 if(ph< phi_1) ph = phi_2 - 0.5/
g;
725 if(ph>=phi_2) ph = phi_1 + 0.5/
g;
726 mPhi =
int(g*(ph-phi_1));
748 fix_arr< int, 8 > result;
749 healpix->neighbors (index, result);
750 for(
int k=0;
k<8;
k++) neighbors[
k]=result[
k];
765 cout <<
"skymap::median Error : healpix not initialized" << endl;
781 for (
int l=0;
l<
L; ++
l) {
786 list2.resize(list.size());
787 for (tsize
i=0;
i<list.size(); ++
i) list2[
i] = (*
healpix)[list[
i]];
788 double x=
::median(list2.begin(),list2.end());
798 void skymap::smoothing(
double fwhm,
int nlmax,
int num_iter) {
808 cout <<
"NOTE: negative FWHM supplied, doing a deconvolution..." << endl;
811 cout <<
"skymap::smoothing Error : healpix not initialized" << endl;
823 wat::Alm alm = getAlm(nlmax, num_iter);
838 void skymap::rotate(
double psi,
double theta,
double phi,
int nlmax,
int num_iter) {
848 cout <<
"skymap::smoothing Error : healpix not initialized" << endl;
853 wat::Alm alm = getAlm(nlmax, num_iter);
855 alm.
rotate(psi, theta, phi);
871 cout <<
"skymap::setAlm Error : healpix not initialized" << endl;
876 Alm<xcomplex<double> > _alm(alm.
Lmax(),alm.
Mmax());
877 for(
int l=0;
l<=_alm.Lmax();
l++) {
878 int limit = TMath::Min(
l,_alm.Mmax());
879 for (
int m=0; m<=limit; m++)
880 _alm(
l,m)=complex<double>(alm(
l,m).real(),alm(
l,m).imag());
895 skymap::getAlm(
int nlmax,
int num_iter) {
905 cout <<
"skymap::getAlm Error : healpix not initialized" << endl;
917 arr<double> weight(2*
healpix->Nside());
918 for(
int i=0;
i<2*
healpix->Nside();
i++) weight[
i]=1.0;
921 Alm<xcomplex<double> > alm(nlmax,nlmax);
924 map2alm_iter(*
healpix,alm,num_iter,weight);
935 skymap::resample(
int order) {
943 cout <<
"skymap::resample Error : healpix not initialized" << endl;
947 if(order == getOrder())
return;
950 int nlmax = 2*
healpix->Nside();
956 int _nlmax = 2*
healpix->Nside();
960 int min_nlmax = TMath::Min(nlmax,_nlmax);
961 for(
int l=0;
l<=min_nlmax;
l++) {
962 int limit = TMath::Min(
l,alm.
Mmax());
963 for (
int m=0; m<=limit; m++) _alm(
l,m)=alm(
l,m);
980 cout <<
"skymap::getRings Error : healpix not initialized" << endl;
985 for(
int i=0;
i<=
healpix->Order();
i++) nrings=2*nrings+1;
993 skymap::getRingPixels(
int ring) {
998 cout <<
"skymap::getRingPixels Error : healpix not initialized" << endl;
1002 if(ring<1 || ring>getRings()) {
1003 cout <<
"skymap::getRingPixels Error : ring index " << ring
1004 <<
" not allowed [1:" << getRings() <<
"]" << endl;
1008 int startpix;
int ringpix;
double costheta;
double sintheta;
bool shifted=
false;
1009 healpix->get_ring_info(ring, startpix, ringpix, costheta, sintheta, shifted);
1016 skymap::getStartRingPixel(
int ring) {
1021 cout <<
"skymap::getStartRingPixel Error : healpix not initialized" << endl;
1025 if(ring<1 || ring>getRings()) {
1026 cout <<
"skymap::getRingPixels Error : ring index " << ring
1027 <<
" not allowed [1:" << getRings() <<
"]" << endl;
1031 int startpix;
int ringpix;
double costheta;
double sintheta;
bool shifted=
false;
1032 healpix->get_ring_info(ring, startpix, ringpix, costheta, sintheta, shifted);
1039 skymap::getEulerCharacteristic(
double threshold) {
1044 cout <<
"skymap::getEulerCharacteristic Error : healpix not initialized" << endl;
1065 index = neighbors(
l);
1067 if(a>threshold) {nE++;F1++;F4++;}
1069 if(a>threshold) {F1++;}
1071 if(a>threshold) {nE++;F1++;F2++;}
1073 if(a>threshold) {F2++;}
1075 if(a>threshold) {nE++;F2++;F3++;}
1077 if(a>threshold) {F3++;}
1079 if(a>threshold) {nE++;F3++;F4++;}
1081 if(a>threshold) {F4++;}
1082 nF+=F1/3+F2/3+F3/3+F4/3;
1083 F1=0; F2=0; F3=0; F4=0;
1095 name.ReplaceAll(
" ",
"");
1097 TObjString* ext_tok = (TObjString*)token->At(token->GetEntries()-1);
1113 cout <<
"skymap operator (>>) : file type " << ext.Data() <<
" not supported" << endl;
1119 void skymap::Streamer(TBuffer &R__b)
1124 if (R__b.IsReading()) {
1125 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
if (R__v) { }
1126 TNamed::Streamer(R__b);
1128 vector<vectorD> &R__stl =
value;
1130 TClass *R__tcl1 = TBuffer::GetClass(
typeid(vector<
double,allocator<double> >));
1132 Error(
"value streamer",
"Missing the TClass object for vector<double,allocator<double> >!");
1137 R__stl.reserve(R__n);
1138 for (R__i = 0; R__i < R__n; R__i++) {
1139 vector<double,allocator<double> > R__t;
1140 R__b.StreamObject(&R__t,R__tcl1);
1141 R__stl.push_back(R__t);
1145 vector<int> &R__stl =
index;
1149 R__stl.reserve(R__n);
1150 for (R__i = 0; R__i < R__n; R__i++) {
1153 R__stl.push_back(R__t);
1156 if(R__v > 2) R__b >> sms;
1166 R__b >> healpix_order;
1167 if(healpix_order > 0) {
1169 healpix =
new Healpix_Map<double>(healpix_order,RING);
1176 R__b.CheckByteCount(R__s, R__c, skymap::IsA());
1178 R__c = R__b.WriteVersion(skymap::IsA(), kTRUE);
1179 TNamed::Streamer(R__b);
1181 vector<vectorD> &R__stl =
value;
1182 int R__n=(&R__stl) ?
int(R__stl.size()) : 0;
1185 TClass *R__tcl1 = TBuffer::GetClass(
typeid(vector<
double,allocator<double> >));
1187 Error(
"value streamer",
"Missing the TClass object for vector<double,allocator<double> >!");
1190 vector<vectorD>::iterator R__k;
1191 for (R__k = R__stl.begin(); R__k != R__stl.end(); ++R__k) {
1192 R__b.StreamObject((vector<
double,allocator<double> >*)&(*R__k),R__tcl1);
1197 vector<int> &R__stl =
index;
1198 int R__n=(&R__stl) ?
int(R__stl.size()) : 0;
1201 vector<int>::iterator R__k;
1202 for (R__k = R__stl.begin(); R__k != R__stl.end(); ++R__k) {
1216 R__b << healpix_order;
1217 R__b.SetByteCount(R__c, kTRUE);
wavearray< double > t(hp.size())
void smoothWithGauss(double fwhm)
virtual size_t size() const
static double g(double e)
wavearray< double > a(hp.size())
int Lmax() const
Returns the maximum l.
skymap & operator-=(const skymap &)
cout<< endl;cout<< "ts size = "<< ts.size()<< " ts rate = "<< ts.rate()<< endl;tf.Forward(ts, wdm);int levels=tf.getLevel();cout<< "tf size = "<< tf.size()<< endl;double dF=tf.resolution();double dT=1./(2 *dF);cout<< "rate(hz) : "<< RATE<< "\t layers : "<< nLAYERS<< "\t dF(hz) : "<< dF<< "\t dT(ms) : "<< dT *1000.<< endl;int itime=TIME_PIXEL_INDEX;int ifreq=FREQ_PIXEL_INDEX;int index=(levels+1)*itime+ifreq;double time=itime *dT;double freq=(ifreq >0)?ifreq *dF:dF/4;cout<< endl;cout<< "PIXEL TIME = "<< time<< " sec "<< endl;cout<< "PIXEL FREQ = "<< freq<< " Hz "<< endl;cout<< endl;wavearray< double > x
double median(std::vector< double > &vec)
skymap & operator*=(const skymap &)
watplot p1(const_cast< char * >("TFMap1"))
void downsample(wavearray< short > &, size_t=4)
size_t getSkyIndex(double th, double ph)
param: theta param: phi
std::vector< vectorD > value
int Mmax() const
Returns the maximum m.
skymap & operator+=(const skymap &)
char * operator>>(char *fname)
void DumpBinary(char *, int)
virtual void DumpBinary(const char *, int=0)
void rotate(double psi, double theta, double phi)
watplot p2(const_cast< char * >("TFMap2"))
double fabs(const Complex &x)
skymap & operator=(const skymap &)
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
double get(size_t i)
param: sky index
virtual void resize(unsigned int)
skymap & operator/=(const skymap &)