LCOV - code coverage report
Current view: top level - synthesis/ImagerObjects - SimpleSIImageStore.cc (source / functions) Hit Total Coverage
Test: ctest_coverage.info Lines: 99 111 89.2 %
Date: 2023-11-06 10:06:49 Functions: 13 13 100.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        3571 :         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        3571 :                const  shared_ptr<ImageInterface<Float> > & tempworkimage, const Bool useweightimage) : SIImageStore() {
      44        3571 :                         if(!psfim && !residim && !modelim)  {
      45           0 :                                 throw(AipsError("SimpleSIImagestore has to have a valid residual or psf image"));
      46             :                         }
      47             :                         else{
      48        7142 :                           shared_ptr<ImageInterface<Float> >theim=psfim ? psfim : residim;
      49             :                           ///this is constructed for divide/mult modelbyweight
      50        3571 :                           if(!theim)
      51          66 :                             theim=modelim;
      52        3571 :                           itsCoordSys=theim->coordinates();
      53        3571 :                           itsImageShape=theim->shape();
      54        3571 :                           itsParentImageShape=itsImageShape; //validate looks for that
      55             :                         }
      56        3571 :                         if(useweightimage && !weightim)
      57           0 :                                 throw(AipsError("SimpleSIImagestore has to have a valid weightimage for this kind of weighting scheme"));
      58        3571 :                         itsImageName = casacore::String(imageName);
      59        3571 :                         itsPsf = psfim;
      60        3571 :                         itsModel=modelim;
      61        3571 :                         itsResidual=residim;
      62        3571 :                         itsWeight=weightim;
      63        3571 :                         itsImage=restoredim;
      64        3571 :                         itsSumWt=sumwtim;
      65        3571 :                         itsMask=maskim;
      66        3571 :                         itsImagePBcor=restoredpbcorim;
      67        3571 :                         itsTempWorkIm=tempworkimage;
      68        3571 :                         itsPB=pbim;
      69        3571 :                         itsGridWt=gridwtim;
      70        3571 :                         itsUseWeight=useweightimage;
      71             :                         
      72             :                 
      73             :                 
      74             :                 
      75        3571 :         }
      76       17781 :         shared_ptr<ImageInterface<Float> > SimpleSIImageStore::psf(uInt){
      77       17781 :                 if(!itsPsf)
      78           0 :                         throw(AipsError("Programmer's error: calling for psf without setting it"));
      79       17781 :                 return itsPsf;
      80             :                 
      81             :         }
      82       33588 :         shared_ptr<ImageInterface<Float> > SimpleSIImageStore::residual(uInt){
      83       33588 :                 if(!itsResidual)
      84           0 :                         throw(AipsError("Programmer's error: calling for residual without setting it"));
      85       33588 :                 return itsResidual;
      86             :                 
      87             :         }
      88        1864 :         shared_ptr<ImageInterface<Float> > SimpleSIImageStore::weight(uInt){
      89        1864 :                 if(!itsWeight)
      90           0 :                         throw(AipsError("Programmer's error: calling for weight without setting it"));
      91        1864 :                 return itsWeight;
      92             :                 
      93             :         }
      94       15855 :         shared_ptr<ImageInterface<Float> > SimpleSIImageStore::model(uInt){
      95       15855 :                 if(!itsModel)
      96           0 :                         throw(AipsError("Programmer's error: calling for model without setting it"));
      97       15855 :                 return itsModel;
      98             :                 
      99             :         }
     100       12715 :        shared_ptr<ImageInterface<Float> > SimpleSIImageStore::mask(uInt){
     101       12715 :                 if(!itsMask)
     102           0 :                         throw(AipsError("Programmer's error: calling for model without setting it"));
     103       12715 :                 return itsMask;
     104             :                 
     105             :         }
     106        1887 :         shared_ptr<ImageInterface<Float> > SimpleSIImageStore::pb(uInt){
     107        1887 :                 if(!itsPB)
     108           0 :                         throw(AipsError("Programmer's error: calling for pb without setting it"));
     109        1887 :                 return itsPB;
     110             :                 
     111             :         }
     112          25 :   shared_ptr<ImageInterface<Float> > SimpleSIImageStore::tempworkimage(uInt){
     113          25 :                 if(!itsTempWorkIm)
     114           0 :                         throw(AipsError("Programmer's error: calling for temporary image without setting it"));
     115          25 :                 return itsTempWorkIm;
     116             :                 
     117             :         }
     118        6114 :         shared_ptr<ImageInterface<Float> > SimpleSIImageStore::sumwt(uInt){
     119        6114 :                 if(!itsSumWt)
     120           0 :                         throw(AipsError("Programmer's error: calling for sumweight without setting it"));
     121        6114 :                 return itsSumWt;
     122             :                 
     123             :         }
     124             :         
     125        1040 :         shared_ptr<ImageInterface<Complex> > SimpleSIImageStore::forwardGrid(uInt){
     126        1040 :                 if ( !itsForwardGrid ) {
     127         520 :                         Vector<Int> whichStokes ( 0 );
     128         520 :                         IPosition cimageShape;
     129             :                         //                      cimageShape=itsImageShape;
     130         260 :                         if(!itsModel)
     131           0 :                           throw(AipsError("have to have model to predict"));
     132         260 :                         cimageShape=itsModel->shape();
     133         520 :                         CoordinateSystem cs=itsModel->coordinates();
     134         260 :                         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         260 :                         if ( freqframe != MFrequency::LSRK && freqframe!=MFrequency::Undefined && freqframe!=MFrequency::REST ) {
     137          14 :                                 itsCoordSys.setSpectralConversion ( "LSRK" );
     138          14 :                                 cs.setSpectralConversion("LSRK");
     139             :                         }
     140             :                         CoordinateSystem cimageCoord = StokesImageUtil::CStokesCoord ( cs,
     141         260 :                                        whichStokes, itsDataPolRep );
     142         260 :                         cimageShape ( 2 ) =whichStokes.nelements();
     143         260 :                         cimageCoord.setObsInfo(itsCoordSys.obsInfo());
     144             :                         //cout << "Making forward grid of shape : " << cimageShape << " for imshape : " << itsImageShape << endl;
     145         260 :                         itsForwardGrid.reset ( new TempImage<Complex> ( TiledShape ( cimageShape, tileShape() ), cimageCoord, memoryBeforeLattice() ) );
     146             : 
     147             :                 }
     148        1040 :                 return itsForwardGrid;
     149             :                 
     150             :         }
     151        1622 :         shared_ptr<ImageInterface<Complex> > SimpleSIImageStore::backwardGrid(uInt){
     152        1622 :                 if(!itsBackwardGrid){
     153        1622 :                         Vector<Int> whichStokes(0);
     154        1622 :                         IPosition cimageShape;
     155         811 :                         cimageShape=itsImageShape;
     156         811 :                         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         811 :                         if(freqframe != MFrequency::LSRK && freqframe!=MFrequency::Undefined && freqframe!=MFrequency::REST ) 
     159          56 :                         { itsCoordSys.setSpectralConversion("LSRK"); }
     160         811 :                         CoordinateSystem cimageCoord = StokesImageUtil::CStokesCoord( itsCoordSys,
     161         811 :                                                                   whichStokes, itsDataPolRep);
     162         811 :                         cimageShape(2)=whichStokes.nelements();
     163         811 :                         cimageCoord.setObsInfo(itsCoordSys.obsInfo());
     164             :                         //cout << "Making backward grid of shape : " << cimageShape << " for imshape : " << itsImageShape << endl;
     165         811 :                         itsBackwardGrid.reset( new TempImage<Complex>(TiledShape(cimageShape, tileShape()), cimageCoord, memoryBeforeLattice()) );
     166             :                         
     167             :                 }
     168        1622 :                 return itsBackwardGrid;
     169             :                 
     170             :         }
     171        2430 :         shared_ptr<SIImageStore> SimpleSIImageStore::getSubImageStore(const Int facet, const Int nfacets, const Int chan, const Int nchanchunks, const Int pol, const Int npolchunks){
     172       34020 :           vector<shared_ptr<ImageInterface<Float> > >myImages={itsModel, itsResidual, itsPsf, itsWeight, itsImage, itsMask, itsSumWt, itsGridWt, itsPB, itsImagePBcor, itsTempWorkIm};
     173        2430 :                 if(itsSumWt){
     174           0 :                         setUseWeightImage(*itsSumWt, itsUseWeight);
     175             :                 }
     176        7290 :                 vector<shared_ptr<ImageInterface<Float> >  > subimPtrs(myImages.size(), nullptr);
     177       29160 :                 for (auto it=myImages.begin(); it != myImages.end() ; ++it){
     178       26730 :                         if((*it))
     179       12242 :                                 subimPtrs[it-myImages.begin()]=makeSubImage(facet, nfacets, chan, nchanchunks, pol, npolchunks, *(*it));
     180             :                 }
     181        2430 :                 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        4860 :                 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             :         }
     195        2361 :         Bool SimpleSIImageStore::releaseLocks(){
     196        2361 :                 if( itsPsf ) itsPsf->unlock();
     197        2361 :                 if( itsModel ) itsModel->unlock(); 
     198        2361 :                 if( itsResidual ) itsResidual->unlock() ;
     199        2361 :                 if( itsImage ) itsImage->unlock();
     200        2361 :                 if( itsWeight ) itsWeight->unlock();
     201        2361 :                 if( itsMask ) itsMask->unlock();
     202        2361 :                 if( itsSumWt ) itsSumWt->unlock() ;
     203        2361 :                 if( itsGridWt ) itsGridWt->unlock();
     204        2361 :                 if( itsPB ) itsPB->unlock() ;
     205        2361 :                 if( itsImagePBcor ) itsImagePBcor->unlock();
     206             :                 
     207        2361 :                 return True;
     208             :         }
     209             :         
     210             :         
     211             :         
     212             :         
     213             : } //# NAMESPACE CASA - END

Generated by: LCOV version 1.16