[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>
|
---|
| 72 | void FITS_SphereThetaPhi<T>::WriteToFits(FitsOutFile& os)
|
---|
| 73 | {
|
---|
| 74 | if(dobj_ == NULL)
|
---|
| 75 | {
|
---|
| 76 | cout << " WriteToFits:: dobj_= null " << endl;
|
---|
| 77 | return;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | DVList dvl( dobj_->Info() );
|
---|
| 81 |
|
---|
| 82 | SphereCoordSys* cs= dobj_->GetCoordSys();
|
---|
| 83 | string description= cs->description();
|
---|
| 84 | dvl["COORDSYS"]= description;
|
---|
| 85 |
|
---|
| 86 | dvl["PIXTYPE"] = "TETAFI";
|
---|
| 87 | dvl.SetComment("PIXTYPE", "Theta-Phi-LAL Pixelization");
|
---|
| 88 | dvl["ORDERING"]= dobj_->TypeOfMap();
|
---|
| 89 | dvl.SetComment("ORDERING", " (unrelevant) ");
|
---|
| 90 |
|
---|
| 91 | int IndTheta= dobj_->SizeIndex();
|
---|
| 92 | dvl["INDTHMAX"]= (int_4) IndTheta;
|
---|
| 93 | dvl.SetComment("INDTHMAX","Resolution parameter for Theta-Phi pixelization sch." );
|
---|
| 94 |
|
---|
| 95 | int nPix= dobj_->NbPixels();
|
---|
| 96 | dvl["FIRSTPIX"]= (int_4) 0;
|
---|
| 97 | dvl.SetComment("FIRSTPIX", "First pixel # (0 based)");
|
---|
| 98 | dvl["LASTPIX"]= (int_4) nPix-1;
|
---|
| 99 | dvl.SetComment("LASTPIX", "Last pixel # (0 based)");
|
---|
| 100 | dvl["Content"]= "SphereThetaPhi";
|
---|
| 101 | dvl.SetComment("Content", "name of SOPHYA object");
|
---|
| 102 |
|
---|
| 103 | // On ecrit les dataBlocks
|
---|
[2197] | 104 |
|
---|
| 105 | // the BINTABLE consits of 4 columns
|
---|
| 106 | // first column : pixels values (type : T ), length : number of pixels
|
---|
| 107 | // second column : number of pixels of each theta slice (type : integer) ,
|
---|
| 108 | // length : number of theta-slices (parameter INDTHMAX above +1)
|
---|
| 109 | // third column : cumulated number of pixels until the beginning of each
|
---|
| 110 | // theta slice (type : integer) , same length as the previous one
|
---|
| 111 | // fourth column : theta values of each slice (type : double_) same length
|
---|
| 112 | // as the previous one.
|
---|
[1752] | 113 | vector<string> Noms(4);
|
---|
| 114 | Noms[0] = dvl.GetS("Content");
|
---|
| 115 | Noms[1] = "NphiParBande";
|
---|
| 116 | Noms[2] = "CumulPixParBande";
|
---|
| 117 | Noms[3] = "ThetaBande";
|
---|
| 118 | string extname("SIMULATION");
|
---|
| 119 |
|
---|
| 120 |
|
---|
| 121 | string Type;
|
---|
| 122 | if (typeid(T) == typeid(r_8) ) Type+='D';
|
---|
[2082] | 123 | else if (typeid(T) == typeid(r_4) ) Type+='E';
|
---|
| 124 | else if (typeid(T) == typeid(int_4) ) Type+='J';
|
---|
[1752] | 125 | else
|
---|
| 126 | {
|
---|
[2082] | 127 | cout << "FITS_SphereThetaPhi<T>::WriteToFits - Unsupported data type ("
|
---|
| 128 | << typeid(T).name() << ") throwing IOExc " << endl;
|
---|
| 129 | throw IOExc("FITS_SphereThetaPhi<T>::WriteToFits() unsupported data type");
|
---|
[1752] | 130 | }
|
---|
| 131 |
|
---|
| 132 | Type += 'J';
|
---|
| 133 | Type += 'J';
|
---|
| 134 | Type += 'D';
|
---|
| 135 |
|
---|
| 136 | vector<int> dummy;
|
---|
| 137 | os.makeHeaderBntblOnFits(Type, Noms, nPix, 4, &dvl, extname, dummy);
|
---|
| 138 | os.PutColToFits(0, nPix, dobj_->pixels_.Data());
|
---|
| 139 | os.PutColToFits(1, IndTheta+1, dobj_->NPhi_.Data());
|
---|
| 140 | os.PutColToFits(2, IndTheta+1, dobj_->TNphi_.Data());
|
---|
| 141 | os.PutColToFits(3, IndTheta+1, dobj_->Theta_.Data());
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | template <class T>
|
---|
| 145 | void FITS_SphereThetaPhi<T>::ReadFromFits(FitsInFile& is)
|
---|
| 146 | {
|
---|
| 147 |
|
---|
| 148 | if(dobj_ == NULL)
|
---|
| 149 | {
|
---|
| 150 | dobj_= new SphereThetaPhi<T>;
|
---|
| 151 | ownobj_= true;
|
---|
| 152 | }
|
---|
| 153 | int nbcols, nbentries;
|
---|
| 154 |
|
---|
| 155 | nbcols = is.NbColsFromFits();
|
---|
| 156 | if (nbcols != 4)
|
---|
| 157 | {
|
---|
| 158 | throw IOExc("le fichier fits n'est pas une sphere ThetaPhi");
|
---|
| 159 | }
|
---|
| 160 | DVList dvl=is.DVListFromFits();
|
---|
| 161 | nbentries = is.NentriesFromFits(0);
|
---|
| 162 | int lastpix=dvl.GetI("LASTPIX");
|
---|
| 163 | if (lastpix>0)
|
---|
| 164 | {
|
---|
| 165 | if (nbentries!=lastpix+1)
|
---|
| 166 | {
|
---|
| 167 | nbentries=lastpix+1;
|
---|
| 168 | }
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | // Let's Read the SphereCoordSys object
|
---|
| 172 | int id= SphereCoordSys_NEUTRAL;
|
---|
| 173 | string description= "NEUTRAL SphereCoordSystem";
|
---|
| 174 | string coordsys= dvl.GetS("COORDSYS");
|
---|
| 175 | if(coordsys.substr(0,8) == "ROTATION")
|
---|
| 176 | {
|
---|
| 177 | id= SphereCoordSys_ROTATION;
|
---|
| 178 | description= "ROTATION SphereCoordSystem";
|
---|
| 179 | }
|
---|
| 180 | else if(coordsys.substr(0,5) == "OTHER" )
|
---|
| 181 | {
|
---|
| 182 | id= SphereCoordSys_OTHER;
|
---|
| 183 | description= "OTHER SphereCoordSystem";
|
---|
| 184 | }
|
---|
| 185 | dobj_->SetCoordSys(new SphereCoordSys(id,description));
|
---|
| 186 |
|
---|
| 187 | int IndThetaMax= dvl.GetI("INDTHMAX");
|
---|
| 188 | int nPix = 0;
|
---|
| 189 | if(IndThetaMax <= 0)
|
---|
| 190 | {
|
---|
| 191 | throw IOExc("FITS_SphereTheta:: No resol parameter INDTHMAX");
|
---|
| 192 | }
|
---|
| 193 | nPix = nbentries;
|
---|
| 194 | double Omega= 4.0*Pi/nPix;
|
---|
| 195 | dobj_->setParameters(IndThetaMax,nPix,Omega);
|
---|
| 196 |
|
---|
| 197 | // On lit les DataBlocks;
|
---|
| 198 | //
|
---|
[2197] | 199 | // the BINTABLE consits of 4 columns
|
---|
| 200 | // first column : pixels values (type : T ), length : number of pixels
|
---|
| 201 | // second column : number of pixels of each theta slice (type : integer) ,
|
---|
| 202 | // length : number of theta-slices (parameter INDTHMAX above +1)
|
---|
| 203 | // third column : cumulated number of pixels until the beginning of each
|
---|
| 204 | // theta slice (type : integer) , same length as the previous one
|
---|
| 205 | // fourth column : theta values of each slice (type : double_) same length
|
---|
| 206 | // as the previous one.
|
---|
| 207 |
|
---|
[1752] | 208 | dobj_->pixels_.ReSize(nPix);
|
---|
| 209 | is.GetBinTabFCol(dobj_->pixels_.Data(),nPix,0);
|
---|
| 210 | dobj_->NPhi_.ReSize(IndThetaMax+1);
|
---|
| 211 | is.GetBinTabFCol(dobj_->NPhi_.Data(),IndThetaMax+1,1);
|
---|
| 212 | dobj_->TNphi_.ReSize(IndThetaMax+1);
|
---|
| 213 | is.GetBinTabFCol(dobj_->TNphi_.Data(),IndThetaMax+1,2);
|
---|
| 214 | dobj_->Theta_.ReSize(IndThetaMax+1);
|
---|
| 215 | is.GetBinTabFCol(dobj_->Theta_.Data(),IndThetaMax+1,3);
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 | template <class T>
|
---|
| 219 | void FITS_SphereThetaPhi<T>::Mollweide_picture_projection(char filename[])
|
---|
| 220 | {
|
---|
| 221 | int ni = 300;
|
---|
| 222 | int nj = 600;
|
---|
| 223 | TMatrix<float> map(ni, nj);
|
---|
| 224 |
|
---|
| 225 | int i,j;
|
---|
| 226 | for(i=0; i < ni; i++)
|
---|
| 227 | {
|
---|
| 228 | double yd = (i+0.5)/ni-0.5;
|
---|
| 229 | double facteur=2.*Pi/sin(acos(yd*2));
|
---|
| 230 | double theta = (0.5-yd)*Pi;
|
---|
| 231 | for(j=0; j < nj; j++)
|
---|
| 232 | {
|
---|
| 233 | double xa = (j+0.5)/nj-0.5;
|
---|
| 234 | double phi = xa*facteur+Pi;
|
---|
| 235 | float th=float(theta);
|
---|
| 236 | float ff=float(phi);
|
---|
| 237 | if (phi<2*Pi && phi>= 0)
|
---|
| 238 | {
|
---|
| 239 | map(i,j) = (float)dobj_->PixValSph(th, ff);
|
---|
| 240 | }
|
---|
| 241 | }
|
---|
| 242 | }
|
---|
| 243 | FitsOutFile fout(filename);
|
---|
| 244 | fout.firstImageOnPrimaryHeader(true);
|
---|
| 245 | FITS_TArray<r_4> fta(map);
|
---|
| 246 | fta.Write(fout);
|
---|
| 247 |
|
---|
| 248 | }
|
---|
| 249 | template <class T>
|
---|
| 250 | void FITS_SphereThetaPhi<T>::sinus_picture_projection(char filename[])
|
---|
| 251 | {
|
---|
| 252 | int ni = 300;
|
---|
| 253 | int nj = 600;
|
---|
| 254 | TMatrix<float> map(ni, nj);
|
---|
| 255 |
|
---|
| 256 | int i,j;
|
---|
| 257 | for(i=0; i < ni; i++)
|
---|
| 258 | {
|
---|
| 259 | double yd = (i+0.5)/ni-0.5;
|
---|
| 260 | double theta = (0.5-yd)*Pi;
|
---|
| 261 | double facteur=1./sin(theta);
|
---|
| 262 | for(j=0; j < nj; j++)
|
---|
| 263 | {
|
---|
| 264 | double xa = (j+0.5)/nj-0.5;
|
---|
| 265 | double phi = 2.*Pi*xa*facteur+Pi;
|
---|
| 266 | float th=float(theta);
|
---|
| 267 | float ff=float(phi);
|
---|
| 268 | if (phi<2*Pi && phi>= 0)
|
---|
| 269 | {
|
---|
| 270 | map(i,j) = (float)dobj_->PixValSph(th, ff);
|
---|
| 271 | }
|
---|
| 272 | }
|
---|
| 273 | }
|
---|
| 274 | FitsOutFile fout(filename);
|
---|
| 275 | fout.firstImageOnPrimaryHeader(true);
|
---|
| 276 | FITS_TArray<r_4> fta(map);
|
---|
| 277 | fta.Write(fout);
|
---|
| 278 |
|
---|
| 279 |
|
---|
| 280 | }
|
---|
| 281 |
|
---|
| 282 |
|
---|
| 283 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
| 284 | #pragma define_template FITS_SphereThetaPhi<r_8>
|
---|
| 285 | #pragma define_template FITS_SphereThetaPhi<r_4>
|
---|
[2197] | 286 | #pragma define_template FITS_SphereThetaPhi<int_4>
|
---|
[1752] | 287 | #endif
|
---|
| 288 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
| 289 | template class FITS_SphereThetaPhi<r_8>;
|
---|
| 290 | template class FITS_SphereThetaPhi<r_4>;
|
---|
[2197] | 291 | template class FITS_SphereThetaPhi<int_4>;
|
---|
[1752] | 292 | #endif
|
---|