1 | // ----------------------------------------------------------------------- |
---|
2 | // saveImage.cc: Write a wavelet-reconstructed or smoothed array to a |
---|
3 | // FITS file. |
---|
4 | // ----------------------------------------------------------------------- |
---|
5 | // Copyright (C) 2006, Matthew Whiting, ATNF |
---|
6 | // |
---|
7 | // This program is free software; you can redistribute it and/or modify it |
---|
8 | // under the terms of the GNU General Public License as published by the |
---|
9 | // Free Software Foundation; either version 2 of the License, or (at your |
---|
10 | // option) any later version. |
---|
11 | // |
---|
12 | // Duchamp is distributed in the hope that it will be useful, but WITHOUT |
---|
13 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
14 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
---|
15 | // for more details. |
---|
16 | // |
---|
17 | // You should have received a copy of the GNU General Public License |
---|
18 | // along with Duchamp; if not, write to the Free Software Foundation, |
---|
19 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA |
---|
20 | // |
---|
21 | // Correspondence concerning Duchamp may be directed to: |
---|
22 | // Internet email: Matthew.Whiting [at] atnf.csiro.au |
---|
23 | // Postal address: Dr. Matthew Whiting |
---|
24 | // Australia Telescope National Facility, CSIRO |
---|
25 | // PO Box 76 |
---|
26 | // Epping NSW 1710 |
---|
27 | // AUSTRALIA |
---|
28 | // ----------------------------------------------------------------------- |
---|
29 | #include <iostream> |
---|
30 | #include <sstream> |
---|
31 | #include <string> |
---|
32 | #include <string.h> |
---|
33 | #include <wcslib/wcs.h> |
---|
34 | #include <wcslib/wcshdr.h> |
---|
35 | #define WCSLIB_GETWCSTAB |
---|
36 | // define this so that we don't try and redefine wtbarr |
---|
37 | // (this is a problem when using cfitsio v.3 and g++ v.4) |
---|
38 | |
---|
39 | #include <fitsio.h> |
---|
40 | #include <duchamp/duchamp.hh> |
---|
41 | #include <duchamp/Cubes/cubes.hh> |
---|
42 | #include <duchamp/PixelMap/Voxel.hh> |
---|
43 | #include <duchamp/PixelMap/Object3D.hh> |
---|
44 | |
---|
45 | namespace duchamp |
---|
46 | { |
---|
47 | |
---|
48 | /// @brief Write FITS headers in correct format for reconstructed array output |
---|
49 | void writeReconHeaderInfo(fitsfile *fptr, Param &par, std::string nature); |
---|
50 | |
---|
51 | /// @brief Write FITS headers in correct format for smoothed array output |
---|
52 | void writeSmoothHeaderInfo(fitsfile *fptr, Param &par); |
---|
53 | |
---|
54 | /// @brief Write FITS headers in correct format for mask array output |
---|
55 | void writeMaskHeaderInfo(fitsfile *fptr, Param &par); |
---|
56 | |
---|
57 | /// @brief Write FITS headers in correct format for moment-0 array output |
---|
58 | void writeMomentMapHeaderInfo(fitsfile *fptr, Param &par); |
---|
59 | |
---|
60 | //--------------------------------------------------------------------------- |
---|
61 | |
---|
62 | char *numerateKeyword(std::string key, int num) |
---|
63 | { |
---|
64 | /// @details A utility function to combine a keyword and a |
---|
65 | /// value, to produce a relevant FITS keyword for a given |
---|
66 | /// axis. For example numerateKeyword(CRPIX,1) returns CRPIX1. |
---|
67 | std::stringstream ss; |
---|
68 | ss << key << num; |
---|
69 | return (char *)ss.str().c_str(); |
---|
70 | } |
---|
71 | |
---|
72 | void Cube::saveMomentMapImage() |
---|
73 | { |
---|
74 | /// @details |
---|
75 | /// A function to save the moment-0 map to a FITS file. |
---|
76 | |
---|
77 | int newbitpix = FLOAT_IMG; |
---|
78 | char *comment = new char[FLEN_COMMENT]; |
---|
79 | strcpy(comment,""); |
---|
80 | long *fpixel = new long[2]; |
---|
81 | for(int i=0;i<2;i++) fpixel[i]=1; |
---|
82 | int status = 0; /* MUST initialize status */ |
---|
83 | fitsfile *fptr; |
---|
84 | |
---|
85 | std::string fileout = "!" + this->par.outputMomentMapFile(); |
---|
86 | // the ! is there so that it writes over an existing file. |
---|
87 | char *keyword = new char[FLEN_KEYWORD]; |
---|
88 | |
---|
89 | status = 0; |
---|
90 | fits_create_file(&fptr,fileout.c_str(),&status); |
---|
91 | if (status){ |
---|
92 | duchampError("saveMomentMapImage","Error creating file:"); |
---|
93 | fits_report_error(stderr, status); |
---|
94 | } |
---|
95 | else { |
---|
96 | status = 0; |
---|
97 | long *dim = new long[2]; |
---|
98 | for (uint i = 0; i < 2; i++) dim[i] = this->axisDim[i]; |
---|
99 | if (fits_create_img(fptr, newbitpix, 2, dim, &status)) { |
---|
100 | duchampError("saveMomentMapImage","Error creating image:"); |
---|
101 | fits_report_error(stderr, status); |
---|
102 | } |
---|
103 | |
---|
104 | if(!this->par.getFlagUsingBeam()){ // if the cube has beam info, copy it |
---|
105 | float bmaj=this->head.getBmajKeyword(), bmin=this->head.getBminKeyword(), bpa=this->head.getBpaKeyword(); |
---|
106 | status = 0; |
---|
107 | strcpy(keyword,"BMAJ"); |
---|
108 | if (fits_update_key(fptr, TFLOAT, keyword, &bmaj, NULL, &status)){ |
---|
109 | duchampError("saveMomentMapImage","Error saving beam info:"); |
---|
110 | fits_report_error(stderr, status); |
---|
111 | } |
---|
112 | status = 0; |
---|
113 | strcpy(keyword,"BMIN"); |
---|
114 | if (fits_update_key(fptr, TFLOAT, keyword, &bmin, NULL, &status)){ |
---|
115 | duchampError("saveMomentMapImage","Error saving beam info:"); |
---|
116 | fits_report_error(stderr, status); |
---|
117 | } |
---|
118 | status = 0; |
---|
119 | strcpy(keyword,"BPA"); |
---|
120 | if (fits_update_key(fptr, TFLOAT, keyword, &bpa, NULL, &status)){ |
---|
121 | duchampError("saveMomentMapImage","Error saving beam info:"); |
---|
122 | fits_report_error(stderr, status); |
---|
123 | } |
---|
124 | } |
---|
125 | status = 0; |
---|
126 | strcpy(keyword,"EQUINOX"); |
---|
127 | if (fits_update_key(fptr, TFLOAT, keyword, &this->head.WCS().equinox, NULL, &status)){ |
---|
128 | duchampError("saveMomentMapImage","Error saving equinox:"); |
---|
129 | fits_report_error(stderr, status); |
---|
130 | } |
---|
131 | status = 0; |
---|
132 | strcpy(keyword,"BUNIT"); |
---|
133 | if (fits_update_key(fptr, TSTRING, keyword, (char *)this->head.getIntFluxUnits().c_str(), NULL, &status)){ |
---|
134 | duchampError("saveMomentMapImage","Error saving BUNIT:"); |
---|
135 | fits_report_error(stderr, status); |
---|
136 | } |
---|
137 | float val; |
---|
138 | int axisNumbers[2]; |
---|
139 | axisNumbers[0] = this->head.WCS().lng; |
---|
140 | axisNumbers[1] = this->head.WCS().lat; |
---|
141 | for (uint d = 0; d < 2; d++) { |
---|
142 | int i = axisNumbers[d]; |
---|
143 | status = 0; |
---|
144 | if (fits_update_key(fptr, TSTRING, numerateKeyword("CTYPE", d + 1), this->head.WCS().ctype[i], NULL, &status)){ |
---|
145 | duchampError("saveMomentMapImage","Error saving CTYPE:"); |
---|
146 | fits_report_error(stderr, status); |
---|
147 | } |
---|
148 | status = 0; |
---|
149 | if (fits_update_key(fptr, TSTRING, numerateKeyword("CUNIT", d + 1), this->head.WCS().cunit[i], NULL, &status)){ |
---|
150 | duchampError("saveMomentMapImage","Error saving CUNIT:"); |
---|
151 | fits_report_error(stderr, status); |
---|
152 | } |
---|
153 | status = 0; |
---|
154 | val = this->head.WCS().crval[i]; |
---|
155 | if (fits_update_key(fptr, TFLOAT, numerateKeyword("CRVAL", d + 1), &val, NULL, &status)){ |
---|
156 | duchampError("saveMomentMapImage","Error saving CRVAL:"); |
---|
157 | fits_report_error(stderr, status); |
---|
158 | } |
---|
159 | val = this->head.WCS().cdelt[i]; |
---|
160 | status = 0; |
---|
161 | if (fits_update_key(fptr, TFLOAT, numerateKeyword("CDELT", d + 1), &val, NULL, &status)){ |
---|
162 | duchampError("saveMomentMapImage","Error saving CDELT:"); |
---|
163 | fits_report_error(stderr, status); |
---|
164 | } |
---|
165 | val = this->head.WCS().crpix[i]; |
---|
166 | status = 0; |
---|
167 | if (fits_update_key(fptr, TFLOAT, numerateKeyword("CRPIX", d + 1), &val, NULL, &status)){ |
---|
168 | duchampError("saveMomentMapImage","Error saving CRPIX:"); |
---|
169 | fits_report_error(stderr, status); |
---|
170 | } |
---|
171 | val = this->head.WCS().crota[i]; |
---|
172 | status = 0; |
---|
173 | if (fits_update_key(fptr, TFLOAT, numerateKeyword("CROTA", d + 1), &val, NULL, &status)){ |
---|
174 | duchampError("saveMomentMapImage","Error saving CROTA:"); |
---|
175 | fits_report_error(stderr, status); |
---|
176 | } |
---|
177 | } |
---|
178 | |
---|
179 | delete [] comment; |
---|
180 | delete [] keyword; |
---|
181 | |
---|
182 | writeMomentMapHeaderInfo(fptr, this->par); |
---|
183 | |
---|
184 | long size = this->axisDim[0] * this->axisDim[1]; |
---|
185 | float *momentMap = new float[size]; |
---|
186 | std::vector<bool> detectionMap; |
---|
187 | this->getMomentMap(momentMap,detectionMap); |
---|
188 | status=0; |
---|
189 | if(fits_write_pix(fptr, TFLOAT, fpixel, size, momentMap, &status)){ |
---|
190 | duchampError("saveMomentMapImage","Error writing data"); |
---|
191 | fits_report_error(stderr,status); |
---|
192 | } |
---|
193 | status = 0; |
---|
194 | if(fits_close_file(fptr, &status)){ |
---|
195 | duchampError("saveMomentMapImage","Error closing file"); |
---|
196 | fits_report_error(stderr, status); |
---|
197 | } |
---|
198 | |
---|
199 | delete [] momentMap; |
---|
200 | |
---|
201 | } |
---|
202 | |
---|
203 | delete [] fpixel; |
---|
204 | |
---|
205 | |
---|
206 | } |
---|
207 | |
---|
208 | void Cube::saveMaskCube() |
---|
209 | { |
---|
210 | /// @details |
---|
211 | /// A function to save a mask to a FITS file, indicating where the |
---|
212 | /// detections where made. The value of the detected pixels is |
---|
213 | /// determined by the flagMaskWithObjectNum parameter: if true, |
---|
214 | /// the value of the pixels is given by the corresponding object |
---|
215 | /// ID number; if false, they take the value 1 for all |
---|
216 | /// objects. Pixels not in a detected object have the value 0. |
---|
217 | |
---|
218 | int newbitpix = SHORT_IMG; |
---|
219 | char *comment = new char[FLEN_COMMENT]; |
---|
220 | strcpy(comment,""); |
---|
221 | long *fpixel = new long[this->header().WCS().naxis]; |
---|
222 | for(int i=0;i<this->header().WCS().naxis;i++) fpixel[i]=1; |
---|
223 | int status = 0; /* MUST initialize status */ |
---|
224 | fitsfile *fptrOld, *fptrNew; |
---|
225 | fits_open_file(&fptrOld,this->par.getImageFile().c_str(),READONLY,&status); |
---|
226 | if (status){ |
---|
227 | duchampError("saveMask","Fits Error 1:"); |
---|
228 | fits_report_error(stderr, status); |
---|
229 | } |
---|
230 | |
---|
231 | std::string fileout = "!" + this->par.outputMaskFile(); |
---|
232 | // the ! is there so that it writes over an existing file. |
---|
233 | |
---|
234 | status = 0; |
---|
235 | fits_create_file(&fptrNew,fileout.c_str(),&status); |
---|
236 | if (status){ |
---|
237 | duchampError("saveMask","Fits Error 2:"); |
---|
238 | fits_report_error(stderr, status); |
---|
239 | } |
---|
240 | else { |
---|
241 | status = 0; |
---|
242 | fits_movabs_hdu(fptrOld, 1, NULL, &status); |
---|
243 | if (status){ |
---|
244 | duchampError("saveMask","Fits Error 3:"); |
---|
245 | fits_report_error(stderr, status); |
---|
246 | } |
---|
247 | status = 0; |
---|
248 | fits_copy_header(fptrOld, fptrNew, &status); |
---|
249 | if (status){ |
---|
250 | duchampError("saveMask","Fits Error 4:"); |
---|
251 | fits_report_error(stderr, status); |
---|
252 | } |
---|
253 | status = 0; |
---|
254 | char *keyword = new char[FLEN_KEYWORD]; |
---|
255 | strcpy(keyword,"BITPIX"); |
---|
256 | strcpy(comment,"number of bits per data pixel"); |
---|
257 | fits_update_key(fptrNew, TINT, keyword, &newbitpix, comment, &status); |
---|
258 | if (status){ |
---|
259 | duchampError("saveMask","Fits Error 5:"); |
---|
260 | fits_report_error(stderr, status); |
---|
261 | } |
---|
262 | float bscale=1., bzero=0.; |
---|
263 | strcpy(comment,""); |
---|
264 | strcpy(keyword,"BSCALE"); |
---|
265 | fits_update_key(fptrNew, TFLOAT, keyword, &bscale, comment, &status); |
---|
266 | if (status){ |
---|
267 | duchampError("saveMask","Fits Error 6:"); |
---|
268 | fits_report_error(stderr, status); |
---|
269 | } |
---|
270 | strcpy(keyword,"BZERO"); |
---|
271 | fits_update_key(fptrNew, TFLOAT, keyword, &bzero, comment, &status); |
---|
272 | if (status){ |
---|
273 | duchampError("saveMask","Fits Error 7:"); |
---|
274 | fits_report_error(stderr, status); |
---|
275 | } |
---|
276 | fits_set_bscale(fptrNew, 1, 0, &status); |
---|
277 | if (status){ |
---|
278 | duchampError("saveMask","Fits Error 8:"); |
---|
279 | fits_report_error(stderr, status); |
---|
280 | } |
---|
281 | std::string newunits; |
---|
282 | if(this->par.getFlagMaskWithObjectNum()) |
---|
283 | newunits = "Object ID"; |
---|
284 | else |
---|
285 | newunits = "Detection flag"; |
---|
286 | strcpy(keyword,"BUNIT"); |
---|
287 | fits_update_key(fptrNew, TSTRING, keyword, (char *)newunits.c_str(), comment, &status); |
---|
288 | if (status){ |
---|
289 | duchampError("saveMask","Fits Error 9:"); |
---|
290 | fits_report_error(stderr, status); |
---|
291 | } |
---|
292 | long dud; |
---|
293 | // Need to correct the dimensions, if we have subsectioned the image |
---|
294 | if(this->par.getFlagSubsection()){ |
---|
295 | std::stringstream naxis; |
---|
296 | fits_read_key(fptrOld, TLONG, (char *)naxis.str().c_str(), &dud, comment, &status); |
---|
297 | fits_update_key(fptrNew, TLONG, (char *)naxis.str().c_str(), |
---|
298 | &(this->axisDim[0]), comment, &status); |
---|
299 | naxis.str(""); |
---|
300 | naxis << "NAXIS" << this->head.WCS().lat; |
---|
301 | fits_read_key(fptrOld, TLONG, (char *)naxis.str().c_str(), &dud, comment, &status); |
---|
302 | fits_update_key(fptrNew, TLONG, (char *)naxis.str().c_str(), |
---|
303 | &(this->axisDim[1]), comment, &status); |
---|
304 | naxis.str(""); |
---|
305 | naxis << "NAXIS" << this->head.WCS().spec; |
---|
306 | fits_read_key(fptrOld, TLONG, (char *)naxis.str().c_str(), &dud, comment, &status); |
---|
307 | fits_update_key(fptrNew, TLONG, (char *)naxis.str().c_str(), |
---|
308 | &(this->axisDim[2]), comment, &status); |
---|
309 | } |
---|
310 | |
---|
311 | delete [] comment; |
---|
312 | delete [] keyword; |
---|
313 | |
---|
314 | writeMaskHeaderInfo(fptrNew, this->par); |
---|
315 | |
---|
316 | short *mask = new short[this->numPixels]; |
---|
317 | for(int i=0;i<this->numPixels;i++) mask[i]=0; |
---|
318 | std::vector<Detection>::iterator obj; |
---|
319 | for(obj=this->objectList->begin();obj<this->objectList->end();obj++){ |
---|
320 | std::vector<PixelInfo::Voxel> voxlist = obj->getPixelSet(); |
---|
321 | std::vector<PixelInfo::Voxel>::iterator vox; |
---|
322 | for(vox=voxlist.begin();vox<voxlist.end();vox++){ |
---|
323 | int pixelpos = vox->getX() + this->axisDim[0]*vox->getY() + |
---|
324 | this->axisDim[0]*this->axisDim[1]*vox->getZ(); |
---|
325 | if(this->par.getFlagMaskWithObjectNum()) mask[pixelpos] = obj->getID(); |
---|
326 | else mask[pixelpos] = 1; |
---|
327 | } |
---|
328 | } |
---|
329 | status=0; |
---|
330 | fits_write_pix(fptrNew, TSHORT, fpixel, this->numPixels, mask, &status); |
---|
331 | if(status){ |
---|
332 | duchampError("saveMask","Fits Error 10:"); |
---|
333 | fits_report_error(stderr,status); |
---|
334 | } |
---|
335 | status = 0; |
---|
336 | fits_close_file(fptrNew, &status); |
---|
337 | if (status){ |
---|
338 | duchampError("saveMask","Fits Error 11:"); |
---|
339 | fits_report_error(stderr, status); |
---|
340 | } |
---|
341 | |
---|
342 | delete [] mask; |
---|
343 | |
---|
344 | } |
---|
345 | |
---|
346 | delete [] fpixel; |
---|
347 | |
---|
348 | } |
---|
349 | |
---|
350 | //--------------------------------------------------------------------------- |
---|
351 | |
---|
352 | void Cube::saveSmoothedCube() |
---|
353 | { |
---|
354 | /// @brief |
---|
355 | /// A function to save the smoothed arrays to a FITS file. |
---|
356 | /// Additional header keywords are written as well, indicating the |
---|
357 | /// width of the Hanning filter or the dimensions of the Gaussian |
---|
358 | /// kernel. |
---|
359 | /// The file is always written -- if the filename (as calculated |
---|
360 | /// based on the parameters) exists, then it is overwritten. |
---|
361 | |
---|
362 | float blankval = this->par.getBlankPixVal(); |
---|
363 | |
---|
364 | int status = 0; /* MUST initialize status */ |
---|
365 | fitsfile *fptrOld, *fptrNew; |
---|
366 | fits_open_file(&fptrOld,this->par.getFullImageFile().c_str(),READONLY,&status); |
---|
367 | if (status) fits_report_error(stderr, status); |
---|
368 | |
---|
369 | if(this->par.getFlagOutputSmooth()){ |
---|
370 | std::string fileout = "!" + this->par.outputSmoothFile(); |
---|
371 | // the ! is there so that it writes over an existing file. |
---|
372 | |
---|
373 | status = 0; |
---|
374 | fits_create_file(&fptrNew,fileout.c_str(),&status); |
---|
375 | if (status) |
---|
376 | fits_report_error(stderr, status); |
---|
377 | else { |
---|
378 | status = 0; |
---|
379 | fits_movabs_hdu(fptrOld, 1, NULL, &status); |
---|
380 | if (status) fits_report_error(stderr, status); |
---|
381 | status = 0; |
---|
382 | fits_copy_header(fptrOld, fptrNew, &status); |
---|
383 | if (status) fits_report_error(stderr, status); |
---|
384 | |
---|
385 | writeSmoothHeaderInfo(fptrNew, this->par); |
---|
386 | |
---|
387 | if(this->par.getFlagBlankPix()) |
---|
388 | fits_write_imgnull(fptrNew, TFLOAT, 1, this->numPixels, this->recon, &blankval, &status); |
---|
389 | else |
---|
390 | fits_write_img(fptrNew, TFLOAT, 1, this->numPixels, this->recon, &status); |
---|
391 | |
---|
392 | status = 0; |
---|
393 | fits_close_file(fptrNew, &status); |
---|
394 | if (status) fits_report_error(stderr, status); |
---|
395 | |
---|
396 | } |
---|
397 | } |
---|
398 | |
---|
399 | } |
---|
400 | |
---|
401 | //--------------------------------------------------------------------------- |
---|
402 | |
---|
403 | void Cube::saveReconstructedCube() |
---|
404 | { |
---|
405 | /// @details |
---|
406 | /// A function to save the reconstructed and/or residual arrays. |
---|
407 | /// A number of header keywords are written as well, indicating the |
---|
408 | /// nature of the reconstruction that has been done. |
---|
409 | /// The file is always written -- if the filename (as calculated |
---|
410 | /// based on the recon parameters) exists, then it is overwritten. |
---|
411 | |
---|
412 | float blankval = this->par.getBlankPixVal(); |
---|
413 | |
---|
414 | int status = 0; /* MUST initialize status */ |
---|
415 | fitsfile *fptrOld, *fptrNew; |
---|
416 | fits_open_file(&fptrOld,this->par.getFullImageFile().c_str(),READONLY,&status); |
---|
417 | if (status) fits_report_error(stderr, status); |
---|
418 | |
---|
419 | if(this->par.getFlagOutputRecon()){ |
---|
420 | std::string fileout = "!" + this->par.outputReconFile(); |
---|
421 | // the ! is there so that it writes over an existing file. |
---|
422 | |
---|
423 | status = 0; |
---|
424 | fits_create_file(&fptrNew,fileout.c_str(),&status); |
---|
425 | if (status) |
---|
426 | fits_report_error(stderr, status); |
---|
427 | else |
---|
428 | { |
---|
429 | status = 0; |
---|
430 | fits_movabs_hdu(fptrOld, 1, NULL, &status); |
---|
431 | if (status) fits_report_error(stderr, status); |
---|
432 | status = 0; |
---|
433 | fits_copy_header(fptrOld, fptrNew, &status); |
---|
434 | if (status) fits_report_error(stderr, status); |
---|
435 | |
---|
436 | writeReconHeaderInfo(fptrNew, this->par, "recon"); |
---|
437 | |
---|
438 | if(this->par.getFlagBlankPix()) |
---|
439 | fits_write_imgnull(fptrNew, TFLOAT, 1, this->numPixels, this->recon, &blankval, &status); |
---|
440 | else |
---|
441 | fits_write_img(fptrNew, TFLOAT, 1, this->numPixels, this->recon, &status); |
---|
442 | |
---|
443 | status = 0; |
---|
444 | fits_close_file(fptrNew, &status); |
---|
445 | if (status) fits_report_error(stderr, status); |
---|
446 | } |
---|
447 | } |
---|
448 | |
---|
449 | |
---|
450 | if(this->par.getFlagOutputResid()){ |
---|
451 | float *resid = new float[this->numPixels]; |
---|
452 | for(int i=0;i<this->numPixels;i++) |
---|
453 | resid[i] = this->array[i] - this->recon[i]; |
---|
454 | |
---|
455 | std::string fileout = "!" + this->par.outputResidFile(); |
---|
456 | // the ! is there so that it writes over an existing file. |
---|
457 | status = 0; |
---|
458 | fits_create_file(&fptrNew,fileout.c_str(),&status); |
---|
459 | if (status) |
---|
460 | fits_report_error(stderr, status); |
---|
461 | else |
---|
462 | { |
---|
463 | status = 0; |
---|
464 | fits_movabs_hdu(fptrOld, 1, NULL, &status); |
---|
465 | if (status) fits_report_error(stderr, status); |
---|
466 | status = 0; |
---|
467 | fits_copy_header(fptrOld, fptrNew, &status); |
---|
468 | if (status) fits_report_error(stderr, status); |
---|
469 | |
---|
470 | writeReconHeaderInfo(fptrNew, this->par, "resid"); |
---|
471 | |
---|
472 | if(this->par.getFlagBlankPix()) |
---|
473 | fits_write_imgnull(fptrNew, TFLOAT, 1, this->numPixels, resid, &blankval, &status); |
---|
474 | else |
---|
475 | fits_write_img(fptrNew, TFLOAT, 1, this->numPixels, resid, &status); |
---|
476 | |
---|
477 | fits_close_file(fptrNew, &status); |
---|
478 | } |
---|
479 | delete [] resid; |
---|
480 | } |
---|
481 | |
---|
482 | |
---|
483 | } |
---|
484 | |
---|
485 | //--------------------------------------------------------------------------- |
---|
486 | |
---|
487 | void writeReconHeaderInfo(fitsfile *fptr, Param &par, std::string nature) |
---|
488 | { |
---|
489 | /// @details |
---|
490 | /// A simple function that writes all the necessary keywords and comments |
---|
491 | /// to the FITS header pointed to by fptr. |
---|
492 | /// The keyword names and comments are taken from duchamp.hh |
---|
493 | /// The parameter "nature" indicates what type of file is being written: |
---|
494 | /// should be either "recon" or "resid". |
---|
495 | |
---|
496 | int status = 0; |
---|
497 | std::string explanation = "",ReconResid=""; |
---|
498 | |
---|
499 | fits_write_history(fptr, (char *)header_reconHistory1.c_str(), &status); |
---|
500 | |
---|
501 | fits_write_history(fptr, (char *)header_reconHistory2.c_str(), &status); |
---|
502 | |
---|
503 | fits_write_history(fptr, (char *)header_reconHistory_input.c_str(), &status); |
---|
504 | |
---|
505 | fits_write_history(fptr, (char *)par.getImageFile().c_str(), &status); |
---|
506 | |
---|
507 | if(par.getFlagSubsection()){ |
---|
508 | fits_write_comment(fptr,(char *)header_reconSubsection_comment.c_str(), |
---|
509 | &status); |
---|
510 | fits_write_key(fptr, TSTRING, (char *)keyword_subsection.c_str(), |
---|
511 | (char *)par.getSubsection().c_str(), |
---|
512 | (char *)comment_subsection.c_str(), &status); |
---|
513 | } |
---|
514 | |
---|
515 | fits_write_comment(fptr, (char *)header_atrous_comment.c_str(), &status); |
---|
516 | |
---|
517 | float valf = par.getAtrousCut(); |
---|
518 | fits_write_key(fptr, TFLOAT, (char *)keyword_snrRecon.c_str(), &valf, |
---|
519 | (char *)comment_snrRecon.c_str(), &status); |
---|
520 | |
---|
521 | int vali = par.getReconDim(); |
---|
522 | fits_write_key(fptr, TINT, (char *)keyword_reconDim.c_str(), &vali, |
---|
523 | (char *)comment_reconDim.c_str(), &status); |
---|
524 | |
---|
525 | vali = par.getMinScale(); |
---|
526 | fits_write_key(fptr, TINT, (char *)keyword_scaleMin.c_str(), &vali, |
---|
527 | (char *)comment_scaleMin.c_str(), &status); |
---|
528 | |
---|
529 | vali = par.getFilterCode(); |
---|
530 | fits_write_key(fptr, TINT, (char *)keyword_filterCode.c_str(), &vali, |
---|
531 | (char *)comment_filterCode.c_str(), &status); |
---|
532 | |
---|
533 | if(nature == "recon"){ |
---|
534 | explanation = "Duchamp: This is the RECONSTRUCTED cube"; |
---|
535 | ReconResid = "RECON"; |
---|
536 | } |
---|
537 | else if(nature == "resid"){ |
---|
538 | explanation = "Duchamp: This is the RESIDUAL cube"; |
---|
539 | ReconResid = "RESID"; |
---|
540 | } |
---|
541 | else duchampWarning("write_header_info","explanation not present!\n"); |
---|
542 | fits_write_comment(fptr, (char *)explanation.c_str(), &status); |
---|
543 | fits_write_key(fptr, TSTRING, (char *)keyword_ReconResid.c_str(), |
---|
544 | (char *)ReconResid.c_str(), |
---|
545 | (char *)comment_ReconResid.c_str(), &status); |
---|
546 | |
---|
547 | } |
---|
548 | |
---|
549 | //--------------------------------------------------------------------------- |
---|
550 | |
---|
551 | void writeSmoothHeaderInfo(fitsfile *fptr, Param &par) |
---|
552 | { |
---|
553 | /// @details |
---|
554 | /// A simple function that writes all the necessary keywords and comments |
---|
555 | /// to the FITS header pointed to by fptr. |
---|
556 | /// The keyword names and comments are taken from duchamp.hh |
---|
557 | |
---|
558 | int status = 0; |
---|
559 | |
---|
560 | fits_write_history(fptr, (char *)header_smoothHistory.c_str(), &status); |
---|
561 | status = 0; |
---|
562 | fits_write_history(fptr, (char *)header_smoothHistory_input.c_str(),&status); |
---|
563 | status = 0; |
---|
564 | fits_write_history(fptr, (char *)par.getImageFile().c_str(), &status); |
---|
565 | |
---|
566 | if(par.getFlagSubsection()){ |
---|
567 | status = 0; |
---|
568 | fits_write_comment(fptr,(char *)header_smoothSubsection_comment.c_str(), |
---|
569 | &status); |
---|
570 | status = 0; |
---|
571 | fits_write_key(fptr, TSTRING, (char *)keyword_subsection.c_str(), |
---|
572 | (char *)par.getSubsection().c_str(), |
---|
573 | (char *)comment_subsection.c_str(), &status); |
---|
574 | } |
---|
575 | |
---|
576 | if(par.getSmoothType()=="spatial"){ |
---|
577 | // if kernMin is negative (not defined), make it equal to kernMaj |
---|
578 | if(par.getKernMin() < 0) par.setKernMin(par.getKernMaj()); |
---|
579 | |
---|
580 | fits_write_key(fptr, TSTRING, (char *)keyword_smoothtype.c_str(), |
---|
581 | (char *)header_smoothSpatial.c_str(), |
---|
582 | (char *)comment_smoothtype.c_str(), &status); |
---|
583 | float valf = par.getKernMaj(); |
---|
584 | fits_write_key(fptr, TFLOAT, (char *)keyword_kernmaj.c_str(), &valf, |
---|
585 | (char *)comment_kernmaj.c_str(), &status); |
---|
586 | valf = par.getKernMin(); |
---|
587 | fits_write_key(fptr, TFLOAT, (char *)keyword_kernmin.c_str(), &valf, |
---|
588 | (char *)comment_kernmin.c_str(), &status); |
---|
589 | valf = par.getKernPA(); |
---|
590 | fits_write_key(fptr, TFLOAT, (char *)keyword_kernpa.c_str(), &valf, |
---|
591 | (char *)comment_kernpa.c_str(), &status); |
---|
592 | } |
---|
593 | else if(par.getSmoothType()=="spectral"){ |
---|
594 | fits_write_key(fptr, TSTRING, (char *)keyword_smoothtype.c_str(), |
---|
595 | (char *)header_smoothSpectral.c_str(), |
---|
596 | (char *)comment_smoothtype.c_str(), &status); |
---|
597 | int vali = par.getHanningWidth(); |
---|
598 | fits_write_key(fptr, TINT, (char *)keyword_hanningwidth.c_str(), &vali, |
---|
599 | (char *)comment_hanningwidth.c_str(), &status); |
---|
600 | } |
---|
601 | } |
---|
602 | |
---|
603 | //--------------------------------------------------------------------------- |
---|
604 | |
---|
605 | void writeMaskHeaderInfo(fitsfile *fptr, Param &par) |
---|
606 | { |
---|
607 | /// @details |
---|
608 | /// A simple function that writes all the necessary keywords and comments |
---|
609 | /// to the FITS header pointed to by fptr. |
---|
610 | /// The keyword names and comments are taken from duchamp.hh |
---|
611 | |
---|
612 | int status = 0; |
---|
613 | |
---|
614 | fits_write_history(fptr, (char *)header_maskHistory.c_str(), &status); |
---|
615 | status = 0; |
---|
616 | fits_write_history(fptr, (char *)header_maskHistory_input.c_str(),&status); |
---|
617 | status = 0; |
---|
618 | fits_write_history(fptr, (char *)par.getImageFile().c_str(), &status); |
---|
619 | |
---|
620 | if(par.getFlagSubsection()){ |
---|
621 | status = 0; |
---|
622 | fits_write_comment(fptr,(char *)header_maskSubsection_comment.c_str(), |
---|
623 | &status); |
---|
624 | status = 0; |
---|
625 | fits_write_key(fptr, TSTRING, (char *)keyword_subsection.c_str(), |
---|
626 | (char *)par.getSubsection().c_str(), |
---|
627 | (char *)comment_subsection.c_str(), &status); |
---|
628 | } |
---|
629 | } |
---|
630 | |
---|
631 | //--------------------------------------------------------------------------- |
---|
632 | |
---|
633 | void writeMomentMapHeaderInfo(fitsfile *fptr, Param &par) |
---|
634 | { |
---|
635 | /// @details |
---|
636 | /// A simple function that writes all the necessary keywords and comments |
---|
637 | /// to the FITS header pointed to by fptr. |
---|
638 | /// The keyword names and comments are taken from duchamp.hh |
---|
639 | |
---|
640 | int status = 0; |
---|
641 | |
---|
642 | fits_write_history(fptr, (char *)header_moment0History.c_str(), &status); |
---|
643 | status = 0; |
---|
644 | fits_write_history(fptr, (char *)header_moment0History_input.c_str(),&status); |
---|
645 | status = 0; |
---|
646 | fits_write_history(fptr, (char *)par.getImageFile().c_str(), &status); |
---|
647 | |
---|
648 | if(par.getFlagSubsection()){ |
---|
649 | status = 0; |
---|
650 | fits_write_comment(fptr,(char *)header_moment0Subsection_comment.c_str(), |
---|
651 | &status); |
---|
652 | status = 0; |
---|
653 | fits_write_key(fptr, TSTRING, (char *)keyword_subsection.c_str(), |
---|
654 | (char *)par.getSubsection().c_str(), |
---|
655 | (char *)comment_subsection.c_str(), &status); |
---|
656 | } |
---|
657 | } |
---|
658 | |
---|
659 | } |
---|