27 #include "TObjArray.h" 28 #include "TObjString.h" 35 unsigned int healpix_repcount (tsize
npix)
37 if (npix<1024)
return 1;
38 if ((npix%1024)==0)
return 1024;
39 return isqrt (npix/12);
62 if(t1<0 || t1>180. || t2<0 || t2>180. || t2<t1) {
63 cout<<
"skymap(): invalid theta parameters"<<endl;
67 if(p1<0 || p1>360. || p2<0 || p2>360. || p2<p1) {
68 cout<<
"skymap(): invalid phi parameters"<<endl;
78 ntheta = 2*size_t((t2-t1)/sms/2.)+1;
79 d = ntheta>1 ? (t2-
t1)/(ntheta-1) : sms;
81 this->
index.reserve(ntheta);
82 this->
value.reserve(ntheta);
84 for(i=-ntheta/2; i<=ntheta/2; i++) {
85 c = cos(((t2+t1)/2.+i*d)*a);
86 s = sin(((t2+t1)/2.+i*d)*a);
87 c = s>0. ? (cos(sms*a)-c*
c)/s/s : 2.;
88 p = c>0&&c<1. ? acos(c)/
a : 361.;
89 nphi = 2*size_t((p2-p1)/p/2.)+1;
91 std::vector<double>
v;
94 for(j=0; j<nphi; j++) v.push_back(0.);
95 index.push_back(nphi);
98 mIndex = mTheta = mPhi = -1;
120 healpix =
new Healpix_Map<double>();
121 read_Healpix_map_from_fits(ifile,*
healpix,1,2);
122 this->healpix_order =
healpix->Order();
125 for(i=0;i<=
healpix->Order();i++) ntheta=2*ntheta+1;
127 this->
index.reserve(ntheta);
128 this->
value.reserve(ntheta);
129 for(i=1; i<=ntheta; i++) {
131 int ring=
i;
int startpix;
int ringpix;
double costheta;
double sintheta;
bool shifted=
false;
132 healpix->get_ring_info(ring, startpix, ringpix, costheta, sintheta, shifted);
135 std::vector<double>
v;
138 for(j=0; j<nphi; j++) v.push_back(0.);
139 index.push_back(nphi);
142 mIndex = mTheta = mPhi = -1;
152 cout <<
"skymap::skymap(char* ifile) : not available - healpix not enabled" << endl;
170 for(i=0;i<=healpix_order;i++) ntheta=2*ntheta+1;
172 healpix =
new Healpix_Map<double>(healpix_order,RING);
174 this->healpix_order =
healpix->Order();
194 this->
index.reserve(ntheta);
195 this->
value.reserve(ntheta);
196 for(i=1; i<=ntheta; i++) {
198 int ring=
i;
int startpix;
int ringpix;
double costheta;
double sintheta;
bool shifted=
false;
199 healpix->get_ring_info(ring, startpix, ringpix, costheta, sintheta, shifted);
202 std::vector<double>
v;
205 for(j=0; j<nphi; j++) v.push_back(0.);
206 index.push_back(nphi);
209 mIndex = mTheta = mPhi = -1;
215 cout <<
"skymap::skymap(int healpix_order) : not available - healpix not enabled" << endl;
225 TFile *rfile = TFile::Open(ifile);
227 cout <<
"skymap::skymap - Error : No " << ifile.Data() <<
" file !!!" << endl;
231 if(rfile->Get(name)!=NULL) {
232 *
this = *(skymap*)rfile->Get(name);
234 cout <<
"skymap::skymap - Error : skymap is not contained in root file " << ifile.Data() << endl;
263 this->healpix_order =
healpix->Order();
267 this->healpix_order = 0;
301 cout<<
"skymap::operator+ - incompatible skymaps"<<endl;
307 if(m != a.
value[i].size()) {
308 cout<<
"skymap::operator+ - incompatible skymaps"<<endl;
330 cout<<
"skymap::operator- - incompatible skymaps"<<endl;
336 if(m != a.
value[i].size()) {
337 cout<<
"skymap::operator- - incompatible skymaps"<<endl;
358 cout<<
"skymap::operator* - incompatible skymaps"<<endl;
364 if(m != a.
value[i].size()) {
365 cout<<
"skymap::operator* - incompatible skymaps"<<endl;
385 cout<<
"skymap::operator/ - incompatible skymaps"<<endl;
391 if(m != a.
value[i].size()) {
392 cout<<
"skymap::operator/ - incompatible skymaps"<<endl;
408 for(j=0; j<
m; j++) { this->
value[
i][
j] =
a; }
421 for(j=0; j<
m; j++) { this->
value[
i][
j] *=
a; }
433 for(j=0; j<
m; j++) { this->
value[
i][
j] +=
a; }
446 mTheta = mPhi = mIndex = -1;
452 if(x>a) { a=
x; mTheta=
i; mPhi=
j; mIndex=
k; }
467 mTheta = mPhi = mIndex = -1;
473 if(x<a) { a=
x; mTheta=
i; mPhi=
j; mIndex=
k; }
508 if(this->
value[i][j]>t) a += 1.;
521 (*this) += 1.-this->max();
532 if(a>0.) (*this) *= 1./
s;
540 size_t m = this->
size();
549 if(i&1) index.
data[
l] = 1;
550 if(j&1 && k==4) index.
data[
l] = 1;
559 void skymap::Dump2fits(
const char* file,
double gps_obs,
const char* configur,
560 const char* TTYPE1,
const char* TUNIT1,
char coordsys)
569 if(fName.EndsWith(
".gz")) fName.Resize(fName.Sizeof()-4);
571 if(!fName.EndsWith(
".fits")) {
572 cout <<
"skymap::Dump2fits Error : wrong file extension" << endl;
573 cout <<
"fits file must ends with '.fits' or '.fits.gz'" << endl;
582 sprintf(cmd,
"rm %s",fName.Data());
584 int err=gSystem->Exec(cmd);
586 cout <<
"skymap::Dump2fits Error : failed to remove file" << endl;
593 out.create(fName.Data());
594 PDT datatype = PLANCK_FLOAT32;
597 arr<string> colname(1);
598 colname[0] = (
TString(TTYPE1)!=
"") ? TTYPE1 :
"unknown ";
599 string tunit1 = (
TString(TUNIT1)!=
"") ? TUNIT1 :
"unknown ";
600 vector<fitscolumn> cols;
601 int repcount = healpix_repcount (
healpix->Npix());
602 for (tsize
m=0;
m<colname.size(); ++
m)
603 cols.push_back (fitscolumn (colname[
m],tunit1,repcount, datatype));
604 out.insert_bintab(cols);
605 out.set_key (
"PIXTYPE",
string(
"HEALPIX"),
"HEALPIX pixelisation");
606 string ordering = (
healpix->Scheme()==RING) ?
"RING" :
"NESTED";
607 out.set_key (
"ORDERING",ordering,
"Pixel ordering scheme, either RING or NESTED");
608 out.set_key (
"NSIDE",
healpix->Nside(),
"Resolution parameter for HEALPIX");
609 out.set_key (
"FIRSTPIX",0,
"First pixel # (0 based)");
610 out.set_key (
"LASTPIX",
healpix->Npix()-1,
"Last pixel # (0 based)");
611 out.set_key (
"INDXSCHM",
string(
"IMPLICIT"),
"Indexing: IMPLICIT or EXPLICIT");
612 if(coordsys==
'c' || coordsys==
'C')
613 out.set_key (
"COORDSYS",
string(
"C "),
"Pixelisation coordinate system");
614 out.set_key (
"CREATOR",
string(
"CWB "),
"Program that created this file");
616 out.set_key (
"CONFIGUR",
string(configur),
"software configuration used to process the data");
623 sdate.ReplaceAll(
" ",
"T");
626 out.set_key (
"DATE-OBS",
string(date_obs),
"UTC date of the observation");
629 out.set_key (
"MJD-OBS",
string(mjd_obs),
"modified Julian date of the observation");
636 sdate.ReplaceAll(
" ",
"T");
639 out.set_key (
"DATE",
string(date_obs),
"UTC date of file creation");
641 out.write_column(1,
healpix->Map());
646 if(
TString(file).EndsWith(
".gz")) {
648 sprintf(cmd,
"gzip -f %s",fName.Data());
650 int err=gSystem->Exec(cmd);
652 cout <<
"skymap::Dump2fits Error : gzip error" << endl;
660 cout <<
"skymap::Dump2fits Error : healpix not initialized" << endl;
669 TFile* rfile =
new TFile(file,
"RECREATE");
670 this->
Write(
"skymap");
711 return this->
value[mTheta][mPhi];
713 mTheta = mPhi = mIndex = -1;
725 pointing P(th*
deg2rad,ph*deg2rad);
733 g = (
value.size()-1)/(theta_2-theta_1);
735 if(th<theta_1) th = theta_1;
736 if(th>theta_2) th = theta_2;
737 mTheta =
int(g*(th-theta_1)+0.5);
741 g =
value[mTheta].size()/(phi_2-phi_1);
742 if(ph< phi_1) ph = phi_2 - 0.5/
g;
743 if(ph>=phi_2) ph = phi_1 + 0.5/
g;
744 mPhi =
int(g*(ph-phi_1));
766 fix_arr< int, 8 > result;
767 healpix->neighbors (index, result);
768 for(
int k=0;
k<8;
k++) neighbors[
k]=result[
k];
783 cout <<
"skymap::median Error : healpix not initialized" << endl;
799 for (
int l=0;
l<
L; ++
l) {
804 list2.resize(list.size());
805 for (tsize
i=0;
i<list.size(); ++
i) list2[
i] = (*
healpix)[list[
i]];
806 double x=
::median(list2.begin(),list2.end());
816 void skymap::smoothing(
double fwhm,
int nlmax,
int num_iter) {
826 cout <<
"NOTE: negative FWHM supplied, doing a deconvolution..." << endl;
829 cout <<
"skymap::smoothing Error : healpix not initialized" << endl;
841 wat::Alm alm = getAlm(nlmax, num_iter);
856 void skymap::rotate(
double psi,
double theta,
double phi,
int nlmax,
int num_iter) {
866 cout <<
"skymap::smoothing Error : healpix not initialized" << endl;
871 wat::Alm alm = getAlm(nlmax, num_iter);
889 cout <<
"skymap::setAlm Error : healpix not initialized" << endl;
894 Alm<xcomplex<double> > _alm(alm.
Lmax(),alm.
Mmax());
895 for(
int l=0;
l<=_alm.Lmax();
l++) {
896 int limit = TMath::Min(
l,_alm.Mmax());
897 for (
int m=0;
m<=limit;
m++)
898 _alm(
l,
m)=complex<double>(alm(
l,
m).real(),alm(
l,
m).imag());
913 skymap::getAlm(
int nlmax,
int num_iter) {
923 cout <<
"skymap::getAlm Error : healpix not initialized" << endl;
935 arr<double> weight(2*
healpix->Nside());
936 for(
int i=0;
i<2*
healpix->Nside();
i++) weight[
i]=1.0;
939 Alm<xcomplex<double> > alm(nlmax,nlmax);
942 map2alm_iter(*
healpix,alm,num_iter,weight);
953 skymap::resample(
int order) {
961 cout <<
"skymap::resample Error : healpix not initialized" << endl;
965 if(order == getOrder())
return;
968 int nlmax = 2*
healpix->Nside();
972 *
this = skymap(order);
974 int _nlmax = 2*
healpix->Nside();
978 int min_nlmax = TMath::Min(nlmax,_nlmax);
979 for(
int l=0;
l<=min_nlmax;
l++) {
980 int limit = TMath::Min(
l,alm.
Mmax());
981 for (
int m=0;
m<=limit;
m++) _alm(
l,
m)=alm(
l,
m);
998 cout <<
"skymap::getRings Error : healpix not initialized" << endl;
1003 for(
int i=0;
i<=
healpix->Order();
i++) nrings=2*nrings+1;
1011 skymap::getRingPixels(
int ring) {
1016 cout <<
"skymap::getRingPixels Error : healpix not initialized" << endl;
1020 if(ring<1 || ring>getRings()) {
1021 cout <<
"skymap::getRingPixels Error : ring index " << ring
1022 <<
" not allowed [1:" << getRings() <<
"]" << endl;
1026 int startpix;
int ringpix;
double costheta;
double sintheta;
bool shifted=
false;
1027 healpix->get_ring_info(ring, startpix, ringpix, costheta, sintheta, shifted);
1034 skymap::getStartRingPixel(
int ring) {
1039 cout <<
"skymap::getStartRingPixel Error : healpix not initialized" << endl;
1043 if(ring<1 || ring>getRings()) {
1044 cout <<
"skymap::getRingPixels Error : ring index " << ring
1045 <<
" not allowed [1:" << getRings() <<
"]" << endl;
1049 int startpix;
int ringpix;
double costheta;
double sintheta;
bool shifted=
false;
1050 healpix->get_ring_info(ring, startpix, ringpix, costheta, sintheta, shifted);
1057 skymap::getEulerCharacteristic(
double threshold) {
1062 cout <<
"skymap::getEulerCharacteristic Error : healpix not initialized" << endl;
1083 index = neighbors(
l);
1085 if(a>threshold) {nE++;F1++;F4++;}
1087 if(a>threshold) {F1++;}
1089 if(a>threshold) {nE++;F1++;F2++;}
1091 if(a>threshold) {F2++;}
1093 if(a>threshold) {nE++;F2++;F3++;}
1095 if(a>threshold) {F3++;}
1097 if(a>threshold) {nE++;F3++;F4++;}
1099 if(a>threshold) {F4++;}
1100 nF+=F1/3+F2/3+F3/3+F4/3;
1101 F1=0; F2=0; F3=0; F4=0;
1113 name.ReplaceAll(
" ",
"");
1115 TObjString* ext_tok = (TObjString*)token->At(token->GetEntries()-1);
1116 TString ext = ext_tok->GetString();
1131 cout <<
"skymap operator (>>) : file type " << ext.Data() <<
" not supported" << endl;
1137 void skymap::Streamer(TBuffer &R__b)
1142 if (R__b.IsReading()) {
1143 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
if (R__v) { }
1144 TNamed::Streamer(R__b);
1146 vector<vectorD> &R__stl =
value;
1148 TClass *R__tcl1 = TBuffer::GetClass(
typeid(vector<
double,allocator<double> >));
1150 Error(
"value streamer",
"Missing the TClass object for vector<double,allocator<double> >!");
1155 R__stl.reserve(R__n);
1156 for (R__i = 0; R__i < R__n; R__i++) {
1157 vector<double,allocator<double> > R__t;
1158 R__b.StreamObject(&R__t,R__tcl1);
1159 R__stl.push_back(R__t);
1163 vector<int> &R__stl =
index;
1167 R__stl.reserve(R__n);
1168 for (R__i = 0; R__i < R__n; R__i++) {
1171 R__stl.push_back(R__t);
1174 if(R__v > 2) R__b >> sms;
1184 R__b >> healpix_order;
1185 if(healpix_order > 0) {
1187 healpix =
new Healpix_Map<double>(healpix_order,RING);
1194 R__b.CheckByteCount(R__s, R__c, skymap::IsA());
1196 R__c = R__b.WriteVersion(skymap::IsA(), kTRUE);
1197 TNamed::Streamer(R__b);
1199 vector<vectorD> &R__stl =
value;
1200 int R__n=(&R__stl) ?
int(R__stl.size()) : 0;
1203 TClass *R__tcl1 = TBuffer::GetClass(
typeid(vector<
double,allocator<double> >));
1205 Error(
"value streamer",
"Missing the TClass object for vector<double,allocator<double> >!");
1208 vector<vectorD>::iterator R__k;
1209 for (R__k = R__stl.begin(); R__k != R__stl.end(); ++R__k) {
1210 R__b.StreamObject((vector<
double,allocator<double> >*)&(*R__k),R__tcl1);
1215 vector<int> &R__stl =
index;
1216 int R__n=(&R__stl) ?
int(R__stl.size()) : 0;
1219 vector<int>::iterator R__k;
1220 for (R__k = R__stl.begin(); R__k != R__stl.end(); ++R__k) {
1234 R__b << healpix_order;
1235 R__b.SetByteCount(R__c, kTRUE);
wavearray< double > t(hp.size())
void smoothWithGauss(double fwhm)
int Mmax() const
Returns the maximum m.
static double g(double e)
wavearray< double > a(hp.size())
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<< "\ layers : "<< nLAYERS<< "\ dF(hz) : "<< dF<< "\ 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 &)
void downsample(wavearray< short > &, size_t=4)
watplot p2(const_cast< char *>("TFMap2"))
size_t getSkyIndex(double th, double ph)
param: theta param: phi
virtual size_t size() const
std::vector< vectorD > value
int Lmax() const
Returns the maximum l.
skymap & operator+=(const skymap &)
watplot p1(const_cast< char *>("TFMap1"))
char * operator>>(char *fname)
void DumpBinary(char *, int)
virtual void DumpBinary(const char *, int=0)
void rotate(double psi, double theta, double phi)
double fabs(const Complex &x)
skymap & operator=(const skymap &)
double GetModJulianDate()
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 &)