LCOV - code coverage report
Current view: top level - msvis/MSVis - ViFrequencySelection.h (source / functions) Hit Total Coverage
Test: ctest_coverage.info Lines: 0 14 0.0 %
Date: 2023-11-02 14:27:30 Functions: 0 7 0.0 %

          Line data    Source code
       1             : //# ViFrequencySelection.h: Step through the MeasurementEquation by visibility
       2             : //# Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003
       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 addressed 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             : //# $Id: ViFrequencySelection.h,v 19.14 2006/02/28 04:48:58 mvoronko Exp $
      27             : 
      28             : #if ! defined (MSVIS_ViFrequencySelection_H_121116_1101)
      29             : #define MSVIS_ViFrequencySelection_H_121116_1101
      30             : 
      31             : #include <casacore/casa/aips.h>
      32             : #include <casacore/casa/BasicSL.h>
      33             : #include <casacore/casa/Arrays/Slicer.h>
      34             : #include <casacore/measures/Measures/MFrequency.h>
      35             : 
      36             : #include <memory>
      37             : #include <set>
      38             : #include <vector>
      39             : 
      40             : using std::set;
      41             : using std::vector;
      42             : 
      43             : namespace casacore{
      44             : 
      45             : class MeasurementSet;
      46             : class MSSelection;
      47             : }
      48             : 
      49             : namespace casa { //# NAMESPACE CASA - BEGIN
      50             : 
      51             : 
      52             : namespace vi {
      53             : 
      54             : ///////////////////////////////////////////////////////////////////
      55             : //
      56             : //  FrequencySelection class
      57             : //
      58             : // A frequency selection is a way to select the channels of interest from the
      59             : // data in a single MeasurementSet.  The user will provide one or more selections
      60             : // for the casacore::MS; each selection effectively specify the desired channel data in a
      61             : // specified spectral window.  If the user uses the FrequencySelectionChannel
      62             : // class then the selection simply selects a range of channels.  The other derived
      63             : // class is FrequencySelectionReferential which specifies a range of frequencies
      64             : // in a specified frame of reference (e.g., LSRK).  Unlike the other first method,
      65             : // the frame-related selection will not necessarily select the same channels across
      66             : // the entire MS.
      67             : //
      68             : // The frame of reference will either be one defined in the casacore::MFrequency::Types enum
      69             : // or one of the special "frames" defined in this class.
      70             : 
      71             : class FrequencySelection {
      72             : 
      73             : public:
      74             : 
      75             :     typedef enum {Unknown = -11, ByChannel = -10} SpecialFrames;
      76             : 
      77           0 :     virtual ~FrequencySelection (){}
      78             : 
      79             :     void addCorrelationSlices (const casacore::Vector <casacore::Vector <casacore::Slice> > & slices);
      80             :     virtual FrequencySelection * clone () const = 0;
      81             :     virtual casacore::Bool empty () const = 0;
      82             :     void filterByWindow (casacore::Int windowId = -1) const;
      83             :     casacore::Vector <casacore::Slice> getCorrelationSlices (casacore::Int polarizationId) const;
      84             :     casacore::Int getFrameOfReference () const;
      85             :     virtual set<int> getSelectedWindows () const = 0;
      86             :     virtual casacore::String toString () const = 0;
      87             : 
      88             :     static casacore::String frameName (casacore::Int referenceFrame);
      89             : 
      90             : //**********************************************************************
      91             : // Internal methods below this line
      92             : //**********************************************************************
      93             : 
      94             : protected:
      95             : 
      96           0 :     FrequencySelection (casacore::Int referenceFrame)
      97           0 :     : filterWindowId_p (-1),
      98           0 :       referenceFrame_p (referenceFrame) {}
      99             :     casacore::Int filterWindow() const;
     100             : 
     101             : private:
     102             : 
     103             :     casacore::Vector <casacore::Vector <casacore::Slice> > correlationSlices_p; // outer index is polarization id
     104             :     mutable casacore::Int filterWindowId_p;
     105             :     casacore::Int referenceFrame_p;
     106             : };
     107             : 
     108             : ///////////////////////////////////////////////////////////////////
     109             : //
     110             : // FrequencySelectionUsingFrame class
     111             : //
     112             : // Selects sets of channels from a single MS.  The selection is created
     113             : // by specifying a sequence of frame-related frequencies in a single MS.
     114             : // By adding multiple selections, the user can select any arbitrary collecton
     115             : // of channels.  The frequencies are related to the specified frame of reference
     116             : // and the actual selected can be a function of time as the telescope moves through
     117             : // space.
     118             : 
     119             : class FrequencySelectionUsingFrame : public FrequencySelection {
     120             : 
     121             : public:
     122             : 
     123             :     class Element {
     124             :     public:
     125             : 
     126           0 :         Element (casacore::Int spectralWindow = -1, double beginFrequency = 0,
     127             :                  double endFrequency = 0, double increment = 0)
     128           0 :         : beginFrequency_p (beginFrequency),
     129             :           endFrequency_p (endFrequency),
     130             :           increment_p (increment),
     131           0 :           spectralWindow_p (spectralWindow)
     132           0 :           {}
     133             : 
     134             :         double getBeginFrequency () const;
     135             :         double getEndFrequency () const;
     136             :                 std::pair<int, int> getChannelRange (const casacore::MeasurementSet * ms) const;
     137             :         int getSpectralWindow () const;
     138             : 
     139             :     private:
     140             : 
     141             :         friend class FrequencySelectionUsingFrame;
     142             : 
     143             :         double beginFrequency_p;
     144             :         double endFrequency_p;
     145             :         double increment_p;
     146             :         int spectralWindow_p;
     147             :     };
     148             : 
     149             :     typedef std::vector<Element> Elements;
     150             :     typedef Elements::const_iterator const_iterator;
     151             : 
     152             :     FrequencySelectionUsingFrame (casacore::MFrequency::Types frameOfReference);
     153             : 
     154             :     void add (casacore::Int spectralWindow, double bottomFrequency, double topFrequency);
     155             :     //void add (casacore::Int spectralWindow, double bottomFrequency, double topFrequency, double increment);
     156             :     const_iterator begin () const;
     157             :     FrequencySelection * clone () const;
     158             :     casacore::Bool empty () const;
     159             :     const_iterator end () const;
     160             :     set<int> getSelectedWindows () const;
     161             :     casacore::String toString () const;
     162             :     ///This will return a map where the key is the spw and the pair is the pair (nchan, start) for that spw
     163             :         std::map<int, std::pair<int, int>  > getChannelRange (const casacore::MeasurementSet& ms) const;
     164             :         
     165             : private:
     166             : 
     167             :     Elements elements_p;
     168             :     mutable Elements filtered_p;
     169             : };
     170             : 
     171             : class SpectralWindowChannels;
     172             : 
     173             : ///////////////////////////////////////////////////////////////////
     174             : //
     175             : // FrequencySelectionUsingChannels class
     176             : //
     177             : // Selects sets of channels from a single MS.  The selection is created
     178             : // by specifying a sequence of channels in a single MS.  By adding multiple
     179             : // selections, the user can select any arbitrary collecton of channels.
     180             : //
     181             : // The order of the "add" operations are unimportant.
     182             : //
     183             : // Imaging finds it convenient to double specify the frequency ranges, first
     184             : // using an MSSelection object and later with a series of frequency ranges.
     185             : // The intent is that only channels which match up with both criteria should
     186             : // be a part of the VisBuffer.  To accomplish this, first create a selection
     187             : // using a FrequencySelectionUsingChannels object (using method "add" with
     188             : // either an MSSelection or a channel range).  When that is complete build
     189             : // up a FrequencySelectionUsingFrequency object to represent the various
     190             : // frequency ranges desired.  Then use FrequencySelectionUsingChannels::refine
     191             : // passing in the FrequencySelectionUsingFrame object created before.  The
     192             : // refinement process will remove any of the originalchannels which are not
     193             : // within the specified frequency bands.  The refinement operation is delayed
     194             : // until the first time selection is actually used (usually after a call to
     195             : // VisibilityIterator2::origin.
     196             : 
     197             : class FrequencySelectionUsingChannels : public FrequencySelection {
     198             : 
     199             : public:
     200             : 
     201             :     class Element {
     202             :     public:
     203             : 
     204           0 :         Element (casacore::Int spectralWindow = -1, casacore::Int firstChannel = -1, casacore::Int nChannels = -1, casacore::Int increment = 1)
     205           0 :         : firstChannel_p (firstChannel),
     206             :           increment_p (increment),
     207             :           nChannels_p (nChannels),
     208           0 :           spectralWindow_p (spectralWindow)
     209           0 :         {}
     210             : 
     211           0 :         casacore::Slice getSlice () const { return casacore::Slice (firstChannel_p, nChannels_p, increment_p);}
     212             : 
     213             :         casacore::Int firstChannel_p;
     214             :         casacore::Int increment_p;
     215             :         casacore::Int nChannels_p;
     216             :         casacore::Int spectralWindow_p;
     217             :     };
     218             : 
     219             :     typedef std::vector<Element> Elements;
     220             :     typedef Elements::const_iterator const_iterator;
     221             : 
     222           0 :     FrequencySelectionUsingChannels () : FrequencySelection (ByChannel){}
     223             :     FrequencySelectionUsingChannels (const FrequencySelectionUsingChannels & other);
     224             : 
     225             :     void add (casacore::Int spectralWindow, casacore::Int firstChannel, casacore::Int nChannels,
     226             :               casacore::Int increment = 1);
     227             :     void add (const casacore::MSSelection & msSelection, const casacore::MeasurementSet * ms);
     228             :     void applyRefinement (std::function <casacore::Slice (int, double, double)>) const;
     229             :     const_iterator begin () const;
     230             :     FrequencySelection * clone () const;
     231             :     casacore::Bool empty () const;
     232             :     const_iterator end () const;
     233             :     casacore::Int getNChannels (casacore::Int spectralWindowId) const;
     234             :     set<int> getSelectedWindows () const;
     235             :     void refine (const FrequencySelectionUsingFrame & frequencySelection);
     236             :     bool refinementNeeded () const;
     237             :     size_t size () const;
     238             :     casacore::String toString () const;
     239             : 
     240             : //**********************************************************************
     241             : // Internal methods below this line
     242             : //**********************************************************************
     243             : 
     244             : private:
     245             : 
     246             :     mutable Elements elements_p;
     247             :     mutable Elements filtered_p;
     248             :     mutable std::unique_ptr<FrequencySelectionUsingFrame> refinements_p;
     249             : 
     250             : //    std::pair<int, int> getChannelRange (const SpectralWindowChannels & spwChannels,
     251             : //                                         double beginFrequency, double endFrequency);
     252             : 
     253             :     void refineSelection (FrequencySelectionUsingChannels::Element & originalElement,
     254             :                           int firstRefiningChannel, int lastRefiningChannel) const;
     255             : 
     256             : 
     257             : };
     258             : 
     259             : 
     260             : ///////////////////////////////////////////////////////////////////
     261             : //
     262             : //    FrequencySelections class
     263             : //
     264             : //    A FrequenceSelections object is a collection of FrequencySelection objects.
     265             : //    It is intended to allow the user to provide a frequency selection per
     266             : //    casacore::MS when the VisibilityIterator is sweeping multiple MSs.  All selections
     267             : //    included in the collection must have the same frame of reference; an
     268             : //    exception will be thrown when attempting to add a frame with a different
     269             : //    frame of reference.
     270             : 
     271             : class FrequencySelections {
     272             : public:
     273             : 
     274             : 
     275             :     FrequencySelections ();
     276             :     FrequencySelections (const FrequencySelections & other);
     277             :     ~FrequencySelections ();
     278             : 
     279             :     void add (const FrequencySelection & selection);
     280             :     FrequencySelections * clone () const;
     281             :     void filterToSpectralWindow (casacore::Int spectralWindowId);
     282             :     const FrequencySelection & get (casacore::Int msIndex) const;
     283             :     casacore::Int getFrameOfReference () const;
     284             :     casacore::Bool isSpectralWindowSelected (casacore::Int msIndex, casacore::Int spectralWindowId) const;
     285             :     casacore::Int size () const;
     286             : 
     287             : //**********************************************************************
     288             : // Internal methods below this line
     289             : //**********************************************************************
     290             : 
     291             : 
     292             : private:
     293             : 
     294             :     typedef std::set<std::pair<casacore::Int, casacore::Int> > SelectedWindows; // pair=(msIndex,spwId)
     295             : 
     296             :     const FrequencySelectionUsingChannels defaultSelection_p;
     297             :     mutable casacore::Int filterWindow_p;
     298             :     SelectedWindows selectedWindows_p;
     299             : 
     300             :     typedef std::vector<FrequencySelection *> Selections;
     301             :     Selections selections_p;
     302             : };
     303             : 
     304             : 
     305             : 
     306             : } // end namespace vi
     307             : 
     308             : } //# NAMESPACE CASA - END
     309             : 
     310             : #endif // ! defined (MSVIS_ViFrequencySelection_H_121116_1101)
     311             : 

Generated by: LCOV version 1.16