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