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

Generated by: LCOV version 1.16