[591] | 1 | #include <iostream.h>
|
---|
| 2 | #include <math.h>
|
---|
| 3 | #include "sambainit.h"
|
---|
| 4 | #include "spheregorski.h"
|
---|
| 5 | #include "spherethetaphi.h"
|
---|
| 6 |
|
---|
| 7 | #include "tod.h"
|
---|
| 8 | #include "fitsioserver.h"
|
---|
| 9 | #include "nbrandom.h"
|
---|
| 10 |
|
---|
| 11 | #include "timing.h"
|
---|
| 12 |
|
---|
| 13 | template <class T>
|
---|
| 14 | void MeanSig(PixelMap<T> const & map, double& gmoy, double& gsig)
|
---|
| 15 | {
|
---|
| 16 | gmoy=0.;
|
---|
| 17 | gsig = 0.;
|
---|
| 18 | double valok;
|
---|
| 19 | for(int k=0; k<map.NbPixels(); k++) {
|
---|
| 20 | valok = map(k);
|
---|
| 21 | gmoy += valok; gsig += valok*valok;
|
---|
| 22 | }
|
---|
| 23 | gmoy /= (double)map.NbPixels();
|
---|
| 24 | gsig = gsig/(double)map.NbPixels() - gmoy*gmoy;
|
---|
| 25 | if (gsig >= 0.) gsig = sqrt(gsig);
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | template <class T>
|
---|
| 29 | void Project_Mol(PixelMap<T> const & map, TMatrix<T> & mtx, T defval=-999.)
|
---|
| 30 | {
|
---|
| 31 | r_8 xa, yd, teta,phi, facteur;
|
---|
| 32 | int_4 l,c,k;
|
---|
| 33 | int_4 nl = mtx.NRows();
|
---|
| 34 | int_4 nc = mtx.NCols();
|
---|
| 35 | mtx.Reset(defval); // On met tout a defval
|
---|
| 36 | cout << " NRows= " << nl << " NCols= " << nc << endl;
|
---|
| 37 | for(l=0; l<nl; l++) {
|
---|
| 38 | yd = (r_8)(l+0.5)/(r_8)nl-0.5;
|
---|
| 39 | facteur=2.*M_PI/sin(acos((double)yd*2));
|
---|
| 40 | teta = (yd+0.5)*Pi;
|
---|
| 41 | // teta = (0.5-yd)*M_PI;
|
---|
| 42 | for(c=0; c<nc; c++) {
|
---|
| 43 | xa = (r_8)(c+0.5)/(r_8)nc-0.5;
|
---|
| 44 | phi = xa*facteur+M_PI;
|
---|
| 45 | if ( (phi <= 2*M_PI) && (phi >= 0.) ) {
|
---|
| 46 | k = map.PixIndexSph(teta, phi);
|
---|
| 47 | mtx(l,c) = map(k);
|
---|
| 48 | }
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | }
|
---|
| 53 | template <class T>
|
---|
| 54 | void Project_Mol_Old(PixelMap<T> const & map, ImageR4 & img, float defval=-999.)
|
---|
| 55 | {
|
---|
| 56 | r_8 xa, yd, teta,phi, facteur;
|
---|
| 57 | int_4 i,j,k,n;
|
---|
| 58 | printf("Xsize= %d Ysize= %d NPix= %d\n",img.XSize(),img.YSize(),img.XSize()*img.YSize() );
|
---|
| 59 | n = 0;
|
---|
[606] | 60 | img.Zero();
|
---|
[591] | 61 | for(j=0; j<img.YSize(); j++) {
|
---|
| 62 | yd = (r_4)(j+0.5)/(r_4)img.YSize()-0.5;
|
---|
| 63 | facteur=2.*M_PI/sin(acos((double)yd*2));
|
---|
| 64 | teta = (yd+0.5)*M_PI;
|
---|
| 65 | // teta = (0.5-yd)*M_PI;
|
---|
| 66 | for(i=0; i<img.XSize(); i++) {
|
---|
| 67 | xa = (r_4)(i+0.5)/(r_4)img.XSize()-0.5;
|
---|
| 68 | phi = xa*facteur+M_PI;
|
---|
| 69 | if ( (phi <= 2*M_PI) && (phi >= 0.) ) {
|
---|
| 70 | k = map.PixIndexSph(teta, phi);
|
---|
| 71 | img(i,j) = map(k);
|
---|
| 72 | // if (n<20) {
|
---|
| 73 | // printf("i,j= %d %d -> %g %g -> k=%d -> val= %g \n",
|
---|
| 74 | // i,j,teta,phi,k,map(k)); n++; }
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | int main(int narg, char* arg[])
|
---|
| 82 | {
|
---|
| 83 | double teta,phi;
|
---|
| 84 | double gmoy=0., gsig=0.;
|
---|
| 85 |
|
---|
| 86 | PeidaInit();
|
---|
| 87 | InitTim(); // Initializing the CPU timer
|
---|
| 88 | if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) {
|
---|
| 89 | cout << " tspm [Gorski_M=32] : Gorski Spherical Map Test " << endl;
|
---|
| 90 | exit(0);
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | int m=32;
|
---|
| 94 | if (narg >1) m = atoi(arg[1]);
|
---|
| 95 | cout << " ===== Gorski Spherical Map Test M= " << m << endl;
|
---|
| 96 |
|
---|
| 97 | POutPersist s("spheres.ppf");
|
---|
| 98 | string nomobj;
|
---|
| 99 |
|
---|
| 100 | {
|
---|
| 101 | SphereGorski<double> sph(m);
|
---|
| 102 |
|
---|
| 103 | cout << "Filling spherical map NPixels= " << sph.NbPixels() << endl;
|
---|
| 104 | for (int j=0;j<sph.NbPixels();j++)
|
---|
| 105 | {
|
---|
| 106 | sph.PixThetaPhi(j,teta,phi);
|
---|
| 107 | sph(j)= 0.2* cos(3.*teta)*sin(8*phi);
|
---|
| 108 | }
|
---|
| 109 | PrtTim("End of Fill ");
|
---|
| 110 |
|
---|
| 111 | {
|
---|
| 112 | FIO_SphereGorski<double> fiog(&sph) ;
|
---|
| 113 | nomobj = "sphg1";
|
---|
| 114 | fiog.Write(s, nomobj);
|
---|
[606] | 115 | cout << "SphMap SphereGorski<double> written to POutPersist with name " << nomobj << endl;
|
---|
[591] | 116 | }
|
---|
| 117 |
|
---|
[606] | 118 | FitsIoServer fios;
|
---|
[591] | 119 | // On projete dans un fichier FITS
|
---|
| 120 | fios.sinus_picture_projection(sph, "gsin1.fits");
|
---|
| 121 | fios.save(sph, "sph1.fits");
|
---|
| 122 |
|
---|
| 123 | TMatrix<double> mtx(3*m, 6*m);
|
---|
| 124 | Project_Mol(sph, mtx);
|
---|
| 125 | fios.save(mtx, "mtx1.fits");
|
---|
| 126 |
|
---|
| 127 | cout << " Project_Mol_Old(sph, img) " << endl;
|
---|
| 128 | ImageR4 img(6*m, 3*m);
|
---|
| 129 | Project_Mol_Old(sph, img);
|
---|
| 130 | img.CheckDyn();
|
---|
| 131 | cout << img;
|
---|
| 132 | fios.save(img, "img1.fits");
|
---|
| 133 | cout << " Apres writeFits " << endl;
|
---|
| 134 | img.CheckDyn();
|
---|
| 135 | cout << img;
|
---|
| 136 | /*
|
---|
| 137 | ImageR4 imgr;
|
---|
| 138 | fios.load(imgr, "img1.fits");
|
---|
| 139 | cout << " Apres readFits " << endl;
|
---|
| 140 | imgr.CheckDyn();
|
---|
| 141 | cout << imgr;
|
---|
| 142 | */
|
---|
| 143 |
|
---|
| 144 | // Computing mean and sigma on the sphere
|
---|
| 145 | MeanSig(sph, gmoy, gsig);
|
---|
| 146 | cout << "SphMap Mean= " << gmoy << " Sigma = " << gsig << endl;
|
---|
| 147 | PrtTim("End of Mean-Sig ");
|
---|
| 148 | }
|
---|
[606] | 149 |
|
---|
[591] | 150 | {
|
---|
[606] | 151 | SphereGorski<float> sph(m);
|
---|
[591] | 152 |
|
---|
| 153 | cout << "Filling spherical map2 NPixels= " << sph.NbPixels() << endl;
|
---|
| 154 | for (int j=0;j<sph.NbPixels();j++)
|
---|
| 155 | {
|
---|
| 156 | sph.PixThetaPhi(j,teta,phi);
|
---|
| 157 | if (teta < 0.3) sph(j) = 30.;
|
---|
| 158 | else if ((teta>1.4) && (teta<1.6) ) sph(j) = 20.;
|
---|
| 159 | else {
|
---|
| 160 | if (phi < 2.) sph(j) = 2.;
|
---|
| 161 | else if (phi > 3.) sph(j) = 5.;
|
---|
| 162 | else sph(j) = 0.;
|
---|
| 163 | }
|
---|
| 164 | }
|
---|
| 165 | PrtTim("End of Fill2 ");
|
---|
| 166 |
|
---|
| 167 | {
|
---|
[606] | 168 | FIO_SphereGorski<float> fiog(&sph) ;
|
---|
[591] | 169 | nomobj = "sphg2";
|
---|
| 170 | fiog.Write(s, nomobj);
|
---|
[606] | 171 | cout << "SphMap SphereGorski<float> written to POutPersist with name " << nomobj << endl;
|
---|
[591] | 172 | }
|
---|
| 173 |
|
---|
| 174 |
|
---|
| 175 | // On projete dans un fichier FITS
|
---|
| 176 | FitsIoServer fios;
|
---|
[606] | 177 | {
|
---|
| 178 | cout << "Test of Write/Read SphereGorski<float> to FITS (sphg_r4.fits) " << endl;
|
---|
| 179 | fios.save(sph, "sphg_r4.fits");
|
---|
| 180 |
|
---|
| 181 | SphereGorski<float> sphr(4);
|
---|
| 182 | fios.load(sphr, "sphg_r4.fits", 2);
|
---|
| 183 | cout << " Read from file - SphereGorski<float> NPixels= " << sphr.NbPixels() << endl;
|
---|
| 184 | int ndiff = 0;
|
---|
| 185 | for(int k=0; k<sphr.NbPixels(); k++) {
|
---|
| 186 | if ( sphr(k) != sph(k) ) {
|
---|
| 187 | ndiff++;
|
---|
| 188 | if (ndiff < 20) cout << "!!!Diff: K= " << k << " SPHR= " << sphr(k) << " SPH= " << sph(k) << endl;
|
---|
| 189 | }
|
---|
| 190 | }
|
---|
| 191 | cout << " ReadFrom FITS NDiff = " << ndiff << " (should be zero = 0) " << endl;
|
---|
| 192 |
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 |
|
---|
[591] | 196 | fios.sinus_picture_projection(sph, "gsin2.fits");
|
---|
| 197 | fios.save(sph, "sph2.fits");
|
---|
| 198 |
|
---|
[606] | 199 | TMatrix<float> mtx(3*m, 6*m);
|
---|
[591] | 200 | Project_Mol(sph, mtx);
|
---|
| 201 | fios.save(mtx, "mtx2.fits");
|
---|
| 202 |
|
---|
| 203 |
|
---|
| 204 | cout << " Project_Mol_Old(sph, img) " << endl;
|
---|
| 205 | ImageR4 img(6*m, 3*m);
|
---|
| 206 | Project_Mol_Old(sph, img);
|
---|
| 207 | img.CheckDyn();
|
---|
| 208 | cout << img;
|
---|
| 209 | fios.save(img, "img2.fits");
|
---|
| 210 | cout << " Apres writeFits " << endl;
|
---|
| 211 | img.CheckDyn();
|
---|
| 212 | cout << img;
|
---|
| 213 |
|
---|
| 214 | // Computing mean and sigma on the sphere
|
---|
| 215 | MeanSig(sph, gmoy, gsig);
|
---|
| 216 | cout << "SphMap2 Mean= " << gmoy << " Sigma = " << gsig << endl;
|
---|
| 217 | PrtTim("End of Mean-Sig2 ");
|
---|
| 218 | }
|
---|
| 219 |
|
---|
| 220 | {
|
---|
| 221 | SphereThetaPhi< complex<float> > sphc(m*10);
|
---|
| 222 |
|
---|
| 223 | cout << "Filling spherical map3 SphereThetaPhi(complex) NPixels= " << sphc.NbPixels() << endl;
|
---|
| 224 | for (int j=0;j<sphc.NbPixels();j++)
|
---|
| 225 | {
|
---|
| 226 | sphc.PixThetaPhi(j,teta,phi);
|
---|
| 227 | if (teta < 0.3) sphc(j) = (30., drandpm1()*3.);
|
---|
| 228 | else if ((teta>1.4) && (teta<1.6) ) sphc(j) = (20., NorRand());
|
---|
| 229 | else {
|
---|
| 230 | if (phi < 2.) sphc(j) = 2.;
|
---|
| 231 | else if (phi > 3.) sphc(j) = 5.;
|
---|
| 232 | else sphc(j) = 0.;
|
---|
| 233 | }
|
---|
| 234 | }
|
---|
| 235 | PrtTim("End of Fill2 ");
|
---|
| 236 |
|
---|
| 237 | {
|
---|
| 238 | FIO_SphereThetaPhi< complex<float> > fio(&sphc) ;
|
---|
| 239 | nomobj = "sphtp";
|
---|
| 240 | fio.Write(s, nomobj);
|
---|
| 241 | cout << "SphMap written to POutPersist with name " << nomobj << endl;
|
---|
| 242 | }
|
---|
| 243 | }
|
---|
| 244 | cout << " ===== Fin de TSPM2_Test ======== " << endl;
|
---|
| 245 | return 0;
|
---|
| 246 | }
|
---|