[2615] | 1 | #include "sopnamsp.h"
|
---|
[1752] | 2 | #include "pexceptions.h"
|
---|
| 3 | #include "fitsspherethetaphi.h"
|
---|
| 4 | #include "tarray.h"
|
---|
| 5 | #include "fitstarray.h"
|
---|
| 6 |
|
---|
| 7 |
|
---|
| 8 |
|
---|
| 9 | ///////////////////////////////////////////////////////////////////////
|
---|
| 10 | // ----objets delegues pour la gestion de persistance I/O format fits--
|
---|
| 11 | // SphereThetaPhi
|
---|
| 12 | ////////////////////////////////////////////////////////////////////
|
---|
| 13 |
|
---|
| 14 | /*!
|
---|
| 15 | \class SOPHYA::FITS_SphereThetaPhi
|
---|
| 16 | \ingroup FitsIOServer
|
---|
| 17 | FITS format I/O handler for SOPHYA::SphereThetaPhi objects.
|
---|
| 18 | */
|
---|
| 19 |
|
---|
| 20 | template <class T>
|
---|
| 21 | FITS_SphereThetaPhi<T>::FITS_SphereThetaPhi()
|
---|
| 22 | {
|
---|
| 23 | dobj_= new SphereThetaPhi<T>;
|
---|
| 24 | ownobj_= true;
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | template <class T>
|
---|
| 28 | FITS_SphereThetaPhi<T>::FITS_SphereThetaPhi(char inputfile[],int hdunum)
|
---|
| 29 | {
|
---|
| 30 | dobj_= new SphereThetaPhi<T>;
|
---|
| 31 | ownobj_= true;
|
---|
| 32 | Read(inputfile,hdunum);
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | template <class T>
|
---|
| 36 | FITS_SphereThetaPhi<T>::FITS_SphereThetaPhi(const SphereThetaPhi<T>& obj)
|
---|
| 37 | {
|
---|
| 38 | dobj_= new SphereThetaPhi<T>(obj);
|
---|
| 39 | ownobj_= true;
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | template <class T>
|
---|
| 43 | FITS_SphereThetaPhi<T>::FITS_SphereThetaPhi(SphereThetaPhi<T>* obj)
|
---|
| 44 | {
|
---|
| 45 | dobj_= obj;
|
---|
| 46 | ownobj_= false;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | template <class T>
|
---|
| 50 | FITS_SphereThetaPhi<T>::~FITS_SphereThetaPhi()
|
---|
| 51 | {
|
---|
| 52 | if (ownobj_ && dobj_) delete dobj_;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | template <class T>
|
---|
| 56 | AnyDataObj* FITS_SphereThetaPhi<T>::DataObj()
|
---|
| 57 | {
|
---|
| 58 | return(dobj_);
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | template <class T>
|
---|
| 62 | void FITS_SphereThetaPhi<T>::SetDataObj(AnyDataObj & o)
|
---|
| 63 | {
|
---|
| 64 | SphereThetaPhi<T> * po = dynamic_cast< SphereThetaPhi<T> * >(&o);
|
---|
| 65 | if (po == NULL) return;
|
---|
| 66 | if (ownobj_ && dobj_) delete dobj_;
|
---|
| 67 | dobj_ = po;
|
---|
| 68 | ownobj_ = false;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | template <class T>
|
---|
[2897] | 72 | int FITS_SphereThetaPhi<T>::CheckHandling(AnyDataObj & o)
|
---|
| 73 | {
|
---|
| 74 | if ( typeid(o) == typeid( SphereThetaPhi< T > ) ) return 2;
|
---|
| 75 | SphereThetaPhi<T> * po = dynamic_cast< SphereThetaPhi<T> * >(&o);
|
---|
| 76 | if (po == NULL) return 0;
|
---|
| 77 | else return 1;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | template <class T>
|
---|
| 81 | int FITS_SphereThetaPhi<T>::CheckReadability(FitsInOutFile& is)
|
---|
| 82 | {
|
---|
| 83 | if (is.CurrentHDUType() != BINARY_TBL ) return 0;
|
---|
| 84 | string key;
|
---|
| 85 | key = "PIXTYPE";
|
---|
| 86 | if ( is.KeyValue(key) != "TETAFI") return 0;
|
---|
| 87 | key = "Content";
|
---|
| 88 | if ( is.KeyValue(key) != "SphereThetaPhi") return 0;
|
---|
| 89 |
|
---|
| 90 | vector<string> colnames;
|
---|
| 91 | vector<int> coltypes;
|
---|
| 92 | vector<long> repcnt;
|
---|
| 93 | vector<long> width;
|
---|
| 94 | long ncols = is.GetColInfo(colnames, coltypes, repcnt, width);
|
---|
| 95 | if (ncols < 1) return 0;
|
---|
[2898] | 96 | T x = 0;
|
---|
[2897] | 97 | if (coltypes[0] == FitsTypes::DataType(x)) return 2 ;
|
---|
| 98 | else return 1;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | template <class T>
|
---|
| 102 | FitsHandlerInterface* FITS_SphereThetaPhi<T>::Clone()
|
---|
| 103 | {
|
---|
| 104 | return new FITS_SphereThetaPhi<T>() ;
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 |
|
---|
| 108 | template <class T>
|
---|
[1752] | 109 | void FITS_SphereThetaPhi<T>::WriteToFits(FitsOutFile& os)
|
---|
| 110 | {
|
---|
| 111 | if(dobj_ == NULL)
|
---|
| 112 | {
|
---|
| 113 | cout << " WriteToFits:: dobj_= null " << endl;
|
---|
| 114 | return;
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | DVList dvl( dobj_->Info() );
|
---|
| 118 |
|
---|
| 119 | SphereCoordSys* cs= dobj_->GetCoordSys();
|
---|
| 120 | string description= cs->description();
|
---|
| 121 | dvl["COORDSYS"]= description;
|
---|
| 122 |
|
---|
| 123 | dvl["PIXTYPE"] = "TETAFI";
|
---|
| 124 | dvl.SetComment("PIXTYPE", "Theta-Phi-LAL Pixelization");
|
---|
| 125 | dvl["ORDERING"]= dobj_->TypeOfMap();
|
---|
| 126 | dvl.SetComment("ORDERING", " (unrelevant) ");
|
---|
| 127 |
|
---|
| 128 | int IndTheta= dobj_->SizeIndex();
|
---|
| 129 | dvl["INDTHMAX"]= (int_4) IndTheta;
|
---|
| 130 | dvl.SetComment("INDTHMAX","Resolution parameter for Theta-Phi pixelization sch." );
|
---|
| 131 |
|
---|
| 132 | int nPix= dobj_->NbPixels();
|
---|
| 133 | dvl["FIRSTPIX"]= (int_4) 0;
|
---|
| 134 | dvl.SetComment("FIRSTPIX", "First pixel # (0 based)");
|
---|
| 135 | dvl["LASTPIX"]= (int_4) nPix-1;
|
---|
| 136 | dvl.SetComment("LASTPIX", "Last pixel # (0 based)");
|
---|
| 137 | dvl["Content"]= "SphereThetaPhi";
|
---|
| 138 | dvl.SetComment("Content", "name of SOPHYA object");
|
---|
[2897] | 139 | dvl["SOPCLSNM"]= "SOPHYA::SphereThetaPhi<T>";
|
---|
| 140 | dvl.SetComment("SOPCLSNM", "SOPHYA class name");
|
---|
[1752] | 141 |
|
---|
| 142 | // On ecrit les dataBlocks
|
---|
[2197] | 143 |
|
---|
| 144 | // the BINTABLE consits of 4 columns
|
---|
| 145 | // first column : pixels values (type : T ), length : number of pixels
|
---|
| 146 | // second column : number of pixels of each theta slice (type : integer) ,
|
---|
| 147 | // length : number of theta-slices (parameter INDTHMAX above +1)
|
---|
| 148 | // third column : cumulated number of pixels until the beginning of each
|
---|
| 149 | // theta slice (type : integer) , same length as the previous one
|
---|
| 150 | // fourth column : theta values of each slice (type : double_) same length
|
---|
| 151 | // as the previous one.
|
---|
[1752] | 152 | vector<string> Noms(4);
|
---|
| 153 | Noms[0] = dvl.GetS("Content");
|
---|
| 154 | Noms[1] = "NphiParBande";
|
---|
| 155 | Noms[2] = "CumulPixParBande";
|
---|
| 156 | Noms[3] = "ThetaBande";
|
---|
[2897] | 157 | //string extname("SIMULATION");
|
---|
| 158 | string extname = os.NextExtensionName();
|
---|
[1752] | 159 |
|
---|
| 160 | string Type;
|
---|
| 161 | if (typeid(T) == typeid(r_8) ) Type+='D';
|
---|
[2082] | 162 | else if (typeid(T) == typeid(r_4) ) Type+='E';
|
---|
| 163 | else if (typeid(T) == typeid(int_4) ) Type+='J';
|
---|
[1752] | 164 | else
|
---|
| 165 | {
|
---|
[2082] | 166 | cout << "FITS_SphereThetaPhi<T>::WriteToFits - Unsupported data type ("
|
---|
| 167 | << typeid(T).name() << ") throwing IOExc " << endl;
|
---|
| 168 | throw IOExc("FITS_SphereThetaPhi<T>::WriteToFits() unsupported data type");
|
---|
[1752] | 169 | }
|
---|
| 170 |
|
---|
| 171 | Type += 'J';
|
---|
| 172 | Type += 'J';
|
---|
| 173 | Type += 'D';
|
---|
| 174 |
|
---|
| 175 | vector<int> dummy;
|
---|
| 176 | os.makeHeaderBntblOnFits(Type, Noms, nPix, 4, &dvl, extname, dummy);
|
---|
| 177 | os.PutColToFits(0, nPix, dobj_->pixels_.Data());
|
---|
| 178 | os.PutColToFits(1, IndTheta+1, dobj_->NPhi_.Data());
|
---|
| 179 | os.PutColToFits(2, IndTheta+1, dobj_->TNphi_.Data());
|
---|
| 180 | os.PutColToFits(3, IndTheta+1, dobj_->Theta_.Data());
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | template <class T>
|
---|
| 184 | void FITS_SphereThetaPhi<T>::ReadFromFits(FitsInFile& is)
|
---|
| 185 | {
|
---|
| 186 |
|
---|
| 187 | if(dobj_ == NULL)
|
---|
| 188 | {
|
---|
| 189 | dobj_= new SphereThetaPhi<T>;
|
---|
| 190 | ownobj_= true;
|
---|
| 191 | }
|
---|
| 192 | int nbcols, nbentries;
|
---|
| 193 |
|
---|
| 194 | nbcols = is.NbColsFromFits();
|
---|
| 195 | if (nbcols != 4)
|
---|
| 196 | {
|
---|
| 197 | throw IOExc("le fichier fits n'est pas une sphere ThetaPhi");
|
---|
| 198 | }
|
---|
| 199 | DVList dvl=is.DVListFromFits();
|
---|
| 200 | nbentries = is.NentriesFromFits(0);
|
---|
| 201 | int lastpix=dvl.GetI("LASTPIX");
|
---|
| 202 | if (lastpix>0)
|
---|
| 203 | {
|
---|
| 204 | if (nbentries!=lastpix+1)
|
---|
| 205 | {
|
---|
| 206 | nbentries=lastpix+1;
|
---|
| 207 | }
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | // Let's Read the SphereCoordSys object
|
---|
[2974] | 211 | int id= SphereCoordSys::NEUTRAL;
|
---|
[1752] | 212 | string description= "NEUTRAL SphereCoordSystem";
|
---|
| 213 | string coordsys= dvl.GetS("COORDSYS");
|
---|
| 214 | if(coordsys.substr(0,8) == "ROTATION")
|
---|
| 215 | {
|
---|
[2974] | 216 | id= SphereCoordSys::ROTATION;
|
---|
[1752] | 217 | description= "ROTATION SphereCoordSystem";
|
---|
| 218 | }
|
---|
| 219 | else if(coordsys.substr(0,5) == "OTHER" )
|
---|
| 220 | {
|
---|
[2974] | 221 | id= SphereCoordSys::OTHER;
|
---|
[1752] | 222 | description= "OTHER SphereCoordSystem";
|
---|
| 223 | }
|
---|
| 224 | dobj_->SetCoordSys(new SphereCoordSys(id,description));
|
---|
| 225 |
|
---|
| 226 | int IndThetaMax= dvl.GetI("INDTHMAX");
|
---|
| 227 | int nPix = 0;
|
---|
| 228 | if(IndThetaMax <= 0)
|
---|
| 229 | {
|
---|
| 230 | throw IOExc("FITS_SphereTheta:: No resol parameter INDTHMAX");
|
---|
| 231 | }
|
---|
| 232 | nPix = nbentries;
|
---|
| 233 | double Omega= 4.0*Pi/nPix;
|
---|
| 234 | dobj_->setParameters(IndThetaMax,nPix,Omega);
|
---|
| 235 |
|
---|
| 236 | // On lit les DataBlocks;
|
---|
| 237 | //
|
---|
[2197] | 238 | // the BINTABLE consits of 4 columns
|
---|
| 239 | // first column : pixels values (type : T ), length : number of pixels
|
---|
| 240 | // second column : number of pixels of each theta slice (type : integer) ,
|
---|
| 241 | // length : number of theta-slices (parameter INDTHMAX above +1)
|
---|
| 242 | // third column : cumulated number of pixels until the beginning of each
|
---|
| 243 | // theta slice (type : integer) , same length as the previous one
|
---|
| 244 | // fourth column : theta values of each slice (type : double_) same length
|
---|
| 245 | // as the previous one.
|
---|
| 246 |
|
---|
[1752] | 247 | dobj_->pixels_.ReSize(nPix);
|
---|
| 248 | is.GetBinTabFCol(dobj_->pixels_.Data(),nPix,0);
|
---|
| 249 | dobj_->NPhi_.ReSize(IndThetaMax+1);
|
---|
| 250 | is.GetBinTabFCol(dobj_->NPhi_.Data(),IndThetaMax+1,1);
|
---|
| 251 | dobj_->TNphi_.ReSize(IndThetaMax+1);
|
---|
| 252 | is.GetBinTabFCol(dobj_->TNphi_.Data(),IndThetaMax+1,2);
|
---|
| 253 | dobj_->Theta_.ReSize(IndThetaMax+1);
|
---|
| 254 | is.GetBinTabFCol(dobj_->Theta_.Data(),IndThetaMax+1,3);
|
---|
| 255 | }
|
---|
| 256 |
|
---|
| 257 | template <class T>
|
---|
| 258 | void FITS_SphereThetaPhi<T>::Mollweide_picture_projection(char filename[])
|
---|
| 259 | {
|
---|
| 260 | int ni = 300;
|
---|
| 261 | int nj = 600;
|
---|
| 262 | TMatrix<float> map(ni, nj);
|
---|
| 263 |
|
---|
| 264 | int i,j;
|
---|
| 265 | for(i=0; i < ni; i++)
|
---|
| 266 | {
|
---|
| 267 | double yd = (i+0.5)/ni-0.5;
|
---|
| 268 | double facteur=2.*Pi/sin(acos(yd*2));
|
---|
| 269 | double theta = (0.5-yd)*Pi;
|
---|
| 270 | for(j=0; j < nj; j++)
|
---|
| 271 | {
|
---|
| 272 | double xa = (j+0.5)/nj-0.5;
|
---|
| 273 | double phi = xa*facteur+Pi;
|
---|
| 274 | float th=float(theta);
|
---|
| 275 | float ff=float(phi);
|
---|
| 276 | if (phi<2*Pi && phi>= 0)
|
---|
| 277 | {
|
---|
| 278 | map(i,j) = (float)dobj_->PixValSph(th, ff);
|
---|
| 279 | }
|
---|
| 280 | }
|
---|
| 281 | }
|
---|
| 282 | FitsOutFile fout(filename);
|
---|
| 283 | fout.firstImageOnPrimaryHeader(true);
|
---|
| 284 | FITS_TArray<r_4> fta(map);
|
---|
| 285 | fta.Write(fout);
|
---|
| 286 |
|
---|
| 287 | }
|
---|
| 288 | template <class T>
|
---|
| 289 | void FITS_SphereThetaPhi<T>::sinus_picture_projection(char filename[])
|
---|
| 290 | {
|
---|
| 291 | int ni = 300;
|
---|
| 292 | int nj = 600;
|
---|
| 293 | TMatrix<float> map(ni, nj);
|
---|
| 294 |
|
---|
| 295 | int i,j;
|
---|
| 296 | for(i=0; i < ni; i++)
|
---|
| 297 | {
|
---|
| 298 | double yd = (i+0.5)/ni-0.5;
|
---|
| 299 | double theta = (0.5-yd)*Pi;
|
---|
| 300 | double facteur=1./sin(theta);
|
---|
| 301 | for(j=0; j < nj; j++)
|
---|
| 302 | {
|
---|
| 303 | double xa = (j+0.5)/nj-0.5;
|
---|
| 304 | double phi = 2.*Pi*xa*facteur+Pi;
|
---|
| 305 | float th=float(theta);
|
---|
| 306 | float ff=float(phi);
|
---|
| 307 | if (phi<2*Pi && phi>= 0)
|
---|
| 308 | {
|
---|
| 309 | map(i,j) = (float)dobj_->PixValSph(th, ff);
|
---|
| 310 | }
|
---|
| 311 | }
|
---|
| 312 | }
|
---|
| 313 | FitsOutFile fout(filename);
|
---|
| 314 | fout.firstImageOnPrimaryHeader(true);
|
---|
| 315 | FITS_TArray<r_4> fta(map);
|
---|
| 316 | fta.Write(fout);
|
---|
| 317 |
|
---|
| 318 |
|
---|
| 319 | }
|
---|
| 320 |
|
---|
| 321 |
|
---|
| 322 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
| 323 | #pragma define_template FITS_SphereThetaPhi<r_8>
|
---|
| 324 | #pragma define_template FITS_SphereThetaPhi<r_4>
|
---|
[2197] | 325 | #pragma define_template FITS_SphereThetaPhi<int_4>
|
---|
[1752] | 326 | #endif
|
---|
| 327 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
[2874] | 328 | namespace SOPHYA {
|
---|
[1752] | 329 | template class FITS_SphereThetaPhi<r_8>;
|
---|
| 330 | template class FITS_SphereThetaPhi<r_4>;
|
---|
[2197] | 331 | template class FITS_SphereThetaPhi<int_4>;
|
---|
[2874] | 332 | }
|
---|
[1752] | 333 | #endif
|
---|