source: branches/fitshead-branch/Cubes/readRecon.cc @ 96

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

Two sets of large changes:
1) Added reconDim, to select which dimension of reconstruction to use.
2) Changed the way the MW channels are dealt with -- now not set to 0. but

simply ignored for searching purposes.

Summary of changes for each file:
duchamp.hh -- added keyword info for reconDim
param.hh -- Introduced reconDim and flagUsingBlank and isInMW.
param.cc -- Introduced reconDim and flagUsingBlank: initialisation etc commands
InputComplete? -- Added reconDim info
mainDuchamp.cc -- Removed the removeMW call. Changed search function names
docs/Guide.tex -- New code to deal with changes: reconDim, MW removal,

up-to-date output examples, better hints & notes section

Detection/thresholding_functions.cc -- minor typo correction

Cubes/cubes.hh -- added isBlank and removeMW functions in Image class, and

renamed search function prototypes

Cubes/cubes.cc -- added removeMW function for Image class, cleaned up

Cube::removeMW as well (although now not used)

Cubes/outputSpectra.cc -- Improved use of isBlank and isInMW functions: now

show MW channels but don't use them in calculating
the flux range

Cubes/getImage.cc -- added line to indicate whether the Param's blank value

is being used, rather than the FITS header.

Cubes/cubicSearch.cc -- renamed functions: front end is now CubicSearch?, and

searching function is search3DArray.

-- Improved way MW removal is dealt with. Changed

location of stats calculations.

Cubes/saveImage.cc -- added code for saving reconDim info
Cubes/readRecon.cc -- added code for reading reconDim info (and added status

intialisations before all cfitsio commands)

ATrous/ReconSearch.cc -- renamed functions: front end is now ReconSearch?, and

searching function is searchReconArray.
Using reconDim to decide which reconstruction to use.

-- Improved way MW removal is dealt with. Changed

location of stats calculations.

ATrous/atrous_1d_reconstruct.cc -- using Median stats
ATrous/atrous_2d_reconstruct.cc -- made code up to date, to conform with 1- &

3-d code. Removed boundary conditions.

ATrous/atrous_3d_reconstruct.cc -- corrected typo (avGapY /= float(xdim)).

Using median stats.

Cubes/cubicSearchNMerge.cc -- Deleted. (not used)
Cubes/readParams.cc -- Deleted. (not used)

