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