Changeset 1446 for branches/alma/src
- Timestamp:
- 11/12/08 17:04:01 (16 years ago)
- Location:
- branches/alma/src
- Files:
-
- 1 added
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/alma/src/MathUtils.cpp
r1400 r1446 37 37 #include <casa/BasicSL/String.h> 38 38 #include <scimath/Mathematics/MedianSlider.h> 39 #include <casa/Exceptions/Error.h> 39 40 40 41 #include "MathUtils.h" … … 47 48 String str(which); 48 49 str.upcase(); 49 if (str. contains(String("MIN"))) {50 if (str.matches(String("MIN"))) { 50 51 return min(data); 51 } else if (str. contains(String("MAX"))) {52 } else if (str.matches(String("MAX"))) { 52 53 return max(data); 53 } else if (str. contains(String("SUMSQ"))) {54 } else if (str.matches(String("SUMSQ"))) { 54 55 return sumsquares(data); 55 } else if (str. contains(String("SUM"))) {56 } else if (str.matches(String("SUM"))) { 56 57 return sum(data); 57 } else if (str. contains(String("MEAN"))) {58 } else if (str.matches(String("MEAN"))) { 58 59 return mean(data); 59 } else if (str. contains(String("VAR"))) {60 } else if (str.matches(String("VAR"))) { 60 61 return variance(data); 61 } else if (str.contains(String("STDDEV"))) {62 } else if (str.matches(String("STDDEV"))) { 62 63 return stddev(data); 63 } else if (str. contains(String("AVDEV"))) {64 } else if (str.matches(String("AVDEV"))) { 64 65 return avdev(data); 65 } else if (str. contains(String("RMS"))) {66 } else if (str.matches(String("RMS"))) { 66 67 uInt n = data.nelementsValid(); 67 68 return sqrt(sumsquares(data)/n); 68 } else if (str. contains(String("MED"))) {69 } else if (str.matches(String("MEDIAN"))) { 69 70 return median(data); 70 } 71 } else { 72 String msg = str + " is not a valid type of statistics"; 73 throw(AipsError(msg)); 74 } 71 75 return 0.0; 72 76 } -
branches/alma/src/MathUtils.h
r1373 r1446 82 82 83 83 /** 84 * Convert casa implementations to stl 85 * @param in casa string 86 * @return a std vector of std strings 84 * Convert a std::vector of std::string 85 * to a casa::Vector casa::String 86 * @param in 87 * @return 87 88 */ 88 89 std::vector<std::string> tovectorstring(const casa::Vector<casa::String>& in); 89 90 90 91 /** 91 * convert stl implementations to casa versions 92 * Convert a casa::Vector of casa::String 93 * to a stl std::vector of stl std::string 92 94 * @param in 93 95 * @return -
branches/alma/src/RowAccumulator.cpp
r1352 r1446 152 152 userMask_ = m; 153 153 } 154 155 // Added by TT check the state of RowAccumulator 156 casa::Bool RowAccumulator::state() const 157 { 158 return initialized_; 159 } -
branches/alma/src/RowAccumulator.h
r1353 r1446 85 85 */ 86 86 void reset(); 87 /** 88 * check the initialization state 89 */ 90 casa::Bool state() const; 87 91 88 92 private: -
branches/alma/src/STAsciiWriter.cpp
r1375 r1446 122 122 String wcs = stable.frequencies().print(rec.asuInt("FREQ_ID"), True); 123 123 addLine(of, "WCS", wcs); 124 addLine(of, "Rest Freq.", 125 stable.molecules().getRestFrequency(rec.asuInt("MOLECULE_ID") )); 124 std::vector<double> restfreqs= stable.molecules().getRestFrequency(rec.asuInt("MOLECULE_ID")); 125 int nf = restfreqs.size(); 126 //addLine(of, "Rest Freq.", 127 // stable.molecules().getRestFrequency(rec.asuInt("MOLECULE_ID") )); 128 addLine(of, "Rest Freq.", restfreqs[0]); 129 for ( unsigned int i=1; i<nf; ++i) { 130 addLine(of, " ", restfreqs[i]); 131 } 126 132 of << setfill('#') << setw(70) << "" << setfill(' ') << endl; 127 133 -
branches/alma/src/STFiller.cpp
r1387 r1446 205 205 } 206 206 } 207 String freqFrame = header_->freqref; 208 //translate frequency reference frame back to 209 //MS style (as PKSMS2reader converts the original frame 210 //in FITS standard style) 211 if (freqFrame == "TOPOCENT") { 212 freqFrame = "TOPO"; 213 } else if (freqFrame == "GEOCENER") { 214 freqFrame = "GEO"; 215 } else if (freqFrame == "BARYCENT") { 216 freqFrame = "BARY"; 217 } else if (freqFrame == "GALACTOC") { 218 freqFrame = "GALACTO"; 219 } else if (freqFrame == "LOCALGRP") { 220 freqFrame = "LGROUP"; 221 } else if (freqFrame == "CMBDIPOL") { 222 freqFrame = "CMB"; 223 } else if (freqFrame == "SOURCE") { 224 freqFrame = "REST"; 225 } 226 table_->frequencies().setFrame(freqFrame); 207 227 208 228 } … … 222 242 Float azimuth, elevation, focusAxi, focusRot, focusTan, 223 243 humidity, parAngle, pressure, temperature, windAz, windSpeed; 224 Double bandwidth, freqInc, interval, mjd, refFreq, restFreq,srcVel;244 Double bandwidth, freqInc, interval, mjd, refFreq, srcVel; 225 245 String fieldName, srcName, tcalTime, obsType; 226 246 Vector<Float> calFctr, sigma, tcal, tsys; 227 247 Matrix<Float> baseLin, baseSub; 228 Vector<Double> direction(2), scanRate(2), srcDir(2), srcPM(2) ;248 Vector<Double> direction(2), scanRate(2), srcDir(2), srcPM(2), restFreq; 229 249 Matrix<Float> spectra; 230 250 Matrix<uChar> flagtra; -
branches/alma/src/STFrequencies.cpp
r1375 r1446 128 128 } 129 129 130 void STFrequencies::setEntry( Double refpix, Double refval, Double inc, uInt id ) 131 { 132 Table t = table_(table_.col("ID") == Int(id) ); 133 if (t.nrow() == 0 ) { 134 throw(AipsError("STFrequencies::getEntry - freqID out of range")); 135 } 136 for ( uInt i = 0 ; i < table_.nrow() ; i++ ) { 137 uInt fid ; 138 idCol_.get( i, fid ) ; 139 if ( fid == id ) { 140 refpixCol_.put( i, refpix ) ; 141 refvalCol_.put( i, refval ) ; 142 incrCol_.put( i, inc ) ; 143 } 144 } 145 } 146 130 147 SpectralCoordinate STFrequencies::getSpectralCoordinate( uInt id ) const 131 148 { … … 140 157 // get first row - there should only be one matching id 141 158 const TableRecord& rec = row.get(0); 159 142 160 return SpectralCoordinate( getFrame(true), rec.asDouble("REFVAL"), 143 161 rec.asDouble("INCREMENT"), … … 145 163 } 146 164 165 /** 147 166 SpectralCoordinate 148 STFrequencies::getSpectralCoordinate( const MDirection& md, 149 const MPosition& mp, 150 const MEpoch& me, 151 Double restfreq, uInt id ) const 167 asap::STFrequencies::getSpectralCoordinate( const MDirection& md, 168 const MPosition& mp, 169 const MEpoch& me, 170 Double restfreq, uInt id ) const 171 **/ 172 SpectralCoordinate 173 asap::STFrequencies::getSpectralCoordinate( const MDirection& md, 174 const MPosition& mp, 175 const MEpoch& me, 176 Vector<Double> restfreq, uInt id ) const 152 177 { 153 178 SpectralCoordinate spc = getSpectralCoordinate(id); 154 spc.setRestFrequency(restfreq, True); 179 //spc.setRestFrequency(restfreq, True); 180 // for now just use the first rest frequency 181 if (restfreq.nelements()==0 ) { 182 restfreq.resize(1); 183 restfreq[0] = 0; 184 } 185 spc.setRestFrequency(restfreq[0], True); 155 186 if ( !spc.setReferenceConversion(getFrame(), me, mp, md) ) { 156 187 throw(AipsError("Couldn't convert frequency frame.")); -
branches/alma/src/STFrequencies.h
r1375 r1446 59 59 casa::Double& inc, casa::uInt id ); 60 60 61 /*** 62 * Set the frequency values for a specific id via references 63 * @param refpix the reference pixel 64 * @param refval the reference value 65 * @param inc the increment 66 * @param id the identifier 67 * 68 * 17/09/2008 Takeshi Nakazato 69 ***/ 70 void setEntry( casa::Double refpix, casa::Double refval, 71 casa::Double inc, casa::uInt id ) ; 72 61 73 62 74 bool conformant(const STFrequencies& other) const; … … 69 81 casa::SpectralCoordinate getSpectralCoordinate( casa::uInt freqID ) const; 70 82 83 /** 71 84 casa::SpectralCoordinate getSpectralCoordinate( const casa::MDirection& md, 72 85 const casa::MPosition& mp, … … 75 88 casa::uInt freqID 76 89 ) const; 90 **/ 91 casa::SpectralCoordinate getSpectralCoordinate( const casa::MDirection& md, 92 const casa::MPosition& mp, 93 const casa::MEpoch& me, 94 casa::Vector<casa::Double> restfreq, 95 casa::uInt freqID 96 ) const; 77 97 78 98 /** -
branches/alma/src/STMath.cpp
r1387 r1446 191 191 } 192 192 //write out 193 Vector<uChar> flg(msk.shape()); 194 convertArray(flg, !msk); 195 flagColOut.put(i, flg); 196 specColOut.put(i, acc.getSpectrum()); 197 tsysColOut.put(i, acc.getTsys()); 198 intColOut.put(i, acc.getInterval()); 199 mjdColOut.put(i, acc.getTime()); 200 // we should only have one cycle now -> reset it to be 0 201 // frequency switched data has different CYCLENO for different IFNO 202 // which requires resetting this value 203 cycColOut.put(i, uInt(0)); 193 if (acc.state()) { 194 Vector<uChar> flg(msk.shape()); 195 convertArray(flg, !msk); 196 flagColOut.put(i, flg); 197 specColOut.put(i, acc.getSpectrum()); 198 tsysColOut.put(i, acc.getTsys()); 199 intColOut.put(i, acc.getInterval()); 200 mjdColOut.put(i, acc.getTime()); 201 // we should only have one cycle now -> reset it to be 0 202 // frequency switched data has different CYCLENO for different IFNO 203 // which requires resetting this value 204 cycColOut.put(i, uInt(0)); 205 } else { 206 ostringstream oss; 207 oss << "For output row="<<i<<", all input rows of data are flagged. no averaging" << endl; 208 pushLog(String(oss)); 209 } 204 210 acc.reset(); 205 211 } … … 947 953 { 948 954 949 955 950 956 STSelector sel; 951 957 CountedPtr< Scantable > ws = getScantable(s, false); 952 958 CountedPtr< Scantable > sig, sigwcal, ref, refwcal; 953 CountedPtr< Scantable > calsig, calref, out; 959 CountedPtr< Scantable > calsig, calref, out, out1, out2; 960 Bool nofold=False; 954 961 955 962 //split the data … … 973 980 calref = dototalpower(refwcal, ref, tcal=tcal); 974 981 975 out=dosigref(calsig,calref,smoothref,tsysv,tau); 976 982 out1=dosigref(calsig,calref,smoothref,tsysv,tau); 983 out2=dosigref(calref,calsig,smoothref,tsysv,tau); 984 985 Table& tabout1=out1->table(); 986 Table& tabout2=out2->table(); 987 ROScalarColumn<uInt> freqidCol1(tabout1, "FREQ_ID"); 988 ROScalarColumn<uInt> freqidCol2(tabout2, "FREQ_ID"); 989 ROArrayColumn<Float> specCol(tabout2, "SPECTRA"); 990 Vector<Float> spec; specCol.get(0, spec); 991 uInt nchan = spec.nelements(); 992 uInt freqid1; freqidCol1.get(0,freqid1); 993 uInt freqid2; freqidCol2.get(0,freqid2); 994 Double rp1, rp2, rv1, rv2, inc1, inc2; 995 out1->frequencies().getEntry(rp1, rv1, inc1, freqid1); 996 out2->frequencies().getEntry(rp2, rv2, inc2, freqid2); 997 if (rp1==rp2) { 998 Double foffset = rv1 - rv2; 999 uInt choffset = static_cast<uInt>(foffset/abs(inc2)); 1000 if (choffset >= nchan) { 1001 cerr<<"out-band frequency switching, no folding"<<endl; 1002 nofold = True; 1003 } 1004 } 1005 1006 if (nofold) { 1007 std::vector< CountedPtr< Scantable > > tabs; 1008 tabs.push_back(out1); 1009 tabs.push_back(out2); 1010 out = merge(tabs); 1011 } 1012 else { //folding is not implemented yet 1013 out = out1; 1014 } 1015 977 1016 return out; 978 1017 } 979 980 1018 981 1019 CountedPtr< Scantable > STMath::freqSwitch( const CountedPtr< Scantable >& in ) … … 1565 1603 id = out->frequencies().addEntry(rp, rv, inc); 1566 1604 freqidcol.put(k,id); 1567 String name,fname;Double rf; 1605 //String name,fname;Double rf; 1606 Vector<String> name,fname;Vector<Double> rf; 1568 1607 (*it)->molecules().getEntry(rf, name, fname, rec.asuInt("MOLECULE_ID")); 1569 1608 id = out->molecules().addEntry(rf, name, fname); … … 1981 2020 return out; 1982 2021 } 2022 2023 // Averaging spectra with different channel/resolution 2024 CountedPtr<Scantable> 2025 STMath::new_average( const std::vector<CountedPtr<Scantable> >& in, 2026 const bool& compel, 2027 const std::vector<bool>& mask, 2028 const std::string& weight, 2029 const std::string& avmode ) 2030 throw ( casa::AipsError ) 2031 { 2032 if ( avmode == "SCAN" && in.size() != 1 ) 2033 throw(AipsError("Can't perform 'SCAN' averaging on multiple tables.\n" 2034 "Use merge first.")); 2035 2036 CountedPtr<Scantable> out ; // processed result 2037 if ( compel ) { 2038 std::vector< CountedPtr<Scantable> > newin ; // input for average process 2039 uInt insize = in.size() ; // number of scantables 2040 2041 // TEST: do normal average in each table before IF grouping 2042 cout << "Do preliminary averaging" << endl ; 2043 vector< CountedPtr<Scantable> > tmpin( insize ) ; 2044 for ( uInt itable = 0 ; itable < insize ; itable++ ) { 2045 vector< CountedPtr<Scantable> > v( 1, in[itable] ) ; 2046 tmpin[itable] = average( v, mask, weight, avmode ) ; 2047 } 2048 2049 // warning 2050 cout << "Average spectra with different spectral resolution" << endl ; 2051 cout << endl ; 2052 2053 // temporarily set coordinfo 2054 vector<string> oldinfo( insize ) ; 2055 for ( uInt itable = 0 ; itable < insize ; itable++ ) { 2056 vector<string> coordinfo = in[itable]->getCoordInfo() ; 2057 oldinfo[itable] = coordinfo[0] ; 2058 coordinfo[0] = "Hz" ; 2059 tmpin[itable]->setCoordInfo( coordinfo ) ; 2060 } 2061 2062 // columns 2063 ScalarColumn<uInt> freqIDCol ; 2064 ScalarColumn<uInt> ifnoCol ; 2065 ScalarColumn<uInt> scannoCol ; 2066 2067 2068 // check IF frequency coverage 2069 //cout << "Check IF settings in each table" << endl ; 2070 vector< vector<uInt> > freqid( insize ); 2071 vector< vector<double> > iffreq( insize ) ; 2072 for ( uInt itable = 0 ; itable < insize ; itable++ ) { 2073 uInt rows = tmpin[itable]->nrow() ; 2074 uInt freqnrows = tmpin[itable]->frequencies().table().nrow() ; 2075 for ( uInt irow = 0 ; irow < rows ; irow++ ) { 2076 if ( freqid[itable].size() == freqnrows ) { 2077 break ; 2078 } 2079 else { 2080 freqIDCol.attach( tmpin[itable]->table(), "FREQ_ID" ) ; 2081 ifnoCol.attach( tmpin[itable]->table(), "IFNO" ) ; 2082 uInt id = freqIDCol( irow ) ; 2083 if ( freqid[itable].size() == 0 || count( freqid[itable].begin(), freqid[itable].end(), id ) == 0 ) { 2084 //cout << "itable = " << itable << ": IF " << id << " is included in the list" << endl ; 2085 vector<double> abcissa = tmpin[itable]->getAbcissa( irow ) ; 2086 freqid[itable].push_back( id ) ; 2087 iffreq[itable].push_back( abcissa[0] - 0.5 * ( abcissa[1] - abcissa[0] ) ) ; 2088 iffreq[itable].push_back( abcissa[abcissa.size()-1] + 0.5 * ( abcissa[1] - abcissa[0] ) ) ; 2089 } 2090 } 2091 } 2092 } 2093 2094 // debug 2095 //cout << "IF settings summary:" << endl ; 2096 //for ( uInt i = 0 ; i < freqid.size() ; i++ ) { 2097 //cout << " Table" << i << endl ; 2098 //for ( uInt j = 0 ; j < freqid[i].size() ; j++ ) { 2099 //cout << " id = " << freqid[i][j] << " (min,max) = (" << iffreq[i][2*j] << "," << iffreq[i][2*j+1] << ")" << endl ; 2100 //} 2101 //} 2102 //cout << endl ; 2103 2104 // IF grouping based on their frequency coverage 2105 //cout << "IF grouping based on their frequency coverage" << endl ; 2106 2107 // IF group 2108 // ifgrp[numgrp][nummember*2] 2109 // ifgrp = [table00, freqrow00, table01, freqrow01, ...], 2110 // [table11, freqrow11, table11, freqrow11, ...], 2111 // ... 2112 // ifgfreq[numgrp*2] 2113 // ifgfreq = [min0, max0, min1, max1, ...] 2114 vector< vector<uInt> > ifgrp ; 2115 vector<double> ifgfreq ; 2116 2117 // parameter for IF grouping 2118 // groupmode = OR retrieve all region 2119 // AND only retrieve overlaped region 2120 //string groupmode = "AND" ; 2121 string groupmode = "OR" ; 2122 uInt sizecr = 0 ; 2123 if ( groupmode == "AND" ) 2124 sizecr = 2 ; 2125 else if ( groupmode == "OR" ) 2126 sizecr = 0 ; 2127 2128 vector<double> sortedfreq ; 2129 for ( uInt i = 0 ; i < iffreq.size() ; i++ ) { 2130 for ( uInt j = 0 ; j < iffreq[i].size() ; j++ ) { 2131 if ( count( sortedfreq.begin(), sortedfreq.end(), iffreq[i][j] ) == 0 ) 2132 sortedfreq.push_back( iffreq[i][j] ) ; 2133 } 2134 } 2135 sort( sortedfreq.begin(), sortedfreq.end() ) ; 2136 for ( vector<double>::iterator i = sortedfreq.begin() ; i != sortedfreq.end()-1 ; i++ ) { 2137 ifgfreq.push_back( *i ) ; 2138 ifgfreq.push_back( *(i+1) ) ; 2139 } 2140 ifgrp.resize( ifgfreq.size()/2 ) ; 2141 for ( uInt itable = 0 ; itable < insize ; itable++ ) { 2142 for ( uInt iif = 0 ; iif < freqid[itable].size() ; iif++ ) { 2143 double range0 = iffreq[itable][2*iif] ; 2144 double range1 = iffreq[itable][2*iif+1] ; 2145 for ( uInt j = 0 ; j < ifgrp.size() ; j++ ) { 2146 double fmin = max( range0, ifgfreq[2*j] ) ; 2147 double fmax = min( range1, ifgfreq[2*j+1] ) ; 2148 if ( fmin < fmax ) { 2149 ifgrp[j].push_back( itable ) ; 2150 ifgrp[j].push_back( freqid[itable][iif] ) ; 2151 } 2152 } 2153 } 2154 } 2155 vector< vector<uInt> >::iterator fiter = ifgrp.begin() ; 2156 vector<double>::iterator giter = ifgfreq.begin() ; 2157 while( fiter != ifgrp.end() ) { 2158 if ( fiter->size() <= sizecr ) { 2159 fiter = ifgrp.erase( fiter ) ; 2160 giter = ifgfreq.erase( giter ) ; 2161 giter = ifgfreq.erase( giter ) ; 2162 } 2163 else { 2164 fiter++ ; 2165 advance( giter, 2 ) ; 2166 } 2167 } 2168 2169 // freqgrp[numgrp][nummember] 2170 // freqgrp = [ifgrp00, ifgrp01, ifgrp02, ...], 2171 // [ifgrp10, ifgrp11, ifgrp12, ...], 2172 // ... 2173 // freqrange[numgrp*2] 2174 // freqrange = [min0, max0, min1, max1, ...] 2175 vector< vector<uInt> > freqgrp ; 2176 double freqrange = 0.0 ; 2177 uInt grpnum = 0 ; 2178 for ( uInt i = 0 ; i < ifgrp.size() ; i++ ) { 2179 // Assumed that ifgfreq was sorted 2180 if ( grpnum != 0 && freqrange == ifgfreq[2*i] ) { 2181 freqgrp[grpnum-1].push_back( i ) ; 2182 } 2183 else { 2184 vector<uInt> grp0( 1, i ) ; 2185 freqgrp.push_back( grp0 ) ; 2186 grpnum++ ; 2187 } 2188 freqrange = ifgfreq[2*i+1] ; 2189 } 2190 2191 2192 // print IF groups 2193 cout << "IF Group summary: " << endl ; 2194 cout << " GROUP_ID [FREQ_MIN, FREQ_MAX]: (TABLE_ID, FREQ_ID)" << endl ; 2195 for ( uInt i = 0 ; i < ifgrp.size() ; i++ ) { 2196 cout << " GROUP " << setw( 2 ) << i << " [" << ifgfreq[2*i] << "," << ifgfreq[2*i+1] << "]: " ; 2197 for ( uInt j = 0 ; j < ifgrp[i].size()/2 ; j++ ) { 2198 cout << "(" << ifgrp[i][2*j] << "," << ifgrp[i][2*j+1] << ") " ; 2199 } 2200 cout << endl ; 2201 } 2202 cout << endl ; 2203 2204 // print frequency group 2205 cout << "Frequency Group summary: " << endl ; 2206 cout << " GROUP_ID [FREQ_MIN, FREQ_MAX]: IF_GROUP_ID" << endl ; 2207 for ( uInt i = 0 ; i < freqgrp.size() ; i++ ) { 2208 cout << " GROUP " << setw( 2 ) << i << " [" << ifgfreq[2*freqgrp[i][0]] << "," << ifgfreq[2*freqgrp[i][freqgrp[i].size()-1]+1] << "]: " ; 2209 for ( uInt j = 0 ; j < freqgrp[i].size() ; j++ ) { 2210 cout << freqgrp[i][j] << " " ; 2211 } 2212 cout << endl ; 2213 } 2214 cout << endl ; 2215 2216 // membership check 2217 // groups[numtable][numIF][nummembership] 2218 vector< vector< vector<uInt> > > groups( insize ) ; 2219 for ( uInt i = 0 ; i < insize ; i++ ) { 2220 groups[i].resize( freqid[i].size() ) ; 2221 } 2222 for ( uInt igrp = 0 ; igrp < ifgrp.size() ; igrp++ ) { 2223 for ( uInt imem = 0 ; imem < ifgrp[igrp].size()/2 ; imem++ ) { 2224 uInt tableid = ifgrp[igrp][2*imem] ; 2225 vector<uInt>::iterator iter = find( freqid[tableid].begin(), freqid[tableid].end(), ifgrp[igrp][2*imem+1] ) ; 2226 if ( iter != freqid[tableid].end() ) { 2227 uInt rowid = distance( freqid[tableid].begin(), iter ) ; 2228 groups[tableid][rowid].push_back( igrp ) ; 2229 } 2230 } 2231 } 2232 2233 // print membership 2234 //for ( uInt i = 0 ; i < insize ; i++ ) { 2235 //cout << "Table " << i << endl ; 2236 //for ( uInt j = 0 ; j < groups[i].size() ; j++ ) { 2237 //cout << " FREQ_ID " << setw( 2 ) << freqid[i][j] << ": " ; 2238 //for ( uInt k = 0 ; k < groups[i][j].size() ; k++ ) { 2239 //cout << setw( 2 ) << groups[i][j][k] << " " ; 2240 //} 2241 //cout << endl ; 2242 //} 2243 //} 2244 2245 // set back coordinfo 2246 for ( uInt itable = 0 ; itable < insize ; itable++ ) { 2247 vector<string> coordinfo = tmpin[itable]->getCoordInfo() ; 2248 coordinfo[0] = oldinfo[itable] ; 2249 tmpin[itable]->setCoordInfo( coordinfo ) ; 2250 } 2251 2252 // Create additional table if needed 2253 bool oldInsitu = insitu_ ; 2254 setInsitu( false ) ; 2255 vector< vector<uInt> > addrow( insize ) ; 2256 vector<uInt> addtable( insize, 0 ) ; 2257 vector<uInt> newtableids( insize ) ; 2258 vector<uInt> newifids( insize, 0 ) ; 2259 for ( uInt itable = 0 ; itable < insize ; itable++ ) { 2260 //cout << "Table " << setw(2) << itable << ": " ; 2261 for ( uInt ifrow = 0 ; ifrow < groups[itable].size() ; ifrow++ ) { 2262 addrow[itable].push_back( groups[itable][ifrow].size()-1 ) ; 2263 //cout << addrow[itable][ifrow] << " " ; 2264 } 2265 addtable[itable] = *max_element( addrow[itable].begin(), addrow[itable].end() ) ; 2266 //cout << "(" << addtable[itable] << ")" << endl ; 2267 } 2268 newin.resize( insize ) ; 2269 copy( tmpin.begin(), tmpin.end(), newin.begin() ) ; 2270 for ( uInt i = 0 ; i < insize ; i++ ) { 2271 newtableids[i] = i ; 2272 } 2273 for ( uInt itable = 0 ; itable < insize ; itable++ ) { 2274 for ( uInt iadd = 0 ; iadd < addtable[itable] ; iadd++ ) { 2275 CountedPtr<Scantable> add = getScantable( newin[itable], false ) ; 2276 vector<int> freqidlist ; 2277 for ( uInt i = 0 ; i < groups[itable].size() ; i++ ) { 2278 if ( groups[itable][i].size() > iadd + 1 ) { 2279 freqidlist.push_back( freqid[itable][i] ) ; 2280 } 2281 } 2282 stringstream taqlstream ; 2283 taqlstream << "SELECT FROM $1 WHERE FREQ_ID IN [" ; 2284 for ( uInt i = 0 ; i < freqidlist.size() ; i++ ) { 2285 taqlstream << i ; 2286 if ( i < freqidlist.size() - 1 ) 2287 taqlstream << "," ; 2288 else 2289 taqlstream << "]" ; 2290 } 2291 string taql = taqlstream.str() ; 2292 //cout << "taql = " << taql << endl ; 2293 STSelector selector = STSelector() ; 2294 selector.setTaQL( taql ) ; 2295 add->setSelection( selector ) ; 2296 newin.push_back( add ) ; 2297 newtableids.push_back( itable ) ; 2298 newifids.push_back( iadd + 1 ) ; 2299 } 2300 } 2301 2302 // udpate ifgrp 2303 for ( uInt itable = 0 ; itable < insize ; itable++ ) { 2304 for ( uInt iadd = 0 ; iadd < addtable[itable] ; iadd++ ) { 2305 for ( uInt ifrow = 0 ; ifrow < groups[itable].size() ; ifrow++ ) { 2306 if ( groups[itable][ifrow].size() > iadd + 1 ) { 2307 uInt igrp = groups[itable][ifrow][iadd+1] ; 2308 for ( uInt imem = 0 ; imem < ifgrp[igrp].size()/2 ; imem++ ) { 2309 if ( ifgrp[igrp][2*imem] == newtableids[iadd+insize] && ifgrp[igrp][2*imem+1] == freqid[newtableids[iadd+insize]][ifrow] ) { 2310 ifgrp[igrp][2*imem] = insize + iadd ; 2311 } 2312 } 2313 } 2314 } 2315 } 2316 } 2317 2318 // print IF groups again for debug 2319 //cout << "IF Group summary: " << endl ; 2320 //cout << " GROUP_ID [FREQ_MIN, FREQ_MAX]: (TABLE_ID, FREQ_ID)" << endl ; 2321 //for ( uInt i = 0 ; i < ifgrp.size() ; i++ ) { 2322 //cout << " GROUP " << setw( 2 ) << i << " [" << ifgfreq[2*i] << "," << ifgfreq[2*i+1] << "]: " ; 2323 //for ( uInt j = 0 ; j < ifgrp[i].size()/2 ; j++ ) { 2324 //cout << "(" << ifgrp[i][2*j] << "," << ifgrp[i][2*j+1] << ") " ; 2325 //} 2326 //cout << endl ; 2327 //} 2328 //cout << endl ; 2329 2330 // reset SCANNO and IF: IF number is reset by the result of sortation 2331 cout << "All scan number is set to 0" << endl ; 2332 //cout << "All IF number is set to IF group index" << endl ; 2333 cout << endl ; 2334 insize = newin.size() ; 2335 for ( uInt itable = 0 ; itable < insize ; itable++ ) { 2336 uInt rows = newin[itable]->nrow() ; 2337 Table &tmpt = newin[itable]->table() ; 2338 freqIDCol.attach( tmpt, "FREQ_ID" ) ; 2339 scannoCol.attach( tmpt, "SCANNO" ) ; 2340 ifnoCol.attach( tmpt, "IFNO" ) ; 2341 for ( uInt irow=0 ; irow < rows ; irow++ ) { 2342 scannoCol.put( irow, 0 ) ; 2343 uInt freqID = freqIDCol( irow ) ; 2344 vector<uInt>::iterator iter = find( freqid[newtableids[itable]].begin(), freqid[newtableids[itable]].end(), freqID ) ; 2345 if ( iter != freqid[newtableids[itable]].end() ) { 2346 uInt index = distance( freqid[newtableids[itable]].begin(), iter ) ; 2347 ifnoCol.put( irow, groups[newtableids[itable]][index][newifids[itable]] ) ; 2348 } 2349 else { 2350 throw(AipsError("IF grouping was wrong in additional tables.")) ; 2351 } 2352 } 2353 } 2354 oldinfo.resize( insize ) ; 2355 setInsitu( oldInsitu ) ; 2356 2357 // temporarily set coordinfo 2358 for ( uInt itable = 0 ; itable < insize ; itable++ ) { 2359 vector<string> coordinfo = newin[itable]->getCoordInfo() ; 2360 oldinfo[itable] = coordinfo[0] ; 2361 coordinfo[0] = "Hz" ; 2362 newin[itable]->setCoordInfo( coordinfo ) ; 2363 } 2364 2365 // save column values in the vector 2366 vector< vector<uInt> > freqTableIdVec( insize ) ; 2367 vector< vector<uInt> > freqIdVec( insize ) ; 2368 vector< vector<uInt> > ifNoVec( insize ) ; 2369 for ( uInt itable = 0 ; itable < insize ; itable++ ) { 2370 ScalarColumn<uInt> freqIDs ; 2371 freqIDs.attach( newin[itable]->frequencies().table(), "ID" ) ; 2372 ifnoCol.attach( newin[itable]->table(), "IFNO" ) ; 2373 freqIDCol.attach( newin[itable]->table(), "FREQ_ID" ) ; 2374 for ( uInt irow = 0 ; irow < newin[itable]->frequencies().table().nrow() ; irow++ ) { 2375 freqTableIdVec[itable].push_back( freqIDs( irow ) ) ; 2376 } 2377 for ( uInt irow = 0 ; irow < newin[itable]->table().nrow() ; irow++ ) { 2378 freqIdVec[itable].push_back( freqIDCol( irow ) ) ; 2379 ifNoVec[itable].push_back( ifnoCol( irow ) ) ; 2380 } 2381 } 2382 2383 // reset spectra and flagtra: pick up common part of frequency coverage 2384 //cout << "Pick common frequency range and align resolution" << endl ; 2385 for ( uInt itable = 0 ; itable < insize ; itable++ ) { 2386 uInt rows = newin[itable]->nrow() ; 2387 int nminchan = -1 ; 2388 int nmaxchan = -1 ; 2389 vector<uInt> freqIdUpdate ; 2390 for ( uInt irow = 0 ; irow < rows ; irow++ ) { 2391 uInt ifno = ifNoVec[itable][irow] ; // IFNO is reset by group index 2392 double minfreq = ifgfreq[2*ifno] ; 2393 double maxfreq = ifgfreq[2*ifno+1] ; 2394 //cout << "frequency range: [" << minfreq << "," << maxfreq << "]" << endl ; 2395 vector<double> abcissa = newin[itable]->getAbcissa( irow ) ; 2396 int nchan = abcissa.size() ; 2397 double resol = abcissa[1] - abcissa[0] ; 2398 //cout << "abcissa range : [" << abcissa[0] << "," << abcissa[nchan-1] << "]" << endl ; 2399 if ( minfreq <= abcissa[0] ) 2400 nminchan = 0 ; 2401 else { 2402 //double cfreq = ( minfreq - abcissa[0] ) / resol ; 2403 double cfreq = ( minfreq - abcissa[0] + 0.5 * resol ) / resol ; 2404 nminchan = int(cfreq) + ( ( cfreq - int(cfreq) <= 0.5 ) ? 0 : 1 ) ; 2405 } 2406 if ( maxfreq >= abcissa[abcissa.size()-1] ) 2407 nmaxchan = abcissa.size() - 1 ; 2408 else { 2409 //double cfreq = ( abcissa[abcissa.size()-1] - maxfreq ) / resol ; 2410 double cfreq = ( abcissa[abcissa.size()-1] - maxfreq + 0.5 * resol ) / resol ; 2411 nmaxchan = abcissa.size() - 1 - int(cfreq) - ( ( cfreq - int(cfreq) >= 0.5 ) ? 1 : 0 ) ; 2412 } 2413 //cout << "channel range (" << irow << "): [" << nminchan << "," << nmaxchan << "]" << endl ; 2414 if ( nmaxchan > nminchan ) { 2415 newin[itable]->reshapeSpectrum( nminchan, nmaxchan, irow ) ; 2416 int newchan = nmaxchan - nminchan + 1 ; 2417 if ( count( freqIdUpdate.begin(), freqIdUpdate.end(), freqIdVec[itable][irow] ) == 0 && newchan < nchan ) 2418 freqIdUpdate.push_back( freqIdVec[itable][irow] ) ; 2419 } 2420 else { 2421 throw(AipsError("Failed to pick up common part of frequency range.")) ; 2422 } 2423 } 2424 for ( uInt i = 0 ; i < freqIdUpdate.size() ; i++ ) { 2425 uInt freqId = freqIdUpdate[i] ; 2426 Double refpix ; 2427 Double refval ; 2428 Double increment ; 2429 2430 // update row 2431 newin[itable]->frequencies().getEntry( refpix, refval, increment, freqId ) ; 2432 refval = refval - ( refpix - nminchan ) * increment ; 2433 refpix = 0 ; 2434 newin[itable]->frequencies().setEntry( refpix, refval, increment, freqId ) ; 2435 } 2436 } 2437 2438 2439 // reset spectra and flagtra: align spectral resolution 2440 //cout << "Align spectral resolution" << endl ; 2441 vector<double> gmaxdnu( freqgrp.size(), 0.0 ) ; 2442 vector<uInt> gmemid( freqgrp.size(), 0 ) ; 2443 for ( uInt igrp = 0 ; igrp < ifgrp.size() ; igrp++ ) { 2444 double maxdnu = 0.0 ; // maximum (coarsest) frequency resolution 2445 int minchan = INT_MAX ; // minimum channel number 2446 Double refpixref = -1 ; // reference of 'reference pixel' 2447 Double refvalref = -1 ; // reference of 'reference frequency' 2448 Double refinc = -1 ; // reference frequency resolution 2449 uInt refreqid ; 2450 uInt reftable = INT_MAX; 2451 // process only if group member > 1 2452 if ( ifgrp[igrp].size() > 2 ) { 2453 // find minchan and maxdnu in each group 2454 for ( uInt imem = 0 ; imem < ifgrp[igrp].size()/2 ; imem++ ) { 2455 uInt tableid = ifgrp[igrp][2*imem] ; 2456 uInt rowid = ifgrp[igrp][2*imem+1] ; 2457 vector<uInt>::iterator iter = find( freqIdVec[tableid].begin(), freqIdVec[tableid].end(), rowid ) ; 2458 if ( iter != freqIdVec[tableid].end() ) { 2459 uInt index = distance( freqIdVec[tableid].begin(), iter ) ; 2460 vector<double> abcissa = newin[tableid]->getAbcissa( index ) ; 2461 int nchan = abcissa.size() ; 2462 double dnu = abcissa[1] - abcissa[0] ; 2463 //cout << "GROUP " << igrp << " (" << tableid << "," << rowid << "): nchan = " << nchan << " (minchan = " << minchan << ")" << endl ; 2464 if ( nchan < minchan ) { 2465 minchan = nchan ; 2466 maxdnu = dnu ; 2467 newin[tableid]->frequencies().getEntry( refpixref, refvalref, refinc, rowid ) ; 2468 refreqid = rowid ; 2469 reftable = tableid ; 2470 } 2471 } 2472 } 2473 // regrid spectra in each group 2474 cout << "GROUP " << igrp << endl ; 2475 cout << " Channel number is adjusted to " << minchan << endl ; 2476 cout << " Corresponding frequency resolution is " << maxdnu << "Hz" << endl ; 2477 for ( uInt imem = 0 ; imem < ifgrp[igrp].size()/2 ; imem++ ) { 2478 uInt tableid = ifgrp[igrp][2*imem] ; 2479 uInt rowid = ifgrp[igrp][2*imem+1] ; 2480 freqIDCol.attach( newin[tableid]->table(), "FREQ_ID" ) ; 2481 //cout << "tableid = " << tableid << " rowid = " << rowid << ": " << endl ; 2482 //cout << " regridChannel applied to " ; 2483 if ( tableid != reftable ) 2484 refreqid = newin[tableid]->frequencies().addEntry( refpixref, refvalref, refinc ) ; 2485 for ( uInt irow = 0 ; irow < newin[tableid]->table().nrow() ; irow++ ) { 2486 uInt tfreqid = freqIdVec[tableid][irow] ; 2487 if ( tfreqid == rowid ) { 2488 //cout << irow << " " ; 2489 newin[tableid]->regridChannel( minchan, maxdnu, irow ) ; 2490 freqIDCol.put( irow, refreqid ) ; 2491 freqIdVec[tableid][irow] = refreqid ; 2492 } 2493 } 2494 //cout << endl ; 2495 } 2496 } 2497 else { 2498 uInt tableid = ifgrp[igrp][0] ; 2499 uInt rowid = ifgrp[igrp][1] ; 2500 vector<uInt>::iterator iter = find( freqIdVec[tableid].begin(), freqIdVec[tableid].end(), rowid ) ; 2501 if ( iter != freqIdVec[tableid].end() ) { 2502 uInt index = distance( freqIdVec[tableid].begin(), iter ) ; 2503 vector<double> abcissa = newin[tableid]->getAbcissa( index ) ; 2504 minchan = abcissa.size() ; 2505 maxdnu = abcissa[1] - abcissa[0] ; 2506 } 2507 } 2508 for ( uInt i = 0 ; i < freqgrp.size() ; i++ ) { 2509 if ( count( freqgrp[i].begin(), freqgrp[i].end(), igrp ) > 0 ) { 2510 if ( maxdnu > gmaxdnu[i] ) { 2511 gmaxdnu[i] = maxdnu ; 2512 gmemid[i] = igrp ; 2513 } 2514 break ; 2515 } 2516 } 2517 } 2518 cout << endl ; 2519 2520 // set back coordinfo 2521 for ( uInt itable = 0 ; itable < insize ; itable++ ) { 2522 vector<string> coordinfo = newin[itable]->getCoordInfo() ; 2523 coordinfo[0] = oldinfo[itable] ; 2524 newin[itable]->setCoordInfo( coordinfo ) ; 2525 } 2526 2527 // accumulate all rows into the first table 2528 // NOTE: assumed in.size() = 1 2529 vector< CountedPtr<Scantable> > tmp( 1 ) ; 2530 if ( newin.size() == 1 ) 2531 tmp[0] = newin[0] ; 2532 else 2533 tmp[0] = merge( newin ) ; 2534 2535 //return tmp[0] ; 2536 2537 // average 2538 CountedPtr<Scantable> tmpout = average( tmp, mask, weight, avmode ) ; 2539 2540 //return tmpout ; 2541 2542 // combine frequency group 2543 cout << "Combine spectra based on frequency grouping" << endl ; 2544 cout << "IFNO is renumbered as frequency group ID (see above)" << endl ; 2545 vector<string> coordinfo = tmpout->getCoordInfo() ; 2546 oldinfo[0] = coordinfo[0] ; 2547 coordinfo[0] = "Hz" ; 2548 tmpout->setCoordInfo( coordinfo ) ; 2549 // create proformas of output table 2550 stringstream taqlstream ; 2551 taqlstream << "SELECT FROM $1 WHERE IFNO IN [" ; 2552 for ( uInt i = 0 ; i < gmemid.size() ; i++ ) { 2553 taqlstream << gmemid[i] ; 2554 if ( i < gmemid.size() - 1 ) 2555 taqlstream << "," ; 2556 else 2557 taqlstream << "]" ; 2558 } 2559 string taql = taqlstream.str() ; 2560 //cout << "taql = " << taql << endl ; 2561 STSelector selector = STSelector() ; 2562 selector.setTaQL( taql ) ; 2563 oldInsitu = insitu_ ; 2564 setInsitu( false ) ; 2565 out = getScantable( tmpout, false ) ; 2566 setInsitu( oldInsitu ) ; 2567 out->setSelection( selector ) ; 2568 // regrid rows 2569 ifnoCol.attach( tmpout->table(), "IFNO" ) ; 2570 for ( uInt irow = 0 ; irow < tmpout->table().nrow() ; irow++ ) { 2571 uInt ifno = ifnoCol( irow ) ; 2572 for ( uInt igrp = 0 ; igrp < freqgrp.size() ; igrp++ ) { 2573 if ( count( freqgrp[igrp].begin(), freqgrp[igrp].end(), ifno ) > 0 ) { 2574 vector<double> abcissa = tmpout->getAbcissa( irow ) ; 2575 double bw = ( abcissa[1] - abcissa[0] ) * abcissa.size() ; 2576 int nchan = (int)( bw / gmaxdnu[igrp] ) ; 2577 tmpout->regridChannel( nchan, gmaxdnu[igrp], irow ) ; 2578 break ; 2579 } 2580 } 2581 } 2582 // combine spectra 2583 ArrayColumn<Float> specColOut ; 2584 specColOut.attach( out->table(), "SPECTRA" ) ; 2585 ArrayColumn<uChar> flagColOut ; 2586 flagColOut.attach( out->table(), "FLAGTRA" ) ; 2587 ScalarColumn<uInt> ifnoColOut ; 2588 ifnoColOut.attach( out->table(), "IFNO" ) ; 2589 ScalarColumn<uInt> polnoColOut ; 2590 polnoColOut.attach( out->table(), "POLNO" ) ; 2591 ScalarColumn<uInt> freqidColOut ; 2592 freqidColOut.attach( out->table(), "FREQ_ID" ) ; 2593 Table &tab = tmpout->table() ; 2594 TableIterator iter( tab, "POLNO" ) ; 2595 vector< vector<uInt> > sizes( freqgrp.size() ) ; 2596 while( !iter.pastEnd() ) { 2597 vector< vector<Float> > specout( freqgrp.size() ) ; 2598 vector< vector<uChar> > flagout( freqgrp.size() ) ; 2599 ArrayColumn<Float> specCols ; 2600 specCols.attach( iter.table(), "SPECTRA" ) ; 2601 ArrayColumn<uChar> flagCols ; 2602 flagCols.attach( iter.table(), "FLAGTRA" ) ; 2603 ifnoCol.attach( iter.table(), "IFNO" ) ; 2604 ScalarColumn<uInt> polnos ; 2605 polnos.attach( iter.table(), "POLNO" ) ; 2606 uInt polno = polnos( 0 ) ; 2607 //cout << "POLNO iteration: " << polno << endl ; 2608 for ( uInt igrp = 0 ; igrp < freqgrp.size() ; igrp++ ) { 2609 sizes[igrp].resize( freqgrp[igrp].size() ) ; 2610 for ( uInt imem = 0 ; imem < freqgrp[igrp].size() ; imem++ ) { 2611 for ( uInt irow = 0 ; irow < iter.table().nrow() ; irow++ ) { 2612 uInt ifno = ifnoCol( irow ) ; 2613 if ( ifno == freqgrp[igrp][imem] ) { 2614 Vector<Float> spec = specCols( irow ) ; 2615 Vector<uChar> flag = flagCols( irow ) ; 2616 vector<Float> svec ; 2617 spec.tovector( svec ) ; 2618 vector<uChar> fvec ; 2619 flag.tovector( fvec ) ; 2620 //cout << "spec.size() = " << svec.size() << " fvec.size() = " << fvec.size() << endl ; 2621 specout[igrp].insert( specout[igrp].end(), svec.begin(), svec.end() ) ; 2622 flagout[igrp].insert( flagout[igrp].end(), fvec.begin(), fvec.end() ) ; 2623 //cout << "specout[" << igrp << "].size() = " << specout[igrp].size() << endl ; 2624 sizes[igrp][imem] = spec.nelements() ; 2625 } 2626 } 2627 } 2628 for ( uInt irow = 0 ; irow < out->table().nrow() ; irow++ ) { 2629 uInt ifout = ifnoColOut( irow ) ; 2630 uInt polout = polnoColOut( irow ) ; 2631 if ( ifout == gmemid[igrp] && polout == polno ) { 2632 // set SPECTRA and FRAGTRA 2633 Vector<Float> newspec( specout[igrp] ) ; 2634 Vector<uChar> newflag( flagout[igrp] ) ; 2635 specColOut.put( irow, newspec ) ; 2636 flagColOut.put( irow, newflag ) ; 2637 // IFNO renumbering 2638 ifnoColOut.put( irow, igrp ) ; 2639 } 2640 } 2641 } 2642 iter++ ; 2643 } 2644 // update FREQUENCIES subtable 2645 vector<bool> updated( freqgrp.size(), false ) ; 2646 for ( uInt igrp = 0 ; igrp < freqgrp.size() ; igrp++ ) { 2647 uInt index = 0 ; 2648 uInt pixShift = 0 ; 2649 while ( freqgrp[igrp][index] != gmemid[igrp] ) { 2650 pixShift += sizes[igrp][index++] ; 2651 } 2652 for ( uInt irow = 0 ; irow < out->table().nrow() ; irow++ ) { 2653 if ( ifnoColOut( irow ) == gmemid[igrp] && !updated[igrp] ) { 2654 uInt freqidOut = freqidColOut( irow ) ; 2655 //cout << "freqgrp " << igrp << " freqidOut = " << freqidOut << endl ; 2656 double refpix ; 2657 double refval ; 2658 double increm ; 2659 out->frequencies().getEntry( refpix, refval, increm, freqidOut ) ; 2660 refpix += pixShift ; 2661 out->frequencies().setEntry( refpix, refval, increm, freqidOut ) ; 2662 updated[igrp] = true ; 2663 } 2664 } 2665 } 2666 2667 //out = tmpout ; 2668 2669 coordinfo = tmpout->getCoordInfo() ; 2670 coordinfo[0] = oldinfo[0] ; 2671 tmpout->setCoordInfo( coordinfo ) ; 2672 } 2673 else { 2674 // simple average 2675 out = average( in, mask, weight, avmode ) ; 2676 } 2677 2678 return out ; 2679 } -
branches/alma/src/STMath.h
r1388 r1446 65 65 * average a vector of Scantables 66 66 * @param in the vector of Scantables to average 67 * @param maskan optional mask to apply on specific weights67 * @param an optional mask to apply on specific weights 68 68 * @param weight weighting scheme 69 69 * @param avmode the mode ov averaging. Per "SCAN" or "ALL". … … 134 134 /** 135 135 * Calibrate total power scans (translated from GBTIDL) 136 * @param calon uncalibrated Scantable with CAL noise signal 136 * @param calon uncalibrated Scantable with CAL noise signal 137 137 * @param caloff uncalibrated Scantable with no CAL signal 138 138 * @param tcal optional scalar Tcal, CAL temperature (K) 139 * @return casa::CountedPtr<Scantable> which holds a calibrated Scantable 139 * @return casa::CountedPtr<Scantable> which holds a calibrated Scantable 140 140 * (spectrum - average of the two CAL on and off spectra; 141 141 * tsys - mean Tsys = <caloff>*Tcal/<calon-caloff> + Tcal/2) 142 */ 142 */ 143 143 casa::CountedPtr<Scantable> dototalpower( const casa::CountedPtr<Scantable>& calon, 144 144 const casa::CountedPtr<Scantable>& caloff, … … 151 151 * @param smoothref optional Boxcar smooth width of the reference scans 152 152 * default: no smoothing (=1) 153 * @param tsysv optional scalar Tsys value at the zenith, required to 154 * set tau, as well 153 * @param tsysv optional scalar Tsys value at the zenith, required to 154 * set tau, as well 155 155 * @param tau optional scalar Tau value 156 156 * @return casa::CountedPtr<Scantable> which holds combined scans … … 163 163 casa::Float tau=0.0 ); 164 164 165 /**165 /** 166 166 * Calibrate GBT Nod scan pairs (translated from GBTIDL) 167 167 * @param s Scantable which contains Nod scans … … 170 170 * @param tsysv optional scalar Tsys value at the zenith, required to 171 171 * set tau, as well 172 * @param tau optional scalar Tau value 172 * @param tau optional scalar Tau value 173 173 * @param tcal optional scalar Tcal, CAL temperature (K) 174 174 * @return casa::CountedPtr<Scantable> which holds calibrated scans … … 266 266 double width); 267 267 268 // test for average spectra with different channel/resolution 269 casa::CountedPtr<Scantable> 270 new_average( const std::vector<casa::CountedPtr<Scantable> >& in, 271 const bool& compel, 272 const std::vector<bool>& mask = std::vector<bool>(), 273 const std::string& weight = "NONE", 274 const std::string& avmode = "SCAN" ) 275 throw (casa::AipsError) ; 276 277 268 278 private: 269 279 casa::CountedPtr<Scantable> applyToPol( const casa::CountedPtr<Scantable>& in, -
branches/alma/src/STMathWrapper.h
r1388 r1446 188 188 { return ScantableWrapper(STMath::lagFlag(in.getCP(), frequency, width)); } 189 189 190 // test for average spectra with different channel/resolution 191 ScantableWrapper 192 new_average( const std::vector<ScantableWrapper>& in, 193 const bool& compel, 194 const std::vector<bool>& mask, 195 const std::string& weight, 196 const std::string& avmode ) 197 { 198 std::vector<casa::CountedPtr<Scantable> > sts; 199 for (unsigned int i=0; i<in.size(); ++i) sts.push_back(in[i].getCP()); 200 return ScantableWrapper(STMath::new_average(sts, compel, mask, weight, avmode)); 201 } 202 190 203 }; 191 204 -
branches/alma/src/STMolecules.cpp
r870 r1446 14 14 #include <tables/Tables/SetupNewTab.h> 15 15 #include <tables/Tables/ScaColDesc.h> 16 #include <tables/Tables/ArrColDesc.h> 16 17 #include <tables/Tables/TableRecord.h> 17 18 #include <tables/Tables/TableParse.h> 18 19 #include <tables/Tables/TableRow.h> 19 20 #include <casa/Containers/RecordField.h> 21 22 #include <tables/Tables/TableProxy.h> 20 23 21 24 #include "STMolecules.h" … … 59 62 { 60 63 // add to base class table 61 table_.addColumn(ScalarColumnDesc<Double>("RESTFREQUENCY")); 62 table_.addColumn(ScalarColumnDesc<String>("NAME")); 63 table_.addColumn(ScalarColumnDesc<String>("FORMATTEDNAME")); 64 //table_.addColumn(ScalarColumnDesc<Double>("RESTFREQUENCY")); 65 table_.addColumn(ArrayColumnDesc<Double>("RESTFREQUENCY")); 66 //table_.addColumn(ScalarColumnDesc<String>("NAME")); 67 table_.addColumn(ArrayColumnDesc<String>("NAME")); 68 //table_.addColumn(ScalarColumnDesc<String>("FORMATTEDNAME")); 69 table_.addColumn(ArrayColumnDesc<String>("FORMATTEDNAME")); 64 70 table_.rwKeywordSet().define("UNIT", String("Hz")); 65 71 // new cached columns … … 69 75 } 70 76 77 /*** 71 78 uInt STMolecules::addEntry( Double restfreq, const String& name, 72 79 const String& formattedname ) … … 94 101 return resultid; 95 102 } 96 103 ***/ 104 uInt STMolecules::addEntry( Vector<Double> restfreq, const Vector<String>& name, 105 const Vector<String>& formattedname ) 106 { 107 // How to handle this...? 108 Table result = 109 table_( nelements(table_.col("RESTFREQUENCY")) == restfreq.size() && 110 all(table_.col("RESTFREQUENCY")== restfreq) ); 111 uInt resultid = 0; 112 if ( result.nrow() > 0) { 113 ROScalarColumn<uInt> c(result, "ID"); 114 c.get(0, resultid); 115 } else { 116 uInt rno = table_.nrow(); 117 table_.addRow(); 118 // get last assigned _id and increment 119 if ( rno > 0 ) { 120 idCol_.get(rno-1, resultid); 121 resultid++; 122 } 123 restfreqCol_.put(rno, restfreq); 124 nameCol_.put(rno, name); 125 formattednameCol_.put(rno, formattedname); 126 idCol_.put(rno, resultid); 127 } 128 return resultid; 129 } 130 131 132 133 134 /*** 97 135 void STMolecules::getEntry( Double& restfreq, String& name, 98 136 String& formattedname, uInt id ) const … … 104 142 ROTableRow row(t); 105 143 // get first row - there should only be one matching id 144 106 145 const TableRecord& rec = row.get(0); 107 146 restfreq = rec.asDouble("RESTFREQUENCY"); … … 109 148 formattedname = rec.asString("FORMATTEDNAME"); 110 149 } 150 ***/ 151 void STMolecules::getEntry( Vector<Double>& restfreq, Vector<String>& name, 152 Vector<String>& formattedname, uInt id ) const 153 { 154 Table t = table_(table_.col("ID") == Int(id) ); 155 if (t.nrow() == 0 ) { 156 throw(AipsError("STMolecules::getEntry - id out of range")); 157 } 158 ROTableRow row(t); 159 // get first row - there should only be one matching id 160 161 const TableRecord& rec = row.get(0); 162 //restfreq = rec.asDouble("RESTFREQUENCY"); 163 restfreq = rec.asArrayDouble("RESTFREQUENCY"); 164 //name = rec.asString("NAME"); 165 name = rec.asArrayString("NAME"); 166 //formattedname = rec.asString("FORMATTEDNAME"); 167 formattedname = rec.asArrayString("FORMATTEDNAME"); 168 } 111 169 112 170 std::vector< double > asap::STMolecules::getRestFrequencies( ) const 113 171 { 114 172 std::vector<double> out; 173 //TableProxy itsTable(table_); 174 //Record rec; 115 175 Vector<Double> rfs = restfreqCol_.getColumn(); 116 176 rfs.tovector(out); 177 //rec = itsTable.getVarColumn("RESTFREQUENCY", 0, 1, 1); 117 178 return out; 118 179 } 119 180 120 double asap::STMolecules::getRestFrequency( uInt id ) const 121 { 181 std::vector< double > asap::STMolecules::getRestFrequency( uInt id ) const 182 { 183 std::vector<double> out; 122 184 Table t = table_(table_.col("ID") == Int(id) ); 123 185 if (t.nrow() == 0 ) { … … 126 188 ROTableRow row(t); 127 189 const TableRecord& rec = row.get(0); 128 return double(rec.asDouble("RESTFREQUENCY")); 129 } 130 190 //return double(rec.asDouble("RESTFREQUENCY")); 191 Vector<Double> rfs = rec.asArrayDouble("RESTFREQUENCY"); 192 rfs.tovector(out); 193 return out; 194 } 195 196 int asap::STMolecules::nrow() const 197 { 198 return int(table_.nrow()); 199 } 131 200 132 201 }//namespace -
branches/alma/src/STMolecules.h
r1353 r1446 17 17 #include <tables/Tables/Table.h> 18 18 #include <tables/Tables/ScalarColumn.h> 19 #include <tables/Tables/ArrayColumn.h> 20 #include <casa/Arrays/Array.h> 19 21 20 22 #include "STSubTable.h" … … 37 39 STMolecules& operator=(const STMolecules& other); 38 40 41 /*** 39 42 casa::uInt addEntry( casa::Double restfreq, const casa::String& name="", 40 43 const casa::String& formattedname=""); 44 ***/ 41 45 46 casa::uInt addEntry( casa::Vector<casa::Double> restfreq, const casa::Vector<casa::String>& name=casa::Vector<casa::String>(0), 47 const casa::Vector<casa::String>& formattedname=casa::Vector<casa::String>(0)); 48 49 /*** 42 50 void getEntry( casa::Double& restfreq, casa::String& name, 43 51 casa::String& formattedname, casa::uInt id) const; 52 ***/ 53 void getEntry( casa::Vector<casa::Double>& restfreq, casa::Vector<casa::String>& name, 54 casa::Vector<casa::String>& formattedname, casa::uInt id) const; 44 55 45 56 std::vector<double> getRestFrequencies() const; 46 doublegetRestFrequency( casa::uInt id ) const;57 std::vector<double> getRestFrequency( casa::uInt id ) const; 47 58 const casa::String& name() const { return name_; } 59 int nrow() const; 48 60 49 61 private: … … 52 64 //casa::Table table_; 53 65 //casa::ScalarColumn<casa::uInt> freqidCol_; 54 casa::ScalarColumn<casa::Double> restfreqCol_; 55 casa::ScalarColumn<casa::String> nameCol_; 56 casa::ScalarColumn<casa::String> formattednameCol_; // e.g. latex 66 //casa::ScalarColumn<casa::Double> restfreqCol_; 67 casa::ArrayColumn<casa::Double> restfreqCol_; 68 //casa::ScalarColumn<casa::String> nameCol_; 69 casa::ArrayColumn<casa::String> nameCol_; 70 //casa::ScalarColumn<casa::String> formattednameCol_; // e.g. latex 71 casa::ArrayColumn<casa::String> formattednameCol_; // e.g. latex 57 72 58 73 }; -
branches/alma/src/STWriter.cpp
r1387 r1446 165 165 Table btable = beamit.table(); 166 166 // position only varies by beam 167 // No, we want to pointing data which varies by cycle! 167 168 MDirection::ScalarColumn dirCol(btable, "DIRECTION"); 168 169 Vector<Double> direction = dirCol(0).getAngle("rad").getValue(); … … 181 182 while (!cycit.pastEnd() ) { 182 183 Table ctable = cycit.table(); 184 //MDirection::ScalarColumn dirCol(ctable, "DIRECTION"); 185 //Vector<Double> direction = dirCol(0).getAngle("rad").getValue(); 183 186 TableIterator ifit(ctable, "IFNO"); 184 187 Int ifno = 1; … … 191 194 ifno = rec.asuInt("IFNO")+1; 192 195 uInt nchan = specCol(0).nelements(); 193 Double cdelt,crval,crpix, restfreq; 196 //Double cdelt,crval,crpix, restfreq; 197 Double cdelt,crval,crpix; 198 Vector<Double> restfreq; 194 199 Float focusAxi, focusTan, focusRot, 195 200 temperature, pressure, humidity, windSpeed, windAz; 196 201 Float tmp0,tmp1,tmp2,tmp3,tmp4; 197 202 Vector<Float> tcalval; 198 String stmp0,stmp1, tcalt; 203 //String stmp0,stmp1, tcalt; 204 String tcalt; 205 Vector<String> stmp0, stmp1; 199 206 in->frequencies().getEntry(crpix,crval,cdelt, rec.asuInt("FREQ_ID")); 200 207 in->focus().getEntry(focusAxi, focusTan, focusRot, … … 215 222 Vector<Float> tsys = tsysFromTable(itable); 216 223 // dummy data 224 //uInt npol; 225 //if ( hdr.antennaname == "GBT" ) { 226 // npol = nPolUsed; 227 //} 228 //else { 229 // npol = specs.ncolumn(); 230 //} 217 231 uInt npol = specs.ncolumn(); 218 232 … … 231 245 refFreqNew, nchan*abs(cdelt), cdelt, 232 246 restfreq, 233 tcal ,247 tcalval, 234 248 tcalt, 235 249 rec.asFloat("AZIMUTH"), … … 253 267 } 254 268 ++count; 255 //++ifno;269 ++ifno; 256 270 ++ifit; 257 271 } … … 259 273 ++cycit; 260 274 } 261 //++beamno;275 ++beamno; 262 276 ++beamit; 263 277 } … … 272 286 if ( format_ == "MS2" ) { 273 287 replacePtTab(table, filename); 274 } 288 } 275 289 return 0; 276 290 } -
branches/alma/src/Scantable.cpp
r1400 r1446 11 11 // 12 12 #include <map> 13 #include <fstream> 13 14 14 15 #include <casa/aips.h> … … 24 25 #include <casa/Arrays/Vector.h> 25 26 #include <casa/Arrays/VectorSTLIterator.h> 27 #include <casa/Arrays/Slice.h> 26 28 #include <casa/BasicMath/Math.h> 27 29 #include <casa/BasicSL/Constants.h> … … 533 535 return int(n); 534 536 } else { 535 // take the first SCANNO,POLNO,BEAMNO,CYCLENO as nbeam shouldn't 536 // vary with these 537 // take the first SCANNO,POLNO,BEAMNO,CYCLENO as nbeam shouldn't vary with these 537 538 Table t = table_(table_.col("IFNO") == ifno); 538 539 if ( t.nrow() == 0 ) return 0; … … 786 787 table_.keywordSet().get("FluxUnit", tmp); 787 788 oss << setw(15) << "Flux Unit:" << tmp << endl; 788 Vector<Double> vec(moleculeTable_.getRestFrequencies()); 789 //Vector<Double> vec(moleculeTable_.getRestFrequencies()); 790 int nid = moleculeTable_.nrow(); 791 Bool firstline = True; 789 792 oss << setw(15) << "Rest Freqs:"; 790 if (vec.nelements() > 0) { 791 oss << setprecision(10) << vec << " [Hz]" << endl; 792 } else { 793 oss << "none" << endl; 793 for (int i=0; i<nid; i++) { 794 Table t = table_(table_.col("MOLECULE_ID") == i); 795 if (t.nrow() > 0) { 796 Vector<Double> vec(moleculeTable_.getRestFrequency(i)); 797 if (vec.nelements() > 0) { 798 if (firstline) { 799 oss << setprecision(10) << vec << " [Hz]" << endl; 800 firstline=False; 801 } 802 else{ 803 oss << setw(15)<<" " << setprecision(10) << vec << " [Hz]" << endl; 804 } 805 } else { 806 oss << "none" << endl; 807 } 808 } 794 809 } 795 810 … … 843 858 oss << setw(10) << ""; 844 859 oss << setw(3) << std::right << irec.asuInt("IFNO") << std::left 845 << setw(2) << "" << frequencies().print(irec.asuInt("FREQ_ID")) 846 << endl; 860 << setw(2) << "" << frequencies().print(irec.asuInt("FREQ_ID")); 847 861 848 862 ++iiter; … … 891 905 const MDirection& md = getDirection(whichrow); 892 906 const MEpoch& me = timeCol_(whichrow); 893 Double rf = moleculeTable_.getRestFrequency(mmolidCol_(whichrow)); 907 //Double rf = moleculeTable_.getRestFrequency(mmolidCol_(whichrow)); 908 Vector<Double> rf = moleculeTable_.getRestFrequency(mmolidCol_(whichrow)); 894 909 SpectralCoordinate spc = 895 910 freqTable_.getSpectralCoordinate(md, mp, me, rf, mfreqidCol_(whichrow)); … … 950 965 const MDirection& md = getDirection(whichrow); 951 966 const MEpoch& me = timeCol_(whichrow); 952 const Double& rf = mmolidCol_(whichrow); 967 //const Double& rf = mmolidCol_(whichrow); 968 const Vector<Double> rf = moleculeTable_.getRestFrequency(mmolidCol_(whichrow)); 953 969 SpectralCoordinate spc = 954 970 freqTable_.getSpectralCoordinate(md, mp, me, rf, mfreqidCol_(whichrow)); … … 967 983 } 968 984 969 void Scantable::setRestFrequencies( double rf, const std::string& name, 985 /** 986 void asap::Scantable::setRestFrequencies( double rf, const std::string& name, 970 987 const std::string& unit ) 988 **/ 989 void Scantable::setRestFrequencies( vector<double> rf, const vector<std::string>& name, 990 const std::string& unit ) 991 971 992 { 972 993 ///@todo lookup in line table to fill in name and formattedname 973 994 Unit u(unit); 974 Quantum<Double> urf(rf, u); 975 uInt id = moleculeTable_.addEntry(urf.getValue("Hz"), name, ""); 995 //Quantum<Double> urf(rf, u); 996 Quantum<Vector<Double> >urf(rf, u); 997 Vector<String> formattedname(0); 998 //cerr<<"Scantable::setRestFrequnecies="<<urf<<endl; 999 1000 //uInt id = moleculeTable_.addEntry(urf.getValue("Hz"), name, ""); 1001 uInt id = moleculeTable_.addEntry(urf.getValue("Hz"), mathutil::toVectorString(name), formattedname); 976 1002 TableVector<uInt> tabvec(table_, "MOLECULE_ID"); 977 1003 tabvec = id; 978 1004 } 979 1005 980 void Scantable::setRestFrequencies( const std::string& name ) 1006 /** 1007 void asap::Scantable::setRestFrequencies( const std::string& name ) 981 1008 { 982 1009 throw(AipsError("setRestFrequencies( const std::string& name ) NYI")); 1010 ///@todo implement 1011 } 1012 **/ 1013 void Scantable::setRestFrequencies( const vector<std::string>& name ) 1014 { 1015 throw(AipsError("setRestFrequencies( const vector<std::string>& name ) NYI")); 983 1016 ///@todo implement 984 1017 } … … 1117 1150 } 1118 1151 1119 } 1120 //namespace asap 1152 void asap::Scantable::reshapeSpectrum( int nmin, int nmax ) 1153 throw( casa::AipsError ) 1154 { 1155 // assumed that all rows have same nChan 1156 Vector<Float> arr = specCol_( 0 ) ; 1157 int nChan = arr.nelements() ; 1158 1159 // if nmin < 0 or nmax < 0, nothing to do 1160 if ( nmin < 0 ) { 1161 throw( casa::indexError<int>( nmin, "asap::Scantable::reshapeSpectrum: Invalid range. Negative index is specified." ) ) ; 1162 } 1163 if ( nmax < 0 ) { 1164 throw( casa::indexError<int>( nmax, "asap::Scantable::reshapeSpectrum: Invalid range. Negative index is specified." ) ) ; 1165 } 1166 1167 // if nmin > nmax, exchange values 1168 if ( nmin > nmax ) { 1169 int tmp = nmax ; 1170 nmax = nmin ; 1171 nmin = tmp ; 1172 cout << "Swap values. Applied range is [" 1173 << nmin << ", " << nmax << "]" << endl ; 1174 } 1175 1176 // if nmin exceeds nChan, nothing to do 1177 if ( nmin >= nChan ) { 1178 throw( casa::indexError<int>( nmin, "asap::Scantable::reshapeSpectrum: Invalid range. Specified minimum exceeds nChan." ) ) ; 1179 } 1180 1181 // if nmax exceeds nChan, reset nmax to nChan 1182 if ( nmax >= nChan ) { 1183 if ( nmin == 0 ) { 1184 // nothing to do 1185 cout << "Whole range is selected. Nothing to do." << endl ; 1186 return ; 1187 } 1188 else { 1189 cout << "Specified maximum exceeds nChan. Applied range is [" 1190 << nmin << ", " << nChan-1 << "]." << endl ; 1191 nmax = nChan - 1 ; 1192 } 1193 } 1194 1195 // reshape specCol_ and flagCol_ 1196 for ( int irow = 0 ; irow < nrow() ; irow++ ) { 1197 reshapeSpectrum( nmin, nmax, irow ) ; 1198 } 1199 1200 // update FREQUENCIES subtable 1201 Double refpix ; 1202 Double refval ; 1203 Double increment ; 1204 int freqnrow = freqTable_.table().nrow() ; 1205 Vector<uInt> oldId( freqnrow ) ; 1206 Vector<uInt> newId( freqnrow ) ; 1207 for ( int irow = 0 ; irow < freqnrow ; irow++ ) { 1208 freqTable_.getEntry( refpix, refval, increment, irow ) ; 1209 /*** 1210 * need to shift refpix to nmin 1211 * note that channel nmin in old index will be channel 0 in new one 1212 ***/ 1213 refval = refval - ( refpix - nmin ) * increment ; 1214 refpix = 0 ; 1215 freqTable_.setEntry( refpix, refval, increment, irow ) ; 1216 } 1217 1218 // update nchan 1219 int newsize = nmax - nmin + 1 ; 1220 table_.rwKeywordSet().define( "nChan", newsize ) ; 1221 1222 // update bandwidth 1223 // assumed all spectra in the scantable have same bandwidth 1224 table_.rwKeywordSet().define( "Bandwidth", increment * newsize ) ; 1225 1226 return ; 1227 } 1228 1229 void asap::Scantable::reshapeSpectrum( int nmin, int nmax, int irow ) 1230 { 1231 // reshape specCol_ and flagCol_ 1232 Vector<Float> oldspec = specCol_( irow ) ; 1233 Vector<uChar> oldflag = flagsCol_( irow ) ; 1234 uInt newsize = nmax - nmin + 1 ; 1235 specCol_.put( irow, oldspec( Slice( nmin, newsize, 1 ) ) ) ; 1236 flagsCol_.put( irow, oldflag( Slice( nmin, newsize, 1 ) ) ) ; 1237 1238 return ; 1239 } 1240 1241 void asap::Scantable::regridChannel( int nChan, double dnu ) 1242 { 1243 cout << "Regrid abcissa with channel number " << nChan << " and spectral resoultion " << dnu << "Hz." << endl ; 1244 // assumed that all rows have same nChan 1245 Vector<Float> arr = specCol_( 0 ) ; 1246 int oldsize = arr.nelements() ; 1247 1248 // if oldsize == nChan, nothing to do 1249 if ( oldsize == nChan ) { 1250 cout << "Specified channel number is same as current one. Nothing to do." << endl ; 1251 return ; 1252 } 1253 1254 // if oldChan < nChan, unphysical operation 1255 if ( oldsize < nChan ) { 1256 cout << "Unphysical operation. Nothing to do." << endl ; 1257 return ; 1258 } 1259 1260 // change channel number for specCol_ and flagCol_ 1261 Vector<Float> newspec( nChan, 0 ) ; 1262 Vector<uChar> newflag( nChan, false ) ; 1263 vector<string> coordinfo = getCoordInfo() ; 1264 string oldinfo = coordinfo[0] ; 1265 coordinfo[0] = "Hz" ; 1266 setCoordInfo( coordinfo ) ; 1267 for ( int irow = 0 ; irow < nrow() ; irow++ ) { 1268 regridChannel( nChan, dnu, irow ) ; 1269 } 1270 coordinfo[0] = oldinfo ; 1271 setCoordInfo( coordinfo ) ; 1272 1273 1274 // NOTE: this method does not update metadata such as 1275 // FREQUENCIES subtable, nChan, Bandwidth, etc. 1276 1277 return ; 1278 } 1279 1280 void asap::Scantable::regridChannel( int nChan, double dnu, int irow ) 1281 { 1282 // logging 1283 //ofstream ofs( "average.log", std::ios::out | std::ios::app ) ; 1284 //ofs << "IFNO = " << getIF( irow ) << " irow = " << irow << endl ; 1285 1286 Vector<Float> oldspec = specCol_( irow ) ; 1287 Vector<uChar> oldflag = flagsCol_( irow ) ; 1288 Vector<Float> newspec( nChan, 0 ) ; 1289 Vector<uChar> newflag( nChan, false ) ; 1290 1291 // regrid 1292 vector<double> abcissa = getAbcissa( irow ) ; 1293 int oldsize = abcissa.size() ; 1294 double olddnu = abcissa[1] - abcissa[0] ; 1295 int refChan = 0 ; 1296 double frac = 0.0 ; 1297 double wedge = 0.0 ; 1298 double pile = 0.0 ; 1299 double wsum = 0.0 ; 1300 /*** 1301 * ichan = 0 1302 ***/ 1303 //ofs << "olddnu = " << olddnu << ", dnu = " << dnu << endl ; 1304 pile += dnu ; 1305 wedge = olddnu * ( refChan + 1 ) ; 1306 while ( wedge < pile ) { 1307 newspec[0] += olddnu * oldspec[refChan] ; 1308 newflag[0] = newflag[0] || oldflag[refChan] ; 1309 //ofs << "channel " << refChan << " is included in new channel 0" << endl ; 1310 refChan++ ; 1311 wedge += olddnu ; 1312 wsum += olddnu ; 1313 //ofs << "newspec[0] = " << newspec[0] << " wsum = " << wsum << endl ; 1314 } 1315 frac = ( wedge - pile ) / olddnu ; 1316 wsum += ( 1.0 - frac ) * olddnu ; 1317 newspec[0] += ( 1.0 - frac ) * olddnu * oldspec[refChan] ; 1318 newflag[0] = newflag[0] || oldflag[refChan] ; 1319 //ofs << "channel " << refChan << " is partly included in new channel 0" << " with fraction of " << ( 1.0 - frac ) << endl ; 1320 //ofs << "newspec[0] = " << newspec[0] << " wsum = " << wsum << endl ; 1321 newspec[0] /= wsum ; 1322 //ofs << "newspec[0] = " << newspec[0] << endl ; 1323 //ofs << "wedge = " << wedge << ", pile = " << pile << endl ; 1324 1325 /*** 1326 * ichan = 1 - nChan-2 1327 ***/ 1328 for ( int ichan = 1 ; ichan < nChan - 1 ; ichan++ ) { 1329 pile += dnu ; 1330 newspec[ichan] += frac * olddnu * oldspec[refChan] ; 1331 newflag[ichan] = newflag[ichan] || oldflag[refChan] ; 1332 //ofs << "channel " << refChan << " is partly included in new channel " << ichan << " with fraction of " << frac << endl ; 1333 refChan++ ; 1334 wedge += olddnu ; 1335 wsum = frac * olddnu ; 1336 //ofs << "newspec[" << ichan << "] = " << newspec[ichan] << " wsum = " << wsum << endl ; 1337 while ( wedge < pile ) { 1338 newspec[ichan] += olddnu * oldspec[refChan] ; 1339 newflag[ichan] = newflag[ichan] || oldflag[refChan] ; 1340 //ofs << "channel " << refChan << " is included in new channel " << ichan << endl ; 1341 refChan++ ; 1342 wedge += olddnu ; 1343 wsum += olddnu ; 1344 //ofs << "newspec[" << ichan << "] = " << newspec[ichan] << " wsum = " << wsum << endl ; 1345 } 1346 frac = ( wedge - pile ) / olddnu ; 1347 wsum += ( 1.0 - frac ) * olddnu ; 1348 newspec[ichan] += ( 1.0 - frac ) * olddnu * oldspec[refChan] ; 1349 newflag[ichan] = newflag[ichan] || oldflag[refChan] ; 1350 //ofs << "channel " << refChan << " is partly included in new channel " << ichan << " with fraction of " << ( 1.0 - frac ) << endl ; 1351 //ofs << "wedge = " << wedge << ", pile = " << pile << endl ; 1352 //ofs << "newspec[" << ichan << "] = " << newspec[ichan] << " wsum = " << wsum << endl ; 1353 newspec[ichan] /= wsum ; 1354 //ofs << "newspec[" << ichan << "] = " << newspec[ichan] << endl ; 1355 } 1356 1357 /*** 1358 * ichan = nChan-1 1359 ***/ 1360 // NOTE: Assumed that all spectra have the same bandwidth 1361 pile += dnu ; 1362 newspec[nChan-1] += frac * olddnu * oldspec[refChan] ; 1363 newflag[nChan-1] = newflag[nChan-1] || oldflag[refChan] ; 1364 //ofs << "channel " << refChan << " is partly included in new channel " << nChan-1 << " with fraction of " << frac << endl ; 1365 refChan++ ; 1366 wedge += olddnu ; 1367 wsum = frac * olddnu ; 1368 //ofs << "newspec[" << nChan - 1 << "] = " << newspec[nChan-1] << " wsum = " << wsum << endl ; 1369 for ( int jchan = refChan ; jchan < oldsize ; jchan++ ) { 1370 newspec[nChan-1] += olddnu * oldspec[jchan] ; 1371 newflag[nChan-1] = newflag[nChan-1] || oldflag[jchan] ; 1372 wsum += olddnu ; 1373 //ofs << "channel " << jchan << " is included in new channel " << nChan-1 << " with fraction of " << frac << endl ; 1374 //ofs << "newspec[" << nChan - 1 << "] = " << newspec[nChan-1] << " wsum = " << wsum << endl ; 1375 } 1376 //ofs << "wedge = " << wedge << ", pile = " << pile << endl ; 1377 //ofs << "newspec[" << nChan - 1 << "] = " << newspec[nChan-1] << " wsum = " << wsum << endl ; 1378 newspec[nChan-1] /= wsum ; 1379 //ofs << "newspec[" << nChan - 1 << "] = " << newspec[nChan-1] << endl ; 1380 1381 specCol_.put( irow, newspec ) ; 1382 flagsCol_.put( irow, newflag ) ; 1383 1384 // ofs.close() ; 1385 1386 return ; 1387 } 1388 1389 } 1390 //namespace asap -
branches/alma/src/Scantable.h
r1400 r1446 22 22 #include <casa/Utilities/CountedPtr.h> 23 23 24 #include <casa/Exceptions/Error.h> 25 24 26 #include <coordinates/Coordinates/SpectralCoordinate.h> 25 27 … … 29 31 30 32 #include <measures/TableMeasures/ScalarMeasColumn.h> 33 34 #include <casa/Arrays/Vector.h> 35 #include <casa/Quanta/Quantum.h> 31 36 32 37 #include "Logger.h" … … 167 172 168 173 /** 169 * get the direction type as a string, e.g. "J2000"174 * get the direction as a string 170 175 * @param[in] whichrow the row number 171 176 * return the direction string … … 277 282 std::vector<uint> getScanNos() { return getNumbers(scanCol_); } 278 283 int getScan(int whichrow) const { return scanCol_(whichrow); } 284 285 //TT addition 286 std::vector<uint> getMolNos() {return getNumbers(mmolidCol_); } 279 287 280 288 /** … … 352 360 std::vector<double> getRestFrequencies() const 353 361 { return moleculeTable_.getRestFrequencies(); } 354 362 std::vector<double> getRestFrequency(int id) const 363 { return moleculeTable_.getRestFrequency(id); } 364 365 /** 355 366 void setRestFrequencies(double rf, const std::string& name = "", 356 367 const std::string& = "Hz"); 357 void setRestFrequencies(const std::string& name); 368 **/ 369 // Modified by Takeshi Nakazato 05/09/2008 370 /*** 371 void setRestFrequencies(vector<double> rf, const vector<std::string>& name = "", 372 const std::string& = "Hz"); 373 ***/ 374 void setRestFrequencies(vector<double> rf, 375 const vector<std::string>& name = vector<std::string>(1,""), 376 const std::string& = "Hz"); 377 378 //void setRestFrequencies(const std::string& name); 379 void setRestFrequencies(const vector<std::string>& name); 358 380 359 381 void shift(int npix); … … 393 415 * against the information found in GBT_GO table for 394 416 * scan number orders to get correct pairs. 395 * @param[in] scan list 396 * @return status 417 * @param[in] scan list 418 * @return status 397 419 */ 398 420 int checkScanInfo(const std::vector<int>& scanlist) const; 399 421 400 422 /** 401 * Get the direction as a vector, for a specific row 423 * Get the direction as a vector, for a specific row 402 424 * @param[in] whichrow the row numbyyer 403 * @return the direction in a vector 425 * @return the direction in a vector 404 426 */ 405 427 std::vector<double> getDirectionVector(int whichrow) const; 406 428 429 /** 430 * Reshape spectrum 431 * @param[in] nmin, nmax minimum and maximum channel 432 * @param[in] irow row number 433 * 434 * 30/07/2008 Takeshi Nakazato 435 **/ 436 void reshapeSpectrum( int nmin, int nmax ) throw( casa::AipsError ); 437 void reshapeSpectrum( int nmin, int nmax, int irow ) ; 438 439 /** 440 * Change channel number under fixed bandwidth 441 * @param[in] nchan, dnu new channel number and spectral resolution 442 * @param[in] irow row number 443 * 444 * 27/08/2008 Takeshi Nakazato 445 **/ 446 void regridChannel( int nchan, double dnu ) ; 447 void regridChannel( int nchan, double dnu, int irow ) ; 448 407 449 private: 408 450 -
branches/alma/src/ScantableWrapper.h
r1400 r1446 133 133 std::vector<uint> getScanNos() { return table_->getScanNos(); } 134 134 int getScan(int whichrow) const {return table_->getScan(whichrow);} 135 std::vector<uint> getMolNos() { return table_->getMolNos();} 135 136 136 137 STSelector getSelection() const { return table_->getSelection(); } … … 157 158 { table_->shift(npix); } 158 159 160 /** 161 commented out by TT 159 162 void setRestFrequencies(double rf, const std::string& name, 160 163 const std::string& unit) 161 164 { table_->setRestFrequencies(rf, name, unit); } 165 **/ 166 void setRestFrequencies(vector<double> rf, const vector<std::string>& name, 167 const std::string& unit) 168 { table_->setRestFrequencies(rf, name, unit); } 169 162 170 /* 163 171 void setRestFrequencies(const std::string& name) { … … 166 174 */ 167 175 176 /* 168 177 std::vector<double> getRestFrequencies() const 169 178 { return table_->getRestFrequencies(); } 179 */ 180 std::vector<double> getRestFrequency(int id) const 181 { return table_->getRestFrequency(id); } 170 182 171 183 void setCoordInfo(std::vector<string> theinfo) { … … 208 220 int checkScanInfo(const vector<int>& scanlist) const 209 221 { return table_->checkScanInfo(scanlist); } 210 222 211 223 std::vector<double> getDirectionVector(int whichrow) const 212 224 { return table_->getDirectionVector(whichrow); } 225 226 void reshapeSpectrum( int nmin, int nmax ) 227 { table_->reshapeSpectrum( nmin, nmax ); } 213 228 214 229 private: -
branches/alma/src/Templates.cpp
r1387 r1446 41 41 template class casa::PtrRep<asap::Scantable>; 42 42 template class casa::SimpleCountedConstPtr<asap::Scantable>; 43 template class casa::SimpleCountedConstPtr<asap::STPol>; 43 44 template class casa::SimpleCountedPtr<asap::Scantable>; 44 45 template class casa::SimpleCountedPtr<asap::STPol>; -
branches/alma/src/python_STMath.cpp
r1387 r1446 73 73 .def("_mx_extract", &STMathWrapper::mxExtract) 74 74 .def("_lag_flag", &STMathWrapper::lagFlag) 75 // testing average spectra with different channel/resolution 76 .def("_new_average", &STMathWrapper::new_average) 75 77 ; 76 78 }; -
branches/alma/src/python_Scantable.cpp
r1387 r1446 58 58 .def("getscannos", &ScantableWrapper::getScanNos) 59 59 .def("getcycle", &ScantableWrapper::getCycle) 60 .def("getmolnos", &ScantableWrapper::getMolNos) 60 61 .def("nif", &ScantableWrapper::nif, 61 62 (boost::python::arg("scanno")=-1) ) … … 107 108 .def("_summary", &ScantableWrapper::summary, 108 109 (boost::python::arg("verbose")=true) ) 109 .def("_getrestfreqs", &ScantableWrapper::getRestFrequencies) 110 //.def("_getrestfreqs", &ScantableWrapper::getRestFrequencies) 111 .def("_getrestfreqs", &ScantableWrapper::getRestFrequency) 110 112 .def("_setrestfreqs", &ScantableWrapper::setRestFrequencies) 111 113 .def("shift_refpix", &ScantableWrapper::shift) … … 123 125 .def("_setsourcetype", &ScantableWrapper::setSourceType) 124 126 .def("_getdirectionvec", &ScantableWrapper::getDirectionVector) 127 .def("_reshape", &ScantableWrapper::reshapeSpectrum, 128 (boost::python::arg("nmin")=-1, 129 boost::python::arg("nmax")=-1) ) 125 130 ; 126 131 };
Note:
See TracChangeset
for help on using the changeset viewer.