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

Last change on this file since 2247 was 2197, checked in by lemeur, 23 years ago

toilette d'ete : rationalisation de types...

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