Line data Source code
1 : //# PWFCleanImageSkyModel.cc: Implementation of WFCleanImageSkyModel class 2 : //# Copyright (C) 1996,1997,1998,1999,2000,2002,2003 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/Arrays/ArrayMath.h> 29 : #include <synthesis/MeasurementComponents/PWFCleanImageSkyModel.h> 30 : #include <casacore/images/Images/PagedImage.h> 31 : #include <casacore/images/Images/ImageInterface.h> 32 : #include <casacore/casa/OS/File.h> 33 : #include <casacore/images/Images/SubImage.h> 34 : #include <casacore/lattices/Lattices/LatticeStepper.h> 35 : #include <casacore/lattices/Lattices/LatticeIterator.h> 36 : #include <casacore/lattices/LEL/LatticeExpr.h> 37 : #include <casacore/lattices/LRegions/LCBox.h> 38 : #include <synthesis/MeasurementEquations/SkyEquation.h> 39 : //#include <synthesis/MeasurementEquations/PSkyEquation.h> 40 : #include <casacore/casa/Exceptions/Error.h> 41 : #include <casacore/casa/BasicSL/String.h> 42 : #include <casacore/casa/Utilities/Assert.h> 43 : #include <casacore/coordinates/Coordinates/DirectionCoordinate.h> 44 : #include <casacore/coordinates/Coordinates/CoordinateSystem.h> 45 : #include <casacore/casa/Logging/LogMessage.h> 46 : #include <casacore/casa/Logging/LogSink.h> 47 : #include <casacore/casa/Logging/LogIO.h> 48 : #include <sstream> 49 : #include <synthesis/MeasurementComponents/MakeApproxPSFAlgorithm.h> 50 : #include <synthesis/Parallel/Applicator.h> 51 : 52 : using namespace casacore; 53 : namespace casa { //# NAMESPACE CASA - BEGIN 54 : 55 : extern Applicator applicator; 56 : 57 : // This is kind of deprecated...good as an example but should be redone 58 0 : PWFCleanImageSkyModel::PWFCleanImageSkyModel() : WFCleanImageSkyModel() { 59 0 : }; 60 : 61 0 : PWFCleanImageSkyModel::PWFCleanImageSkyModel(const Int facets): WFCleanImageSkyModel(facets) { 62 0 : }; 63 : 64 0 : Bool PWFCleanImageSkyModel::solve(SkyEquation& se) { 65 : // Solve for the sky model 66 : 67 0 : LogIO os(LogOrigin("PWFCleanImageSkyModel","solve")); 68 : os << "Starting parallel wide-field clean with " << nfacets_p << " facets" 69 0 : << " and " << this->WFCleanImageSkyModel::numberOfModels()-nfacets_p 70 0 : << " outliers" << LogIO::POST; 71 : 72 : // MFCleanImageSkyModel::solve() will call the parallel 73 : // PSkyEquation::solveSkyModel() method, so no explicit 74 : // parallelization of MFCleanImageSkyModel is required 75 : // for the wide-field case. This would be required for 76 : // mosaicing however. 77 0 : if(!MFCleanImageSkyModel::solve(se)) { 78 0 : os << "Wide-field clean failed" << LogIO::POST; 79 0 : return false; 80 : } 81 0 : return(true); 82 : }; 83 : 84 0 : void PWFCleanImageSkyModel::makeApproxPSFs(SkyEquation& se){ 85 : // This function runs on the controller process. It distributes 86 : // the MakeApproxPSFAlgorithm task to worker processes, and 87 : // receives back the PSF for each facet and the associated 88 : // beam fit values. 89 : 90 : // Unlock the MS for the worker as the controller process in 91 : // imager will have locked it 92 0 : se.unlock(); 93 : 94 0 : LogIO os(LogOrigin("PWFCleanImageSkyModel", "makeApproxPSFs")); 95 0 : MakeApproxPSFAlgorithm makepsf ; 96 : Int rank; 97 : Bool allDone, assigned; 98 0 : std::map<Int, Int> psfNo; 99 0 : Int gotten=0; 100 : 101 : try{ 102 : 103 0 : for (Int thismodel=0; thismodel<nmodels_p; thismodel++) { 104 0 : assigned=applicator.nextAvailProcess(makepsf, rank); 105 0 : while(!assigned){ 106 0 : rank= applicator.nextProcessDone(makepsf, allDone); 107 : // Receive PSF and fit to PSF info 108 : //applicator.get(beam(psfNo(rank))); 109 0 : Array<Float> psfArray; 110 0 : applicator.get(psfArray); 111 0 : PSF(psfNo.at(rank)).putSlice(psfArray, IPosition(4, 0, 0, 0, 0)); 112 0 : ++gotten; 113 : /*if((*beam_p[psfNo(rank)])(0) == Float(-1.0)){ 114 : os << "Model " << thismodel << "PSF formation failed " 115 : <<LogIO::POST ; 116 : }*/ 117 : // Assign next avail. child processor. 118 0 : assigned = applicator.nextAvailProcess(makepsf, rank); 119 : 120 : } 121 : // Send the worker the data it needs to build an FTMachine, 122 : // make a PSF and fit the beam 123 : 124 0 : Record container_ft; 125 0 : String errorString; 126 0 : se.fTMachine().toRecord(errorString, container_ft); 127 0 : applicator.put(container_ft); 128 0 : applicator.put(se.associatedMSName()); 129 : // The above is for the creation of FTMachine below should be for the 130 : // cImage 131 0 : applicator.put(this->weight(thismodel)); 132 0 : Record image_container; 133 0 : cImage(thismodel).toRecord(errorString, image_container); 134 0 : applicator.put(image_container); 135 0 : psfNo.insert( std::pair<Int,Int>(rank, thismodel) ); 136 : 137 : //Serial transport execution 138 0 : applicator.apply(makepsf); 139 : } 140 : 141 : // Wait for the outstanding processes 142 0 : rank= applicator.nextProcessDone(makepsf,allDone); 143 : 144 0 : while (!allDone) { 145 : //applicator.get(beam(psfNo(rank))); 146 0 : Array<Float> psfArray; 147 0 : applicator.get(psfArray); 148 0 : PSF(psfNo.at(rank)).putSlice(psfArray, IPosition(4, 0, 0, 0, 0)); 149 : /*if((*beam_p[psfNo(rank)])(0)== Float(-1.0)){ 150 : os << "Model "<< psfNo(rank) <<"Beam forming failed "<< LogIO::POST ; 151 : }*/ 152 0 : rank=applicator.nextProcessDone(makepsf,allDone); 153 : } 154 : 155 0 : }catch (AipsError x){ 156 : 157 0 : cout << x.getMesg() << endl; 158 : } ; 159 : 160 0 : se.lock(); 161 0 : } 162 : 163 : 164 : } //# NAMESPACE CASA - END 165 :