LCOV - code coverage report
Current view: top level - synthesis/ImagerObjects - SimpleSIImageStore.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 115 0.0 %
Date: 2024-10-29 13:38:20 Functions: 0 13 0.0 %

          Line data    Source code
       1             : /*
       2             :  * SimpleSIImageStore is an implementation without much checking the caller must make sure pointers exist before using them
       3             :  * Copyright (C) 2019  Associated Universities, Inc. Washington DC, USA.
       4             :  *
       5             :  * This program is free software: you can redistribute it and/or modify
       6             :  * it under the terms of the GNU General Public License as published by
       7             :  * the Free Software Foundation, either version 3 of the License, or
       8             :  * (at your option) any later version.
       9             :  *
      10             :  * This program is distributed in the hope that it will be useful,
      11             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      12             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13             :  * GNU General Public License for more details.
      14             :  *
      15             :  * You should have received a copy of the GNU General Public License
      16             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
      17             :  * 
      18             :  * 
      19             :  * Queries concerning CASA should be submitted at
      20             :  *        https://help.nrao.edu
      21             :  *
      22             :  *         Postal address: CASA Project Manager 
      23             :  *         National Radio Astronomy Observatory
      24             :  *         520 Edgemont Road
      25             :  *         Charlottesville, VA 22903-2475 USA
      26             :  */
      27             : #include <casacore/casa/Exceptions/Error.h>
      28             : #include <iostream>
      29             : #include <synthesis/ImagerObjects/SimpleSIImageStore.h>
      30             : 
      31             : using namespace std;
      32             : 
      33             : using namespace casacore;
      34             : 
      35             : namespace casa { //# NAMESPACE CASA - BEGIN
      36             :         
      37           0 :         SimpleSIImageStore::SimpleSIImageStore  (casacore::String &imageName, const shared_ptr<ImageInterface<Float> > &modelim,
      38             :                const shared_ptr<ImageInterface<Float> > &residim, const shared_ptr<ImageInterface<Float> > &psfim,
      39             :                const shared_ptr<ImageInterface<Float> > &weightim,const shared_ptr<ImageInterface<Float> > &restoredim,
      40             :                const shared_ptr<ImageInterface<Float> > &maskim,const shared_ptr<ImageInterface<Float> > &sumwtim,
      41             :                const shared_ptr<ImageInterface<Float> > &gridwtim, const shared_ptr<ImageInterface<Float> > &pbim,
      42             :                const shared_ptr<ImageInterface<Float> > &restoredpbcorim,
      43           0 :                const  shared_ptr<ImageInterface<Float> > & tempworkimage, const Bool useweightimage) : SIImageStore() {
      44           0 :                         if(!psfim && !residim && !modelim)  {
      45           0 :                                 throw(AipsError("SimpleSIImagestore has to have a valid residual or psf image"));
      46             :                         }
      47             :                         else{
      48           0 :                           shared_ptr<ImageInterface<Float> >theim=psfim ? psfim : residim;
      49             :                           ///this is constructed for divide/mult modelbyweight
      50           0 :                           if(!theim)
      51           0 :                             theim=modelim;
      52           0 :                           itsCoordSys=theim->coordinates();
      53           0 :                           itsImageShape=theim->shape();
      54           0 :                           itsParentImageShape=itsImageShape; //validate looks for that
      55           0 :                         }
      56           0 :                         if(useweightimage && !weightim)
      57           0 :                                 throw(AipsError("SimpleSIImagestore has to have a valid weightimage for this kind of weighting scheme"));
      58           0 :                         itsImageName = casacore::String(imageName);
      59           0 :                         itsPsf = psfim;
      60           0 :                         itsModel=modelim;
      61           0 :                         itsResidual=residim;
      62           0 :                         itsWeight=weightim;
      63           0 :                         itsImage=restoredim;
      64           0 :                         itsSumWt=sumwtim;
      65           0 :                         itsMask=maskim;
      66           0 :                         itsImagePBcor=restoredpbcorim;
      67           0 :                         itsTempWorkIm=tempworkimage;
      68           0 :                         itsPB=pbim;
      69           0 :                         itsGridWt=gridwtim;
      70           0 :                         itsUseWeight=useweightimage;
      71             :                         
      72             :                 
      73             :                 
      74             :                 
      75           0 :         }
      76           0 :         shared_ptr<ImageInterface<Float> > SimpleSIImageStore::psf(uInt){
      77           0 :                 if(!itsPsf)
      78           0 :                         throw(AipsError("Programmer's error: calling for psf without setting it"));
      79           0 :                 return itsPsf;
      80             :                 
      81             :         }
      82           0 :         shared_ptr<ImageInterface<Float> > SimpleSIImageStore::residual(uInt){
      83           0 :                 if(!itsResidual)
      84           0 :                         throw(AipsError("Programmer's error: calling for residual without setting it"));
      85           0 :                 return itsResidual;
      86             :                 
      87             :         }
      88           0 :         shared_ptr<ImageInterface<Float> > SimpleSIImageStore::weight(uInt){
      89           0 :                 if(!itsWeight)
      90           0 :                         throw(AipsError("Programmer's error: calling for weight without setting it"));
      91           0 :                 return itsWeight;
      92             :                 
      93             :         }
      94           0 :         shared_ptr<ImageInterface<Float> > SimpleSIImageStore::model(uInt){
      95           0 :                 if(!itsModel)
      96           0 :                         throw(AipsError("Programmer's error: calling for model without setting it"));
      97           0 :                 return itsModel;
      98             :                 
      99             :         }
     100           0 :        shared_ptr<ImageInterface<Float> > SimpleSIImageStore::mask(uInt){
     101           0 :                 if(!itsMask)
     102           0 :                         throw(AipsError("Programmer's error: calling for model without setting it"));
     103           0 :                 return itsMask;
     104             :                 
     105             :         }
     106           0 :         shared_ptr<ImageInterface<Float> > SimpleSIImageStore::pb(uInt){
     107           0 :                 if(!itsPB)
     108           0 :                         throw(AipsError("Programmer's error: calling for pb without setting it"));
     109           0 :                 return itsPB;
     110             :                 
     111             :         }
     112           0 :   shared_ptr<ImageInterface<Float> > SimpleSIImageStore::tempworkimage(uInt){
     113           0 :                 if(!itsTempWorkIm)
     114           0 :                         throw(AipsError("Programmer's error: calling for temporary image without setting it"));
     115           0 :                 return itsTempWorkIm;
     116             :                 
     117             :         }
     118           0 :         shared_ptr<ImageInterface<Float> > SimpleSIImageStore::sumwt(uInt){
     119           0 :                 if(!itsSumWt)
     120           0 :                         throw(AipsError("Programmer's error: calling for sumweight without setting it"));
     121           0 :                 return itsSumWt;
     122             :                 
     123             :         }
     124             :         
     125           0 :         shared_ptr<ImageInterface<Complex> > SimpleSIImageStore::forwardGrid(uInt){
     126           0 :                 if ( !itsForwardGrid ) {
     127           0 :                         Vector<Int> whichStokes ( 0 );
     128           0 :                         IPosition cimageShape;
     129             :                         //                      cimageShape=itsImageShape;
     130           0 :                         if(!itsModel)
     131           0 :                           throw(AipsError("have to have model to predict"));
     132           0 :                         cimageShape=itsModel->shape();
     133           0 :                         CoordinateSystem cs=itsModel->coordinates();
     134           0 :                         MFrequency::Types freqframe = cs.spectralCoordinate ( cs.findCoordinate ( Coordinate::SPECTRAL ) ).frequencySystem ( True );
     135             :                         // No need to set a conversion layer if image is in LSRK already or it is 'Undefined'
     136           0 :                         if ( freqframe != MFrequency::LSRK && freqframe!=MFrequency::Undefined && freqframe!=MFrequency::REST ) {
     137           0 :                                 itsCoordSys.setSpectralConversion ( "LSRK" );
     138           0 :                                 cs.setSpectralConversion("LSRK");
     139             :                         }
     140             :                         CoordinateSystem cimageCoord = StokesImageUtil::CStokesCoord ( cs,
     141           0 :                                        whichStokes, itsDataPolRep );
     142           0 :                         cimageShape ( 2 ) =whichStokes.nelements();
     143           0 :                         cimageCoord.setObsInfo(itsCoordSys.obsInfo());
     144             :                         //cout << "Making forward grid of shape : " << cimageShape << " for imshape : " << itsImageShape << endl;
     145           0 :                         itsForwardGrid.reset ( new TempImage<Complex> ( TiledShape ( cimageShape, tileShape() ), cimageCoord, memoryBeforeLattice() ) );
     146             : 
     147           0 :                 }
     148           0 :                 return itsForwardGrid;
     149             :                 
     150             :         }
     151           0 :         shared_ptr<ImageInterface<Complex> > SimpleSIImageStore::backwardGrid(uInt){
     152           0 :                 if(!itsBackwardGrid){
     153           0 :                         Vector<Int> whichStokes(0);
     154           0 :                         IPosition cimageShape;
     155           0 :                         cimageShape=itsImageShape;
     156           0 :                         MFrequency::Types freqframe = itsCoordSys.spectralCoordinate(itsCoordSys.findCoordinate(Coordinate::SPECTRAL)).frequencySystem(True);
     157             :                         // No need to set a conversion layer if image is in LSRK already or it is 'Undefined'
     158           0 :                         if(freqframe != MFrequency::LSRK && freqframe!=MFrequency::Undefined && freqframe!=MFrequency::REST ) 
     159           0 :                         { itsCoordSys.setSpectralConversion("LSRK"); }
     160           0 :                         CoordinateSystem cimageCoord = StokesImageUtil::CStokesCoord( itsCoordSys,
     161           0 :                                                                   whichStokes, itsDataPolRep);
     162           0 :                         cimageShape(2)=whichStokes.nelements();
     163           0 :                         cimageCoord.setObsInfo(itsCoordSys.obsInfo());
     164             :                         //cout << "Making backward grid of shape : " << cimageShape << " for imshape : " << itsImageShape << endl;
     165           0 :                         itsBackwardGrid.reset( new TempImage<Complex>(TiledShape(cimageShape, tileShape()), cimageCoord, memoryBeforeLattice()) );
     166             :                         
     167           0 :                 }
     168           0 :                 return itsBackwardGrid;
     169             :                 
     170             :         }
     171           0 :         shared_ptr<SIImageStore> SimpleSIImageStore::getSubImageStore(const Int facet, const Int nfacets, const Int chan, const Int nchanchunks, const Int pol, const Int npolchunks){
     172           0 :           vector<shared_ptr<ImageInterface<Float> > >myImages={itsModel, itsResidual, itsPsf, itsWeight, itsImage, itsMask, itsSumWt, itsGridWt, itsPB, itsImagePBcor, itsTempWorkIm};
     173           0 :                 if(itsSumWt){
     174           0 :                         setUseWeightImage(*itsSumWt, itsUseWeight);
     175             :                 }
     176           0 :                 vector<shared_ptr<ImageInterface<Float> >  > subimPtrs(myImages.size(), nullptr);
     177           0 :                 for (auto it=myImages.begin(); it != myImages.end() ; ++it){
     178           0 :                         if((*it))
     179           0 :                                 subimPtrs[it-myImages.begin()]=makeSubImage(facet, nfacets, chan, nchanchunks, pol, npolchunks, *(*it));
     180             :                 }
     181           0 :                 shared_ptr<SIImageStore> retval(new SimpleSIImageStore(itsImageName, subimPtrs[0], subimPtrs[1], subimPtrs[2], subimPtrs[3], subimPtrs[4], subimPtrs[5], subimPtrs[6], subimPtrs[7], subimPtrs[8], subimPtrs[9], subimPtrs[10], itsUseWeight));
     182             :                 
     183             :                 
     184           0 :                 return retval;
     185             :                 /*
     186             :                const std::shared_ptr<casacore::ImageInterface<casacore::Float> > &weightim,
     187             :                const std::shared_ptr<casacore::ImageInterface<casacore::Float> > &restoredim,
     188             :                const std::shared_ptr<casacore::ImageInterface<casacore::Float> > &maskim,
     189             :                const std::shared_ptr<casacore::ImageInterface<casacore::Float> > &sumwtim,
     190             :                const std::shared_ptr<casacore::ImageInterface<casacore::Float> > &gridwtim,
     191             :                const std::shared_ptr<casacore::ImageInterface<casacore::Float> > &pbim,
     192             :                const std::shared_ptr<casacore::ImageInterface<casacore::Float> > &restoredpbcorim,
     193             :                 */
     194           0 :         }
     195           0 :         Bool SimpleSIImageStore::releaseLocks(){
     196           0 :                 if( itsPsf ) itsPsf->unlock();
     197           0 :                 if( itsModel ) itsModel->unlock(); 
     198           0 :                 if( itsResidual ) itsResidual->unlock() ;
     199           0 :                 if( itsImage ) itsImage->unlock();
     200           0 :                 if( itsWeight ) itsWeight->unlock();
     201           0 :                 if( itsMask ) itsMask->unlock();
     202           0 :                 if( itsSumWt ) itsSumWt->unlock() ;
     203           0 :                 if( itsGridWt ) itsGridWt->unlock();
     204           0 :                 if( itsPB ) itsPB->unlock() ;
     205           0 :                 if( itsImagePBcor ) itsImagePBcor->unlock();
     206             :                 
     207           0 :                 return True;
     208             :         }
     209             :         
     210             :         
     211             :         
     212             :         
     213             : } //# NAMESPACE CASA - END

Generated by: LCOV version 1.16