source: branches/casa-release-4_3-test/external-alma/asdm2ASAP/asdm2ASAP.cc@ 3127

Last change on this file since 3127 was 2754, checked in by Takeshi Nakazato, 12 years ago

New Development: No

JIRA Issue: Yes CSV-2532 (may be related to CSV-1908 and CSV-2161)

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: In tool level, added parameter 'freq_tolsr' to

scantable constructor and function sd.splitant.

Test Programs: test_sdsave, test_importasdm_sd

Put in Release Notes: Yes

Module(s): Module Names change impacts.

Description: Describe your changes here...

In importing MS to Scantable, frequency frame information is
imported as is by default, i.e., base frame in Scantable is
TOPO for ALMA data, which is forcibly converted to LSRK with
wrong time and direction reference.

Some functions have a boolean parameter 'freq_tolsr' that controls
the above behavior. If freq_tolsr is False (default), frequency
is imported as is, while frequency is converted to LSRK (wrongly)
when it is True.


  • Property svn:keywords set to Id
File size: 6.7 KB
Line 
1#include <iostream>
2#include <fstream>
3#include <casa/Utilities/Regex.h>
4#include <casa/Inputs/Input.h>
5#include <casa/BasicSL/String.h>
6#include <casa/Containers/Record.h>
7#include <casa/OS/Directory.h>
8#include <casa/Logging/LogIO.h>
9#include <casa/Logging/LogSink.h>
10#include <casa/Logging/StreamLogSink.h>
11#include <casa/Logging/LogFilter.h>
12#include "../../src/Scantable.h"
13#include "ASDMFiller.h"
14
15using namespace std ;
16using namespace asdm ;
17using namespace casa ;
18using namespace asap ;
19
20int main( int argc, char *argv[] )
21{
22 // options
23 Input inp ;
24 String indent = " " ;
25 String versionInfo = "$Id: asdm2ASAP.cc 2754 2013-01-31 02:14:27Z TakeshiNakazato $\nConverts an ASDM dataset into Scantable.\nUsage:\n"+indent+argv[0]+" -antenna <antenna name or id> -asdm <ASDM directory> -asap <Scantable name> [-apc both|yes|no] [-corr-mode ca|ao|ca,ao] [-ocorr-mode ao] [-time-sampling all|integration|subintegration] [-srt fr|bw|ca|fr,bw|fr,ca|ca,bw|all]" ;
26 Bool helpMode = False ;
27 for ( int i = 1 ; i < argc ; i++ ) {
28 if ( strncmp( argv[i], "-h", 2 ) == 0
29 || strncmp( argv[i], "--help", 6 ) == 0
30 || strncmp( argv[i], "-v", 2 ) == 0
31 || strncmp( argv[i], "--version", 9 ) == 0 ) {
32 helpMode = True ;
33 break ;
34 }
35 }
36 if ( helpMode )
37 inp.version( versionInfo ) ;
38 else
39 inp.version( "" ) ;
40
41 inp.create( "antenna", "0", "antenna name or id", "String" ) ;
42 inp.create( "asdm", "", "ASDM directory name", "String" ) ;
43 inp.create( "asap", "", "Scantable name", "String" ) ;
44 inp.create( "apc", "both", "Retrieve Atm Phase Corrected data or not: both|yes|no", "String" ) ;
45 inp.create( "overwrite", "True", "Overwrite existing Scantable or not: True|False", "Bool" ) ;
46 inp.create( "corr-mode", "ca,ao", "Input correlator mode: ca+ao|ca|ao", "String" ) ;
47 inp.create( "ocorr-mode", "ao", "Output correlator mode: ao", "String" ) ;
48 inp.create( "time-sampling", "all", "time sampling mode: all|integration|subintegration", "String" ) ;
49 inp.create( "srt", "all", "spectral resolution mode: all|fr(full resolution)|ca(channel average)|bw(baseband wide)|fr+ca|fr+bw|ca+bw", "String" ) ;
50 inp.create( "logfile", "", "logger output", "String" ) ;
51 inp.create( "freq-tolsr", "False", "Convert frequency frame to LSRK or not: True|False", "Bool" ) ;
52 inp.readArguments( argc, argv ) ;
53
54 string asdmname = inp.getString( "asdm" ) ;
55 string antenna = inp.getString( "antenna" ) ;
56 string asapname = inp.getString( "asap" ) ;
57 string apc = inp.getString( "apc" ) ;
58 Bool overwrite = inp.getBool( "overwrite" ) ;
59 string corrMode = inp.getString( "corr-mode" ) ;
60 string timeSampling = inp.getString( "time-sampling" ) ;
61 string resolutionType = inp.getString( "srt" ) ;
62 string logfile = inp.getString( "logfile" ) ;
63 Bool freqToLsr = inp.getBool( "freq-tolsr" ) ;
64
65 int numApc = 1 ;
66 Vector<Bool> apcCorrected ;
67 apcCorrected.resize( numApc ) ;
68 if ( apc == "both" ) {
69 numApc = 2 ;
70 apcCorrected.resize( numApc ) ;
71 apcCorrected[0] = True ;
72 apcCorrected[1] = False ;
73 }
74 else if ( apc == "yes" ) {
75 apcCorrected.resize( numApc ) ;
76 apcCorrected[0] = True ;
77 }
78 else if ( apc == "no" ) {
79 apcCorrected.resize( numApc ) ;
80 apcCorrected[0] = False ;
81 }
82 else {
83 throw AipsError( "Unrecognized value for -apc option" ) ;
84 }
85
86
87 ofstream ofs ;
88 CountedPtr<LogSinkInterface> logsink_p ;
89 String funcname( argv[0] ) ;
90 if ( logfile.size() != 0 ) {
91 ofs.open( logfile.c_str(), ios_base::app ) ;
92 logsink_p = new StreamLogSink( &ofs ) ;
93 logsink_p->cerrToo( false ) ;
94 }
95 else {
96 logsink_p = new StreamLogSink() ;
97 }
98 // create ASDMFiller object
99 //logsink_p->postLocally( LogMessage( "numApc = "+String::toString(numApc), LogOrigin(funcname,WHERE) ) ) ;
100 for ( int iapc = 0 ; iapc < numApc ; iapc++ ) {
101 CountedPtr<Scantable> stable( new Scantable() ) ;
102 ASDMFiller *filler = new ASDMFiller( stable ) ;
103
104 // set logger
105 filler->setLogger( logsink_p ) ;
106
107 // open data
108 Record rec ;
109 Record asdmRec ;
110 Regex reg( "[0-9]+$" ) ;
111 //asdmRec.define( "apc", apcCorrected ) ;
112 asdmRec.define( "apc", apcCorrected[iapc] ) ;
113 asdmRec.define( "corr", corrMode ) ;
114 asdmRec.define( "sampling", timeSampling ) ;
115 asdmRec.define( "srt", resolutionType ) ;
116 asdmRec.define( "freq_tolsr", freqToLsr ) ;
117 if ( reg.match( antenna.c_str(), antenna.size() ) != String::npos ) {
118 // antenna is specifiec as id
119 int aid = atoi( antenna.c_str() ) ;
120 asdmRec.define( "antenna", aid ) ;
121 }
122 else {
123 // antenna is specified as name
124 asdmRec.define( "antenna", antenna ) ;
125 }
126 rec.defineRecord( "asdm", asdmRec ) ;
127 filler->open( asdmname, rec ) ;
128
129 // output filename
130 CountedPtr<ASDMReader> reader = filler->getReader() ;
131 string aname = reader->getAntennaName() ;
132 string outname = asapname ;
133 if ( asapname.size() == 0 ) {
134 outname = asdmname + "." + aname + ".asap" ;
135 }
136 if ( apcCorrected[iapc] == True ) {
137 outname += ".wvr-corrected" ;
138 }
139
140 //logsink_p->postLocally( LogMessage("specified option summary:",LogOrigin(funcname,WHERE)) ) ;
141 //logsink_p->postLocally( LogMessage(" antenna = "+String(aname)+" (ID: "+String::toString(reader->getAntennaId())+")",LogOrigin(funcname,WHERE)) ) ;
142 //logsink_p->postLocally( LogMessage(" asdmname = "+asdmname,LogOrigin(funcname,WHERE)) ) ;
143 //logsink_p->postLocally( LogMessage(" asapname = "+outname,LogOrigin(funcname,WHERE)) ) ;
144 //logsink_p->postLocally( LogMessage(" apcCorrected = "+String::toString(apcCorrected[iapc]),LogOrigin(funcname,WHERE) ) ) ;
145 //logsink_p->postLocally( LogMessage(" timeSampling = "+timeSampling,LogOrigin(funcname,WHERE) ) ) ;
146 //logsink_p->postLocally( LogMessage(" corrMode = "+corrMode,LogOrigin(funcname,WHERE) ) ) ;
147
148 // save scantable on disk
149 Directory dir( outname ) ;
150 if ( dir.exists() ) {
151 if ( overwrite ) {
152 logsink_p->postLocally( LogMessage("Delete existing file "+outname+" ...",LogOrigin(funcname,WHERE)) ) ;
153 dir.removeRecursive() ;
154 }
155 else {
156 logsink_p->postLocally( LogMessage("Output file "+outname+" exists.",LogOrigin(funcname,WHERE),LogMessage::WARN) ) ;
157 return 1 ;
158 }
159 }
160
161 // fill data
162 filler->fill() ;
163
164 // close data
165 filler->close() ;
166
167 // save data only if nrow is not zero
168 if ( stable->nrow() > 0 ) {
169 logsink_p->postLocally( LogMessage("Creating "+outname+"...",LogOrigin(funcname,WHERE)) ) ;
170 stable->makePersistent( outname ) ;
171 }
172 else {
173 logsink_p->postLocally( LogMessage(outname+" will not be created since there are no data associate with the selection",LogOrigin(funcname,WHERE)) ) ;
174 }
175
176 // finalize
177 reader = 0 ;
178 delete filler ;
179
180 }
181
182 if ( logfile.size() != 0 )
183 ofs.close() ;
184
185 return 0 ;
186}
Note: See TracBrowser for help on using the repository browser.