LCOV - code coverage report
Current view: top level - synthesis/MeasurementComponents - DelayRateFFT.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 24 38 63.2 %
Date: 2025-08-21 08:01:32 Functions: 18 25 72.0 %

          Line data    Source code
       1             : //# DelayRateFFT.h: Declaration of fringe-fitting aux class
       2             : //# Copyright (C) 1996,1997,2000,2001,2002,2003,2011,2016
       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: casa-feedback@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             : 
      28             : namespace casa { //# NAMESPACE CASA - BEGIN
      29             : 
      30             :      class SDBListGridManager {
      31             :      public:
      32             :           casacore::Double fmin_, fmax_, df_;
      33             :           casacore::Double tmin_, tmax_, dt_;
      34             :           std::set< casacore::Int > spwins_;
      35             :           std::set< casacore::Double > times_;
      36             :           casacore::Int nt_;
      37             :      protected:
      38             :           SDBList& sdbs_;
      39             :      public:
      40           0 :           virtual void describe() { std::cerr << "I'm a SDBListGridManager superclass!" << endl; }
      41         225 :           casacore::Int nSPW() { return spwins_.size(); }
      42      125547 :           casacore::Int getTimeIndex(casacore::Double t) {
      43      125547 :                casacore::Int i = round( (t - tmin_)/dt_ );
      44      125547 :                if (i < 0) {
      45           0 :                     cerr << "Index < 0! " << endl;
      46           0 :                     cerr << "t " << t << " tmin_ " << tmin_ << " dt_ " << dt_ << endl;
      47             :                }
      48      125547 :                return i;
      49             :           }
      50         225 :           SDBListGridManager(SDBList& sdbs) :  sdbs_(sdbs) {}
      51             :      };
      52             :      
      53             : // A utility class that provides an API that allows clients to find
      54             : // grid indices in time and frequency from a SBDList that can include
      55             : // multiple spectral windows.
      56             :      class SDBListGridManagerCombo : public SDBListGridManager {
      57             :      public:
      58             :           casacore::Int nchan_;
      59             :      public:
      60             :           std::map< casacore::Int, casacore::Int > spwPMap_; // Maps MS spws to indices in our visibility arrays
      61             :           // You can't store references in a map.
      62             :           // C++ 11 has a reference_wrapper type, but for now:
      63             :           std::map< casacore::Int, casacore::Vector<casacore::Double> const * > pspwIdToFreqMap_;
      64             :      public:
      65             :           SDBListGridManagerCombo(SDBList& sdbs_); 
      66           0 :           void describe() { std::cerr << "I'm a SDBListGridManagerCombo" << endl; }
      67             :           // pspw is the physical spw; the one the SolveDataBuffer returns from ::spectralWindow()
      68             :           // lspw is the logical spw; the one used as an index in the fringe fitter
      69        7128 :           casacore::Int getLSPW(casacore::Int i) { return spwPMap_.find(i)->second; }
      70             :           casacore::Float getRefFreqFromLSPW(casacore::Int lspw);
      71             :      };
      72             : 
      73             : 
      74             :      class SDBListGridManagerConcat : public SDBListGridManager {
      75             :      public:
      76             :           casacore::Double fmin_, fmax_, df_;
      77             :           casacore::Int totalChans_ = 0;
      78             :           std::map<casacore::Int, casacore::Int> chansPerSPW_;
      79             :      private:
      80             :           // You can't store references in a map.
      81             :           // C++ 11 has a reference_wrapper type, but for now:
      82             :           std::map< casacore::Int, casacore::Vector<casacore::Double> const * > spwIdToFreqMap_;
      83             :      public:
      84             :           SDBListGridManagerConcat(SDBList&);
      85      118419 :           casacore::Int bigFreqGridIndex(casacore::Double f) { return round( (f - fmin_)/df_ ); }
      86             :           casacore::Int swStartIndex(casacore::Int);
      87         217 :           casacore::Int nChannels() { return totalChans_;  }
      88         229 :           void setNChans(casacore::Int spw, casacore::Int nchans) {
      89         229 :             chansPerSPW_.insert({spw, nchans});
      90         229 :             }
      91      118419 :           casacore::Int getNChans(casacore::Int spw) {
      92      118419 :             return chansPerSPW_[spw];
      93             :           }
      94           0 :           void describe() { std::cerr << "I'm a SDBListGridManagerConcat" << endl; }
      95             :           void checkAllGridpoints();
      96             :      };
      97             : 
      98             : 
      99             : // DelayRateFFT is responsible for the two-dimensional FFT of
     100             : // visibility phases to find an estimate for deay. rate and phase
     101             : // offset parameters during fringe-fitting.
     102             :      // The idiom used in KJones solvers is:
     103             :      // DelayFFT delfft1(vbga(ibuf), ptbw, refant());
     104             :      // delfft1.FFT();
     105             :      // delfft1.shift(f0[0]);
     106             :      // delfft1.searchPeak();
     107             :      // This class is designed to follow that API (without the shift).
     108             : 
     109             :      class DelayRateFFT {
     110             :      protected:
     111             :           casacore::Double dt_, f0_, df_;
     112             :           casacore::Int nt_;
     113             :           casacore::Int nChan_;
     114             :           casacore::Int refant_;
     115             :           // SBDListGridManager handles all the sizing and interpolating of
     116             :           // multiple spectral windows onto a single frequency grid.
     117             :           casacore::Array<casacore::Double>& delayWindow_;
     118             :           casacore::Array<casacore::Double>& rateWindow_;
     119             :           casacore::Array<casacore::Complex> Vall_;
     120             :           casacore::Array<casacore::Int> xcount_;
     121             :           casacore::Array<casacore::Float> sumw_;
     122             :           casacore::Array<casacore::Float> sumww_;
     123             :           casacore::Array<casacore::Float> peak_;
     124             :           casacore::Int nCorr_;
     125             :           casacore::Int nElem_;
     126             :           std::map< casacore::Int, std::set<casacore::Int> > activeAntennas_;
     127             :           std::set<casacore::Int> allActiveAntennas_;
     128             :           casacore::Matrix<casacore::Float> param_;
     129             :           casacore::Matrix<casacore::Bool> flag_; 
     130             :      public:
     131             :           DelayRateFFT(SDBList& sdbs,
     132             :                        casacore::Int refant,
     133             :                        casacore::Array<casacore::Double>& delayWindow_,
     134             :                        casacore::Array<casacore::Double>& rateWindow_
     135             :                );
     136         225 :           virtual ~DelayRateFFT() {};
     137             :           // Declaring makeAChild static seems to upset the package builder
     138             :           // Meanwhile *not* making it static means that calling it without an object
     139             :           // (which we do) is an error.
     140             :           static DelayRateFFT *makeAChild(int concat, SDBList& sdbs,
     141             :                                           casacore::Int refant,
     142             :                                           casacore::Array<casacore::Double>& delayWindow_,
     143             :                                           casacore::Array<casacore::Double>& rateWindow_);
     144        7974 :           const casacore::Matrix<casacore::Float>& param() { return param_; }
     145        7538 :           casacore::Int refant() const { return refant_; }
     146         225 :           const std::map<casacore::Int, std::set<casacore::Int> >& getActiveAntennas() const
     147         225 :           { return activeAntennas_; }
     148        4268 :           const std::set<casacore::Int>& getActiveAntennasCorrelation(casacore::Int icor) const
     149        4268 :           { return activeAntennas_.find(icor)->second; }
     150             :           void removeAntennasCorrelation(casacore::Int, std::set< casacore::Int >);
     151        7524 :           const casacore::Matrix<casacore::Bool>& flag() const { return flag_; }
     152             :           void printActive();
     153             :           casacore::Matrix<casacore::Float> delay() const;
     154             :           casacore::Matrix<casacore::Float> rate() const;
     155             :           // If I make these NULL then the class is abstract and I can't define a factory
     156             :           // method to generate subclass instances, so I define them (recklessly!) empty
     157             :           // instead
     158           0 :           virtual void FFT() { 
     159           0 :                cerr << "DelayRateFFT::FFT()" << endl;
     160           0 :           } 
     161           0 :           virtual void searchPeak() {
     162           0 :                cerr << "DelayRateFFT::searchPeak()" << endl;
     163           0 :           }
     164           0 :           virtual casacore::Float snr(casacore::Int icorr, casacore::Int ielem, casacore::Float delay,
     165             :                                       casacore::Float rate) {
     166           0 :                cerr << "DelayRateFFTConcat::snr"<< endl;
     167           0 :                return 0.0; }
     168             :      };
     169             : 
     170             :      class DelayRateFFTCombo : public DelayRateFFT {
     171             :      private:
     172             :           SDBListGridManagerCombo gm_;
     173             :           casacore::Int nspw_;
     174             :           casacore::Int nPadFactor_;
     175             :           casacore::Int nPadChan_;
     176             :           casacore::Int nPadT_;
     177             :           // 
     178             :      public:
     179             :           
     180             :           DelayRateFFTCombo(SDBList& sdbs, casacore::Int refant,
     181             :                             casacore::Array<casacore::Double>& delayWindow_,
     182             :                             casacore::Array<casacore::Double>& rateWindow_
     183             :                );
     184             :           DelayRateFFTCombo(casacore::Array<casacore::Complex>& data, 
     185             :                             casacore::Float f0, casacore::Float df, casacore::Float dt, SDBList& s,
     186             :                             casacore::Array<casacore::Double>& delayWindow_,
     187             :                             casacore::Array<casacore::Double>& rateWindow_
     188             :                );
     189          16 :           ~DelayRateFFTCombo() {};
     190             :           void FFT() override;
     191             :           void searchPeak() override;
     192             :           casacore::Float snr(casacore::Int icorr, casacore::Int ielem, casacore::Float delay,
     193             :                               casacore::Float rate) override;
     194             :           const casacore::Array<casacore::Complex>& Vall() const { return Vall_; }
     195             :           std::tuple<casacore::Double, casacore::Double, casacore::Double, casacore::Double>
     196             :                refineSearch(const casacore::Cube<casacore::Complex>&,
     197             :                             const casacore::Vector<casacore::Float>&,
     198             :                             casacore::Double, casacore::Double);
     199             :      }; // End of class DelayRateFFTCombo.
     200             : 
     201             :      
     202             : // DelayRateFFTConcat is responsible for the two-dimensional FFT of
     203             : // visibility phases to find an estimate for deay. rate and phase
     204             : // offset parameters during fringe-fitting.
     205             :      class DelayRateFFTConcat : public DelayRateFFT {
     206             :      private:
     207             :           casacore::Int nPadFactor_;
     208             :           casacore::Int nPadT_;
     209             :           casacore::Int nPadChan_;
     210             :           casacore::Double df_all_;
     211             :           casacore::Array<casacore::Complex> Vpad_;
     212             :           SDBListGridManagerConcat gm_;
     213             :      public:
     214             :           DelayRateFFTConcat(SDBList& sdbs, casacore::Int refant,
     215             :                              casacore::Array<casacore::Double>& delayWindow_,
     216             :                              casacore::Array<casacore::Double>& rateWindow_);
     217             :           DelayRateFFTConcat(casacore::Array<casacore::Complex>& data, casacore::Int nPadFactor,
     218             :                              casacore::Float f0, casacore::Float df, casacore::Float dt, SDBList& s,
     219             :                              casacore::Array<casacore::Double>& delayWindow_,
     220             :                              casacore::Array<casacore::Double>& rateWindow_);
     221         434 :           ~DelayRateFFTConcat() {};
     222             :           casacore::Double get_df_all() { return df_all_; }
     223             :           std::pair<casacore::Bool, casacore::Float> xinterp(casacore::Float alo, casacore::Float amax,
     224             :                                                               casacore::Float ahi);
     225             :           const casacore::Array<casacore::Complex>& Vpad() const { return Vpad_; }
     226             :           void FFT() override;
     227             :           void searchPeak() override;
     228             :           casacore::Float snr(casacore::Int icorr, casacore::Int ielem, casacore::Float delay,
     229             :                               casacore::Float rate) override;
     230             :           
     231             : 
     232             :      }; // End of class DelayRateFFTConcat.
     233             : 
     234             : 
     235             : 
     236             : 
     237             : } //# NAMESPACE CASA - END
     238             : 

Generated by: LCOV version 1.16