source: Sophya/trunk/SophyaExt/FitsIOServer/fitsspherethetaphi.cc@ 4086

Last change on this file since 4086 was 3572, checked in by cmv, 17 years ago

char* -> const char* pour regler les problemes de deprecated string const... + comparaison unsigned signed + suppression EVOL_PLANCK rz+cmv 07/02/2009

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