00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00025 #if !defined(ALMA_ASDM2MSFILLER_H)
00026 #define ALMA_ASDM2MSFILLER_H
00027
00028
00029 #include <casa/aips.h>
00030 #include <casa/Utilities/Assert.h>
00031 #include <tables/Tables.h>
00032 #include <ms/MeasurementSets/MeasurementSet.h>
00033 #include <ms/MeasurementSets/MSAntennaColumns.h>
00034 #include <ms/MeasurementSets/MSDataDescColumns.h>
00035 #include <ms/MeasurementSets/MSFeedColumns.h>
00036 #include <ms/MeasurementSets/MSFieldColumns.h>
00037 #include <ms/MeasurementSets/MSFlagCmdColumns.h>
00038 #include <ms/MeasurementSets/MSHistoryColumns.h>
00039 #include <ms/MeasurementSets/MSMainColumns.h>
00040
00041 #include <ms/MeasurementSets/MSObsColumns.h>
00042 #include <ms/MeasurementSets/MSPointingColumns.h>
00043 #include <ms/MeasurementSets/MSPolColumns.h>
00044 #include <ms/MeasurementSets/MSProcessorColumns.h>
00045 #include <ms/MeasurementSets/MSSourceColumns.h>
00046 #include <ms/MeasurementSets/MSStateColumns.h>
00047 #include <ms/MeasurementSets/MSSpWindowColumns.h>
00048 #include <ms/MeasurementSets/MSSysCalColumns.h>
00049 #include <ms/MeasurementSets/MSWeatherColumns.h>
00050
00051 #include <tables/Tables/StandardStMan.h>
00052 #include <tables/Tables/TiledShapeStMan.h>
00053 #include <tables/Tables/SetupNewTab.h>
00054 #include <tables/Tables/TableDesc.h>
00055 #include <tables/Tables/TableRecord.h>
00056 #include <casa/Arrays/Vector.h>
00057 #include <casa/Arrays/Cube.h>
00058 #include <casa/Arrays/Matrix.h>
00059 #include <casa/Arrays/ArrayMath.h>
00060 #include <casa/Arrays/ArrayUtil.h>
00061 #include <casa/Arrays/ArrayLogical.h>
00062 #include <casa/Containers/Block.h>
00063 #include <casa/Containers/OrderedMap.h>
00064 #include <measures/Measures/MPosition.h>
00065 #include <measures/Measures/MBaseline.h>
00066 #include <measures/Measures/Muvw.h>
00067 #include <measures/Measures/MeasTable.h>
00068 #include <measures/Measures/Stokes.h>
00069 #include <measures/Measures/MeasConvert.h>
00070 #include "measures/Measures/Stokes.h"
00071 #include <casa/BasicSL/Constants.h>
00072 #include <casa/OS/File.h>
00073 #include <casa/OS/Path.h>
00074 #include <complex>
00075
00076 #include <vector>
00077
00078
00079 using namespace casa;
00080 using namespace std;
00081
00082
00083
00084 class TimeRange;
00085 class MPosition;
00086 class MeasFrame;
00087 class MeasurementSet;
00088 class MSMainColumns;
00089
00090
00091
00092
00093 struct s_overTheTop {
00094 unsigned int start;
00095 unsigned int len;
00096 bool value;
00097 };
00098
00099
00100
00101
00102 class timeMgr {
00103 private:
00104 int index;
00105 double startTime;
00106
00107 public:
00108 timeMgr();
00109 timeMgr(int i, double t);
00110 void setIndex(int i);
00111 void setStartTime(double t);
00112 int getIndex();
00113 double getStartTime();
00114 };
00115
00116
00117
00118
00119
00120
00121
00122 class ddMgr {
00123 private:
00124 int numCorr[100];
00125 int numChan[100];
00126 struct {
00127 int polId;
00128 int swId;
00129 } dd[100];
00130
00131 public:
00132
00133 ddMgr();
00134
00135 int setNumCorr(int i, int numChan);
00136 int setNumChan(int i, int numCorr);
00137
00138 int getNumCorr(int i);
00139 int getNumChan(int i);
00140
00141 int setDD(int i, int polId, int swId);
00142
00143 int getPolId(int i);
00144 int getSwId(int i);
00145 };
00146
00147
00148
00149
00150 class ASDM2MSFiller
00151 {
00152 private:
00153 double itsCreationTime;
00154 const string itsName;
00155 int itsNumAntenna;
00156 int itsNumChan;
00157 int itsNumCorr;
00158 casa::MeasurementSet *itsMS;
00159 casa::MSMainColumns *itsMSCol;
00160
00161
00162
00163
00164
00165
00166
00167
00168 String itsMSPath;
00169 timeMgr* itsFeedTimeMgr;
00170 timeMgr* itsFieldTimeMgr;
00171 timeMgr* itsObservationTimeMgr;
00172 timeMgr* itsPointingTimeMgr;
00173
00174 timeMgr* itsSourceTimeMgr;
00175 timeMgr* itsSyscalTimeMgr;
00176 timeMgr* itsWeatherTimeMgr;
00177
00178 Bool itsWithRadioMeters;
00179 Bool itsFirstScan;
00180 uInt itsMSMainRow;
00181
00182 Block<IPosition> itsDataShapes;
00183
00184 int itsScanNumber;
00185 int itsNCat;
00186
00187 ddMgr itsDDMgr;
00188
00189
00190 int createMS(const string& msName, bool complexData, bool withCompression, bool withCorrectedData=false);
00191
00192 const char** getPolCombinations(int numCorr);
00193
00194
00195 public:
00196 ASDM2MSFiller (const string& name_,
00197 double creation_time_,
00198 bool withRadioMeters,
00199 bool complexData,
00200 bool withCompression,
00201 bool withCorrectedData=false);
00202
00203
00204 ~ASDM2MSFiller();
00205
00206 const casa::MeasurementSet* ms();
00207
00208 int addAntenna(const string& name_,
00209 const string& station_,
00210 double lx_,
00211 double ly_,
00212 double lz_,
00213 double offset_x_,
00214 double offset_y_,
00215 double offset_z_,
00216 float dish_diam_);
00217
00218 void addData (bool complexData,
00219 vector<double> &time_,
00220 vector<int> &antennaId1_,
00221 vector<int> &antennaId2_,
00222 vector<int> &feedId1_,
00223 vector<int> &feedId2_,
00224 vector<int> &dataDescId_,
00225 int processorId_,
00226 vector<int> &fieldId_,
00227 vector<double> &interval_,
00228 vector<double> &exposure_,
00229 vector<double> &timeCentroid_,
00230 int scanNumber_,
00231 int arrayId_,
00232 int observationId_,
00233 vector<int> &stateId_,
00234 vector<double> &uvw_,
00235 vector<vector<unsigned int> > &dataShape_,
00236 vector<float *> &uncorrectedData_,
00237 vector<float *> &correctedData_,
00238 vector<unsigned int> &flag_);
00239
00240 void addData (bool complexData,
00241 vector<double> &time_,
00242 vector<int> &antennaId1_,
00243 vector<int> &antennaId2_,
00244 vector<int> &feedId1_,
00245 vector<int> &feedId2_,
00246 vector<int> &dataDescId_,
00247 int processorId_,
00248 vector<int> &fieldId_,
00249 vector<double> &interval_,
00250 vector<double> &exposure_,
00251 vector<double> &timeCentroid_,
00252 int scanNumber_,
00253 int arrayId_,
00254 int observationId_,
00255 vector<int> &stateId_,
00256 vector<double> &uvw_,
00257 vector<vector<unsigned int> > &dataShape_,
00258 vector<float *> &data_,
00259 vector<unsigned int> &flag_);
00260
00261
00262
00263 int addDataDescription(int spectral_window_id_,
00264 int polarizarion_id_);
00265
00266 int addUniqueDataDescription(int spectral_window_id_,
00267 int polarizarion_id_);
00268
00269 int exists(char *path);
00270 String msPath();
00271
00272
00273 void addFeed(int antenna_id_,
00274 int feed_id_,
00275 int spectral_window_id_,
00276 double time_,
00277 double interval_,
00278 int num_receptors_,
00279 int beam_id_,
00280 vector<double> & beam_offset_,
00281 vector<std::string> & pol_type_,
00282 vector<std::complex<float> > & polarization_response_,
00283 vector<double>& position_,
00284 vector<double>& receptor_angle_);
00285
00286 void addField( const string& name_,
00287 const string& code_,
00288 double time_,
00289 vector<double>& delay_dir_,
00290 vector<double>& phase_dir_,
00291 vector<double>& reference_dir_,
00292 int source_id_);
00293
00294 void addFlagCmd(double time_,
00295 double interval_,
00296 const string& type_,
00297 const string& reason_,
00298 int level_,
00299 int severity_,
00300 int applied_,
00301 string& command_);
00302
00303 void addHistory( double time_,
00304 int observation_id_,
00305 const string& message_,
00306 const string& priority_,
00307 const string& origin_,
00308 int object_id_,
00309 const string& application_,
00310 const string& cli_command_,
00311 const string& app_parms_ );
00312
00313 void addObservation(const string& telescopeName_,
00314 double startTime_,
00315 double endTime_,
00316 const string& observer_,
00317 const vector<string>& log_,
00318 const string& schedule_type_,
00319 const vector<string>& schedule_,
00320 const string& project_,
00321 double release_date_);
00322
00323 void addPointingSlice(unsigned int n_row_,
00324 vector<int>& antenna_id_,
00325 vector<double>& time_,
00326 vector<double>& interval_,
00327 vector<double>& direction_,
00328 vector<double>& target_,
00329 vector<double>& pointing_offset_,
00330 vector<double>& encoder_,
00331 vector<bool>& tracking_,
00332 bool overTheTopExists4All_,
00333 vector<bool>& v_overTheTop_,
00334 vector<s_overTheTop>& v_s_overTheTop_);
00335
00336 int addPolarization(int num_corr_,
00337 vector<int>& corr_type_,
00338 vector<int>& corr_product_);
00339
00340 int addUniquePolarization(int num_corr_,
00341
00342 const vector<int>& corr_type_,
00343 const vector<int>& corr_product_);
00344
00345 void addProcessor(string& type_,
00346 string& sub_type_,
00347 int type_id_,
00348 int mode_id_);
00349
00350 void addSource(int source_id_,
00351 double time_,
00352 double interval_,
00353 int spectral_window_id_,
00354 int num_lines_,
00355 string& name_,
00356 int calibration_group_,
00357 string& code_,
00358 vector<double>& direction_,
00359 vector<double>& position_,
00360 vector<double>& proper_motion_,
00361 vector<string>& transition_,
00362 vector<double>& rest_frequency_,
00363 vector<double>& sysvel_);
00364
00365 int addSpectralWindow(int num_chan_,
00366 const string& name_,
00367 double ref_frequency_,
00368 const vector<double>& chan_freq_,
00369 const vector<double>& chan_width_,
00370 int meas_freq_ref_,
00371 const vector<double>& effective_bw_,
00372 const vector<double>& resolution_,
00373 double total_bandwidth_,
00374 int net_sideband_,
00375 int bbc_no_,
00376 int if_conv_chain_,
00377 int freq_group_,
00378 const string& freq_group_name_,
00379 int num_assoc_,
00380 const vector<int>& assoc_sp_id_,
00381 const vector<string>& assoc_nature_);
00382
00383 int addUniqueState(bool sig_,
00384 bool ref_,
00385 double cal_,
00386 double load_,
00387 unsigned int sub_scan_,
00388 string& obs_mode_,
00389 bool flag_row_);
00390
00391
00392 void addState(bool sig_,
00393 bool ref_,
00394 double cal_,
00395 double load_,
00396 int sub_scan_,
00397 string& obs_mode_);
00398
00399 void addSysCal(int antenna_id,
00400 int feed_id,
00401 int spectral_window_id,
00402 double time_,
00403 double interval_,
00404 int numReceptor_,
00405 int numChan_,
00406 pair<bool, vector<float> >& tcal_spectrum_pair,
00407 pair<bool, bool>& tcal_flag_pair,
00408 pair<bool, vector<float> >& trx_spectrum_pair,
00409 pair<bool, bool>& trx_flag_pair,
00410 pair<bool, vector<float> >& tsky_spectrum_pair,
00411 pair<bool, bool>& tsky_flag_pair,
00412 pair<bool, vector<float> >& tsys_spectrum_pair,
00413 pair<bool, bool>& tsys_flag_pair,
00414 pair<bool, vector<float> >& tant_spectrum_pair,
00415 pair<bool, bool>& tant_flag_pair,
00416 pair<bool, vector<float> >& tant_tsys_spectrum_pair,
00417 pair<bool, bool>& tant_tsys_flag_pair);
00418
00419 void addWeather(int antennaId_,
00420 double time_,
00421 double interval_,
00422 float pressure_,
00423 bool pressure_flag_,
00424 float rel_humidity_,
00425 bool rel_humidity_flag_,
00426 float temperature_,
00427 bool temperature_flag_,
00428 float wind_direction_,
00429 bool wind_direction_flag_,
00430 float wind_speed_,
00431 bool wind_speed_flag_,
00432 bool has_dew_point_,
00433 float dew_point_,
00434 bool dew_point_flag_,
00435 int wx_station_id_,
00436 vector<double>& wx_station_position_);
00437
00438 void end(double time_);
00439 };
00440 #endif
00441