Line data Source code
1 : //# ResidualAlgorithm.cc:class providing for parallelized residualimagemaking 2 : //# Copyright (C) 1996,1997,1998,1999,2000,2001,2002 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 Library General Public License as published by 7 : //# the Free Software Foundation; either version 2 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 Library General Public 13 : //# License for more details. 14 : //# 15 : //# You should have received a copy of the GNU Library General Public License 16 : //# along with this library; if not, write to the Free Software Foundation, 17 : //# Inc., 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 : //# $Id$ 27 : 28 : #include <casacore/casa/Utilities/Assert.h> 29 : #include <msvis/MSVis/VisSet.h> 30 : #include <msvis/MSVis/VisSetUtil.h> 31 : #include <msvis/MSVis/VisibilityIterator.h> 32 : #include <msvis/MSVis/VisBuffer.h> 33 : #include <casacore/casa/Arrays/ArrayMath.h> 34 : #include <casacore/casa/Arrays/MatrixMath.h> 35 : #include <casacore/casa/Logging/LogMessage.h> 36 : #include <casacore/casa/Logging/LogIO.h> 37 : #include <casacore/casa/Logging/LogSink.h> 38 : #include <casacore/ms/MeasurementSets/MeasurementSet.h> 39 : #include <casacore/ms/MeasurementSets/MSColumns.h> 40 : #include <synthesis/MeasurementComponents/ResidualAlgorithm.h> 41 : #include <casacore/casa/OS/Time.h> 42 : #include <casacore/images/Images/ImageInterface.h> 43 : #include <casacore/images/Images/PagedImage.h> 44 : #include <casacore/images/Images/TempImage.h> 45 : #include <synthesis/TransformMachines/StokesImageUtil.h> 46 : #include <casacore/lattices/LRegions/LCBox.h> 47 : #include <casacore/lattices/Lattices/SubLattice.h> 48 : #include <casacore/lattices/Lattices/TiledShape.h> 49 : #include <casacore/casa/System/ProgressMeter.h> 50 : #include <synthesis/Parallel/Applicator.h> 51 : #include <unistd.h> 52 : #include <casacore/casa/Containers/Record.h> 53 : 54 : using namespace casacore; 55 : namespace casa { //# NAMESPACE CASA - BEGIN 56 : 57 : extern Applicator applicator; 58 : 59 : 60 0 : ResidualAlgorithm::ResidualAlgorithm() : myName_p("ResidualAlgorithm") 61 : { 62 : 63 0 : }; 64 : 65 0 : ResidualAlgorithm::~ResidualAlgorithm() 66 : { 67 : 68 0 : }; 69 : 70 0 : void ResidualAlgorithm::get(){ 71 : 72 : // Receive data from the controller process 73 0 : applicator.get(model_p); 74 0 : applicator.get(msName_p); 75 0 : applicator.get(incremental_p); 76 : 77 : // Receiving image parameters 78 0 : Record container_image; 79 0 : String errorString; 80 0 : applicator.get(container_image); 81 0 : cImage_p= new TempImage<Complex>(); 82 0 : cImage_p->fromRecord(errorString, container_image); 83 : 84 : // Receiving and making FT machine 85 0 : Record container_ft; 86 0 : applicator.get(container_ft); 87 0 : ft_p=new GridFT(container_ft); 88 0 : Matrix<Float> weight_temp; 89 0 : applicator.get(weight_temp); 90 : 91 0 : if (weight_p) delete weight_p; 92 0 : weight_p = new Matrix<Float> (weight_temp); 93 : 94 0 : }; 95 : 96 0 : void ResidualAlgorithm::put(){ 97 : 98 : // Send data back to the controller process 99 0 : applicator.put(model_p); 100 : 101 : // Sending image parameters 102 0 : Record container_image; 103 0 : String errorString; 104 0 : cImage_p->toRecord(errorString, container_image); 105 0 : applicator.put(container_image); 106 0 : Bool withImage=false; 107 : 108 : // Sending FT machine parameters 109 0 : Record container_ft; 110 0 : ft_p->toRecord(errorString, container_ft, withImage); 111 0 : applicator.put(container_ft); 112 0 : applicator.put(*weight_p); 113 : 114 0 : delete ft_p; 115 0 : delete cImage_p; 116 0 : weight_p->resize(); 117 : 118 0 : }; 119 : 120 0 : String& ResidualAlgorithm::name(){ 121 : 122 : // Return the algorithm name 123 0 : return myName_p; 124 : 125 : }; 126 : 127 0 : void ResidualAlgorithm::task(){ 128 : 129 : // Form the parallel residual image 130 : 131 0 : ms_p= new MeasurementSet(msName_p, TableLock(TableLock::UserNoReadLocking) 132 0 : , Table::Update); 133 : 134 0 : Block<Int> sort(0); 135 0 : Matrix<Int> noselection; 136 0 : noselection=MeasurementSet::ANTENNA1; 137 0 : Double interval=0; 138 : 139 : // Construct the VisibilityIterator 140 0 : VisSet vs(*ms_p, sort, noselection, interval); 141 0 : ROVisIter& vi(vs.iter()); 142 : 143 : 144 : 145 : // Row blocking defines the memory used 146 0 : vi.setRowBlocking(100000); 147 0 : VisBuffer vb(vi); 148 : 149 : // Change the model polarization frame 150 0 : if(vb.polFrame()==MSIter::Linear) { 151 0 : StokesImageUtil::changeCStokesRep(*cImage_p, 152 : StokesImageUtil::LINEAR); 153 : } 154 : else { 155 0 : StokesImageUtil::changeCStokesRep(*cImage_p, 156 : StokesImageUtil::CIRCULAR); 157 : } 158 : 159 0 : vi.originChunks(); 160 0 : vi.origin(); 161 0 : initializePut(vb, model_p); 162 : 163 : // Iterate through the visibility data 164 0 : for (vi.originChunks();vi.moreChunks();vi.nextChunk()) { 165 0 : for (vi.origin(); vi.more(); vi++) { 166 : 167 0 : vb.modelVisCube()-=vb.correctedVisCube(); 168 0 : vb.setVisCube(vb.modelVisCube()); 169 0 : putResidualVis(vb, model_p); 170 : 171 : } 172 : } 173 : 174 0 : ft_p->finalizeToSky(); 175 : 176 0 : Matrix<Float> delta; 177 0 : cImage_p->copyData(ft_p->getImage(delta, false)); 178 0 : (*weight_p)+=delta; 179 : 180 0 : ms_p->unlock(); 181 0 : delete ms_p; 182 0 : }; 183 : 184 0 : void ResidualAlgorithm::initializePut(const VisBuffer& vb, Int /*model*/) { 185 0 : ft_p->initializeToSky(*cImage_p, *weight_p,vb); 186 : // Need to add support for varying SkyJones 187 0 : } 188 : 189 : 190 0 : void ResidualAlgorithm::putResidualVis(VisBuffer& vb, Int /*model*/) { 191 0 : Bool dopsf=false; 192 : // Need to add support for varying SkyJones 193 0 : ft_p->put(vb, -1, dopsf); 194 0 : } 195 : 196 : 197 : 198 : 199 : 200 : } //# NAMESPACE CASA - END 201 :