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

Last change on this file since 2103 was 2082, checked in by ansari, 23 years ago

Modifs HEALPixUtils.cc concernant la transformation des fmod() en operateur % et les floor() en div entier, + instanciation ecriture spherehealpix et autres cartes en int_4 (PPF et FITS) - Reza 3/7/2002

  • Property svn:executable set to *
File size: 6.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 vector<string> Noms(4);
104 Noms[0] = dvl.GetS("Content");
105 Noms[1] = "NphiParBande";
106 Noms[2] = "CumulPixParBande";
107 Noms[3] = "ThetaBande";
108 string extname("SIMULATION");
109
110
111 string Type;
112 if (typeid(T) == typeid(r_8) ) Type+='D';
113 else if (typeid(T) == typeid(r_4) ) Type+='E';
114 else if (typeid(T) == typeid(int_4) ) Type+='J';
115 else
116 {
117 cout << "FITS_SphereThetaPhi<T>::WriteToFits - Unsupported data type ("
118 << typeid(T).name() << ") throwing IOExc " << endl;
119 throw IOExc("FITS_SphereThetaPhi<T>::WriteToFits() unsupported data type");
120 }
121
122 Type += 'J';
123 Type += 'J';
124 Type += 'D';
125
126 vector<int> dummy;
127 os.makeHeaderBntblOnFits(Type, Noms, nPix, 4, &dvl, extname, dummy);
128 os.PutColToFits(0, nPix, dobj_->pixels_.Data());
129 os.PutColToFits(1, IndTheta+1, dobj_->NPhi_.Data());
130 os.PutColToFits(2, IndTheta+1, dobj_->TNphi_.Data());
131 os.PutColToFits(3, IndTheta+1, dobj_->Theta_.Data());
132}
133
134template <class T>
135void FITS_SphereThetaPhi<T>::ReadFromFits(FitsInFile& is)
136{
137
138 if(dobj_ == NULL)
139 {
140 dobj_= new SphereThetaPhi<T>;
141 ownobj_= true;
142 }
143 int nbcols, nbentries;
144
145 nbcols = is.NbColsFromFits();
146 if (nbcols != 4)
147 {
148 throw IOExc("le fichier fits n'est pas une sphere ThetaPhi");
149 }
150 DVList dvl=is.DVListFromFits();
151 nbentries = is.NentriesFromFits(0);
152 int lastpix=dvl.GetI("LASTPIX");
153 if (lastpix>0)
154 {
155 if (nbentries!=lastpix+1)
156 {
157 nbentries=lastpix+1;
158 }
159 }
160
161 // Let's Read the SphereCoordSys object
162 int id= SphereCoordSys_NEUTRAL;
163 string description= "NEUTRAL SphereCoordSystem";
164 string coordsys= dvl.GetS("COORDSYS");
165 if(coordsys.substr(0,8) == "ROTATION")
166 {
167 id= SphereCoordSys_ROTATION;
168 description= "ROTATION SphereCoordSystem";
169 }
170 else if(coordsys.substr(0,5) == "OTHER" )
171 {
172 id= SphereCoordSys_OTHER;
173 description= "OTHER SphereCoordSystem";
174 }
175 dobj_->SetCoordSys(new SphereCoordSys(id,description));
176
177 int IndThetaMax= dvl.GetI("INDTHMAX");
178 int nPix = 0;
179 if(IndThetaMax <= 0)
180 {
181 throw IOExc("FITS_SphereTheta:: No resol parameter INDTHMAX");
182 }
183 nPix = nbentries;
184 double Omega= 4.0*Pi/nPix;
185 dobj_->setParameters(IndThetaMax,nPix,Omega);
186
187 // On lit les DataBlocks;
188 //
189 dobj_->pixels_.ReSize(nPix);
190 is.GetBinTabFCol(dobj_->pixels_.Data(),nPix,0);
191 dobj_->NPhi_.ReSize(IndThetaMax+1);
192 is.GetBinTabFCol(dobj_->NPhi_.Data(),IndThetaMax+1,1);
193 dobj_->TNphi_.ReSize(IndThetaMax+1);
194 is.GetBinTabFCol(dobj_->TNphi_.Data(),IndThetaMax+1,2);
195 dobj_->Theta_.ReSize(IndThetaMax+1);
196 is.GetBinTabFCol(dobj_->Theta_.Data(),IndThetaMax+1,3);
197}
198
199template <class T>
200void FITS_SphereThetaPhi<T>::Mollweide_picture_projection(char filename[])
201{
202 int ni = 300;
203 int nj = 600;
204 TMatrix<float> map(ni, nj);
205
206 int i,j;
207 for(i=0; i < ni; i++)
208 {
209 double yd = (i+0.5)/ni-0.5;
210 double facteur=2.*Pi/sin(acos(yd*2));
211 double theta = (0.5-yd)*Pi;
212 for(j=0; j < nj; j++)
213 {
214 double xa = (j+0.5)/nj-0.5;
215 double phi = xa*facteur+Pi;
216 float th=float(theta);
217 float ff=float(phi);
218 if (phi<2*Pi && phi>= 0)
219 {
220 map(i,j) = (float)dobj_->PixValSph(th, ff);
221 }
222 }
223 }
224 FitsOutFile fout(filename);
225 fout.firstImageOnPrimaryHeader(true);
226 FITS_TArray<r_4> fta(map);
227 fta.Write(fout);
228
229}
230template <class T>
231void FITS_SphereThetaPhi<T>::sinus_picture_projection(char filename[])
232{
233 int ni = 300;
234 int nj = 600;
235 TMatrix<float> map(ni, nj);
236
237 int i,j;
238 for(i=0; i < ni; i++)
239 {
240 double yd = (i+0.5)/ni-0.5;
241 double theta = (0.5-yd)*Pi;
242 double facteur=1./sin(theta);
243 for(j=0; j < nj; j++)
244 {
245 double xa = (j+0.5)/nj-0.5;
246 double phi = 2.*Pi*xa*facteur+Pi;
247 float th=float(theta);
248 float ff=float(phi);
249 if (phi<2*Pi && phi>= 0)
250 {
251 map(i,j) = (float)dobj_->PixValSph(th, ff);
252 }
253 }
254 }
255 FitsOutFile fout(filename);
256 fout.firstImageOnPrimaryHeader(true);
257 FITS_TArray<r_4> fta(map);
258 fta.Write(fout);
259
260
261}
262
263
264#ifdef __CXX_PRAGMA_TEMPLATES__
265#pragma define_template FITS_SphereThetaPhi<r_8>
266#pragma define_template FITS_SphereThetaPhi<r_4>
267//#pragma define_template FITS_SphereThetaPhi<int_4>
268#endif
269#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
270template class FITS_SphereThetaPhi<r_8>;
271template class FITS_SphereThetaPhi<r_4>;
272//template class FITS_SphereThetaPhi<int_4>;
273#endif
Note: See TracBrowser for help on using the repository browser.