casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MS2ASDM.h
Go to the documentation of this file.
1 //# MS2ASDM.h
2 //#
3 //# ALMA - Atacama Large Millimeter Array
4 //# (c) European Southern Observatory, 2002
5 //# (c) Associated Universities Inc., 2002
6 //# Copyright by ESO (in the framework of the ALMA collaboration),
7 //# Copyright by AUI (in the framework of the ALMA collaboration),
8 //# All rights reserved.
9 //#
10 //# This library is free software; you can redistribute it and/or
11 //# modify it under the terms of the GNU Lesser General Public
12 //# License as published by the Free software Foundation; either
13 //# version 2.1 of the License, or (at your option) any later version.
14 //#
15 //# This library is distributed in the hope that it will be useful,
16 //# but WITHOUT ANY WARRANTY, without even the implied warranty of
17 //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 //# Lesser General Public License for more details.
19 //#
20 //# You should have received a copy of the GNU Lesser General Public
21 //# License along with this library; if not, write to the Free Software
22 //# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 //# MA 02111-1307 USA
24 //# $Id: $
27 #include <casa/aips.h>
28 #include <casa/Arrays/Array.h>
29 #include <casa/Arrays/Vector.h>
30 #include <map>
31 #include <vector>
32 #include <casa/OS/Directory.h>
33 
34 #include <alma/ASDM/ASDM.h>
35 #include <alma/ASDM/Tag.h>
37 #include <alma/ASDM/Frequency.h>
38 #include <alma/ASDM/Angle.h>
39 #include <alma/ASDM/AngularRate.h>
40 #include <alma/ASDM/ArrayTime.h>
41 #include <alma/ASDM/Length.h>
42 #include <alma/ASDM/Temperature.h>
44 #include <alma/ASDM/EntityRef.h>
53 
54 
55 #ifndef MS2ASDM_MS2ASDM_H
56 #define MS2ASDM_MS2ASDM_H
57 
58 namespace casa { //# NAMESPACE CASA - BEGIN
59 
60 // <summary>
61 // MS2ASDM provides functionalities to create an ASDM (ALMA science data model)
62 // from an existing MS
63 // </summary>
64 
65 // <visibility=export>
66 
67 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
68 // </reviewed>
69 
70 // <prerequisite>
71 // <li> MeasurementSet
72 // </prerequisite>
73 //
74 // <etymology>
75 // </etymology>
76 //
77 // <synopsis>
78 // </synopsis>
79 
81 {
82 
83  public:
84 
85  // construct from an MS
87 
88  ~MS2ASDM();
89 
91 
92  // set verbosity of the write methods
93  void setVerbosity(const casacore::uInt verbosity = 2){ // 0 = only warnings, 1 = most, 2 = everything
94  verbosity_p = verbosity; }
95 
96  void setBaseUid(const casacore::String& baseuid);
97 
99 
100  const std::string& getCurrentUid();
101 
102  // return currentUid_p with all ":" and "/" characters replaced by "_"
103  const std::string& getCurrentUidAsFileName();
104 
105  // set maximum duration of a subscan in seconds, 0. == no time limit
106  void setSubScanDuration(const casacore::Double subscanDuration = 24.*3600.){
107  subscanDuration_p = subscanDuration; }
108 
109  // get maximum duration of a subscan in seconds
111 
112  // set maximum duration of a Scheduling casacore::Block in seconds
113  void setSBDuration(const casacore::Double sBDuration = 2700.){ // 45 minutes
114  schedBlockDuration_p = sBDuration; }
115 
116  // get maximum duration of a Scheduling casacore::Block in seconds
118 
119  void setDataAPCorrected(const casacore::Bool isCorrected = true){
120  dataIsAPCorrected_p = isCorrected; }
121 
123 
124  void setObservatoryName(const casacore::String& telName){
125  telName_p = telName; }
126 
128  telName = telName_p; }
129 
130  // convert CASA casacore::Stokes to ASDM Stokes
131  StokesParameterMod::StokesParameter ASDMStokesParameter( casacore::Stokes::StokesTypes s);
132 
133  // convert CASA antenna type string to ASDM antenna type enum
134  AntennaTypeMod::AntennaType ASDMAntennaType( const casacore::String& type );
135 
136  // convert time in seconds to an array time
138  return asdm::ArrayTime((int64_t) (floor(seconds*asdm::ArrayTime::unitsInASecond))); }
139 
140  // convert array time to time in seconds
143 
145  return asdm::Interval((int64_t) (floor(seconds*asdm::ArrayTime::unitsInASecond))); }
146 
147  // convert casacore::MS style time interval to ASDM ArrayTimeInterval
149 
150  // return start of casacore::MS main table timestamp (seconds)
152  return timeQuant()(mainTabRow).getValue("s") - intervalQuant()(mainTabRow).getValue("s")/2.; }
153 
154  // return end of casacore::MS main table timestamp (seconds)
156  return timeQuant()(mainTabRow).getValue("s") + intervalQuant()(mainTabRow).getValue("s")/2.; }
157 
158  // convert casacore::MDirection to a vector of Angles
159  std::vector< asdm::Angle > ASDMAngleV(const casacore::MDirection mDir);
160 
161  // convert casacore::MDirection type to ASDM DirectionReferenceCode
162  DirectionReferenceCodeMod::DirectionReferenceCode ASDMDirRefCode(const casacore::MDirection::Types type);
163 
164  // convert a base band converter number to an ASDM base band name
165  BasebandNameMod::BasebandName ASDMBBName( const casacore::Int bbcNo );
166 
167  // convert a casacore::MS net sideband no. to an ASDM enum
168  NetSidebandMod::NetSideband ASDMNetSideBand( const casacore::Int netSideband );
169 
170  // set a representative frequency, the receiver band and receiver sideband based on a frequency refFreq
171  // and the previously set observatory name telName_p, return the band id as an casacore::Int (1 to 10),
172  // -1 if refFreq is outside ALMA bands but observatory is ALMA, 0 if observatory not ALMA
174  casacore::Double& frequency,
175  ReceiverBandMod::ReceiverBand& frequencyBand,
176  ReceiverSidebandMod::ReceiverSideband& receiverSideband);
177 
178  FrequencyReferenceCodeMod::FrequencyReferenceCode ASDMFreqRefCode( const casacore::MFrequency::Types refFrame );
179 
181 
183 
185 
187 
189 
190  asdm::Complex ASDMComplex( casacore::Complex x ){ return asdm::Complex(x.real(), x.imag()); }
191 
192  // write the entire ASDM from scratch
193  casacore::Bool writeASDM(const casacore::String& asdmfile="",
194  const casacore::String& datacolumn="data",
195  const casacore::String& archiveid="S0",
196  const casacore::String& rangeid="X1",
197  const casacore::Bool verbose=true,
198  const casacore::Double maxSubscanDuration = 24.*3600.,
199  const casacore::Double maxSchedBlockDuration = 2700.,
200  const casacore::Bool msDataIsAPCorrected=true
201  );
202 
203  private:
204  // *** Private member functions ***
205 
206  casacore::Bool incrementUid(); // returns true if successful
207 
209 
210 
212 
214 
216 
218 
220 
221  casacore::Bool writeCorrelatorMode(); // not called directly but optionally called by writeProcessor()
222  casacore::Bool writeAlmaRadiometer(); // optionally called by writeProcessor()
223  casacore::Bool writeHolography(); // optionally called by writeProcessor()
224 
226 
228 
230 
232 
234 
235  casacore::Bool writeSwitchCycle(); // not yet fully implemented
236 
238 
240 
242 
243  // Scheme
244  // 1) We regard one casacore::MS Observation as a set of ASDM ExecBlocks modelled on
245  // a single ASDM Scheduling Block
246  // 2) ALMA ExecBlocks are at most 30 minutes long.
247  // If an casacore::MS Observation is more than 30 Minutes long, it is split up into
248  // several ASDM ExecBlocks each referring to the same Scheduling Block.
249  // 3) Each ASDM ExecBlock contains one or more ASDM Scans based on the casacore::MS scans
250  // 4) Each ASDM Scan contains one or more ASDM Subscans
251  // 5) Each ASDM Subscan is at most subscanduration long. (external parameter)
252  // 6) If an casacore::MS Scan is longer than subscanduration, it is split up into
253  // several ASDM subscans.
254 
255  casacore::Bool writeSBSummaryAndExecBlockStubs(); // "stubs" because these tables will be completed later
256  // with information from the APDM
258 
259  // write the Main binary data for one DataDescId/FieldId pair and one SubScan
260  // (return number of integrations written and set the last three parameters in the list)
262  const casacore::String& datacolumn,
263  const casacore::uInt theScan, const casacore::uInt theSubScan,
264  const casacore::uInt startRow, const casacore::uInt endRow,
265  const asdm::Tag eBlockId,
266  int& datasize, asdm::EntityRef& dataOid,
267  std::vector< asdm::Tag >& stateId);
268 
269  casacore::Bool writePointingModel(); // write dummy pointing models
270 
272 
273  // *** Aux. methods ***
274 
275  // check if vector corrT already contains a stokes type equivalent to st
277 
278  // *** Member variables ***
279 
280  // Initialized* by ctors. (Maintain order both here and in ctors.)
281  casacore::MeasurementSet ms_p; // the measurement set from which the ASDM is filled
282 
283  asdm::ASDM* ASDM_p; // the new ASDM
284 
285  string asdmVersion_p; // the version of the new ASDM
286 
287  casacore::uInt verbosity_p; // verbosity of the write methods
288 
289  casacore::String baseUid_p; // the part of the UID which is common to all elements of the ASDM,
290  // i.e. typically "uid://archiveid/rangeid/"
291 
292  casacore::uInt runningId_p; // counter for the tables written; starts at 1!
293  // used to construct the UIDs: uid = baseUid_p + (runningId_p converted to unpadded hex string)
294 
295  casacore::String currentUid_p; // the last used uid
296 
297  casacore::String telName_p; // the name of the observatory from first row of casacore::MS observation table
298 
299  casacore::Double subscanDuration_p; // maximum duration of a subscan in seconds
300 
301  casacore::Double schedBlockDuration_p; // maximum duration of a scheduling or exec block in seconds
302 
303  casacore::Bool dataIsAPCorrected_p; // true if the data in the selected casacore::MS data column is
304  // AtmPhaseCorrectionMod::AP_CORRECTED, false if it is
305  // AtmPhaseCorrectionMod::AP_UNCORRECTED
306 
307  string asdmUID_p; // ASDM UID == container ID of all tables
308 
309  casacore::String asdmDir_p; // ASDM output directory name
310 
311  // The default value for the Tag keys is Tag(), so the std::map works as is
312  std::map <casacore::String, asdm::Tag> asdmStationId_p;
313  std::map <casacore::Int, asdm::Tag> asdmAntennaId_p;
314  std::map <casacore::Int, asdm::Tag> asdmSpectralWindowId_p;
315  std::map <casacore::Int, asdm::Tag> asdmPolarizationId_p;
316  std::map <casacore::Int, asdm::Tag> asdmProcessorId_p;
317  std::map <casacore::Int, asdm::Tag> asdmFieldId_p;
318  std::map <casacore::Int, asdm::Tag> asdmEphemerisId_p;
319  std::map <casacore::Int, asdm::Tag> asdmDataDescriptionId_p;
320  std::map <casacore::Int, asdm::Tag> asdmStateId_p;
321  std::map <casacore::uInt, asdm::Tag> asdmConfigDescriptionId_p; // maps from casacore::MS Main rows
322  std::map <casacore::Int, asdm::Tag> asdmSBSummaryId_p; // maps from casacore::MS Observation Id + 10000*SpwId
323  std::map <casacore::Double, asdm::Tag> asdmExecBlockId_p; // maps from casacore::MS Main timestamps
324  // the default value for the int values is -1, needs MapWithDefault
325  MapWithDefault <casacore::Int, int> asdmFeedId_p; // ASDM feed id is not a Tag
327  MapWithDefault <asdm::Tag, int> asdmPointingModelId_p; // maps ASDM Antenna Id to dummy pointing model
328 
329  std::vector< std::vector< casacore::Bool > > skipCorr_p; // skipCorr_p[j][PolId] indicates that correlation
330  // product j for POLARIZATION_ID PolId should not
331  // be written in the ASDM
332 
333 };
334 
335 
336 } //# NAMESPACE CASA - END
337 
338 #endif
339 
static std::string unit()
Returns the abbreviated name of the unit implicitely associated to any Angle.
Definition: Angle.h:445
casacore::Bool writeState()
A Measure: astronomical direction.
Definition: MDirection.h:174
casacore::MeasurementSet ms_p
*** Member variables ***
Definition: MS2ASDM.h:281
MapWithDefault< casacore::Int, int > asdmFeedId_p
the default value for the int values is -1, needs MapWithDefault
Definition: MS2ASDM.h:325
casacore::Bool writeConfigDescription()
int Int
Definition: aipstype.h:50
The Interval class implements an interval of time in units of nanoseconds.
Definition: Interval.h:58
casacore::Double timestampEndSecs(const casacore::uInt mainTabRow)
return end of casacore::MS main table timestamp (seconds)
Definition: MS2ASDM.h:155
casacore::uInt verbosity_p
Definition: MS2ASDM.h:287
void setSBDuration(const casacore::Double sBDuration=2700.)
set maximum duration of a Scheduling casacore::Block in seconds
Definition: MS2ASDM.h:113
asdm::ASDM * ASDM_p
Definition: MS2ASDM.h:283
casacore::Bool dataIsAPCorrected_p
Definition: MS2ASDM.h:303
casacore::Bool writePointing()
static std::string unit()
Returns the abbreviated name of the unit implicitely associated to any Frequency. ...
Definition: Frequency.h:445
AntennaTypeMod::AntennaType ASDMAntennaType(const casacore::String &type)
convert CASA antenna type string to ASDM antenna type enum
casacore::Bool writeSBSummaryAndExecBlockStubs()
Scheme 1) We regard one casacore::MS Observation as a set of ASDM ExecBlocks modelled on a single ASD...
void setVerbosity(const casacore::uInt verbosity=2)
set verbosity of the write methods
Definition: MS2ASDM.h:93
The ArrayTimeInterval class aggregates an instance of ArrayTime and an instance of Interval...
static std::string unit()
Returns the abbreviated name of the unit implicitely associated to any Length.
Definition: Length.h:445
casacore::Bool writeSwitchCycle()
std::vector< std::vector< casacore::Bool > > skipCorr_p
Definition: MS2ASDM.h:329
const std::string & getCurrentUid()
virtual Type type()
Return the type enum.
std::map< casacore::Int, asdm::Tag > asdmProcessorId_p
Definition: MS2ASDM.h:316
static std::string unit()
Returns the abbreviated name of the unit implicitely associated to any AngularRate.
Definition: AngularRate.h:445
casacore::Bool writeCorrelatorMode()
casacore::Bool dataIsAPCorrected()
Definition: MS2ASDM.h:122
casacore::Bool writeAntenna()
The ASDM class is the container for all tables.
Definition: ASDM.h:273
MapWithDefault< casacore::Int, int > asdmSourceId_p
Definition: MS2ASDM.h:326
DirectionReferenceCodeMod::DirectionReferenceCode ASDMDirRefCode(const casacore::MDirection::Types type)
convert casacore::MDirection type to ASDM DirectionReferenceCode
const ROScalarColumn< Int > & stateId() const
casacore::Bool writeMainAndScanAndSubScan(const casacore::String &datacolumn)
with information from the APDM
void setObservatoryName(const casacore::String &telName)
Definition: MS2ASDM.h:124
casacore::Bool writePointingModel()
std::vector< asdm::Angle > ASDMAngleV(const casacore::MDirection mDir)
convert casacore::MDirection to a vector of Angles
void setDataAPCorrected(const casacore::Bool isCorrected=true)
Definition: MS2ASDM.h:119
casacore::Bool writeAlmaRadiometer()
std::map< casacore::Int, asdm::Tag > asdmSBSummaryId_p
Definition: MS2ASDM.h:322
LatticeExprNode floor(const LatticeExprNode &expr)
void setSubScanDuration(const casacore::Double subscanDuration=24.*3600.)
set maximum duration of a subscan in seconds, 0.
Definition: MS2ASDM.h:106
casacore::Bool writeStation()
The Complex class extends the Complex class in the C++ standard library.
casacore::Bool writeDataDescription()
StokesTypes
The Stokes types are defined by this enum.
Definition: Stokes.h:66
Types
Types of known MDirections Warning: The order defines the order in the translation matrix FromTo in ...
Definition: MDirection.h:188
The EntityRef class is an identification of a persistant entity in the ALMA archive.
Definition: EntityRef.h:58
defines physical units
Definition: Unit.h:189
asdm::Complex ASDMComplex(casacore::Complex x)
Definition: MS2ASDM.h:190
casacore::Double MSTimeSecs(const asdm::ArrayTime atime)
convert array time to time in seconds
Definition: MS2ASDM.h:141
casacore::Bool writeReceiver()
int64_t get() const
Definition: Interval.h:295
casacore::Bool writeField()
static std::string unit()
Returns the abbreviated name of the unit implicitely associated to any Temperature.
Definition: Temperature.h:445
asdm::Interval ASDMInterval(const casacore::Double seconds)
Definition: MS2ASDM.h:144
casacore::Bool setDirectory(const casacore::String &asdmfile)
std::map< casacore::Int, asdm::Tag > asdmDataDescriptionId_p
Definition: MS2ASDM.h:319
const ROScalarColumn< Double > & interval() const
casacore::Bool incrementUid()
*** Private member functions ***
MS2ASDM(casacore::MeasurementSet &ms)
construct from an MS
casacore::Double getSubScanDuration()
get maximum duration of a subscan in seconds
Definition: MS2ASDM.h:110
casacore::Bool writeFeed()
MapWithDefault< asdm::Tag, int > asdmPointingModelId_p
Definition: MS2ASDM.h:327
std::map< casacore::Int, asdm::Tag > asdmAntennaId_p
Definition: MS2ASDM.h:313
string asdmVersion_p
Definition: MS2ASDM.h:285
casacore::Double timestampStartSecs(const casacore::uInt mainTabRow)
return start of casacore::MS main table timestamp (seconds)
Definition: MS2ASDM.h:151
casacore::Unit unitASDMAngularRate()
Definition: MS2ASDM.h:184
double Double
Definition: aipstype.h:55
A class to provide easy read-only access to MeasurementSet columns.
Definition: MSColumns.h:111
std::map< casacore::uInt, asdm::Tag > asdmConfigDescriptionId_p
Definition: MS2ASDM.h:321
FrequencyReferenceCodeMod::FrequencyReferenceCode ASDMFreqRefCode(const casacore::MFrequency::Types refFrame)
casacore::Bool stokesTypePresent(const casacore::Vector< casacore::Int > corrT, const casacore::Stokes::StokesTypes st)
*** Aux.
std::map< casacore::Int, asdm::Tag > asdmSpectralWindowId_p
Definition: MS2ASDM.h:314
casacore::Int setRecBands(const asdm::Frequency refFreq, casacore::Double &frequency, ReceiverBandMod::ReceiverBand &frequencyBand, ReceiverSidebandMod::ReceiverSideband &receiverSideband)
set a representative frequency, the receiver band and receiver sideband based on a frequency refFreq ...
std::map< casacore::String, asdm::Tag > asdmStationId_p
The default value for the Tag keys is Tag(), so the std::map works as is.
Definition: MS2ASDM.h:312
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
casacore::String telName_p
Definition: MS2ASDM.h:297
casacore::Double subscanDuration_p
Definition: MS2ASDM.h:299
The ArrayTime class implements the concept of a point in time, implemented as an Interval of time sin...
Definition: ArrayTime.h:89
casacore::Double getSBDuration()
get maximum duration of a Scheduling casacore::Block in seconds
Definition: MS2ASDM.h:117
NetSidebandMod::NetSideband ASDMNetSideBand(const casacore::Int netSideband)
convert a casacore::MS net sideband no.
casacore::Bool writeProcessor()
casacore::Unit unitASDMFreq()
Definition: MS2ASDM.h:180
const std::string & getCurrentUidAsFileName()
return currentUid_p with all &quot;:&quot; and &quot;/&quot; characters replaced by &quot;_&quot;
std::map< casacore::Int, asdm::Tag > asdmPolarizationId_p
Definition: MS2ASDM.h:315
const ROScalarQuantColumn< Double > & intervalQuant() const
The Tag class is an implementation of a unique index identifying a row of an ASDM table...
Definition: Tag.h:73
casacore::Bool writePolarization()
casacore::Bool writeASDM(const casacore::String &asdmfile="", const casacore::String &datacolumn="data", const casacore::String &archiveid="S0", const casacore::String &rangeid="X1", const casacore::Bool verbose=true, const casacore::Double maxSubscanDuration=24.*3600., const casacore::Double maxSchedBlockDuration=2700., const casacore::Bool msDataIsAPCorrected=true)
write the entire ASDM from scratch
std::map< casacore::Int, asdm::Tag > asdmEphemerisId_p
Definition: MS2ASDM.h:318
casacore::Int writeMainBinSubScanForOneDDIdFIdPair(const casacore::Int theDDId, const casacore::Int theFieldId, const casacore::String &datacolumn, const casacore::uInt theScan, const casacore::uInt theSubScan, const casacore::uInt startRow, const casacore::uInt endRow, const asdm::Tag eBlockId, int &datasize, asdm::EntityRef &dataOid, std::vector< asdm::Tag > &stateId)
write the Main binary data for one DataDescId/FieldId pair and one SubScan (return number of integrat...
A Table intended to hold astronomical data (a set of Measurements).
const ROScalarQuantColumn< Double > & timeQuant() const
casacore::Unit unitASDMAngle()
Definition: MS2ASDM.h:182
asdm::ArrayTime ASDMArrayTime(const casacore::Double seconds)
convert time in seconds to an array time
Definition: MS2ASDM.h:137
std::map< casacore::Int, asdm::Tag > asdmFieldId_p
Definition: MS2ASDM.h:317
std::map< casacore::Double, asdm::Tag > asdmExecBlockId_p
Definition: MS2ASDM.h:323
BasebandNameMod::BasebandName ASDMBBName(const casacore::Int bbcNo)
convert a base band converter number to an ASDM base band name
std::map< casacore::Int, asdm::Tag > asdmStateId_p
Definition: MS2ASDM.h:320
casacore::Double schedBlockDuration_p
Definition: MS2ASDM.h:301
casacore::Bool writeHolography()
static const int64_t unitsInASecond
Definition: ArrayTime.h:95
casacore::Unit unitASDMTemp()
Definition: MS2ASDM.h:188
StokesParameterMod::StokesParameter ASDMStokesParameter(casacore::Stokes::StokesTypes s)
convert CASA casacore::Stokes to ASDM Stokes
string asdmUID_p
AtmPhaseCorrectionMod::AP_CORRECTED, false if it is AtmPhaseCorrectionMod::AP_UNCORRECTED.
Definition: MS2ASDM.h:307
void getObservatoryName(casacore::String &telName)
Definition: MS2ASDM.h:127
String: the storage and methods of handling collections of characters.
Definition: String.h:223
const casacore::String & showversion()
casacore::Bool writeSysCal()
void setBaseUid(const casacore::String &baseuid)
casacore::Unit unitASDMLength()
Definition: MS2ASDM.h:186
Types
Types of known MFrequencies Warning: The order defines the order in the translation matrix FromTo in...
Definition: MFrequency.h:176
The Frequency class implements a quantity of frequency in hertz.
Definition: Frequency.h:53
MS2ASDM provides functionalities to create an ASDM (ALMA science data model) from an existing MS...
Definition: MS2ASDM.h:80
casacore::String currentUid_p
used to construct the UIDs: uid = baseUid_p + (runningId_p converted to unpadded hex string) ...
Definition: MS2ASDM.h:295
casacore::String baseUid_p
Definition: MS2ASDM.h:289
casacore::Bool writeSpectralWindow()
unsigned int uInt
Definition: aipstype.h:51
casacore::String asdmDir_p
Definition: MS2ASDM.h:309
const casacore::String & getBaseUid()
casacore::uInt runningId_p
i.e.
Definition: MS2ASDM.h:292
casacore::Bool writeSource()
asdm::ArrayTimeInterval ASDMTimeInterval(const casacore::Quantity midpoint, const casacore::Quantity interval)
convert casacore::MS style time interval to ASDM ArrayTimeInterval