File size: 6.8 KB
Line 
1#include <iostream>
2#include <sstream>
3#include <string>
4#include <wcs.h>
5#include <wcshdr.h>
6#include <fitsio.h>
7#include <duchamp.hh>
8#include <Cubes/cubes.hh>
9
10int Cube::readReconCube()
11{
12  /**
13   *  Cube::readReconCube()
14   *   
15   *   A way to read in a previously reconstructed array, corresponding to the
16   *    requested parameters, or in the filename given by reconFile.
17   *   Performs various tests to make sure there are no clashes between the requested
18   *    parameters and those stored in the header of the FITS file.
19   */
20
21
22  fitsfile *fptr;
23  int status = 0;
24
25  // Check to see whether the parameters reconFile and/or residFile are defined.
26  bool reconGood = false;
27  bool residGood = false;
28  int exists;
29  if(this->par.getReconFile() != ""){
30    reconGood = true;
31    fits_file_exists(this->par.getReconFile().c_str(),&exists,&status);
32    if(exists<=0){
33      fits_report_error(stderr, status);
34      std::cerr <<
35        "  WARNING <readReconCube> : Cannot find requested ReconFile. Trying with parameters.\n";
36      std::cerr <<
37        "                            Bad reconFile was: "<<this->par.getReconFile()<<std::endl;
38      reconGood = false;
39    }
40  }
41  else{
42    std::cerr <<
43      "  WARNING <readReconCube> : ReconFile not specified. Working out name from parameters.\n";
44  }
45 
46  if(!reconGood){ // if bad, need to look at parameters
47
48    string reconFile = this->par.getImageFile();
49    reconFile = reconFile.substr(0,reconFile.size()-5); // remove the ".fits" on the end.
50    std::stringstream ss;
51    ss << ".RECON"<<this->par.getAtrousCut()<<".fits";
52    reconFile += ss.str();
53    std::cerr << "                          : Trying file " << reconFile << std::endl;
54    reconGood = true;
55    fits_file_exists(reconFile.c_str(),&exists,&status);
56    if(exists<=0){
57      fits_report_error(stderr, status);
58      std::cerr <<
59        "  WARNING <readReconCube> : ReconFile not present\n";
60      reconGood = false;
61    }
62
63    if(reconGood){ // were able to open this file -- use this, so reset the relevant parameter
64      this->par.setReconFile(reconFile);
65    }
66    else { // if STILL bad, give error message and exit.
67      std::cerr << "  ERROR <readReconCube> : Cannot find reconstructed file.\n";
68      return FAILURE;
69    }
70
71  }
72
73  // if we get to here, reconGood is true (ie. file is open);
74  status=0;
75  fits_open_file(&fptr,this->par.getReconFile().c_str(),READONLY,&status);
76  short int maxdim=3;
77  long *fpixel = new long[maxdim];
78  for(int i=0;i<maxdim;i++) fpixel[i]=1;
79  long *dimAxesNew = new long[maxdim];
80  for(int i=0;i<maxdim;i++) dimAxesNew[i]=1;
81  long nelements;
82  int bitpix,numAxesNew,anynul;
83
84  status = 0;
85  fits_get_img_param(fptr, maxdim, &bitpix, &numAxesNew, dimAxesNew, &status);
86  if(status){
87    fits_report_error(stderr, status);
88    return FAILURE;
89  }
90
91  if(numAxesNew != this->numDim){
92    std::cerr << "  ERROR <readReconCube> : "
93              << "  Reconstructed cube has a different number of axes to original! ("
94              << numAxesNew << " cf. " << this->numDim << ")\n";
95    return FAILURE;
96  }
97
98  for(int i=0;i<numAxesNew;i++){
99    if(dimAxesNew[i]!=this->axisDim[i]){
100      std::cerr << "  ERROR <readReconCube> : "
101                << "  Reconstructed cube has different axis dimensions to original!\n"
102                << "        Axis #" << i << " has size " << dimAxesNew[i]
103                << "   cf. " << this->axisDim[i] <<" in original.\n";   
104      return FAILURE;
105    }
106  }     
107
108  char *comment = new char[80];
109  int flagMW;
110  status = 0;
111  fits_read_key(fptr, TINT, (char *)keyword_flagMW.c_str(), &flagMW, comment, &status);
112  if(flagMW != int(this->par.getFlagMW())){
113    std::cerr << "  ERROR <readReconCube> : Reconstructed cube has different flagMW parameter to original!\n"
114              << "        Reconstructed cube has "<<flagMW
115              << "   cf. " <<this->par.getFlagMW() << " as requested.\n";
116    return FAILURE;
117  }
118  if(flagMW==1){
119    int minMW;
120    status = 0;
121    fits_read_key(fptr, TINT, (char *)keyword_minMW.c_str(), &minMW, comment, &status);
122    if(minMW != this->par.getMinMW()){
123      std::cerr << "  ERROR <readReconCube> : Reconstructed cube has different minMW parameter to original!\n"
124                << "        Reconstructed cube has "<<minMW
125                << "   cf. " <<this->par.getMinMW() << " as requested.\n";
126      return FAILURE;
127    }
128    int maxMW;
129    status = 0;
130    fits_read_key(fptr, TINT, (char *)keyword_maxMW.c_str(), &maxMW, comment, &status);
131    if(maxMW != this->par.getMaxMW()){
132      std::cerr << "  ERROR <readReconCube> : Reconstructed cube has different maxMW parameter to original!\n"
133                << "        Reconstructed cube has "<<maxMW
134                << "   cf. " <<this->par.getMaxMW() << " as requested.\n";
135      return FAILURE;
136    }
137  }
138   
139  float *reconArray = new float[this->numPixels];
140  //  fits_read_pix(fptr, TFLOAT, fpixel, this->numPixels, NULL, this->recon, &anynul, &status);
141  status = 0;
142  fits_read_pix(fptr, TFLOAT, fpixel, this->numPixels, NULL, reconArray, &anynul, &status);
143  this->saveRecon(reconArray,this->numPixels);
144 
145  // Make the a trous parameters match what the recon file has.
146  int scaleMin,filterCode,reconDim;
147  float snrRecon;
148  if(!this->par.getFlagATrous()){
149    this->par.setFlagATrous(true);
150    std::cerr << "  WARNING <readReconCube> : Setting flagAtrous from false to true, as the reconstruction exists.\n";
151  }
152  status = 0;
153  fits_read_key(fptr, TINT, (char *)keyword_scaleMin.c_str(), &scaleMin, comment, &status);
154  if(scaleMin != this->par.getMinScale()){
155    this->par.setMinScale(scaleMin);
156    std::cerr << "  WARNING <readReconCube> : Changing scaleMin parameter to match ReconFile.\n";
157  }
158  status = 0;
159  fits_read_key(fptr, TINT, (char *)keyword_filterCode.c_str(), &filterCode, comment, &status);
160  if(filterCode != this->par.getFilterCode()){
161    this->par.setFilterCode(filterCode);
162    std::cerr << "  WARNING <readReconCube> : Changing filterCode parameter to match ReconFile.\n";
163  }
164  status = 0;
165  fits_read_key(fptr, TFLOAT, (char *)keyword_snrRecon.c_str(), &snrRecon, comment, &status);
166  if(snrRecon != this->par.getAtrousCut()){
167    this->par.setAtrousCut(snrRecon);
168    std::cerr << "  WARNING <readReconCube> : Changing snrRecon parameter to match ReconFile.\n";
169  }
170  status = 0;
171  fits_read_key(fptr, TINT, (char *)keyword_reconDim.c_str(), &reconDim, comment, &status);
172  if(reconDim != this->par.getReconDim()){
173    this->par.setReconDim(reconDim);
174    std::cerr << "  WARNING <readReconCube> : Changing reconDim parameter to match ReconFile.\n";
175  }
176
177  status = 0;
178  fits_close_file(fptr, &status);
179  if (status){
180    std::cerr << "  WARNING <readReconCube> : Error closing file: ";
181    fits_report_error(stderr, status);
182    //    return FAILURE;
183  }
184
185  // We don't want to write out the recon or resid files at the end
186  this->par.setFlagOutputRecon(false);
187  this->par.setFlagOutputResid(false);
188
189  // The reconstruction is done -- set the appropriate flag
190  this->reconExists = true;
191
192  return SUCCESS;
193}
Note: See TracBrowser for help on using the repository browser.