Changeset 827
- Timestamp:
- 02/17/06 15:01:57 (19 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/STWriter.cpp
r822 r827 42 42 #include <atnf/PKSIO/PKSSDwriter.h> 43 43 44 #include <tables/Tables/Table.h> 45 #include <tables/Tables/TableIter.h> 46 #include <tables/Tables/TableRow.h> 44 47 #include <tables/Tables/ArrayColumn.h> 45 48 46 47 48 49 //#include "SDFITSImageWriter.h" 50 //#include "STAsciiWriter.h" 51 //#include "SDPol.h" 49 52 #include "SDContainer.h" 50 #include "SDMemTable.h" 53 51 54 #include "STWriter.h" 52 #include "SDFITSImageWriter.h"53 #include "SDAsciiWriter.h"54 #include "SDPol.h"55 55 56 56 using namespace casa; 57 using namespace asap; 58 59 //--------------------------------------------------------- STWriter::STWriter 60 61 // Default constructor. 57 namespace asap { 62 58 63 59 STWriter::STWriter(const std::string &format) 64 60 { 65 cFormat = format;66 //67 String t(cFormat);68 t.upcase();69 if (t== "MS2") {70 cWriter = new PKSMS2writer();71 } else if (t== "SDFITS") {72 cWriter = new PKSSDwriter();73 } else if (t== "FITS") {74 cWriter = 0;75 } else if (t== "ASCII") {76 cWriter = 0;77 } else {78 throw (AipsError("Unrecognized Format"));79 }80 }81 82 //-------------------------------------------------------- STWriter::~STWriter83 84 // Destructor.85 86 STWriter::~STWriter()87 {88 if (cWriter) {89 delete cWriter;90 }91 }92 93 //-------------------------------------------------------- STWriter::setFormat94 95 // Reset the output format.96 97 Int STWriter::setFormat(const std::string &format)98 {99 if (format != cFormat) {100 if (cWriter) delete cWriter;101 }102 //103 61 cFormat = format; 104 62 String t(cFormat); … … 115 73 throw (AipsError("Unrecognized Format")); 116 74 } 75 } 76 77 STWriter::~STWriter() 78 { 79 if (cWriter) { 80 delete cWriter; 81 } 82 } 83 84 Int STWriter::setFormat(const std::string &format) 85 { 86 if (format != cFormat) { 87 if (cWriter) delete cWriter; 88 } 89 90 cFormat = format; 91 String t(cFormat); 92 t.upcase(); 93 if (t== "MS2") { 94 cWriter = new PKSMS2writer(); 95 } else if (t== "SDFITS") { 96 cWriter = new PKSSDwriter(); 97 } else if (t== "FITS") { 98 cWriter = 0; 99 } else if (t== "ASCII") { 100 cWriter = 0; 101 } else { 102 throw (AipsError("Unrecognized Format")); 103 } 117 104 return 0; 118 105 } 119 106 120 //------------------------------------------------------------ STWriter::write 121 122 // Write an SDMemTable to file in the desired format, closing the file when 123 // finished. 124 125 Int STWriter::write(const CountedPtr<SDMemTable> in, 126 const std::string &filename, Bool toStokes) 107 Int STWriter::write(const CountedPtr<Scantable> in, 108 const std::string &filename) 127 109 { 128 110 … … 130 112 131 113 if (cFormat=="FITS") { 132 Bool verbose = True; 133 SDFITSImageWriter iw; 134 if (iw.write(*in, filename, verbose, toStokes)) { 114 // Bool verbose = True; 115 // SDFITSImageWriter iw; 116 // if (iw.write(*in, filename, verbose)) { 117 // return 0; 118 // } else { 119 // return 1; 120 // } 121 } else if (cFormat=="ASCII") { 122 /*SDAsciiWriter iw; 123 if (iw.write(*in, filename)) { 135 124 return 0; 136 125 } else { 137 126 return 1; 138 } 139 } else if (cFormat=="ASCII") { 140 SDAsciiWriter iw; 141 if (iw.write(*in, filename, toStokes)) { 142 return 0; 143 } else { 144 return 1; 145 } 146 } 147 148 // MS or SDFITS 127 }*/ 128 } 129 130 // MS or SDFITS 149 131 150 132 // Extract the header from the table. … … 153 135 const Int nChan = hdr.nchan; 154 136 155 // Get Freq table156 157 SDFrequencyTable sdft = in->getSDFreqTable();158 Vector<Double> restFreqs;159 String restFreqUnit;160 sdft.restFrequencies(restFreqs, restFreqUnit);161 Double restFreq = 0.0;162 if (restFreqs.nelements()>0) {163 Quantum<Double> rF(restFreqs(0), Unit(restFreqUnit));164 restFreq = rF.getValue(Unit("Hz"));165 }166 167 // Table columns168 169 137 const Table table = in->table(); 170 ROArrayColumn<uInt> freqIDCol(table, "FREQID");171 Vector<uInt> freqIDs;138 // ROArrayColumn<uInt> freqIDCol(table, "FREQ_ID"); 139 // Vector<uInt> freqIDs; 172 140 173 141 // Create the output file and write static data. … … 180 148 } 181 149 182 Vector<Double> srcPM(2, 0.0);183 150 Double srcVel = 0.0; 184 185 Array<Float> spectra, tSys, stokes;186 Array<uChar> flags;187 Bool doLinear = True;188 151 189 152 String fieldName, srcName, tcalTime; … … 203 166 while (!beamit.pastEnd() ) { 204 167 Table btable = beamit.table(); 168 // position only varies by beam 169 MDirection::ScalarColumn dirCol(btable, "DIRECTION"); 170 Vector<Double> direction = dirCol(0).getAngle("rad").getValue(); 205 171 TableIterator ifit(btable, "IFNO"); 206 172 Int ifno = 1; … … 213 179 TableRow row(ctable); 214 180 // use the first row to fill in all the "metadata" 215 const TableRecord& rec = row. record(0);181 const TableRecord& rec = row.get(0); 216 182 ROArrayColumn<Float> specCol(ctable, "SPECTRA"); 217 183 uInt nchan = specCol(0).nelements(); 218 184 Double cdelt,crval,crpix, restfreq; 219 String tmp,tmp2; 185 Float focusAxi, focusTan, focusRot, 186 temperature, pressure, humidity, windSpeed, windAz; 187 Vector<Float> tcalval; 188 String tmp,tmp2, tcalt; 220 189 in->frequencies().getEntry(crpix,crval,cdelt, rec.asuInt("FREQ_ID")); 221 190 in->molecules().getEntry(restfreq,tmp,tmp2,rec.asuInt("RESTFREQ_ID")); 191 in->tcal().getEntry(tcalt,tcalval,rec.asuInt("TCAL_ID")); 192 in->weather().getEntry(temperature, pressure, humidity, 193 windSpeed, windAz, 194 rec.asuInt("WEATHER_ID")); 222 195 Double pixel = Double(nchan/2); 223 196 Double refFreqNew = (pixel-crpix)*cdelt + crval; … … 227 200 Vector<Complex> xpol; 228 201 polConversion(specs, flags, xpol, ctable); 202 Vector<Float> tsys = tsysFromTable(ctable); 229 203 // dummy data 230 uInt n Pol = specs.ncolumns();204 uInt npol = specs.ncolumn(); 231 205 Matrix<Float> baseLin(npol,2, 0.0f); 232 206 Matrix<Float> baseSub(npol,9, 0.0f); … … 237 211 238 212 239 if (status = cWriter->write(scan o, cycno, rec.asDouble("TIME"),213 if (status = cWriter->write(scanno, cycno, rec.asDouble("TIME"), 240 214 rec.asDouble("INTERVAL"), 241 215 rec.asString("FIELDNAME"), 242 216 rec.asString("SRCNAME"), 243 direction ,//217 direction, 244 218 srcPM, srcVel, // not in scantable yet 245 219 ifno, 246 220 refFreqNew, nchan*abs(cdelt), cdelt, 247 221 restfreq, 248 tcal, //249 tcalt ime,//222 tcal, 223 tcalt, 250 224 rec.asFloat("AZIMUTH"), 251 225 rec.asFloat("ELEVATION"), 252 226 rec.asFloat("PARANGLE"), 253 227 focusAxi, focusTan, focusRot,// 254 temperature, //255 pressure, humidity, windSpeed, windAz, //228 temperature, 229 pressure, humidity, windSpeed, windAz, 256 230 rec.asInt("REFBEAM"), beamno, 257 direction, //231 direction, 258 232 scanRate,// not in scantable 259 t Sys, //233 tsys, 260 234 sigma, calFctr,// not in scantable 261 235 baseLin, baseSub,// not in scantable … … 288 262 } 289 263 290 void STWriter::polConversion( Matrix< Float >& specs, Matrix< Float >& flags, 264 Vector<Float> STWriter::tsysFromTable(const Table& tab) 265 { 266 ROArrayColumn<Float> tsysCol(tab, "TSYS"); 267 Vector<Float> out(tab.nrow()); 268 Vector<Float> tmp; 269 for (uInt i=0; i<tab.nrow(); ++i) { 270 tmp = tsysCol(i); 271 out[i] = tmp[0]; 272 } 273 } 274 275 void STWriter::polConversion( Matrix< Float >& specs, Matrix< uChar >& flags, 291 276 Vector< Complex > & xpol, const Table & tab ) 292 277 { … … 297 282 throw(AipsError("msg")); 298 283 // use the first row to fill in all the "metadata" 299 const TableRecord& rec = row. record(0);300 ROArrayColumn<Float> specCol( ctable, "SPECTRA");301 ROArrayColumn<uChar> flagCol( ctable, "FLAGTRA");284 const TableRecord& rec = row.get(0); 285 ROArrayColumn<Float> specCol(tab, "SPECTRA"); 286 ROArrayColumn<uChar> flagCol(tab, "FLAGTRA"); 302 287 uInt nchan = specCol(0).nelements(); 303 uInt ncols = ( ctable.nrow()==1 ? 1: 2 );288 uInt ncols = (tab.nrow()==1 ? 1: 2 ); 304 289 specs.resize(nchan, ncols); 305 290 flags.resize(nchan, ncols); … … 310 295 } 311 296 // now the complex if exists 312 Vector<Complex> xpol;313 297 Bool hasxpol = False; 314 298 xpol.resize(); 315 if ( ctable.nrow() == 4 ) {299 if ( tab.nrow() == 4 ) { 316 300 hasxpol = True; 317 301 xpol.resize(nchan); … … 319 303 reals = specCol(2); imags = specCol(3); 320 304 for (uInt k=0; k < nchan; ++k) { 321 `xpol[k] = Complex(reals[k], imags[k]);305 xpol[k] = Complex(reals[k], imags[k]); 322 306 } 323 307 } 324 308 } 309 310 311 } -
trunk/src/STWriter.h
r822 r827 37 37 #include <casa/Utilities/CountedPtr.h> 38 38 39 #include <SDMemTable.h> 40 #include <SDMemTableWrapper.h> 41 42 #include <SDLog.h> 39 #include "SDLog.h" 40 #include "Scantable.h" 43 41 44 42 class PKSwriter; 43 class casa::Table; 45 44 46 45 namespace asap { … … 54 53 // Stokes conversion available for FITS and ASCII at present 55 54 casa::Int setFormat(const string &format = "SDFITS"); 56 casa::Int write(const casa::CountedPtr<S DMemTable> table,57 const string &filename , casa::Bool toStokes);55 casa::Int write(const casa::CountedPtr<Scantable> table, 56 const string &filename); 58 57 59 58 private: 59 casa::Vector<casa::Float> tsysFromTable(const casa::Table& tab); 60 60 61 void polConversion( casa::Matrix<casa::Float>& spec, 61 casa::Matrix<casa:: Float>& flag,62 casa::Matrix<casa::uChar>& flag, 62 63 casa::Vector<casa::Complex>& xpol, 63 const Table& tab);64 const casa::Table& tab); 64 65 std::string cFormat; 65 66 PKSwriter *cWriter;
Note:
See TracChangeset
for help on using the changeset viewer.