Line data Source code
1 : //# CubeMajorCycleAlgorithm.cc: implementation of class to grid cube in parallel/serial 2 : //# Copyright (C) 2019 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 General Public License as published by 7 : //# the Free Software Foundation; either version 3 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 General Public 13 : //# License for more details. 14 : //# 15 : //# https://www.gnu.org/licenses/ 16 : //# 17 : //# Queries concerning CASA should be submitted at 18 : //# https://help.nrao.edu 19 : //# 20 : //# Postal address: CASA Project Manager 21 : //# National Radio Astronomy Observatory 22 : //# 520 Edgemont Road 23 : //# Charlottesville, VA 22903-2475 USA 24 : //# 25 : //# 26 : //# $Id$ 27 : #include <casacore/lattices/Lattices/LatticeLocker.h> 28 : #include <synthesis/ImagerObjects/CubeMakeImageAlgorithm.h> 29 : #include <synthesis/ImagerObjects/SynthesisImagerVi2.h> 30 : #include <casacore/casa/Containers/Record.h> 31 : #include <synthesis/ImagerObjects/SimpleSIImageStore.h> 32 : #include <imageanalysis/Utilities/SpectralImageUtil.h> 33 : 34 : using namespace casacore; 35 : namespace casa { //# NAMESPACE CASA - BEGIN 36 : extern Applicator applicator; 37 : 38 2 : CubeMakeImageAlgorithm::CubeMakeImageAlgorithm() : myName_p("CubeMakeImageAlgorithm"), polRep_p(0), status_p(False){ 39 : 40 2 : } 41 2 : CubeMakeImageAlgorithm::~CubeMakeImageAlgorithm() { 42 : 43 2 : } 44 : 45 1 : void CubeMakeImageAlgorithm::get() { 46 : 47 : //cerr << "in get for child process " << applicator.isWorker() << endl; 48 1 : Record imParsRec; 49 1 : Record vecSelParsRec; 50 1 : Record gridParsRec; 51 : // get data sel params #1 52 1 : applicator.get(vecSelParsRec); 53 : // get image sel params #2 54 1 : applicator.get(imParsRec); 55 : // get gridders params #3 56 1 : applicator.get(gridParsRec); 57 : // get which channel to process #4 58 1 : applicator.get(chanRange_p); 59 : //cerr <<"GET chanRange " << chanRange_p << endl; 60 : // which type of image #5 61 1 : applicator.get(imageType_p); 62 : // weight params #6 63 1 : applicator.get(weightParams_p); 64 : // output complex_image name #7 65 1 : applicator.get(cimageName_p); 66 : //Somewhere before this we have to make sure that vecSelPars has more than 0 fields) 67 1 : dataSel_p.resize(vecSelParsRec.nfields()); 68 : /// Fill the private variables 69 2 : for (Int k=0; k < Int(dataSel_p.nelements()); ++k){ 70 1 : (dataSel_p[k]).fromRecord(vecSelParsRec.asRecord(String::toString(k))); 71 : //cerr << k << "datasel " << vecSelParsRec.asRecord(String::toString(k)) << endl; 72 : } 73 : //cerr << "GET record " << imParsRec << endl; 74 1 : imSel_p.fromRecord(imParsRec); 75 1 : gridSel_p.fromRecord(gridParsRec); 76 1 : if(gridParsRec.isDefined("ftmachine")){ 77 0 : ftmRec_p=gridParsRec.asRecord("ftmachine"); 78 : } 79 : 80 : 81 : 82 : 83 1 : } 84 1 : void CubeMakeImageAlgorithm::put() { 85 : 86 : 87 : //cerr << "in put " << status_p << endl; 88 1 : applicator.put(status_p); 89 : 90 1 : } 91 : 92 1 : void CubeMakeImageAlgorithm::task(){ 93 1 : status_p = False; 94 : //SynthesisImagerVi2 imgr; 95 : //imgr.selectData(dataSel_p); 96 : // We do not use chanchunking in this model 97 1 : gridSel_p.chanchunks = 1; 98 : 99 : //imgr.defineImage(imSel_p,gridSel_p); 100 : // need to find how many subfields/outliers have been set 101 : //CountedPtr<SIImageStore> imstor =imgr.imageStore(0); 102 : //CountedPtr<ImageInterface<Float> > resid=imstor->residual(); 103 : //Int nchan = resid->shape()(3); 104 : //std::shared_ptr<SIImageStore> subImStor=imstor->getSubImageStore(0, 1, chanId_p, nchan, 0,1); 105 : 106 1 : SynthesisImagerVi2 subImgr; 107 2 : for (Int k=0; k < Int(dataSel_p.nelements()); ++k){ 108 : //model is already cleared in original SythesisImagerVi2 109 1 : dataSel_p[k].incrmodel=True; 110 1 : subImgr.selectData(dataSel_p[k]); 111 : } 112 1 : subImgr.defineImage(imSel_p, gridSel_p); 113 : // TO DO get weight param and set weight 114 1 : if(!weightParams_p.isDefined("type") || weightParams_p.asString("type")=="natural") 115 0 : subImgr.weight("natural"); 116 : else 117 1 : subImgr.weight(weightParams_p); 118 : 119 : //get the vi and ft machine 120 1 : CountedPtr<vi::VisibilityIterator2> vi=subImgr.getVi(); 121 1 : CountedPtr<refim::FTMachine> ift=subImgr.getFTM(0); 122 1 : refim::FTMachine::Type seType=(refim::FTMachine::Type)imageType_p; 123 : 124 1 : if(seType >= refim::FTMachine::N_types || seType < refim::FTMachine::OBSERVED) 125 0 : throw(AipsError("CubeMakeImage error: Donot know how to make type of image requested")); 126 1 : PagedImage<Complex> origCImage(cimageName_p, TableLock::UserNoReadLocking); 127 1 : shared_ptr<ImageInterface<Complex> > subCimage; 128 1 : subCimage.reset(SpectralImageUtil::getChannel(origCImage, chanRange_p[0], chanRange_p[1], true)); 129 1 : Matrix<Float> weight; 130 1 : ift->makeImage(seType, *vi, *subCimage, weight); 131 1 : ift->cleanupTempFiles(""); 132 1 : status_p = True; 133 1 : } 134 5 : String& CubeMakeImageAlgorithm::name(){ 135 5 : return myName_p; 136 : } 137 : 138 : 139 : 140 : 141 : 142 : } //# NAMESPACE CASA - END