LCOV - code coverage report
Current view: top level - synthesis/MeasurementEquations - SideBandSeparator.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 1 1 100.0 %
Date: 2024-11-06 17:42:47 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  * SideBandSeparator.h
       3             :  *
       4             :  *  Created on: 2017/07/19
       5             :  *      Author: kana
       6             :  */
       7             : 
       8             : #ifndef SIDEBANDSEPARATOR_H_
       9             : #define SIDEBANDSEPARATOR_H_
      10             : // STL
      11             : #include <iostream>
      12             : #include <string>
      13             : #include <vector>
      14             : // casacore
      15             : #include <casacore/casa/aips.h>
      16             : #include <casacore/casa/Arrays/Vector.h>
      17             : #include <casacore/casa/Arrays/Matrix.h>
      18             : #include <casacore/casa/Quanta/Quantum.h>
      19             : 
      20             : #include <casacore/coordinates/Coordinates/CoordinateSystem.h>
      21             : #include <casacore/coordinates/Coordinates/DirectionCoordinate.h>
      22             : #include <casacore/coordinates/Coordinates/SpectralCoordinate.h>
      23             : #include <casacore/scimath/Mathematics/FFTServer.h>
      24             : 
      25             : // casa
      26             : #include <imageanalysis/ImageTypedefs.h>
      27             : 
      28             : namespace casa { //# NAMESPACE CASA - BEGIN
      29             : 
      30             : /**
      31             :  * The base class of side band separation algorithm using FFT.
      32             :  * Data model independent functions are defined.
      33             :  * Data model dependent functions should be defined in derived class.
      34             :  **/
      35             : class SideBandSeparatorBase {
      36             : public:
      37             : 
      38             :           /**
      39             :            * @brief The constructor
      40             :            *
      41             :            * @param[in] inputname       A vector of file names of input data
      42             :            *
      43             :            **/
      44             :           SideBandSeparatorBase(const std::vector<std::string>& inputname);
      45             :           /**
      46             :            * @brief The destructor
      47             :            **/
      48             :           virtual ~SideBandSeparatorBase();
      49             : 
      50             :           /**
      51             :            * @brief Set the number of channels shifted in each input data
      52             :            *
      53             :            * @param[in] shift   The number of channels shifted in each input data.
      54             :            * The number of elements must be equal to the number of input data.
      55             :            * @param[in] signal  If true, the @a shift is interpreted as that of
      56             :            * signal sideband. If false, image sideband is assumed.
      57             :            **/
      58             :           void setShift(const std::vector<double> &shift, const bool signal = true);
      59             : 
      60             :           /**
      61             :            * @brief Set rejection limit of solution.
      62             :            *
      63             :            * @param[in] limit   Rejection limit of channels with poor solution.
      64             :            **/
      65             :           void setThreshold(const double limit);
      66             : 
      67             :           /**
      68             :            * @brief Resolve both image and signal sideband when true is set.
      69             :            *
      70             :            * @param[in] flag    if true, both singnal and image sidebands are
      71             :            * solved. If false, sideband suppression is invoked and only signal
      72             :            * sideband is solved.
      73             :            **/
      74             :           void solveBoth(const bool flag) { doboth_ = flag; };
      75             : 
      76             :           /**
      77             :            * @brief Obtain spectra by subtracting the solution of the other sideband.
      78             :            *
      79             :            * This is an experimental feature to investigate the algorithm.
      80             :            *
      81             :            * @param[in] flag    if false, the solution of its own sideband is adopted.
      82             :            * if true, the solution is obtained for the other sideband and subtracted
      83             :            * from an average of observed spectrum.
      84             :            **/
      85             :           void solvefromOther(const bool flag) { otherside_ = flag; };
      86             : 
      87             :           /**
      88             :           * @brief invoke sideband separation
      89             :           *
      90             :           * The function should be defined in derived class.
      91             :           *
      92             :           * @param[in] outfile  the prefix of output file names.
      93             :           * Suffixes which indicates sideband, i.e., 'signalband' and 'imageband',
      94             :           * are added to @a outfile .
      95             :           * @param[in] overwrite        if true overwrite existing output files.
      96             :           * if false, an error is raised if an output file already exists.
      97             :           **/
      98             :           virtual void separate(const std::string& outfile, const bool overwrite) = 0;
      99             : 
     100             : protected:
     101             :           /** Initialize member variables **/
     102             :           void init();
     103             :           void initshift();
     104             : 
     105             :           void setInput(const std::vector<std::string>& inputname);
     106             : 
     107             :           /** Return if the path exists (optionally, check file type) **/
     108             :           casacore::Bool checkFile(const std::string name, std::string type="");
     109             : 
     110             :           casacore::Vector<float> solve(const casacore::Matrix<float> &specMat,
     111             :                               const std::vector<casacore::uInt> &inIdvec,
     112             :                               const bool signal = true);
     113             : 
     114             :           casacore::Vector<bool> collapseMask(const casacore::Matrix<bool> &flagMat,
     115             :                                     const std::vector<casacore::uInt> &inIdvec,
     116             :                                     const bool signal = true);
     117             :           void shiftSpectrum(const casacore::Vector<float> &invec, double shift,
     118             :                              casacore::Vector<float> &outvec);
     119             : 
     120             :           void shiftFlag(const casacore::Vector<bool> &invec, double shift,
     121             :                              casacore::Vector<bool> &outvec);
     122             : 
     123             :           void deconvolve(casacore::Matrix<float> &specmat, const std::vector<double> shiftvec,
     124             :                           const double threshold, casacore::Matrix<float> &outmat);
     125             : 
     126             :           void aggregateMat(const casacore::Matrix<float> &inmat, std::vector<float> &outvec);
     127             : 
     128             :           void subtractFromOther(const casacore::Matrix<float> &shiftmat,
     129             :                                  const std::vector<float> &invec,
     130             :                                  const std::vector<double> &shift,
     131             :                                  std::vector<float> &outvec);
     132             :           ////
     133             :           size_t setupShift();
     134             : 
     135             :           /*
     136             :            * Interpolate masked spectrum channels
     137             :            * In-place interpolation is performed to elements with mask being false.
     138             :            * This function interpolates masked channels in the following rules.
     139             :            * o nearest interpolation for edge channels
     140             :            * o linear interpolation for intermediate masked ranges
     141             :            *
     142             :            * @param[inout] spectrum an 1-D array to be interpolated (in-place).
     143             :            * the number of elements should be equal to that of @a mask.
     144             :            * @param[in] mask an 1-D mask array. the elements in spectrum is valid
     145             :            * when corresponding elements in mask is true.
     146             :            * the number of elements should be equal to that of @a spectrum.
     147             :            *
     148             :            * the function returns false if no valid channel (mask is all false)
     149             :            */
     150             :           bool interpolateMaskedChannels(casacore::Array<float> spectrum,
     151             :                           const casacore::Array<bool> maskp);
     152             : 
     153             :           /** Member variables **/
     154             :           // name of images
     155             :           std::vector<std::string> inputNames_;
     156             :           // frequency and direction setup to select data.
     157             :           std::vector<double> sigShift_, imgShift_;
     158             :           unsigned int nshift_, nchan_;
     159             :           // solution parameters
     160             :           bool otherside_, doboth_;
     161             :           double rejlimit_;
     162             : 
     163             :           casacore::FFTServer<casacore::Float, casacore::Complex> fftsf, fftsi;
     164             : 
     165             : 
     166             : }; // SideBandSeparatorBase
     167             : 
     168             : /**
     169             :  * Data model dependent side band separator class.
     170             :  * Input: CASA image
     171             :  * Output : CASA image
     172             :  **/
     173             : class SideBandSeparatorII : public SideBandSeparatorBase {
     174             : public:
     175             :           /**
     176             :            * @brief The constructor
     177             :            *
     178             :            * @param[in] inputname       A vector of file names of input data
     179             :            *
     180             :            **/
     181             :           SideBandSeparatorII(const std::vector<std::string>& imagename);
     182             :           /**
     183             :            * @brief The destructor
     184             :            **/
     185          56 :           virtual ~SideBandSeparatorII(){};
     186             : 
     187             :           /**
     188             :           * @brief invoke sideband separation
     189             :           *
     190             :           * @param[in] outfile  the prefix of output file names.
     191             :           * Suffixes which indicates sideband, i.e., 'signalband' and 'imageband',
     192             :           * are added to @a outfile .
     193             :           * @param[in] overwrite        if true overwrite existing output files.
     194             :           * if false, an error is raised if an output file already exists.
     195             :           **/
     196             :           virtual void separate(const std::string& outfile, const bool overwrite);
     197             : 
     198             :           /**
     199             :            * @brief set frequency information of output image in image sideband
     200             :            *
     201             :            * @param[in] refpix  reference channel of image sideband
     202             :            * @param[in' refval  frequency in reference channel
     203             :            **/
     204             :           void setImageBandFrequency(const double refpix, const casacore::Quantity refval);
     205             : 
     206             :           //protected:
     207             : private:
     208             :           void initLocal();
     209             :           void checkImage();
     210             : 
     211             :           bool getImageCoordinate(const string& imagename, casacore::CoordinateSystem &csys, casacore::IPosition &npix);
     212             :           bool compareImageAxes(const string& imagename, const casacore::CoordinateSystem &refcsys, const casacore::IPosition &refnpix);
     213             :           bool getSpectraToSolve(const std::vector<casa::SPIIF> &images, const casacore::Slicer &slicer,
     214             :                           casacore::Matrix<float>& specMat, casacore::Matrix<bool>& maskMat, std::vector<casacore::uInt>& imgIdvec);
     215             :           double refFreqPix_, refFreqHz_;
     216             : 
     217             : };
     218             : 
     219             : 
     220             : } //# NAMESPACE CASA - END
     221             : #endif /* SIDEBANDSEPARATOR_H_ */

Generated by: LCOV version 1.16