casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VisModelData.h
Go to the documentation of this file.
1 //# VisModelData.h: Calculate Model Visibilities for a buffer from model images / complist
2 //# Copyright (C) 2011
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 adressed 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 //#
27 //# $Id$
28 #ifndef TRANSFORM2_TRANSFORM2_VISMODELDATA_H
29 #define TRANSFORM2_TRANSFORM2_VISMODELDATA_H
30 #include <casa/aips.h>
31 #include <casa/Containers/Record.h>
32 #include <casa/Containers/Block.h>
33 #include <casa/Arrays/Cube.h>
36 #include <msvis/MSVis/VisBuffer.h> //here only for the pure virtual function that uses this
37 
38 namespace casacore{
39 
40  class MeasurementSet;
41  template <class T> class Vector;
42  template <class T> class CountedPtr;
43 }
44 
45 namespace casa { //# NAMESPACE CASA - BEGIN
46 //#forward
47  namespace vi{class VisBuffer2;}
48  class ComponentList;
49  namespace refim{ //namespace refim
50  class FTMachine;
51 // <summary>
52 // Object to provide MODEL_DATA visibilities on demand
53 // </summary>
54 
55 // <reviewed reviewer="" date="" tests="" demos="">
56 
57 // <prerequisite>
58 // FTMachine and ComponentFTMachine
59 //
60 // </prerequisite>
61 //
62 // <etymology>
63 // Vis for Visibility
64 // ModelData is self explanatory
65 // </etymology>
66 //
67 // <synopsis>
68 // This Class also offer a lot of helper functions to query add and delete/modify models
69 // To be noted the models that are supported are FTMachines and Componentlist
70 // A given FIELD_ID can have multiple models added to the same record
71 // (i.e for e.g multiple spw models or multiple outlier images or in the
72 // case of componentlist multiple component list models.
73 // A model may be valid for multiple fields e.g a mosaic
74 // To save storage in such cases multiple field id will point to the same model
75 // Look for the keyword "definedmodel_field_x" in the Source table keywords (or the main
76 // table if source is not present).
77 // This will point to another key which is going to point to the model.
78 // Thus multiple "definedmodel_field_x" may point to the same key.
79 // If there is no valid SOURCE table the key will hold a casacore::Record of the model to use
80 // in the main table
81 // Otherwise in the SOURCE table the key will hold the row of the SOURCE table in whose
82 // SOURCE_MODEL cell the casacore::Record of the model to use will be resident.
83 // Now a given model casacore::Record in a SOURCE_MODEL cell
84 // can hold multiple FTMachine's or Compnentlist (e.g multiple direction images or
85 // spw images associated with a given field)
86 // and they are all cumulative (while respecting spw selection conditions)
87 // when a request is made for the model visibility
88 // </synopsis>
89 //
90 // <example>
91 // <srcblock>
92 // casacore::MeasurementSet theMS(.....)
93 
94 // VisibilityIterator vi(theMS,sort);
95 // VisBuffer vb(vi);
96 // casacore::MDirection myDir=vi.msColumns().field().phaseDirMeas(0);
97 // ComponentList cl;
98 // SkyComponent otherPoint(ComponentType::POINT);
99 // otherPoint.flux() = Flux<casacore::Double>(0.00001, 0.0, 0.0, 0.00000);
100 // otherPoint.shape().setRefDirection(myDir);
101 // cl.add(otherPoint);
102 // casacore::Record clrec;
103 // clrec.define("type", "componentlist");
104 // ///Define the fields ans spw for which this model is valid
105 // clrec.define("fields", field);
106 // clrec.define("spws", casacore::Vector<casacore::Int>(1, 0));
107 // clrec.defineRecord("container", container);
108 // casacore::Record outRec;
109 // outRec.define("numcl", 1);
110 // outRec.defineRecord("cl_0", clrec);
111 
112 // casacore::Vector<casacore::Int>spws(1,0);
113 // Save model to the MS
114 // VisModelData.putModel(theMS, container, field, spws, casacore::Vector<casacore::Int>(1,0), casacore::Vector<casacore::Int>(1,63), casacore::Vector<casacore::Int>(1,1), true, false);
115 //
117 // vi.origin();
119 //VisModelData vm;
121 // casacore::Int snum;
122 // casacore::Bool hasmodkey=VisModelData::isModelDefined(vb.fieldId(), vi.ms(), modelkey, snum);
123 // Setup vm to serve the model for the fieldid()
124 // if( hasmodkey){
125 // casacore::TableRecord modrec;
126 // VisModelData::getModelRecord(modelkey, modrec, visIter_p->ms())
127 // vm.addModel(modrec, casacore::Vector<casacore::Int>(1, msId()), vb);
128 // }
129 // for (vi.originChunks();vi.moreChunks(); vi.nextChunk()){
130 // for (vi.origin(); vi.more(); vi++){
131 // This fills the vb.modelVisCube with the appropriate model visibility
132 // vm.getModelVis(vb);
133 // cerr << "field " << vb.fieldId() << " spw " << vb.spectralWindow() <<" max " << max(amplitude(vb.modelVisCube())) << endl;
134 
135 // }
136 // }
137 // </srcblock>
138 // </example>
139 //
140 // <motivation>
141 // </motivation>
142 //
143 // <todo asof="2013/05/24">
144 // Allow validity of models for a given section of time only
145 //
146 // </todo>
147 
148  class VisModelData : public VisModelDataI {
149  public:
150  //empty constructor
151  VisModelData();
152  //From a FTMachine Record
153  //VisModelData(const casacore::Record& ftmachinerec, const casacore::Vector<casacore::Int>& validfieldids, const casacore::Vector<casacore::Int>& msIds);
154  virtual ~VisModelData();
155  //Add Image/FTMachine to generate visibilities for
156  //void addFTMachine(const casacore::Record& recordFTMachine, const casacore::Vector<casacore::Int>& validfieldids, const casacore::Vector<casacore::Int>& msIds);
157  //Add componentlist to generate visibilities for
158  //void addCompFTMachine(const ComponentList& cl, const casacore::Vector<casacore::Int>& validfieldids,
159  // const casacore::Vector<casacore::Int>& msIds);
160  //For simple model a special case for speed
161 
163  const casacore::Vector<casacore::Int>& msIds);
164 
165  //add componentlists or ftmachines
166  void addModel(const casacore::RecordInterface& rec, const casacore::Vector<casacore::Int>& msids, const vi::VisBuffer2& vb);
167  void addModel(const casacore::RecordInterface& /*rec*/, const casacore::Vector<casacore::Int>& /*msids*/, const VisBuffer& /*vb*/){throw(casacore::AipsError("Called the wrong version of VisModelData"));};
168 
169 
170  VisModelDataI * clone ();
171 
172  //put the model data for this VisBuffer in the modelVisCube
174  casacore::Bool getModelVis(VisBuffer& /*vb*/){throw(casacore::AipsError("called the wrong version of VisModelData"));};
175  //this is a helper function that writes the model record to the ms
179  const casacore::Vector<casacore::Int>& incr, casacore::Bool iscomponentlist=true, casacore::Bool incremental=false)
180  {
181  putModel (thems, rec, validfields, spws, starts, nchan, incr, iscomponentlist, incremental);
182  }
183  static void putModel(const casacore::MeasurementSet& thems, const casacore::RecordInterface& rec, const casacore::Vector<casacore::Int>& validfields, const casacore::Vector<casacore::Int>& spws, const casacore::Vector<casacore::Int>& starts, const casacore::Vector<casacore::Int>& nchan, const casacore::Vector<casacore::Int>& incr, casacore::Bool iscomponentlist=true, casacore::Bool incremental=false);
184  //Verion 2.0 of putModel to support Intent
185  // index Comb is a Matrix of n rows 4 columns
186  //Each row is a unique combination of field_id, spw_id, scan_number, state_id for which this
187  //record is valid
188  //chansel is Matrix of nspw rows and 4 columns (spw_id, start, nchan, incr)
189  static void putModel(const casacore::MeasurementSet& thems,const casacore::RecordInterface& rec,
190  const casacore::Matrix<casacore::Int>& indexComb, const casacore::Matrix<casacore::Int>& chansel,
191  casacore::Bool iscomponentlist=true, casacore::Bool incremental=false);
193  const casacore::Matrix<casacore::Int>& chansel,
194  casacore::Bool iscomponentlist=true, casacore::Bool incremental=false){
195  putModel(thems, rec, indexComb, chansel, iscomponentlist, incremental);
196  };
197 
198 
199  //helper function to clear the keywordSet of the ms of the model for the fields
200  //in that ms
201  void clearModelI(const casacore::MeasurementSet& thems) { clearModel (thems); }
202  static void clearModel(const casacore::MeasurementSet& thems);
203  // ...with field selection and optionally spw
204  static void clearModel(const casacore::MeasurementSet& thems, const casacore::String field, const casacore::String spws=casacore::String(""));
205 
206  //Functions to see if model is defined in the casacore::MS either in the SOURCE table or else in the MAIN
208  {
209  return isModelDefined (fieldId, thems, key, sourceRow);
210  }
211  static casacore::Bool isModelDefined(const casacore::Int fieldId, const casacore::MeasurementSet& thems, casacore::String& key, casacore::Int& sourceRow);
212  static casacore::Bool isModelDefined(const casacore::String& elkey, const casacore::MeasurementSet& thems);
213 
214  //Get a given model that is defined by key
215  //Forcing user to use a casacore::TableRecord rather than Generic casacore::RecordInterface ...just so as to avoid a copy.
217  {
218  return getModelRecord (theKey, theRec, theMs);
219  }
221 
222  // List the fields in the logger
223  static void listModel(const casacore::MeasurementSet& thems);
224 
225  // Returns true if any valid virtual model is found, fieldids of which are also returned
227  static FTMachine* NEW_FT(const casacore::Record& ftrec);
228  //check if an addFT or addCompFT is necessary
229  //casacore::Bool hasFT(casacore::Int msid, casacore::Int fieldid);
230  //casacore::Bool hasCL(casacore::Int msid, casacore::Int fieldid);
231  //returns a -1 if there is no model for this combination of ms,field,spw...but has not been // checked yet if there is one
232  //returns a -2 if it has been tested before but does have it.
233  //returns a 1 if it has a model stored
236  void init(const vi::VisBuffer2& vb);
237  void init(const VisBuffer& /*vb*/){throw(casacore::AipsError("Called the wrong version of VisModelData"));};
238  private:
239  void initializeToVis();
243  //Version 2.0
246  static casacore::Bool removeFTFromRec(casacore::TableRecord& therec, const casacore::String& keyval, const casacore::Bool relabel=true);
249  //Remove the casacore::Record which has the given key...will exterminate it from both the Source table or Main table
250  static void removeRecordByKey(casacore::MeasurementSet& theMS, const casacore::String& theKey);
251  //put the casacore::Record by key if sourcerownum=-1 then it is saved in the main table
252  //this default should only be used if the optional SOURCE table in non-existant
253  static void putRecordByKey(casacore::MeasurementSet& theMS, const casacore::String& theKey, const casacore::TableRecord& theRec, const casacore::Int sourceRowNum=-1);
254  static void deleteDiskImage(casacore::MeasurementSet& theMS, const casacore::String& theKey);
256  casacore::TableRecord& rec);
257  static void modifyDiskImagePath(casacore::Record& rec, const vi::VisBuffer2& vb);
259  void updateHolders(const vi::VisBuffer2& vb, const std::vector<casacore::Int>& index);
260  //get all the combinations of field, spw, scan, state in this visbuffer
268  //These 2 maps will hold the index of ftholder_p or clholder_p from key (field_id, spw_id, scan, state, msid)
269  std::map<std::vector<casacore::Int>, casacore::Int > ftindex2_p;
270  std::map<std::vector<casacore::Int>, casacore::Int > clindex2_p;
273 };
274 
275 }// end namespace refim
276 }//end namespace
277 
278 #endif // VISMODELDATA_H
static casacore::Bool removeSpw(casacore::TableRecord &therec, const casacore::Vector< casacore::Int > &spws, const casacore::Vector< casacore::Int > &fields=casacore::Vector< casacore::Int >(0))
int Int
Definition: aipstype.h:50
std::vector< double > Vector
Definition: ds9context.h:24
casacore::Vector< casacore::CountedPtr< ComponentList > > getCL(const casacore::Int msId, const casacore::Int fieldId, casacore::Int spw)
void putModelI(const casacore::MeasurementSet &thems, const casacore::RecordInterface &rec, const casacore::Matrix< casacore::Int > &indexComb, const casacore::Matrix< casacore::Int > &chansel, casacore::Bool iscomponentlist=true, casacore::Bool incremental=false)
Version 2 record to keep track of state and scan number.
Definition: VisModelData.h:192
static void listModel(const casacore::MeasurementSet &thems)
List the fields in the logger.
static casacore::Bool removeSpwFromMachineRec(casacore::RecordInterface &ftclrec, const casacore::Vector< casacore::Int > &spws)
defines interface for the Fourier Transform Machine
Definition: FTMachine.h:122
static casacore::Bool initialize
Definition: VisModelData.h:272
static void putModel(const casacore::MeasurementSet &thems, const casacore::RecordInterface &rec, const casacore::Vector< casacore::Int > &validfields, const casacore::Vector< casacore::Int > &spws, const casacore::Vector< casacore::Int > &starts, const casacore::Vector< casacore::Int > &nchan, const casacore::Vector< casacore::Int > &incr, casacore::Bool iscomponentlist=true, casacore::Bool incremental=false)
virtual ~VisModelData()
From a FTMachine Record VisModelData(const casacore::Record&amp; ftmachinerec, const casacore::Vector&lt;cas...
casacore::Int hasModel(casacore::Int msid, casacore::Int field, casacore::Int spw)
check if an addFT or addCompFT is necessary casacore::Bool hasFT(casacore::Int msid, casacore::Int fieldid); casacore::Bool hasCL(casacore::Int msid, casacore::Int fieldid); returns a -1 if there is no model for this combination of ms,field,spw...but has not been // checked yet if there is one returns a -2 if it has been tested before but does have it.
static casacore::Bool isModelDefined(const casacore::Int fieldId, const casacore::MeasurementSet &thems, casacore::String &key, casacore::Int &sourceRow)
void addModel(const casacore::RecordInterface &rec, const casacore::Vector< casacore::Int > &msids, const vi::VisBuffer2 &vb)
add componentlists or ftmachines
void updateHolders(const vi::VisBuffer2 &vb, const std::vector< casacore::Int > &index)
casacore::Vector< casacore::CountedPtr< FTMachine > > getFT(const casacore::Int msId, const casacore::Int fieldId, casacore::Int spw)
static void putRecordByKey(casacore::MeasurementSet &theMS, const casacore::String &theKey, const casacore::TableRecord &theRec, const casacore::Int sourceRowNum=-1)
put the casacore::Record by key if sourcerownum=-1 then it is saved in the main table this default sh...
void getUniqueIndicesComb(const vi::VisBuffer2 &vb, casacore::Vector< casacore::Vector< casacore::Int > > &retval)
get all the combinations of field, spw, scan, state in this visbuffer
casacore::Bool isModelDefinedI(const casacore::Int fieldId, const casacore::MeasurementSet &thems, casacore::String &key, casacore::Int &sourceRow)
Functions to see if model is defined in the casacore::MS either in the SOURCE table or else in the MA...
Definition: VisModelData.h:207
static casacore::Bool addToRec(casacore::TableRecord &therec, const casacore::Vector< casacore::Int > &spws)
casacore::Block< casacore::Vector< casacore::CountedPtr< ComponentList > > > clholder_p
Definition: VisModelData.h:262
static void clearModel(const casacore::MeasurementSet &thems)
casacore::Bool getModelRecordI(const casacore::String &theKey, casacore::TableRecord &theRec, const casacore::MeasurementSet &theMs)
Get a given model that is defined by key Forcing user to use a casacore::TableRecord rather than Gene...
Definition: VisModelData.h:216
static void removeRecordByKey(casacore::MeasurementSet &theMS, const casacore::String &theKey)
Remove the casacore::Record which has the given key...will exterminate it from both the Source table ...
Referenced counted pointer for constant data.
Definition: VisModelData.h:42
void clearModelI(const casacore::MeasurementSet &thems)
helper function to clear the keywordSet of the ms of the model for the fields in that ms ...
Definition: VisModelData.h:201
static casacore::Bool getModelRecord(const casacore::String &theKey, casacore::TableRecord &theRec, const casacore::MeasurementSet &theMs)
casacore::Cube< casacore::Int > ftindex_p
Definition: VisModelData.h:266
static casacore::Int firstSourceRowRecord(const casacore::Int field, const casacore::MeasurementSet &theMS, casacore::TableRecord &rec)
Object to provide MODEL_DATA visibilities on demand.
Definition: VisModelData.h:148
void addFlatModel(const casacore::Vector< casacore::Double > &value, const casacore::Vector< casacore::Int > &validfieldids, const casacore::Vector< casacore::Int > &msIds)
Add Image/FTMachine to generate visibilities for void addFTMachine(const casacore::Record&amp; recordFTMa...
casacore::Block< casacore::Vector< casacore::CountedPtr< FTMachine > > > ftholder_p
Definition: VisModelData.h:263
void getMatchingMachines(casacore::Vector< casacore::CountedPtr< FTMachine > > &ft, casacore::Vector< casacore::CountedPtr< ComponentList > > &cl, const vi::VisBuffer2 &vb)
A hierarchical collection of named fields of various types.
Definition: Record.h:180
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
VisModelData()
empty constructor
casacore::Block< casacore::Vector< casacore::Double > > flatholder_p
Definition: VisModelData.h:264
void init(const vi::VisBuffer2 &vb)
static void deleteDiskImage(casacore::MeasurementSet &theMS, const casacore::String &theKey)
A hierarchical collection of named fields of various types.
Definition: TableRecord.h:182
void addModel(const casacore::RecordInterface &, const casacore::Vector< casacore::Int > &, const VisBuffer &)
Add Image/FTMachine to generate visibilities for void addFTMachine(const casacore::Record&amp; recordFTMa...
Definition: VisModelData.h:167
A Table intended to hold astronomical data (a set of Measurements).
simple 1-D array
static casacore::Bool hasAnyModel(const casacore::MeasurementSet &thems, casacore::Vector< casacore::Int > &fieldids)
Returns true if any valid virtual model is found, fieldids of which are also returned.
std::map< std::vector< casacore::Int >, casacore::Int > ftindex2_p
These 2 maps will hold the index of ftholder_p or clholder_p from key (field_id, spw_id, scan, state, msid)
Definition: VisModelData.h:269
std::map< std::vector< casacore::Int >, casacore::Int > clindex2_p
Definition: VisModelData.h:270
VisBuffer2s encapsulate one chunk of visibility data for processing.
Definition: VisBuffer2.h:141
void init(const VisBuffer &)
Make sure that VisModel has been called once loaded checks and detection of version 1 or 2 is valid...
Definition: VisModelData.h:237
static void modifyDiskImagePath(casacore::Record &rec, const vi::VisBuffer2 &vb)
Base class for all Casacore library errors.
Definition: Error.h:134
casacore::Bool isVersion2()
Definition: VisModelData.h:235
static FTMachine * NEW_FT(const casacore::Record &ftrec)
casacore::Bool getModelVis(vi::VisBuffer2 &vb)
put the model data for this VisBuffer in the modelVisCube
String: the storage and methods of handling collections of characters.
Definition: String.h:223
casacore::CountedPtr< ComponentFTMachine > cft_p
Definition: VisModelData.h:265
static casacore::Bool removeFTFromRec(casacore::TableRecord &therec, const casacore::String &keyval, const casacore::Bool relabel=true)
VisBuffers encapsulate one chunk of visibility data for processing.
Definition: VisBuffer.h:153
VisModelDataI * clone()
casacore::Bool getModelVis(VisBuffer &)
//put the model data for this VisBuffer in the modelVisCube
Definition: VisModelData.h:174
Abstract base class for Record classes.
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
casacore::Cube< casacore::Int > clindex_p
Definition: VisModelData.h:267
void putModelI(const casacore::MeasurementSet &thems, const casacore::RecordInterface &rec, const casacore::Vector< casacore::Int > &validfields, const casacore::Vector< casacore::Int > &spws, const casacore::Vector< casacore::Int > &starts, const casacore::Vector< casacore::Int > &nchan, const casacore::Vector< casacore::Int > &incr, casacore::Bool iscomponentlist=true, casacore::Bool incremental=false)
this is a helper function that writes the model record to the ms
Definition: VisModelData.h:176
static casacore::Bool putModelRecord(const casacore::Vector< casacore::Int > &fieldIds, casacore::TableRecord &theRec, casacore::MeasurementSet &theMS)
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42