Line data Source code
1 : //# MSUtil.cc: Some MS specific Utilities
2 : //# Copyright (C) 2011
3 : //# Associated Universities, Inc. Washington DC, USA.
4 : //#
5 : //# This library is free software; you can redistribute it and/or modify it
6 : //# under the terms of the GNU Library General Public License as published by
7 : //# the Free Software Foundation; either version 2 of the License, or (at your
8 : //# option) any later version.
9 : //#
10 : //# This library is distributed in the hope that it will be useful, but WITHOUT
11 : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 : //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 : //# License for more details.
14 : //#
15 : //# You should have received a copy of the GNU Library General Public License
16 : //# along with this library; if not, write to the Free Software Foundation,
17 : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 : //#
19 : //# Correspondence concerning AIPS++ should be adressed as follows:
20 : //# Internet email: aips2-request@nrao.edu.
21 : //# Postal address: AIPS++ Project Office
22 : //# National Radio Astronomy Observatory
23 : //# 520 Edgemont Road
24 : //# Charlottesville, VA 22903-2475 USA
25 : //#
26 : //#
27 : //# $Id$
28 : #include <casacore/casa/Utilities/Sort.h>
29 : #include <casacore/measures/Measures/MeasTable.h>
30 : #include <casacore/ms/MeasurementSets/MSColumns.h>
31 : #include <casacore/ms/MSSel/MSSpwIndex.h>
32 : #include <casacore/ms/MSSel/MSDataDescIndex.h>
33 : #include <msvis/MSVis/MSUtil.h>
34 : #include <casacore/casa/Arrays/ArrayMath.h>
35 : #include <casacore/casa/OS/Path.h>
36 : #include <casacore/casa/Utilities/GenSort.h>
37 : #include <iomanip>
38 : using namespace casacore;
39 : namespace casa { //# NAMESPACE CASA - BEGIN
40 :
41 0 : MSUtil::MSUtil(){};
42 7 : void MSUtil::getSpwInFreqRange(Vector<Int>& spw, Vector<Int>& start,
43 : Vector<Int>& nchan,
44 : const MeasurementSet& ms,
45 : const Double freqStart,
46 : const Double freqEnd,
47 : const Double freqStep,
48 : const MFrequency::Types freqframe,
49 : const Int fieldId)
50 : {
51 7 : spw.resize();
52 7 : start.resize();
53 7 : nchan.resize();
54 14 : Vector<Double> t;
55 7 : ScalarColumn<Double> (ms,MS::columnName(MS::TIME)).getColumn(t);
56 : //Vector<Int> ddId;
57 : //Vector<Int> fldId;
58 :
59 14 : MSFieldColumns fieldCol(ms.field());
60 14 : MSDataDescColumns ddCol(ms.dataDescription());
61 14 : MSSpWindowColumns spwCol(ms.spectralWindow());
62 14 : ROScalarMeasColumn<MEpoch> timeCol(ms, MS::columnName(MS::TIME));
63 14 : Vector<uInt> uniqIndx;
64 7 : uInt nTimes=GenSortIndirect<Double>::sort (uniqIndx, t, Sort::Ascending, Sort::QuickSort|Sort::NoDuplicates);
65 :
66 7 : t.resize(0);
67 : //ScalarColumn<Int> (ms,MS::columnName(MS::DATA_DESC_ID)).getColumn(ddId);
68 : //ScalarColumn<Int> (ms,MS::columnName(MS::FIELD_ID)).getColumn(fldId);
69 14 : ScalarColumn<Int> ddId(ms,MS::columnName(MS::DATA_DESC_ID));
70 14 : ScalarColumn<Int> fldId(ms,MS::columnName(MS::FIELD_ID));
71 : //now need to do the conversion to data frame from requested frame
72 : //Get the epoch mesasures of the first row
73 14 : MEpoch ep;
74 7 : timeCol.get(0, ep);
75 14 : String observatory;
76 14 : MPosition obsPos;
77 : /////observatory position
78 14 : MSColumns msc(ms);
79 7 : if (ms.observation().nrow() > 0) {
80 7 : observatory = msc.observation().telescopeName()(msc.observationId()(0));
81 : }
82 14 : if (observatory.length() == 0 ||
83 7 : !MeasTable::Observatory(obsPos,observatory)) {
84 : // unknown observatory, use first antenna
85 0 : obsPos=msc.antenna().positionMeas()(0);
86 : }
87 : //////
88 7 : Int oldDD=ddId(0);
89 7 : Int newDD=oldDD;
90 : //For now we will assume that the field is not moving very far from polynome 0
91 14 : MDirection dir =fieldCol.phaseDirMeas(fieldId);
92 7 : MFrequency::Types obsMFreqType= (MFrequency::Types) (spwCol.measFreqRef()(ddCol.spectralWindowId()(ddId(0))));
93 : //cout << "nTimes " << nTimes << endl;
94 : //cout << " obsframe " << obsMFreqType << " reqFrame " << freqframe << endl;
95 14 : MeasFrame frame(ep, obsPos, dir);
96 : MFrequency::Convert toObs(freqframe,
97 14 : MFrequency::Ref(obsMFreqType, frame));
98 7 : Double freqEndMax=freqEnd;
99 7 : Double freqStartMin=freqStart;
100 7 : if(freqframe != obsMFreqType){
101 7 : freqEndMax=0.0;
102 7 : freqStartMin=C::dbl_max;
103 : }
104 3367 : for (uInt j=0; j< nTimes; ++j){
105 3360 : if(fldId(uniqIndx[j]) ==fieldId){
106 3360 : timeCol.get(uniqIndx[j], ep);
107 3360 : newDD=ddId(uniqIndx[j]);
108 3360 : if(oldDD != newDD){
109 0 : oldDD=newDD;
110 0 : if(spwCol.measFreqRef()(ddCol.spectralWindowId()(newDD)) != obsMFreqType){
111 0 : obsMFreqType= (MFrequency::Types) (spwCol.measFreqRef()(ddCol.spectralWindowId()(newDD)));
112 0 : toObs.setOut(MFrequency::Ref(obsMFreqType, frame));
113 : }
114 : }
115 3360 : if(obsMFreqType != freqframe){
116 3360 : frame.resetEpoch(ep);
117 3360 : Double freqTmp=toObs(Quantity(freqStart, "Hz")).get("Hz").getValue();
118 3360 : freqStartMin=(freqStartMin > freqTmp) ? freqTmp : freqStartMin;
119 3360 : freqTmp=toObs(Quantity(freqEnd, "Hz")).get("Hz").getValue();
120 3360 : freqEndMax=(freqEndMax < freqTmp) ? freqTmp : freqEndMax;
121 : }
122 : }
123 : }
124 :
125 : //cout << "freqStartMin " << freqStartMin << " freqEndMax " << freqEndMax << endl;
126 14 : MSSpwIndex spwIn(ms.spectralWindow());
127 7 : spwIn.matchFrequencyRange(freqStartMin-0.5*freqStep, freqEndMax+0.5*freqStep, spw, start, nchan);
128 :
129 :
130 :
131 7 : }
132 :
133 0 : void MSUtil::getSpwInSourceFreqRange(Vector<Int>& spw, Vector<Int>& start,
134 : Vector<Int>& nchan,
135 : const MeasurementSet& ms,
136 : const Double freqStart,
137 : const Double freqEnd,
138 : const Double freqStep,
139 : const String& ephemtab,
140 : const Int fieldId)
141 : {
142 0 : spw.resize();
143 0 : start.resize();
144 0 : nchan.resize();
145 0 : Vector<Double> t;
146 0 : ScalarColumn<Double> (ms,MS::columnName(MS::TIME)).getColumn(t);
147 : //Vector<Int> ddId;
148 : //Vector<Int> fldId;
149 :
150 0 : MSFieldColumns fieldCol(ms.field());
151 0 : MSDataDescColumns ddCol(ms.dataDescription());
152 0 : MSSpWindowColumns spwCol(ms.spectralWindow());
153 0 : ROScalarMeasColumn<MEpoch> timeCol(ms, MS::columnName(MS::TIME));
154 0 : Vector<uInt> uniqIndx;
155 0 : uInt nTimes=GenSortIndirect<Double>::sort (uniqIndx, t, Sort::Ascending, Sort::QuickSort|Sort::NoDuplicates);
156 :
157 0 : t.resize(0);
158 : //ScalarColumn<Int> (ms,MS::columnName(MS::DATA_DESC_ID)).getColumn(ddId);
159 : //ScalarColumn<Int> (ms,MS::columnName(MS::FIELD_ID)).getColumn(fldId);
160 0 : ScalarColumn<Int> ddId(ms,MS::columnName(MS::DATA_DESC_ID));
161 0 : ScalarColumn<Int> fldId(ms,MS::columnName(MS::FIELD_ID));
162 : //now need to do the conversion to data frame from requested frame
163 : //Get the epoch mesasures of the first row
164 0 : MEpoch ep;
165 0 : timeCol.get(0, ep);
166 0 : String observatory;
167 0 : MPosition obsPos;
168 : /////observatory position
169 0 : MSColumns msc(ms);
170 0 : if (ms.observation().nrow() > 0) {
171 0 : observatory = msc.observation().telescopeName()(msc.observationId()(0));
172 : }
173 0 : if (observatory.length() == 0 ||
174 0 : !MeasTable::Observatory(obsPos,observatory)) {
175 : // unknown observatory, use first antenna
176 0 : obsPos=msc.antenna().positionMeas()(0);
177 : }
178 : //////
179 : // Int oldDD=ddId(0); // unused/commented out below in the oldDD!=newDD if
180 : // Int newDD=oldDD; // unused/commented out below in the oldDD!=newDD if
181 : //For now we will assume that the field is not moving very far from polynome 0
182 0 : MDirection dir =fieldCol.phaseDirMeas(fieldId);
183 0 : MFrequency::Types obsMFreqType= (MFrequency::Types) (spwCol.measFreqRef()(ddCol.spectralWindowId()(ddId(0))));
184 0 : if( obsMFreqType != MFrequency::TOPO)
185 0 : throw(AipsError("No dealing with non topo data for moving source yet"));
186 : //cout << "nTimes " << nTimes << endl;
187 : //cout << " obsframe " << obsMFreqType << " reqFrame " << freqframe << endl;
188 0 : MeasFrame frame(ep, obsPos, dir);
189 : // MFrequency::Convert toObs(freqframe,MFrequency::Ref(obsMFreqType, frame);
190 0 : MDoppler toObs;
191 0 : MDoppler toSource;
192 0 : setupSourceObsVelSystem(ephemtab, ms, fieldId, toSource, toObs,frame);
193 0 : Double freqEndMax=0.0;
194 0 : Double freqStartMin=C::dbl_max;
195 :
196 0 : for (uInt j=0; j< nTimes; ++j){
197 0 : if(fldId(uniqIndx[j]) ==fieldId){
198 0 : timeCol.get(uniqIndx[j], ep);
199 : // newDD=ddId(uniqIndx[j]); // unused below
200 : /*if(oldDD != newDD){
201 : oldDD=newDD;
202 : if(spwCol.measFreqRef()(ddCol.spectralWindowId()(newDD)) != obsMFreqType){
203 : obsMFreqType= (MFrequency::Types) (spwCol.measFreqRef()(ddCol.spectralWindowId()(newDD)));
204 : toObs.setOut(MFrequency::Ref(obsMFreqType, frame));
205 : }
206 : }
207 : */
208 : //if(obsMFreqType != freqframe){
209 0 : frame.resetEpoch(ep);
210 0 : Vector<Double> freqTmp(2);
211 0 : freqTmp[0]=freqStart;
212 0 : freqTmp[1]=freqEnd;
213 0 : Vector<Double> newFreqs=toObs.shiftFrequency(freqTmp);
214 : //Double freqTmp=toObs(Quantity(freqStart, "Hz")).get("Hz").getValue();
215 0 : freqStartMin=(freqStartMin > newFreqs[0]) ? newFreqs[0] : freqStartMin;
216 : //freqTmp=toObs(Quantity(freqEnd, "Hz")).get("Hz").getValue();
217 0 : freqEndMax=(freqEndMax < newFreqs[1]) ? newFreqs[1] : freqEndMax;
218 : //}
219 : }
220 : }
221 :
222 : //cout << "freqStartMin " << freqStartMin << " freqEndMax " << freqEndMax << endl;
223 0 : MSSpwIndex spwIn(ms.spectralWindow());
224 0 : spwIn.matchFrequencyRange(freqStartMin-0.5*freqStep, freqEndMax+0.5*freqStep, spw, start, nchan);
225 :
226 :
227 :
228 0 : }
229 0 : void MSUtil:: setupSourceObsVelSystem(const String& ephemTable, const MeasurementSet& ms, const Int& fieldid, MDoppler& toSource, MDoppler& toObs, MeasFrame& mFrame){
230 0 : String ephemtab("");
231 0 : const MSColumns mscol(ms);
232 0 : if(Table::isReadable(ephemTable)){
233 0 : ephemtab=ephemTable;
234 : }
235 0 : else if(ephemTable=="TRACKFIELD"){
236 0 : ephemtab=(mscol.field()).ephemPath(fieldid);
237 :
238 : }
239 0 : MRadialVelocity::Types refvel=MRadialVelocity::GEO;
240 0 : MEpoch ep(mFrame.epoch());
241 0 : if(ephemtab != ""){
242 :
243 0 : MeasComet mcomet(Path(ephemtab).absoluteName());
244 0 : if(mFrame.comet())
245 0 : mFrame.resetComet(mcomet);
246 : else
247 0 : mFrame.set(mcomet);
248 0 : if(mcomet.getTopo().getLength("km").getValue() > 1.0e-3){
249 0 : refvel=MRadialVelocity::TOPO;
250 : }
251 : ////Will use UT for now for ephem tables as it is not clear that they are being
252 : ///filled with TDB as intended in MeasComet.h
253 0 : MEpoch::Convert toUT(ep, MEpoch::UT);
254 0 : MVRadialVelocity cometvel;
255 0 : mcomet.getRadVel(cometvel, toUT(ep).get("d").getValue());
256 0 : MRadialVelocity::Convert obsvelconv(MRadialVelocity(MVRadialVelocity(0.0),
257 0 : MRadialVelocity::Ref(MRadialVelocity::TOPO, mFrame)), MRadialVelocity::Ref(refvel));
258 0 : toSource=MDoppler(Quantity(-cometvel.get("km/s").getValue("km/s")+obsvelconv().get("km/s").getValue("km/s") , "km/s"), MDoppler::RELATIVISTIC);
259 0 : toObs=MDoppler(Quantity(cometvel.get("km/s").getValue("km/s")-obsvelconv().get("km/s").getValue("km/s") , "km/s"), MDoppler::RELATIVISTIC);
260 :
261 :
262 : }
263 : else{//Must be a DE-200 canned source that measures know
264 0 : ephemtab=upcase(ephemTable);
265 0 : MeasTable::Types mtype=MeasTable::BARYEARTH;
266 : MDirection::Types planettype;
267 0 : if(!MDirection::getType(planettype, ephemtab))
268 0 : throw(AipsError("Did not understand sourcename as a known solar system object"));
269 0 : switch(planettype){
270 0 : case MDirection::MERCURY :
271 0 : mtype=MeasTable::MERCURY;
272 0 : break;
273 0 : case MDirection::VENUS :
274 0 : mtype=MeasTable::VENUS;
275 0 : break;
276 0 : case MDirection::MARS :
277 0 : mtype=MeasTable::MARS;
278 0 : break;
279 0 : case MDirection::JUPITER :
280 0 : mtype=MeasTable::JUPITER;
281 0 : break;
282 0 : case MDirection::SATURN :
283 0 : mtype=MeasTable::SATURN;
284 0 : break;
285 0 : case MDirection::URANUS :
286 0 : mtype=MeasTable::URANUS;
287 0 : break;
288 0 : case MDirection::NEPTUNE :
289 0 : mtype=MeasTable::NEPTUNE;
290 0 : break;
291 0 : case MDirection::PLUTO :
292 0 : mtype=MeasTable::PLUTO;
293 0 : break;
294 0 : case MDirection::MOON :
295 0 : mtype=MeasTable::MOON;
296 0 : break;
297 0 : case MDirection::SUN :
298 0 : mtype=MeasTable::SUN;
299 0 : break;
300 0 : default:
301 0 : throw(AipsError("Cannot translate to known major solar system object"));
302 : }
303 :
304 0 : Vector<Double> planetparam;
305 0 : Vector<Double> earthparam;
306 0 : MEpoch::Convert toTDB(ep, MEpoch::TDB);
307 0 : earthparam=MeasTable::Planetary(MeasTable::EARTH, toTDB(ep).get("d").getValue());
308 0 : planetparam=MeasTable::Planetary(mtype, toTDB(ep).get("d").getValue());
309 : //GEOcentric param
310 0 : planetparam=planetparam-earthparam;
311 0 : Vector<Double> unitdirvec(3);
312 0 : Double dist=sqrt(planetparam(0)*planetparam(0)+planetparam(1)*planetparam(1)+planetparam(2)*planetparam(2));
313 0 : unitdirvec(0)=planetparam(0)/dist;
314 0 : unitdirvec(1)=planetparam(1)/dist;
315 0 : unitdirvec(2)=planetparam(2)/dist;
316 0 : MRadialVelocity::Convert obsvelconv(MRadialVelocity(MVRadialVelocity(0.0),
317 0 : MRadialVelocity::Ref(MRadialVelocity::TOPO, mFrame)), MRadialVelocity::Ref(refvel));
318 0 : Quantity planetradvel(planetparam(3)*unitdirvec(0)+planetparam(4)*unitdirvec(1)+planetparam(5)*unitdirvec(2), "AU/d");
319 0 : toSource=MDoppler(Quantity(-planetradvel.getValue("km/s")+obsvelconv().get("km/s").getValue("km/s") , "km/s"), MDoppler::RELATIVISTIC);
320 0 : toObs=MDoppler(Quantity(planetradvel.getValue("km/s")-obsvelconv().get("km/s").getValue("km/s") , "km/s"), MDoppler::RELATIVISTIC);
321 : }
322 0 : }
323 :
324 :
325 0 : void MSUtil::getSpwInFreqRangeAllFields(Vector<Int>& outspw, Vector<Int>& outstart,
326 : Vector<Int>& outnchan,
327 : const MeasurementSet& ms,
328 : const Double freqStart,
329 : const Double freqEnd,
330 : const Double freqStep,
331 : const MFrequency::Types freqframe){
332 0 : Vector<Int> fldId;
333 0 : ScalarColumn<Int> (ms, MS::columnName (MS::FIELD_ID)).getColumn (fldId);
334 0 : const Int option = Sort::HeapSort | Sort::NoDuplicates;
335 0 : const Sort::Order order = Sort::Ascending;
336 :
337 0 : Int nfields = GenSort<Int>::sort (fldId, order, option);
338 :
339 0 : fldId.resize(nfields, true);
340 0 : outspw.resize();
341 0 : outstart.resize();
342 0 : outnchan.resize();
343 0 : for (Int k=0; k < nfields; ++k){
344 0 : Vector<Int> locspw, locstart, locnchan;
345 0 : MSUtil::getSpwInFreqRange(locspw, locstart, locnchan, ms, freqStart, freqEnd, freqStep, freqframe, fldId[k]);
346 0 : for (Int j=0; j< locspw.shape()(0); ++j ){
347 0 : Bool hasthisspw=false;
348 0 : for (Int i=0; i< outspw.shape()(0); ++i){
349 0 : if(outspw[i]==locspw[j]){
350 0 : hasthisspw=true;
351 0 : if(locstart[j] < outstart[i]){
352 0 : Int endchan=outstart[i]+outnchan[i]-1;
353 0 : outstart[i]=locstart[j];
354 0 : if(endchan < (locstart[j]+ locnchan[j]-1))
355 0 : endchan=locstart[j]+ locnchan[j]-1;
356 0 : outnchan[i]=endchan+outstart[i]+1;
357 : }
358 : }
359 : }
360 0 : if(!hasthisspw){
361 0 : uInt nout=outspw.nelements();
362 0 : outspw.resize(nout+1, true);
363 0 : outnchan.resize(nout+1, true);
364 0 : outstart.resize(nout+1, true);
365 0 : outspw[nout]=locspw[j];
366 0 : outstart[nout]=locstart[j];
367 0 : outnchan[nout]=locnchan[j];
368 :
369 :
370 :
371 : }
372 : }
373 :
374 : }
375 :
376 :
377 0 : }
378 17 : void MSUtil::getChannelRangeFromFreqRange(Int& start,
379 : Int& nchan,
380 : const MeasurementSet& ms,
381 : const Int spw,
382 : const Double freqStart,
383 : const Double freqEnd,
384 : const Double freqStep,
385 : const MFrequency::Types freqframe)
386 : {
387 17 : start=-1;
388 17 : nchan=-1;
389 17 : MSFieldColumns fieldCol(ms.field());
390 17 : MSDataDescColumns ddCol(ms.dataDescription());
391 17 : Vector<Int> dataDescSel=MSDataDescIndex(ms.dataDescription()).matchSpwId(spw);
392 : //cerr << "dataDescSel " << dataDescSel << endl;
393 17 : if(dataDescSel.nelements()==0)
394 0 : return;
395 17 : Vector<Double> t;
396 17 : ScalarColumn<Double> (ms,MS::columnName(MS::TIME)).getColumn(t);
397 17 : Vector<Int> ddId;
398 17 : ScalarColumn<Int> (ms,MS::columnName(MS::DATA_DESC_ID)).getColumn(ddId);
399 17 : MSSpWindowColumns spwCol(ms.spectralWindow());
400 17 : Vector<Double> ddIdD(ddId.shape());
401 17 : convertArray(ddIdD, ddId);
402 17 : ddIdD+= 1.0; //no zero id
403 : //we have to do this as one can have multiple dd for the same time.
404 17 : t*=ddIdD;
405 : //t(fldId != fieldId)=-1.0;
406 17 : Vector<Double> elt;
407 17 : Vector<Int> elindx;
408 : //rejecting the large blocks of same time for all baselines
409 : //this speeds up by a lot GenSort::sort
410 17 : rejectConsecutive(t, elt, elindx);
411 :
412 17 : ROScalarMeasColumn<MEpoch> timeCol(ms, MS::columnName(MS::TIME));
413 17 : Vector<uInt> uniqIndx;
414 17 : uInt nTimes=GenSortIndirect<Double>::sort (uniqIndx, elt, Sort::Ascending, Sort::QuickSort|Sort::NoDuplicates);
415 :
416 17 : t.resize(0);
417 :
418 : //ScalarColumn<Int> ddId(ms,MS::columnName(MS::DATA_DESC_ID));
419 17 : ScalarColumn<Int> fldId(ms,MS::columnName(MS::FIELD_ID));
420 : //now need to do the conversion to data frame from requested frame
421 : //Get the epoch mesasures of the first row
422 17 : MEpoch ep;
423 17 : timeCol.get(0, ep);
424 17 : String observatory;
425 17 : MPosition obsPos;
426 : /////observatory position
427 17 : MSColumns msc(ms);
428 17 : if (ms.observation().nrow() > 0) {
429 17 : observatory = msc.observation().telescopeName()(msc.observationId()(0));
430 : }
431 34 : if (observatory.length() == 0 ||
432 17 : !MeasTable::Observatory(obsPos,observatory)) {
433 : // unknown observatory, use first antenna
434 0 : obsPos=msc.antenna().positionMeas()(0);
435 : }
436 : //////
437 17 : Int oldDD=dataDescSel(0);
438 17 : Int newDD=oldDD;
439 : //For now we will assume that the field is not moving very far from polynome 0
440 17 : MDirection dir =fieldCol.phaseDirMeas(0);
441 17 : MFrequency::Types obsMFreqType= (MFrequency::Types) (spwCol.measFreqRef()(ddCol.spectralWindowId()(dataDescSel(0))));
442 17 : MeasFrame frame(ep, obsPos, dir);
443 : MFrequency::Convert toObs(freqframe,
444 17 : MFrequency::Ref(obsMFreqType, frame));
445 17 : Double freqEndMax=freqEnd+0.5*fabs(freqStep);
446 17 : Double freqStartMin=freqStart-0.5*fabs(freqStep);
447 17 : if(freqframe != obsMFreqType){
448 17 : freqEndMax=0.0;
449 17 : freqStartMin=C::dbl_max;
450 : }
451 8177 : for (uInt j=0; j< nTimes; ++j) {
452 8160 : if(anyEQ(dataDescSel, ddId(elindx[uniqIndx[j]]))){
453 8160 : timeCol.get(elindx[uniqIndx[j]], ep);
454 8160 : newDD=ddId(elindx[uniqIndx[j]]);
455 8160 : if(oldDD != newDD) {
456 :
457 0 : oldDD=newDD;
458 0 : if(spwCol.measFreqRef()(ddCol.spectralWindowId()(newDD)) != obsMFreqType) {
459 0 : obsMFreqType= (MFrequency::Types) (spwCol.measFreqRef()(ddCol.spectralWindowId()(newDD)));
460 0 : toObs.setOut(MFrequency::Ref(obsMFreqType, frame));
461 : }
462 : }
463 8160 : if(obsMFreqType != freqframe) {
464 8160 : dir=fieldCol.phaseDirMeas(fldId(elindx[uniqIndx[j]]));
465 8160 : frame.resetEpoch(ep);
466 8160 : frame.resetDirection(dir);
467 8160 : Double freqTmp=toObs(Quantity(freqStart, "Hz")).get("Hz").getValue();
468 8160 : freqStartMin=(freqStartMin > freqTmp) ? freqTmp : freqStartMin;
469 8160 : freqTmp=toObs(Quantity(freqEnd, "Hz")).get("Hz").getValue();
470 8160 : freqEndMax=(freqEndMax < freqTmp) ? freqTmp : freqEndMax;
471 : }
472 : }
473 : }
474 :
475 :
476 17 : MSSpwIndex spwIn(ms.spectralWindow());
477 17 : Vector<Int> spws;
478 17 : Vector<Int> starts;
479 17 : Vector<Int> nchans;
480 17 : if(!spwIn.matchFrequencyRange(freqStartMin-0.5*freqStep, freqEndMax+0.5*freqStep, spws, starts, nchans)){
481 0 : return;
482 : }
483 34 : for (uInt k=0; k < spws.nelements(); ++k){
484 17 : if(spws[k]==spw){
485 17 : start=starts[k];
486 17 : nchan=nchans[k];
487 : }
488 :
489 : }
490 : }
491 153 : Bool MSUtil::getFreqRangeInSpw( Double& freqStart,
492 : Double& freqEnd, const Vector<Int>& spw, const Vector<Int>& start,
493 : const Vector<Int>& nchan,
494 : const MeasurementSet& ms,
495 : const MFrequency::Types freqframe,
496 : const Int fieldId, const Bool fromEdge){
497 306 : Vector<Int> fields(1, fieldId);
498 153 : return MSUtil::getFreqRangeInSpw( freqStart, freqEnd, spw, start,
499 306 : nchan,ms, freqframe,fields, fromEdge);
500 :
501 :
502 : }
503 1789 : Bool MSUtil::getFreqRangeInSpw( Double& freqStart,
504 : Double& freqEnd, const Vector<Int>& spw, const Vector<Int>& start,
505 : const Vector<Int>& nchan,
506 : const MeasurementSet& ms,
507 : const MFrequency::Types freqframe,
508 : const Bool fromEdge){
509 3578 : Vector<Int> fields(0);
510 1789 : return MSUtil::getFreqRangeInSpw( freqStart, freqEnd, spw, start,
511 3578 : nchan,ms, freqframe,fields, fromEdge, True);
512 :
513 :
514 : }
515 4191 : Bool MSUtil::getFreqRangeInSpw( Double& freqStart,
516 : Double& freqEnd, const Vector<Int>& spw, const Vector<Int>& start,
517 : const Vector<Int>& nchan,
518 : const MeasurementSet& ms,
519 : const MFrequency::Types freqframe,
520 : const Vector<Int>& fieldIds, const Bool fromEdge, const Bool useFieldsInMS){
521 :
522 4191 : Bool retval=False;
523 4191 : freqStart=C::dbl_max;
524 4191 : freqEnd=0.0;
525 8382 : Vector<Double> t;
526 4191 : ScalarColumn<Double> (ms,MS::columnName(MS::TIME)).getColumn(t);
527 8382 : Vector<Int> ddId;
528 8382 : Vector<Int> fldId;
529 4191 : ScalarColumn<Int> (ms,MS::columnName(MS::DATA_DESC_ID)).getColumn(ddId);
530 4191 : ScalarColumn<Int> (ms,MS::columnName(MS::FIELD_ID)).getColumn(fldId);
531 8382 : MSFieldColumns fieldCol(ms.field());
532 8382 : MSDataDescColumns ddCol(ms.dataDescription());
533 8382 : MSSpWindowColumns spwCol(ms.spectralWindow());
534 8382 : ROScalarMeasColumn<MEpoch> timeCol(ms, MS::columnName(MS::TIME));
535 8382 : Vector<Double> ddIdD(ddId.shape());
536 4191 : convertArray(ddIdD, ddId);
537 4191 : ddIdD+= 1.0; //no zero id
538 : //we have to do this as one can have multiple dd for the same time.
539 4191 : t*=ddIdD;
540 : //t(fldId != fieldId)=-1.0;
541 8382 : Vector<Double> elt;
542 8382 : Vector<Int> elindx;
543 : //rejecting the large blocks of same time for all baselines
544 : //this speeds up by a lot GenSort::sort
545 4191 : rejectConsecutive(t, elt, elindx);
546 8382 : Vector<uInt> uniqIndx;
547 :
548 4191 : uInt nTimes=GenSortIndirect<Double>::sort (uniqIndx, elt, Sort::Ascending, Sort::QuickSort|Sort::NoDuplicates);
549 :
550 8382 : MDirection dir;
551 4191 : if(useFieldsInMS)
552 1789 : dir=fieldCol.phaseDirMeas(fldId[0]);
553 : else
554 2402 : dir=fieldCol.phaseDirMeas(fieldIds[0]);
555 8382 : MSDataDescIndex mddin(ms.dataDescription());
556 4191 : MFrequency::Types obsMFreqType= (MFrequency::Types) (spwCol.measFreqRef()(0));
557 8382 : MEpoch ep;
558 4191 : timeCol.get(0, ep);
559 8382 : String observatory;
560 8382 : MPosition obsPos;
561 : /////observatory position
562 8382 : MSColumns msc(ms);
563 4191 : if (ms.observation().nrow() > 0) {
564 4191 : observatory = msc.observation().telescopeName()(msc.observationId()(0));
565 : }
566 8382 : if (observatory.length() == 0 ||
567 4191 : !MeasTable::Observatory(obsPos,observatory)) {
568 : // unknown observatory, use first antenna
569 0 : obsPos=msc.antenna().positionMeas()(0);
570 : }
571 : //////
572 4191 : MeasFrame frame(ep, obsPos, dir);
573 :
574 :
575 8947 : for (uInt ispw =0 ; ispw < spw.nelements() ; ++ispw){
576 4756 : if(nchan[ispw]>0 && start[ispw] >-1){
577 4756 : Double freqStartObs=C::dbl_max;
578 4756 : Double freqEndObs=0.0;
579 9512 : Vector<Double> chanfreq=spwCol.chanFreq()(spw[ispw]);
580 9512 : Vector<Double> chanwid=spwCol.chanWidth()(spw[ispw]);
581 9512 : Vector<Int> ddOfSpw=mddin.matchSpwId(spw[ispw]);
582 175997 : for (Int ichan=start[ispw]; ichan<start[ispw]+nchan[ispw]; ++ichan){
583 171241 : if(fromEdge){
584 107504 : if(freqStartObs > (chanfreq[ichan]-fabs(chanwid[ichan])/2.0)) freqStartObs=chanfreq[ichan]-fabs(chanwid[ichan])/2.0;
585 107504 : if(freqEndObs < (chanfreq[ichan]+fabs(chanwid[ichan])/2.0)) freqEndObs=chanfreq[ichan]+fabs(chanwid[ichan])/2.0;
586 : }
587 : else{
588 63737 : if(freqStartObs > (chanfreq[ichan])) freqStartObs=chanfreq[ichan];
589 63737 : if(freqEndObs < (chanfreq[ichan])) freqEndObs=chanfreq[ichan];
590 : }
591 : }
592 4756 : obsMFreqType= (MFrequency::Types) (spwCol.measFreqRef()(spw[ispw]));
593 4756 : if((obsMFreqType==MFrequency::REST) || (obsMFreqType==freqframe && obsMFreqType != MFrequency::TOPO)){
594 591 : if(freqStart > freqStartObs) freqStart=freqStartObs;
595 591 : if(freqEnd < freqStartObs) freqEnd=freqStartObs;
596 591 : if(freqStart > freqEndObs) freqStart=freqEndObs;
597 591 : if(freqEnd < freqEndObs) freqEnd=freqEndObs;
598 591 : retval=True;
599 : }
600 : else{
601 : MFrequency::Convert toframe(obsMFreqType,
602 8330 : MFrequency::Ref(freqframe, frame));
603 1060551 : for (uInt j=0; j< nTimes; ++j){
604 1056386 : if((useFieldsInMS || anyEQ(fieldIds, fldId[elindx[uniqIndx[j]]])) && anyEQ(ddOfSpw, ddId[elindx[uniqIndx[j]]])){
605 924163 : timeCol.get(elindx[uniqIndx[j]], ep);
606 924163 : dir=fieldCol.phaseDirMeas(fldId[elindx[uniqIndx[j]]]);
607 924163 : frame.resetEpoch(ep);
608 924163 : frame.resetDirection(dir);
609 924163 : Double freqTmp=toframe(Quantity(freqStartObs, "Hz")).get("Hz").getValue();
610 924163 : if(freqStart > freqTmp) freqStart=freqTmp;
611 924163 : if(freqEnd < freqTmp) freqEnd=freqTmp;
612 924163 : freqTmp=toframe(Quantity(freqEndObs, "Hz")).get("Hz").getValue();
613 924163 : if(freqStart > freqTmp) freqStart=freqTmp;
614 924163 : if(freqEnd < freqTmp) freqEnd=freqTmp;
615 924163 : retval=True;
616 : }
617 : }
618 : }
619 : }
620 : }
621 8382 : return retval;
622 : }
623 :
624 :
625 3 : Bool MSUtil::getFreqRangeAndRefFreqShift( Double& freqStart,
626 : Double& freqEnd, Quantity& sysvel, const MEpoch& refEp, const Vector<Int>& spw, const Vector<Int>& start,
627 : const Vector<Int>& nchan,
628 : const MeasurementSet& ms,
629 : const String& ephemPath, const MDirection& trackDir,
630 : const Bool fromEdge){
631 :
632 3 : casacore::MDirection::Types planetType=MDirection::castType(trackDir.getRef().getType());
633 3 : if( (! Table::isReadable(ephemPath)) && ( (planetType <= MDirection::N_Types) || (planetType >= MDirection::COMET)))
634 0 : throw(AipsError("getFreqRange in SOURCE frame has to have a valid ephemeris table or major solar system object defined"));
635 3 : Bool isephem=False;
636 6 : MeasComet mcomet;
637 3 : MeasTable::Types mtype=MeasTable::BARYEARTH;
638 3 : if(Table::isReadable(ephemPath)){
639 3 : mcomet=MeasComet(Path(ephemPath).absoluteName());
640 3 : isephem=True;
641 : }
642 : else{
643 :
644 0 : if(planetType >=MDirection::MERCURY && planetType < MDirection::COMET){
645 : //Damn these enums are not in the same order
646 0 : switch(planetType){
647 0 : case MDirection::MERCURY :
648 0 : mtype=MeasTable::MERCURY;
649 0 : break;
650 0 : case MDirection::VENUS :
651 0 : mtype=MeasTable::VENUS;
652 0 : break;
653 0 : case MDirection::MARS :
654 0 : mtype=MeasTable::MARS;
655 0 : break;
656 0 : case MDirection::JUPITER :
657 0 : mtype=MeasTable::JUPITER;
658 0 : break;
659 0 : case MDirection::SATURN :
660 0 : mtype=MeasTable::SATURN;
661 0 : break;
662 0 : case MDirection::URANUS :
663 0 : mtype=MeasTable::URANUS;
664 0 : break;
665 0 : case MDirection::NEPTUNE :
666 0 : mtype=MeasTable::NEPTUNE;
667 0 : break;
668 0 : case MDirection::PLUTO :
669 0 : mtype=MeasTable::PLUTO;
670 0 : break;
671 0 : case MDirection::MOON :
672 0 : mtype=MeasTable::MOON;
673 0 : break;
674 0 : case MDirection::SUN :
675 0 : mtype=MeasTable::SUN;
676 0 : break;
677 0 : default:
678 0 : throw(AipsError("Cannot translate to known major solar system object"));
679 : }
680 : }
681 :
682 : }
683 :
684 :
685 6 : Vector<Double> planetparam;
686 6 : Vector<Double> earthparam;
687 :
688 :
689 :
690 :
691 :
692 :
693 3 : Bool retval=False;
694 3 : freqStart=C::dbl_max;
695 3 : freqEnd=0.0;
696 6 : Vector<Double> t;
697 3 : ScalarColumn<Double> (ms,MS::columnName(MS::TIME)).getColumn(t);
698 6 : Vector<Int> ddId;
699 6 : Vector<Int> fldId;
700 3 : ScalarColumn<Int> (ms,MS::columnName(MS::DATA_DESC_ID)).getColumn(ddId);
701 3 : ScalarColumn<Int> (ms,MS::columnName(MS::FIELD_ID)).getColumn(fldId);
702 6 : MSFieldColumns fieldCol(ms.field());
703 6 : MSDataDescColumns ddCol(ms.dataDescription());
704 6 : MSSpWindowColumns spwCol(ms.spectralWindow());
705 6 : ROScalarMeasColumn<MEpoch> timeCol(ms, MS::columnName(MS::TIME));
706 6 : Vector<Double> ddIdD(ddId.shape());
707 3 : convertArray(ddIdD, ddId);
708 3 : ddIdD+= 1.0; //no zero id
709 : //we have to do this as one can have multiple dd for the same time.
710 3 : t*=ddIdD;
711 : //t(fldId != fieldId)=-1.0;
712 6 : Vector<Double> elt;
713 6 : Vector<Int> elindx;
714 : //rejecting the large blocks of same time for all baselines
715 : //this speeds up by a lot GenSort::sort
716 3 : rejectConsecutive(t, elt, elindx);
717 6 : Vector<uInt> uniqIndx;
718 :
719 3 : uInt nTimes=GenSortIndirect<Double>::sort (uniqIndx, elt, Sort::Ascending, Sort::QuickSort|Sort::NoDuplicates);
720 :
721 6 : MDirection dir;
722 3 : dir=fieldCol.phaseDirMeas(fldId[0]);
723 6 : MSDataDescIndex mddin(ms.dataDescription());
724 6 : MEpoch ep;
725 3 : timeCol.get(0, ep);
726 6 : String observatory;
727 6 : MPosition obsPos;
728 : /////observatory position
729 6 : MSColumns msc(ms);
730 3 : if (ms.observation().nrow() > 0) {
731 3 : observatory = msc.observation().telescopeName()(msc.observationId()(0));
732 : }
733 6 : if (observatory.length() == 0 ||
734 3 : !MeasTable::Observatory(obsPos,observatory)) {
735 : // unknown observatory, use first antenna
736 0 : obsPos=msc.antenna().positionMeas()(0);
737 : }
738 : //////
739 : //cerr << "obspos " << obsPos << endl;
740 6 : MeasFrame mframe(ep, obsPos, dir);
741 : ////Will use UT for now for ephem tables as it is not clear that they are being
742 : ///filled with TDB as intended in MeasComet.h
743 6 : MEpoch::Convert toUT(ep, MEpoch::UT);
744 6 : MEpoch::Convert toTDB(ep, MEpoch::TDB);
745 3 : MRadialVelocity::Types refvel=MRadialVelocity::GEO;
746 3 : if(isephem){
747 : //cerr << "dist " << mcomet.getTopo().getLength("km") << endl;
748 3 : if(mcomet.getTopo().getLength("km").getValue() > 1.0e-3){
749 0 : refvel=MRadialVelocity::TOPO;
750 : }
751 : }
752 6 : MRadialVelocity::Convert obsvelconv (MRadialVelocity(MVRadialVelocity(0.0),
753 6 : MRadialVelocity::Ref(MRadialVelocity::TOPO, mframe)),
754 9 : MRadialVelocity::Ref(refvel));
755 3 : MVRadialVelocity cometvel;
756 :
757 6 : for (uInt ispw =0 ; ispw < spw.nelements() ; ++ispw){
758 3 : if(nchan[ispw]>0 && start[ispw] >-1){
759 3 : Double freqStartObs=C::dbl_max;
760 3 : Double freqEndObs=0.0;
761 6 : Vector<Double> chanfreq=spwCol.chanFreq()(spw[ispw]);
762 6 : Vector<Double> chanwid=spwCol.chanWidth()(spw[ispw]);
763 6 : Vector<Int> ddOfSpw=mddin.matchSpwId(spw[ispw]);
764 6 : for (Int ichan=start[ispw]; ichan<start[ispw]+nchan[ispw]; ++ichan){
765 3 : if(fromEdge){
766 3 : if(freqStartObs > (chanfreq[ichan]-fabs(chanwid[ichan])/2.0)) freqStartObs=chanfreq[ichan]-fabs(chanwid[ichan])/2.0;
767 3 : if(freqEndObs < (chanfreq[ichan]+fabs(chanwid[ichan])/2.0)) freqEndObs=chanfreq[ichan]+fabs(chanwid[ichan])/2.0;
768 : }
769 : else{
770 0 : if(freqStartObs > (chanfreq[ichan])) freqStartObs=chanfreq[ichan];
771 0 : if(freqEndObs < (chanfreq[ichan])) freqEndObs=chanfreq[ichan];
772 : }
773 : }
774 :
775 3 : MFrequency::Types obsMFreqType= (MFrequency::Types) (spwCol.measFreqRef()(spw[ispw]));
776 3 : if(obsMFreqType==MFrequency::REST)
777 0 : throw(AipsError("cannot do Source frame conversion from REST"));
778 : MFrequency::Convert toTOPO(obsMFreqType,
779 6 : MFrequency::Ref(MFrequency::TOPO, mframe));
780 3 : Double diffepoch=1e37;
781 3 : sysvel=Quantity(0.0,"m/s");
782 :
783 1620 : for (uInt j=0; j< nTimes; ++j){
784 1617 : if(anyEQ(ddOfSpw, ddId[elindx[uniqIndx[j]]])){
785 1617 : timeCol.get(elindx[uniqIndx[j]], ep);
786 1617 : dir=fieldCol.phaseDirMeas(fldId[elindx[uniqIndx[j]]], ep.get("s").getValue());
787 1617 : mframe.resetEpoch(ep);
788 1617 : mframe.resetDirection(dir);
789 1617 : if(obsMFreqType != MFrequency::TOPO){
790 0 : freqStartObs=toTOPO(Quantity(freqStartObs, "Hz")).get("Hz").getValue();
791 0 : freqEndObs=toTOPO(Quantity(freqEndObs, "Hz")).get("Hz").getValue();
792 : }
793 3234 : MDoppler mdop;
794 1617 : if(isephem){
795 1617 : mcomet.getRadVel(cometvel, toUT(ep).get("d").getValue());
796 1617 : mdop=MDoppler(Quantity(-cometvel.get("km/s").getValue("km/s")+obsvelconv().get("km/s").getValue("km/s") , "km/s"), MDoppler::RELATIVISTIC);
797 : // cerr << std::setprecision(10) << toUT(ep).get("d").getValue() << " fieldid " << fldId[elindx[uniqIndx[j]]] << " cometvel " << cometvel.get("km/s").getValue("km/s") << " obsvel " << obsvelconv().get("km/s").getValue("km/s") << endl;
798 : }
799 : else{
800 0 : earthparam=MeasTable::Planetary(MeasTable::EARTH, toTDB(ep).get("d").getValue());
801 0 : planetparam=MeasTable::Planetary(mtype, toTDB(ep).get("d").getValue());
802 : //GEOcentric param
803 0 : planetparam=planetparam-earthparam;
804 0 : Vector<Double> unitdirvec(3);
805 0 : Double dist=sqrt(planetparam(0)*planetparam(0)+planetparam(1)*planetparam(1)+planetparam(2)*planetparam(2));
806 0 : unitdirvec(0)=planetparam(0)/dist;
807 0 : unitdirvec(1)=planetparam(1)/dist;
808 0 : unitdirvec(2)=planetparam(2)/dist;
809 0 : Quantity planetradvel(planetparam(3)*unitdirvec(0)+planetparam(4)*unitdirvec(1)+planetparam(5)*unitdirvec(2), "AU/d");
810 0 : mdop=MDoppler(Quantity(-planetradvel.getValue("km/s")+obsvelconv().get("km/s").getValue("km/s") , "km/s"), MDoppler::RELATIVISTIC);
811 :
812 : }
813 1617 : Vector<Double> range(2); range(0)=freqStartObs; range(1)=freqEndObs;
814 1617 : range=mdop.shiftFrequency(range);
815 1617 : if(diffepoch > fabs(ep.get("s").getValue("s")-refEp.get("s").getValue("s"))){
816 3 : diffepoch= fabs(ep.get("s").getValue("s")-refEp.get("s").getValue("s"));
817 3 : sysvel=mdop.get("km/s");
818 : //cerr << std::setprecision(10) << "shifts " << range(0)-freqStartObs << " " << range(1)-freqEndObs << endl;
819 : }
820 :
821 :
822 1617 : if(freqStart > range[0]) freqStart=range[0];
823 1617 : if(freqEnd < range[0]) freqEnd=range[0];
824 :
825 1617 : if(freqStart > range[1]) freqStart=range[1];
826 1617 : if(freqEnd < range[1]) freqEnd=range[1];
827 1617 : retval=True;
828 : }
829 : }
830 : }
831 :
832 : }
833 6 : return retval;
834 : }
835 4211 : void MSUtil::rejectConsecutive(const Vector<Double>& t, Vector<Double>& retval, Vector<Int>& indx){
836 4211 : uInt n=t.nelements();
837 4211 : if(n >0){
838 4211 : retval.resize(n);
839 4211 : indx.resize(n);
840 4211 : retval[0]=t[0];
841 4211 : indx[0]=0;
842 : }
843 : else
844 0 : return;
845 4211 : Int prev=0;
846 275884482 : for (uInt k=1; k < n; ++k){
847 275880271 : if(t[k] != retval(prev)){
848 1647621 : ++prev;
849 : //retval.resize(prev+1, true);
850 1647621 : retval[prev]=t[k];
851 : //indx.resize(prev+1, true);
852 1647621 : indx[prev]=k;
853 : }
854 : }
855 4211 : retval.resize(prev+1, true);
856 4211 : indx.resize(prev+1, true);
857 :
858 : }
859 :
860 0 : Vector<String> MSUtil::getSpectralFrames(Vector<MFrequency::Types>& types, const MeasurementSet& ms)
861 : {
862 0 : Vector<String> retval;
863 0 : Vector<Int> typesAsInt=MSSpWindowColumns(ms.spectralWindow()).measFreqRef().getColumn();
864 0 : if(ms.nrow()==Table(ms.getPartNames()).nrow()){
865 0 : types.resize(typesAsInt.nelements());
866 0 : for (uInt k=0; k < types.nelements(); ++k)
867 0 : types[k]=MFrequency::castType(typesAsInt[k]);
868 : }
869 : else{
870 0 : Vector<Int> ddId;
871 0 : ScalarColumn<Int> (ms,MS::columnName(MS::DATA_DESC_ID)).getColumn(ddId);
872 0 : Vector<uInt> uniqIndx;
873 0 : uInt nTimes=GenSort<Int>::sort (ddId, Sort::Ascending, Sort::QuickSort|Sort::NoDuplicates);
874 0 : ddId.resize(nTimes, true);
875 0 : Vector<Int> spwids(nTimes);
876 0 : Vector<Int> spwInDD=MSDataDescColumns(ms.dataDescription()).spectralWindowId().getColumn();
877 0 : for (uInt k=0; k < nTimes; ++k)
878 0 : spwids[k]=spwInDD[ddId[k]];
879 :
880 0 : nTimes=GenSort<Int>::sort (spwids, Sort::Ascending, Sort::QuickSort|Sort::NoDuplicates);
881 0 : spwids.resize(nTimes, true);
882 0 : types.resize(nTimes);
883 0 : for(uInt k=0; k <nTimes; ++k)
884 0 : types[k]=MFrequency::castType(typesAsInt[spwids[k]]);
885 : }
886 :
887 0 : retval.resize(types.nelements());
888 0 : for (uInt k=0; k < types.nelements(); ++k){
889 0 : retval[k]=MFrequency::showType(types[k]);
890 : }
891 :
892 :
893 0 : return retval;
894 :
895 : }
896 42 : void MSUtil::getIndexCombination(const MSColumns& mscol, Matrix<Int>& retval2){
897 84 : Vector<Vector<Int> >retval;
898 84 : Vector<Int> state = mscol.stateId().getColumn();
899 84 : Vector<Int> scan=mscol.scanNumber().getColumn();
900 84 : Vector<Double> t=mscol.time().getColumn();
901 84 : Vector<Int> fldid=mscol.fieldId().getColumn();
902 84 : Vector<Int> ddId=mscol.dataDescId().getColumn();
903 84 : Vector<Int> spwid=mscol.dataDescription().spectralWindowId().getColumn();
904 84 : Vector<uInt> uniqIndx;
905 : {
906 84 : Vector<Double> ddIdD(ddId.shape());
907 42 : convertArray(ddIdD, ddId);
908 42 : ddIdD+= 1.0; //no zero id
909 : //we have to do this as one can have multiple dd for the same time.
910 42 : t*=ddIdD;
911 : }
912 42 : uInt nTimes=GenSortIndirect<Double>::sort (uniqIndx, t, Sort::Ascending, Sort::QuickSort|Sort::NoDuplicates);
913 84 : Vector<Int> comb(4);
914 :
915 11733 : for (uInt k=0; k < nTimes; ++k){
916 11691 : comb(0)=fldid[uniqIndx[k]];
917 11691 : comb(1)=spwid[ddId[uniqIndx[k]]];
918 11691 : comb(2)=scan(uniqIndx[k]);
919 11691 : comb(3)=state(uniqIndx[k]);
920 11691 : Bool hasComb=False;
921 11691 : if(retval.nelements() >0){
922 30493 : for (uInt j=0; j < retval.nelements(); ++j){
923 18844 : if(allEQ(retval[j], comb))
924 11579 : hasComb=True;
925 : }
926 :
927 : }
928 11691 : if(!hasComb){
929 112 : retval.resize(retval.nelements()+1, True);
930 112 : retval[retval.nelements()-1]=comb;
931 : }
932 : }
933 42 : retval2.resize(retval.nelements(),4);
934 154 : for (uInt j=0; j < retval.nelements(); ++j)
935 112 : retval2.row(j)=retval[j];
936 :
937 42 : }
938 :
939 :
940 : } //# NAMESPACE CASA - END
|