[854] | 1 | #include "pexceptions.h"
|
---|
| 2 | #include "fitsspherehealpix.h"
|
---|
[1176] | 3 | #include "tarray.h"
|
---|
| 4 | #include "fitstarray.h"
|
---|
[854] | 5 |
|
---|
| 6 |
|
---|
| 7 |
|
---|
| 8 | ///////////////////////////////////////////////////////////////////////
|
---|
| 9 | // ----objets delegues pour la gestion de persistance I/O format fits--
|
---|
| 10 | // SphereHealpix
|
---|
| 11 | ////////////////////////////////////////////////////////////////////
|
---|
| 12 |
|
---|
| 13 |
|
---|
| 14 | template <class T>
|
---|
| 15 | FITS_SphereHEALPix<T>::FITS_SphereHEALPix()
|
---|
| 16 | {
|
---|
| 17 | dobj_= new SphereHEALPix<T>;
|
---|
[1136] | 18 | ownobj_= true;
|
---|
[854] | 19 | }
|
---|
| 20 |
|
---|
| 21 | template <class T>
|
---|
| 22 | FITS_SphereHEALPix<T>::FITS_SphereHEALPix(char inputfile[],int hdunum)
|
---|
| 23 | {
|
---|
[1174] | 24 | dobj_= new SphereHEALPix<T>;
|
---|
| 25 | ownobj_= true;
|
---|
[1136] | 26 | Read(inputfile,hdunum);
|
---|
[854] | 27 | }
|
---|
| 28 |
|
---|
| 29 |
|
---|
| 30 | template <class T>
|
---|
| 31 | FITS_SphereHEALPix<T>::FITS_SphereHEALPix(const SphereHEALPix<T>& obj)
|
---|
| 32 | {
|
---|
[1174] | 33 | dobj_= new SphereHEALPix<T>(obj);
|
---|
[1136] | 34 | ownobj_= true;
|
---|
[854] | 35 | }
|
---|
| 36 |
|
---|
| 37 | template <class T>
|
---|
| 38 | FITS_SphereHEALPix<T>::FITS_SphereHEALPix(SphereHEALPix<T>* obj)
|
---|
| 39 | {
|
---|
| 40 | dobj_= obj;
|
---|
[1136] | 41 | ownobj_= false;
|
---|
[854] | 42 | }
|
---|
| 43 |
|
---|
| 44 | template <class T>
|
---|
| 45 | FITS_SphereHEALPix<T>::~FITS_SphereHEALPix()
|
---|
| 46 | {
|
---|
[1136] | 47 | if (ownobj_ && dobj_) delete dobj_;
|
---|
[854] | 48 | }
|
---|
| 49 |
|
---|
| 50 | template <class T>
|
---|
| 51 | AnyDataObj* FITS_SphereHEALPix<T>::DataObj()
|
---|
| 52 | {
|
---|
| 53 | return(dobj_);
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | template <class T>
|
---|
[921] | 57 | void FITS_SphereHEALPix<T>::SetDataObj(AnyDataObj & o)
|
---|
| 58 | {
|
---|
| 59 | SphereHEALPix<T> * po = dynamic_cast< SphereHEALPix<T> * >(&o);
|
---|
| 60 | if (po == NULL) return;
|
---|
[1136] | 61 | if (ownobj_ && dobj_) delete dobj_;
|
---|
[921] | 62 | dobj_ = po;
|
---|
[1136] | 63 | ownobj_ = false;
|
---|
[921] | 64 | }
|
---|
| 65 |
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 |
|
---|
| 69 | template <class T>
|
---|
[1136] | 70 | void FITS_SphereHEALPix<T>::WriteToFits(FitsOutFile& os)
|
---|
[854] | 71 | {
|
---|
| 72 | if(dobj_ == NULL)
|
---|
| 73 | {
|
---|
[921] | 74 | cout << " WriteToFits:: dobj_= null " << endl;
|
---|
[854] | 75 | return;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
[1143] | 78 | DVList dvl( dobj_->Info() );
|
---|
[854] | 79 |
|
---|
| 80 | SphereCoordSys* cs= dobj_->GetCoordSys();
|
---|
| 81 | string description= cs->description();
|
---|
| 82 | dvl["COORDSYS"]= description;
|
---|
| 83 |
|
---|
[972] | 84 | dvl["PIXTYPE"] = "HEALPIX";
|
---|
| 85 | dvl.SetComment("PIXTYPE", "HEALPIX Pixelization");
|
---|
[854] | 86 | dvl["ORDERING"]= dobj_->TypeOfMap();
|
---|
[972] | 87 | dvl.SetComment("ORDERING", "Pixel ordering scheme, either RING or NESTED");
|
---|
[854] | 88 |
|
---|
| 89 | int nSide= dobj_->SizeIndex();
|
---|
[1004] | 90 | dvl["NSIDE"]= (int_4) nSide;
|
---|
[972] | 91 | dvl.SetComment("NSIDE","Resolution parameter for HEALPIX" );
|
---|
[854] | 92 |
|
---|
| 93 | int nPix= dobj_->NbPixels();
|
---|
[1004] | 94 | dvl["FIRSTPIX"]= (int_4) 0;
|
---|
[972] | 95 | dvl.SetComment("FIRSTPIX", "First pixel # (0 based)");
|
---|
[1004] | 96 | dvl["LASTPIX"]= (int_4) nPix-1;
|
---|
[972] | 97 | dvl.SetComment("LASTPIX", "Last pixel # (0 based)");
|
---|
[854] | 98 | dvl["Content"]= "SphereHEALPix";
|
---|
[1300] | 99 | dvl.SetComment("Content", "name of SOPHYA object");
|
---|
| 100 |
|
---|
[854] | 101 | // On ecrit les dataBlocks
|
---|
[1194] | 102 | vector<string> Noms;
|
---|
| 103 | Noms.push_back(dvl.GetS("Content"));
|
---|
| 104 | string extname("SIMULATION");
|
---|
[854] | 105 |
|
---|
[1194] | 106 | string Type;
|
---|
| 107 | if (typeid(T) == typeid(r_8) ) Type+='D';
|
---|
[854] | 108 | else
|
---|
[1194] | 109 | if (typeid(T) == typeid(r_4) ) Type+='E';
|
---|
[854] | 110 | else
|
---|
| 111 | {
|
---|
| 112 | cout << " type de la sphere= " << typeid(T).name() << endl;
|
---|
| 113 | throw IOExc("FITS_SphereHEALPix:: unknown type");
|
---|
| 114 | }
|
---|
| 115 | vector<int> dummy;
|
---|
[1221] | 116 | os.makeHeaderBntblOnFits(Type, Noms, nPix, 1, &dvl, extname, dummy);
|
---|
[1210] | 117 | os.PutColToFits(0, nPix, dobj_->pixels_.Data());
|
---|
[854] | 118 | }
|
---|
| 119 |
|
---|
| 120 | template <class T>
|
---|
[1136] | 121 | void FITS_SphereHEALPix<T>::ReadFromFits(FitsInFile& is)
|
---|
[854] | 122 | {
|
---|
| 123 | if(dobj_ == NULL)
|
---|
| 124 | {
|
---|
| 125 | dobj_= new SphereHEALPix<T>;
|
---|
[1136] | 126 | ownobj_= true;
|
---|
[854] | 127 | }
|
---|
[1174] | 128 | int nbcols, nbentries;
|
---|
| 129 | //
|
---|
[854] | 130 |
|
---|
[1136] | 131 | nbcols = is.NbColsFromFits();
|
---|
[854] | 132 | if (nbcols != 1)
|
---|
| 133 | {
|
---|
| 134 | throw IOExc("le fichier fits n'est pas une sphere Healpix");
|
---|
| 135 | }
|
---|
[1136] | 136 | DVList dvl=is.DVListFromFits();
|
---|
| 137 | nbentries = is.NentriesFromFits(0);
|
---|
[854] | 138 | int lastpix=dvl.GetI("LASTPIX");
|
---|
| 139 | if (lastpix>0)
|
---|
| 140 | {
|
---|
| 141 | if (nbentries!=lastpix+1)
|
---|
| 142 | {
|
---|
| 143 | nbentries=lastpix+1;
|
---|
| 144 | }
|
---|
| 145 | }
|
---|
| 146 | // Let's Read the SphereCoordSys object
|
---|
| 147 | int id= SphereCoordSys_NEUTRAL;
|
---|
| 148 | string description= "NEUTRAL SphereCoordSystem";
|
---|
[985] | 149 | string coordsys= dvl.GetS("COORDSYS");
|
---|
| 150 | // $CHECK$ - Reza 2/05/2000 - compare(size_t, size_t,...) passe pas sur g++
|
---|
| 151 | // if(coordsys.compare(0,7,"ROTATION",0,7) == 0) $CHECK$
|
---|
| 152 | if(coordsys.substr(0,8) == "ROTATION")
|
---|
[854] | 153 | {
|
---|
| 154 | id= SphereCoordSys_ROTATION;
|
---|
| 155 | description= "ROTATION SphereCoordSystem";
|
---|
| 156 | }
|
---|
[985] | 157 | // else if(coordsys.compare(0,4,"OTHER",0,4) == 0) $CHECK$ Reza 2/05/2000
|
---|
| 158 | else if(coordsys.substr(0,5) == "OTHER" )
|
---|
[854] | 159 | {
|
---|
| 160 | id= SphereCoordSys_OTHER;
|
---|
| 161 | description= "OTHER SphereCoordSystem";
|
---|
| 162 | }
|
---|
| 163 | dobj_->SetCoordSys(new SphereCoordSys(id,description));
|
---|
| 164 |
|
---|
[972] | 165 | string ordering= dvl.GetS("ORDERING");
|
---|
[985] | 166 | // if(ordering.compare(0,3,"RING",0,3) != 0) $CHECK$ Reza 2/05/2000
|
---|
| 167 | if(ordering.substr(0,4) != "RING" )
|
---|
[854] | 168 | {
|
---|
[985] | 169 | cerr << "FITS_SphereHEALPix/Error Not supported ORDERING= "
|
---|
| 170 | << ordering << " substr(0,4)=[" << ordering.substr(0,4) << "]" << endl;
|
---|
[854] | 171 | throw IOExc(" FITS_SphereHEALPix:: numerotation non RING");
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | int nside= dvl.GetI("NSIDE");
|
---|
[1182] | 175 | int nPix = 0;
|
---|
[854] | 176 | if(nside <= 0)
|
---|
[1182] | 177 | {
|
---|
| 178 | // throw IOExc("FITS_SphereHEALPix:: No resol parameter nside");
|
---|
| 179 | if (lastpix>0)
|
---|
| 180 | {
|
---|
[1250] | 181 | nside = sqrt((double)(nbentries/12));
|
---|
[1182] | 182 | }
|
---|
| 183 | else
|
---|
| 184 | {
|
---|
| 185 | throw IOExc("FITS_SphereHEALPix:: No NSIDE nor LASTPIX on file");
|
---|
| 186 | }
|
---|
| 187 | }
|
---|
| 188 | nPix = 12*nside*nside;
|
---|
[854] | 189 | if (nPix != nbentries)
|
---|
| 190 | {
|
---|
[873] | 191 | cout << "WARNING: le nombre de pixels relu " << nbentries << " est incoherent avec la pixelisation Healpix qui donne nPix= " << nPix << endl;
|
---|
[854] | 192 | }
|
---|
| 193 | double Omega= 4.0*Pi/nPix;
|
---|
| 194 | dobj_->setParameters(nside,nPix,Omega);
|
---|
| 195 | // On lit les DataBlocks;
|
---|
[1174] | 196 | //
|
---|
| 197 | dobj_->pixels_.ReSize(nPix);
|
---|
[1136] | 198 | is.GetSingleColumn(dobj_->pixels_.Data(),nPix);
|
---|
[1174] | 199 | //
|
---|
[854] | 200 |
|
---|
| 201 | // on effectue le decoupage en tranches
|
---|
| 202 | dobj_->SetThetaSlices();
|
---|
[1174] | 203 | //
|
---|
| 204 | dobj_->Info() = is.DVListFromFits();
|
---|
| 205 | cout << " end of file reading " << endl;
|
---|
[854] | 206 | }
|
---|
| 207 |
|
---|
[1176] | 208 | template <class T>
|
---|
| 209 | void FITS_SphereHEALPix<T>::Mollweide_picture_projection(char filename[])
|
---|
| 210 | {
|
---|
| 211 | int ni = 300;
|
---|
| 212 | int nj = 600;
|
---|
| 213 | TMatrix<float> map(ni, nj);
|
---|
[854] | 214 |
|
---|
[1176] | 215 | int i,j;
|
---|
| 216 | for(i=0; i < ni; i++)
|
---|
| 217 | {
|
---|
| 218 | double yd = (i+0.5)/ni-0.5;
|
---|
| 219 | double facteur=2.*Pi/sin(acos(yd*2));
|
---|
| 220 | double theta = (0.5-yd)*Pi;
|
---|
| 221 | for(j=0; j < nj; j++)
|
---|
| 222 | {
|
---|
| 223 | double xa = (j+0.5)/nj-0.5;
|
---|
| 224 | double phi = xa*facteur+Pi;
|
---|
| 225 | float th=float(theta);
|
---|
| 226 | float ff=float(phi);
|
---|
| 227 | if (phi<2*Pi && phi>= 0)
|
---|
| 228 | {
|
---|
| 229 | map(i,j) = (float)dobj_->PixValSph(th, ff);
|
---|
| 230 | }
|
---|
| 231 | }
|
---|
| 232 | }
|
---|
| 233 | FitsOutFile fout(filename);
|
---|
[1234] | 234 | fout.firstImageOnPrimaryHeader(true);
|
---|
[1176] | 235 | FITS_TArray<r_4> fta(map);
|
---|
| 236 | fta.Write(fout);
|
---|
| 237 |
|
---|
| 238 | }
|
---|
| 239 | template <class T>
|
---|
| 240 | void FITS_SphereHEALPix<T>::sinus_picture_projection(char filename[])
|
---|
| 241 | {
|
---|
| 242 | int ni = 300;
|
---|
| 243 | int nj = 600;
|
---|
| 244 | TMatrix<float> map(ni, nj);
|
---|
| 245 |
|
---|
| 246 | int i,j;
|
---|
| 247 | for(i=0; i < ni; i++)
|
---|
| 248 | {
|
---|
| 249 | double yd = (i+0.5)/ni-0.5;
|
---|
| 250 | double theta = (0.5-yd)*Pi;
|
---|
| 251 | double facteur=1./sin(theta);
|
---|
| 252 | for(j=0; j < nj; j++)
|
---|
| 253 | {
|
---|
| 254 | double xa = (j+0.5)/nj-0.5;
|
---|
| 255 | double phi = 2.*Pi*xa*facteur+Pi;
|
---|
| 256 | float th=float(theta);
|
---|
| 257 | float ff=float(phi);
|
---|
| 258 | if (phi<2*Pi && phi>= 0)
|
---|
| 259 | {
|
---|
| 260 | map(i,j) = (float)dobj_->PixValSph(th, ff);
|
---|
| 261 | }
|
---|
| 262 | }
|
---|
| 263 | }
|
---|
| 264 | FitsOutFile fout(filename);
|
---|
[1234] | 265 | fout.firstImageOnPrimaryHeader(true);
|
---|
[1176] | 266 | FITS_TArray<r_4> fta(map);
|
---|
| 267 | fta.Write(fout);
|
---|
| 268 |
|
---|
| 269 |
|
---|
| 270 | }
|
---|
| 271 |
|
---|
| 272 |
|
---|
[854] | 273 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
| 274 | #pragma define_template FITS_SphereHEALPix<r_8>
|
---|
| 275 | #pragma define_template FITS_SphereHEALPix<r_4>
|
---|
[1300] | 276 | #pragma define_template FITS_SphereHEALPix<int_4>
|
---|
[854] | 277 | #endif
|
---|
| 278 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
| 279 | template class FITS_SphereHEALPix<r_8>;
|
---|
| 280 | template class FITS_SphereHEALPix<r_4>;
|
---|
[1300] | 281 | template class FITS_SphereHEALPix<int_4>;
|
---|
[854] | 282 | #endif
|
---|