LCOV - code coverage report
Current view: top level - imageanalysis/ImageAnalysis - ImageInputProcessor.cc (source / functions) Hit Total Coverage
Test: casa_coverage.info Lines: 7 57 12.3 %
Date: 2023-10-25 08:47:59 Functions: 2 6 33.3 %

          Line data    Source code
       1             : 
       2             : //# Copyright (C) 1998,1999,2000,2001,2003
       3             : //# Associated Universities, Inc. Washington DC, USA.
       4             : //#
       5             : //# This program is free software; you can redistribute it and/or modify it
       6             : //# under the terms of the GNU General Public License as published by the Free
       7             : //# Software Foundation; either version 2 of the License, or (at your option)
       8             : //# any later version.
       9             : //#
      10             : //# This program 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 General Public License for
      13             : //# more details.
      14             : //#
      15             : //# You should have received a copy of the GNU General Public License along
      16             : //# with this program; if not, write to the Free Software Foundation, Inc.,
      17             : //# 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             : 
      27             : #include <imageanalysis/ImageAnalysis/ImageInputProcessor.h>
      28             : 
      29             : #include <casacore/casa/Utilities/Sort.h>
      30             : #include <iostream>
      31             : 
      32             : #include <casacore/images/Images/FITSImage.h>
      33             : #include <casacore/images/Images/ImageUtilities.h>
      34             : #include <casacore/images/Images/MIRIADImage.h>
      35             : #include <casacore/images/Regions/WCBox.h>
      36             : #include <imageanalysis/ImageAnalysis/ImageMetaData.h>
      37             : 
      38             : #include <casacore/measures/Measures/Stokes.h>
      39             : 
      40             : #include <casacore/lattices/LRegions/LCSlicer.h>
      41             : 
      42             : using namespace casacore;
      43             : namespace casa {
      44             : 
      45       29212 : ImageInputProcessor::ImageInputProcessor()
      46       29212 : : _log(new LogIO()), _processHasRun(false),
      47       29212 :   _nSelectedChannels(0)
      48       29212 : {}
      49             : 
      50       58424 : ImageInputProcessor::~ImageInputProcessor() {
      51       29212 :         delete _log;
      52       29212 : }
      53             : 
      54           0 : uInt ImageInputProcessor::nSelectedChannels() const {
      55           0 :         if (! _processHasRun) {
      56           0 :             *_log << LogOrigin("ImageInputProcessor", __func__);
      57           0 :                 *_log << "Programming logic error, ImageInputProcessor::process() must be called "
      58           0 :                         << "before ImageInputProcessor::" << __func__ << "()" << LogIO::EXCEPTION;
      59             :         }
      60           0 :         return _nSelectedChannels;
      61             : }
      62             : 
      63           0 : String ImageInputProcessor::_stokesFromRecord(
      64             :         const Record& region, const CoordinateSystem& csys
      65             : ) const {
      66             :         // FIXME This implementation is incorrect for complex, recursive records
      67           0 :     String stokes = "";
      68           0 :         if(csys.hasPolarizationCoordinate()) {
      69           0 :                 Int polAxis = csys.polarizationAxisNumber();
      70             :                 uInt stokesBegin, stokesEnd;
      71           0 :                 std::unique_ptr<ImageRegion> imreg(ImageRegion::fromRecord(region, ""));
      72           0 :                 Array<Float> blc, trc;
      73           0 :                 Bool oneRelAccountedFor = false;
      74           0 :                 if (imreg->isLCSlicer()) {
      75           0 :                         blc = imreg->asLCSlicer().blc();
      76           0 :                         trc = imreg->asLCSlicer().trc();
      77           0 :                         stokesBegin = (uInt)((Vector<Float>)blc)[polAxis];
      78           0 :                         stokesEnd = (uInt)((Vector<Float>)trc)[polAxis];
      79           0 :                         oneRelAccountedFor = true;
      80             :                 }
      81           0 :                 else if (RegionManager::isPixelRegion(*(ImageRegion::fromRecord(region, "")))) {
      82           0 :                         region.toArray("blc", blc);
      83           0 :                         region.toArray("trc", trc);
      84           0 :                         stokesBegin = (uInt)((Vector<Float>)blc)[polAxis];
      85           0 :                         stokesEnd = (uInt)((Vector<Float>)trc)[polAxis];
      86             :                 }
      87             :                 else {
      88           0 :                         Record blcRec = region.asRecord("blc");
      89           0 :                         Record trcRec = region.asRecord("trc");
      90           0 :                         stokesBegin = (Int)blcRec.asRecord(
      91           0 :                                 String("*" + String::toString(polAxis - 1))
      92           0 :                         ).asDouble("value");
      93           0 :                         stokesEnd = (Int)trcRec.asRecord(
      94           0 :                                 String("*" + String::toString(polAxis - 1))
      95           0 :                         ).asDouble("value");
      96             :                 }
      97             : 
      98           0 :                 if (! oneRelAccountedFor && region.isDefined("oneRel") && region.asBool("oneRel")) {
      99           0 :                         stokesBegin--;
     100           0 :                         stokesEnd--;
     101             :                 }
     102           0 :                 for (uInt i=stokesBegin; i<=stokesEnd; i++) {
     103           0 :                         stokes += csys.stokesAtPixel(i);
     104             :                 }
     105             :         }
     106           0 :         return stokes;
     107             : }
     108             : 
     109           0 : void ImageInputProcessor::_setRegion(
     110             :         Record& regionRecord, String& diagnostics,
     111             :         const Record* regionPtr
     112             : ) const {
     113             :         // region record pointer provided
     114           0 :         regionRecord = *(regionPtr->clone());
     115             :         // set stokes from the region record
     116           0 :         diagnostics = "used provided region record";
     117           0 : }
     118             : 
     119           0 : String ImageInputProcessor::_pairsToString(const std::vector<uInt>& pairs) const {
     120           0 :         ostringstream os;
     121           0 :         uInt nPairs = pairs.size()/2;
     122           0 :         for (uInt i=0; i<nPairs; i++) {
     123           0 :                 os << pairs[2*i] << " - " << pairs[2*i + 1];
     124           0 :                 if (i < nPairs - 1) {
     125           0 :                         os << "; ";
     126             :                 }
     127             :         }
     128           0 :         return os.str();
     129             : }
     130             : 
     131             : }
     132             :  

Generated by: LCOV version 1.16