source: trunk/src/Cubes/getImage.cc @ 160

Last change on this file since 160 was 160, checked in by Matthew Whiting, 18 years ago

Changed the way the FITS file is read in, so that it can deal with
naxis>4 files, where the order of the dimensions is not necessarily
lng,lat,spec,...

Summary of changes:

*Cubes/getImage.cc:

*Removed most of the code that goes in new functions.
*Changed order of tasks, so that the WCS is derived first, then the data array, and then the remaining header information.
*Also reports both the FITS dimensions and the data array dimensions.

*FitsIO/headerIO.cc:

*Moved defineWCS to wcsIO.cc.
*Made array declarations more robust (use CFITSIO constants for lengths).
*Changed type of BLANK keyword to TINT.

*FitsIO/dataIO.cc:

*New function, designed to read in data from FITS file.
*Reads in subset of just the spatial and spectral axes.
*Also takes care of setting blank pixels to appropriate value.

*FitsIO/wcsIO.cc:

*New file, contains the function FitsHeader::defineWCS

  • Utils/wcsFunctions.cc:

*Generalised the wcs functions, so that they make no

assumptions about the location of the spatial and spectral axes.

*Cubes/cubes.cc:

*Improved Cube::initialiseCube so that it gets the dimensions correct.
*Enabled Cube::getopts to deal with non-existant param file.
*Improved error reporting in saveArray functions.

*Cubes/cubes.hh:

*Changed prototypes for readParam. Added one for getFITSdata

*Cubes/ReadAndSearch?.cc :

*Minor comment added.

*param.cc:

*Generalised way fixUnits works, to cope with new axis concept.
*Made readParams return int, so it can indicate whether reading failed.

*ATrous/ReconSearch.cc:

*Improved way the goodness of the pixels and channels was determined.

*src/param.hh

*New prototype for Param::readParams

*Guide:

*Changed text about dimensionality of FITS files.
*Changed location of images.
*Minor changes to improve readability.

File size: 2.4 KB
Line 
1#include <iostream>
2#include <string>
3#include <string.h>
4#include <wcs.h>
5#include <wcshdr.h>
6#include <fitshdr.h>
7#include <wcsfix.h>
8#include <wcsunits.h>
9#define WCSLIB_GETWCSTAB // define this so that we don't try and redefine
10                         //  wtbarr (this is a problem when using gcc v.4+
11#include <fitsio.h>
12#include <math.h>
13#include <duchamp.hh>
14#include <Cubes/cubes.hh>
15
16string imageType[4] = {"point", "spectrum", "image", "cube"};
17
18int Cube::getCube(string fname)
19{
20  /**
21   * Cube::getCube(string )
22   *  Read in a cube from the file fname (assumed to be in FITS format).
23   *  Function reads in the following:
24   *      - axis dimensions
25   *      - pixel array
26   *      - WCS information (in form of WCSLIB wcsprm structure)
27   *      - Header keywords: BUNIT (brightness unit),
28   *                         BLANK, BZERO, BSCALE (for blank pixel value)
29   *                         BMAJ, BMIN, CDELT1, CDELT2 (for beam size)
30   */
31
32  long nelements;
33  int bitpix,numAxes;
34  int status = 0,  nkeys;  /* MUST initialize status */
35  fitsfile *fptr;         
36
37  status = 0;
38  if( fits_open_file(&fptr,fname.c_str(),READONLY,&status) ){
39    fits_report_error(stderr, status);
40    return FAILURE;
41  }
42
43  status = 0;
44  if(fits_get_img_dim(fptr, &numAxes, &status)){
45    fits_report_error(stderr, status);
46    return FAILURE;
47  }
48  long *dimAxes = new long[numAxes];
49  for(int i=0;i<numAxes;i++) dimAxes[i]=1;
50  status = 0;
51  if(fits_get_img_size(fptr, numAxes, dimAxes, &status)){
52    fits_report_error(stderr, status);
53    return FAILURE;
54  }
55  status = 0;
56  fits_close_file(fptr, &status);
57  if (status){
58    duchampWarning("getCube","Error closing file: ");
59    fits_report_error(stderr, status);
60  }
61
62  if(numAxes<=3)  std::cout << "Dimensions of FITS file: ";
63  int dim = 0;
64  std::cout << dimAxes[dim];
65  while(dim+1<numAxes) std::cout << "x" << dimAxes[++dim];
66  std::cout << std::endl;
67
68  delete [] dimAxes;
69
70  this->head.defineWCS(fname, this->par);
71
72  if(!this->head.isWCS())
73    duchampWarning("getCube","WCS is not good enough to be used.\n");
74
75  std::cerr << "Reading data ... ";
76  this->getFITSdata(fname);
77  std::cerr << "Done. Data array has dimensions: ";
78  std::cerr << this->axisDim[0] <<"x"
79            << this->axisDim[1] <<"x"
80            << this->axisDim[2] << std::endl;
81
82  this->head.readHeaderInfo(fname, this->par);
83  this->par.copyHeaderInfo(this->head);
84
85  return SUCCESS;
86
87}
88
Note: See TracBrowser for help on using the repository browser.