source: Sophya/trunk/SophyaExt/FitsIOServer/fitsspherehealpix.cc@ 1192

Last change on this file since 1192 was 1182, checked in by ansari, 25 years ago

suppression controle sur nside

File size: 7.0 KB
Line 
1#include "pexceptions.h"
2#include "fitsspherehealpix.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// SphereHealpix
11////////////////////////////////////////////////////////////////////
12
13
14template <class T>
15FITS_SphereHEALPix<T>::FITS_SphereHEALPix()
16{
17 dobj_= new SphereHEALPix<T>;
18 ownobj_= true;
19}
20
21template <class T>
22FITS_SphereHEALPix<T>::FITS_SphereHEALPix(char inputfile[],int hdunum)
23{
24 dobj_= new SphereHEALPix<T>;
25 ownobj_= true;
26 Read(inputfile,hdunum);
27}
28
29
30template <class T>
31FITS_SphereHEALPix<T>::FITS_SphereHEALPix(const SphereHEALPix<T>& obj)
32{
33 dobj_= new SphereHEALPix<T>(obj);
34 ownobj_= true;
35}
36
37template <class T>
38FITS_SphereHEALPix<T>::FITS_SphereHEALPix(SphereHEALPix<T>* obj)
39{
40 dobj_= obj;
41 ownobj_= false;
42}
43
44template <class T>
45FITS_SphereHEALPix<T>::~FITS_SphereHEALPix()
46{
47 if (ownobj_ && dobj_) delete dobj_;
48}
49
50template <class T>
51AnyDataObj* FITS_SphereHEALPix<T>::DataObj()
52{
53 return(dobj_);
54}
55
56template <class T>
57void FITS_SphereHEALPix<T>::SetDataObj(AnyDataObj & o)
58{
59 SphereHEALPix<T> * po = dynamic_cast< SphereHEALPix<T> * >(&o);
60 if (po == NULL) return;
61 if (ownobj_ && dobj_) delete dobj_;
62 dobj_ = po;
63 ownobj_ = false;
64}
65
66
67
68
69template <class T>
70void FITS_SphereHEALPix<T>::WriteToFits(FitsOutFile& os)
71{
72 if(dobj_ == NULL)
73 {
74 cout << " WriteToFits:: dobj_= null " << endl;
75 return;
76 }
77
78 DVList dvl( dobj_->Info() );
79
80 SphereCoordSys* cs= dobj_->GetCoordSys();
81 string description= cs->description();
82 dvl["COORDSYS"]= description;
83
84 dvl["PIXTYPE"] = "HEALPIX";
85 dvl.SetComment("PIXTYPE", "HEALPIX Pixelization");
86 dvl["ORDERING"]= dobj_->TypeOfMap();
87 dvl.SetComment("ORDERING", "Pixel ordering scheme, either RING or NESTED");
88
89 int nSide= dobj_->SizeIndex();
90 dvl["NSIDE"]= (int_4) nSide;
91 cout << " je n'ecris plus nside " << endl;
92 dvl.SetComment("NSIDE","Resolution parameter for HEALPIX" );
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"]= "SphereHEALPix";
100
101 // On ecrit les dataBlocks
102 char** Noms = new char*[1];
103 Noms[0]= new char[15];
104 strncpy(Noms[0],dvl.GetS("Content").c_str(),15);
105 char extname[15] = "SIMULATION";
106
107 char Type[2];
108 if (typeid(T) == typeid(r_8) ) Type[0]='D';
109 else
110 if (typeid(T) == typeid(r_4) ) Type[0]='E';
111 else
112 {
113 cout << " type de la sphere= " << typeid(T).name() << endl;
114 throw IOExc("FITS_SphereHEALPix:: unknown type");
115 }
116 Type[1]='\0';
117 vector<int> dummy;
118 os.makeHeaderBntblOnFits(Type, Noms, nPix, 1, dvl, extname, dummy);
119 delete [] Noms[0];
120 delete [] Noms;
121 os.putColToFits(0, nPix, dobj_->pixels_.Data());
122}
123
124template <class T>
125void FITS_SphereHEALPix<T>::ReadFromFits(FitsInFile& is)
126{
127 if(dobj_ == NULL)
128 {
129 dobj_= new SphereHEALPix<T>;
130 ownobj_= true;
131 }
132 int nbcols, nbentries;
133 //
134
135 nbcols = is.NbColsFromFits();
136 if (nbcols != 1)
137 {
138 throw IOExc("le fichier fits n'est pas une sphere Healpix");
139 }
140 DVList dvl=is.DVListFromFits();
141 nbentries = is.NentriesFromFits(0);
142 int lastpix=dvl.GetI("LASTPIX");
143 if (lastpix>0)
144 {
145 if (nbentries!=lastpix+1)
146 {
147 nbentries=lastpix+1;
148 }
149 }
150 // Let's Read the SphereCoordSys object
151 int id= SphereCoordSys_NEUTRAL;
152 string description= "NEUTRAL SphereCoordSystem";
153 string coordsys= dvl.GetS("COORDSYS");
154 // $CHECK$ - Reza 2/05/2000 - compare(size_t, size_t,...) passe pas sur g++
155 // if(coordsys.compare(0,7,"ROTATION",0,7) == 0) $CHECK$
156 if(coordsys.substr(0,8) == "ROTATION")
157 {
158 id= SphereCoordSys_ROTATION;
159 description= "ROTATION SphereCoordSystem";
160 }
161 // else if(coordsys.compare(0,4,"OTHER",0,4) == 0) $CHECK$ Reza 2/05/2000
162 else if(coordsys.substr(0,5) == "OTHER" )
163 {
164 id= SphereCoordSys_OTHER;
165 description= "OTHER SphereCoordSystem";
166 }
167 dobj_->SetCoordSys(new SphereCoordSys(id,description));
168
169 string ordering= dvl.GetS("ORDERING");
170 // if(ordering.compare(0,3,"RING",0,3) != 0) $CHECK$ Reza 2/05/2000
171 if(ordering.substr(0,4) != "RING" )
172 {
173 cerr << "FITS_SphereHEALPix/Error Not supported ORDERING= "
174 << ordering << " substr(0,4)=[" << ordering.substr(0,4) << "]" << endl;
175 throw IOExc(" FITS_SphereHEALPix:: numerotation non RING");
176 }
177
178 int nside= dvl.GetI("NSIDE");
179 int nPix = 0;
180 if(nside <= 0)
181 {
182 // throw IOExc("FITS_SphereHEALPix:: No resol parameter nside");
183 if (lastpix>0)
184 {
185 nside = sqrt(nbentries/12);
186 }
187 else
188 {
189 throw IOExc("FITS_SphereHEALPix:: No NSIDE nor LASTPIX on file");
190 }
191 }
192 nPix = 12*nside*nside;
193 if (nPix != nbentries)
194 {
195 cout << "WARNING: le nombre de pixels relu " << nbentries << " est incoherent avec la pixelisation Healpix qui donne nPix= " << nPix << endl;
196 }
197 double Omega= 4.0*Pi/nPix;
198 dobj_->setParameters(nside,nPix,Omega);
199 // On lit les DataBlocks;
200 //
201 dobj_->pixels_.ReSize(nPix);
202 is.GetSingleColumn(dobj_->pixels_.Data(),nPix);
203 //
204
205 // on effectue le decoupage en tranches
206 dobj_->SetThetaSlices();
207 //
208 dobj_->Info() = is.DVListFromFits();
209 cout << " end of file reading " << endl;
210}
211
212template <class T>
213void FITS_SphereHEALPix<T>::Mollweide_picture_projection(char filename[])
214{
215 int ni = 300;
216 int nj = 600;
217 TMatrix<float> map(ni, nj);
218
219 int i,j;
220 for(i=0; i < ni; i++)
221 {
222 double yd = (i+0.5)/ni-0.5;
223 double facteur=2.*Pi/sin(acos(yd*2));
224 double theta = (0.5-yd)*Pi;
225 for(j=0; j < nj; j++)
226 {
227 double xa = (j+0.5)/nj-0.5;
228 double phi = xa*facteur+Pi;
229 float th=float(theta);
230 float ff=float(phi);
231 if (phi<2*Pi && phi>= 0)
232 {
233 map(i,j) = (float)dobj_->PixValSph(th, ff);
234 }
235 }
236 }
237 FitsOutFile fout(filename);
238 fout.firstImageOnPrimaryHeader();
239 FITS_TArray<r_4> fta(map);
240 fta.Write(fout);
241
242}
243template <class T>
244void FITS_SphereHEALPix<T>::sinus_picture_projection(char filename[])
245{
246 int ni = 300;
247 int nj = 600;
248 TMatrix<float> map(ni, nj);
249
250 int i,j;
251 for(i=0; i < ni; i++)
252 {
253 double yd = (i+0.5)/ni-0.5;
254 double theta = (0.5-yd)*Pi;
255 double facteur=1./sin(theta);
256 for(j=0; j < nj; j++)
257 {
258 double xa = (j+0.5)/nj-0.5;
259 double phi = 2.*Pi*xa*facteur+Pi;
260 float th=float(theta);
261 float ff=float(phi);
262 if (phi<2*Pi && phi>= 0)
263 {
264 map(i,j) = (float)dobj_->PixValSph(th, ff);
265 }
266 }
267 }
268 FitsOutFile fout(filename);
269 fout.firstImageOnPrimaryHeader();
270 FITS_TArray<r_4> fta(map);
271 fta.Write(fout);
272
273
274}
275
276
277#ifdef __CXX_PRAGMA_TEMPLATES__
278#pragma define_template FITS_SphereHEALPix<r_8>
279#pragma define_template FITS_SphereHEALPix<r_4>
280#endif
281#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
282template class FITS_SphereHEALPix<r_8>;
283template class FITS_SphereHEALPix<r_4>;
284#endif
Note: See TracBrowser for help on using the repository browser.