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