ASDM2MSFiller.h

Go to the documentation of this file.
00001 // ASDM2MSFiller.h: implementation of a MeasurementSet's filler
00002 // for Francois Viallefond & Frederic Badia ALMA Simulator
00003 //
00004 //  Copyright (C) 2001
00005 //  OBSERVATOIRE DE PARIS - DEMIRM
00006 //  Avenue Denfert Rochereau - 75014 - PARIS
00007 //
00008 //  This program is free software; you can redistribute it and/or modify
00009 //  it under the terms of the GNU General Public License as published by
00010 //  the Free Software Foundation; either version 2 of the License, or
00011 //  (at your option) any later version.
00012 //
00013 //  This program is distributed in the hope that it will be useful,
00014 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 //  GNU General Public License for more details.
00017 //
00018 //  You should have received a copy of the GNU General Public License
00019 //  along with this program; if not, write to the Free Software
00020 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 //
00022 //
00023 //
00025 #if !defined(ALMA_ASDM2MSFILLER_H)
00026 #define ALMA_ASDM2MSFILLER_H
00027 //# Includes
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/DataMan/StandardStMan.h>
00052 #include <tables/DataMan/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/TableMeasures/TableMeasValueDesc.h>
00071 #include <measures/TableMeasures/TableMeasOffsetDesc.h>
00072 #include <measures/TableMeasures/TableMeasRefDesc.h>
00073 #include <measures/TableMeasures/TableMeasDesc.h>
00074 #include <measures/Measures/MeasConvert.h>
00075 #include "measures/Measures/Stokes.h"
00076 #include <casa/BasicSL/Constants.h>
00077 #include <casa/OS/File.h>
00078 #include <casa/OS/Path.h>
00079 #include <complex>
00080 
00081 #include <vector>
00082 
00083 
00084 using namespace casa;
00085 using namespace std;
00086 
00087 //# Forward Declarations
00088 
00089 class TimeRange;
00090 class MPosition;
00091 class MeasFrame;
00092 class MeasurementSet;
00093 class MSMainColumns;
00094 
00095 //
00096 // A structure to define a range of rows in the Pointing table where the attribute overTheTop is defined and with which value.
00097 //
00098 struct s_overTheTop {
00099   unsigned int  start;   // The index of the first row of the range. 
00100   unsigned int  len;     // The number of consecutive rows in the range.
00101   bool value;   // The value of overTheTop in that range.
00102 };
00103 
00104 //
00105 // Class timeMgr is a utility to help for the management
00106 // of time in tables with TIME and INTERVAL columns
00107 class timeMgr {
00108  private:
00109   int index;
00110   double startTime;
00111 
00112  public:
00113   timeMgr();
00114   timeMgr(int i, double t);
00115   void   setIndex(int i);
00116   void   setStartTime(double t);
00117   int    getIndex();
00118   double getStartTime();
00119 };
00120 
00121 
00122 // Class ddMgr is a utility to help for the management
00123 // of DataDescription, SpectralWindow and Polarization ids.
00124 // Here we provide enough space to store 100 values for 
00125 // each quantity; this is very likeky far beyond the actual
00126 // needs.
00127 class ddMgr {
00128  private:
00129   int     numCorr[100];
00130   int     numChan[100];
00131   struct  {
00132     int polId;
00133     int swId;
00134   } dd[100];
00135   
00136  public:
00137 
00138   ddMgr();
00139 
00140   int setNumCorr(int i, int numChan);
00141   int setNumChan(int i, int numCorr);
00142 
00143   int getNumCorr(int i);
00144   int getNumChan(int i);
00145 
00146   int setDD(int i, int polId, int swId); 
00147 
00148   int getPolId(int i);
00149   int getSwId(int i);
00150 };
00151 
00152 
00153  
00154 // Class ASDM2MSFiller
00155 class ASDM2MSFiller
00156 {
00157  private:
00158   double         itsCreationTime;
00159   const string   itsName;
00160   int            itsNumAntenna;
00161   int            itsNumChan;
00162   int            itsNumCorr;
00163   casa::MeasurementSet *itsMS;
00164   casa::MSMainColumns  *itsMSCol;
00165   /*
00166     Block<timeMgr> itsFeedTimeMgr;
00167     Block<timeMgr> itsPointingTimeMgr;
00168     Block<timeMgr> itsSyscalTimeMgr;
00169     Block<timeMgr> itsWeatherTimeMgr;
00170     Block<timeMgr> itsObservationTimeMgr;
00171   */
00172     
00173   String     itsMSPath;
00174   timeMgr* itsFeedTimeMgr;
00175   timeMgr* itsFieldTimeMgr;
00176   timeMgr* itsObservationTimeMgr;
00177   timeMgr* itsPointingTimeMgr;
00178   //OrderedMap<int, timeMgr> itsSourceTimeMgr;
00179   timeMgr* itsSourceTimeMgr;
00180   timeMgr* itsSyscalTimeMgr;
00181   timeMgr* itsWeatherTimeMgr;
00182     
00183   Bool     itsWithRadioMeters;     /* Are we building an ALMA MS ?*/
00184   Bool     itsFirstScan;
00185   uInt     itsMSMainRow;
00186   /*TiledDataStManAccessor itsImWgtAcc;*/
00187   Block<IPosition> itsDataShapes;
00188 
00189   int itsScanNumber;
00190   int itsNCat;
00191     
00192   ddMgr    itsDDMgr;
00193 
00194   int itsCalDeviceNumberOfRows;
00195   Table itsMSCalDeviceTable;
00196 
00197   int createMS(const string& msName, 
00198                bool complexData, 
00199                bool withCompression, 
00200                const string& telName, 
00201                int maxNumCorr,
00202                int maxNumChan,
00203                bool withCorrectedData=false,
00204                bool useAsdmStMan4DATA=false);
00205 
00206   const char** getPolCombinations(int numCorr);
00207     
00208   static map<string, MDirection::Types> string2MDirection;
00209   static map<string, MDirection::Types> string2MDirectionInit();
00210    
00211  public:  
00212   ASDM2MSFiller (const string&  name_,
00213                  double         creation_time_,
00214                  bool           withRadioMeters,
00215                  bool           complexData,
00216                  bool           withCompression,
00217                  const string&  telName, 
00218                  int            intintmaxNumCorr,
00219                  int            maxNumChan,
00220                  bool           withCorrectedData=false,
00221                  bool           useAsdmStMan4DATA=false);
00222   
00223   // Destructor
00224   ~ASDM2MSFiller();
00225 
00226   const casa::MeasurementSet* ms();
00227 
00228   int addAntenna(const string&   name_,
00229                  const string&   station_,
00230                  double          lx_,
00231                  double          ly_,
00232                  double          lz_,
00233                  double          offset_x_,
00234                  double          offset_y_,
00235                  double          offset_z_,
00236                  float           dish_diam_);
00237 
00238 
00239   void addData (bool                      complexData,
00240                 vector<double>            &time_,
00241                 vector<int>               &antennaId1_,
00242                 vector<int>               &antennaId2_,
00243                 vector<int>               &feedId1_,
00244                 vector<int>               &feedId2_,
00245                 vector<int>               &dataDescId_,
00246                 int                       processorId_,
00247                 int                       fieldId_,
00248                 vector<double>            &interval_,
00249                 vector<double>            &exposure_,
00250                 vector<double>            &timeCentroid_,
00251                 int                       scanNumber_,
00252                 int                       arrayId_,
00253                 int                       observationId_,
00254                 vector<int>               &stateId_,
00255                 vector<pair<int, int> >   &nChanNPol_,
00256                 vector<double>            &uvw_,
00257                 vector<double>            &weight_,
00258                 vector<double>            &sigma_);
00259 
00260   void addData (bool                      complexData,
00261                 vector<double>            &time_,
00262                 vector<int>               &antennaId1_,
00263                 vector<int>               &antennaId2_,
00264                 vector<int>               &feedId1_,
00265                 vector<int>               &feedId2_,
00266                 vector<int>               &dataDescId_,
00267                 int                       processorId_,
00268                 vector<int>               &fieldId_,
00269                 vector<double>            &interval_,
00270                 vector<double>            &exposure_,
00271                 vector<double>            &timeCentroid_,
00272                 int                       scanNumber_,
00273                 int                       arrayId_,
00274                 int                       observationId_,
00275                 vector<int>               &stateId_,
00276                 vector<double>            &uvw_,
00277                 vector<vector<unsigned int> >      &dataShape_,
00278                 vector<float *>           &uncorrectedData_,
00279                 vector<float *>           &correctedData_,
00280                 vector<unsigned int>      &flag_);
00281 
00282   void addData (bool                      complexData,
00283                 vector<double>            &time_,
00284                 vector<int>               &antennaId1_,
00285                 vector<int>               &antennaId2_,
00286                 vector<int>               &feedId1_,
00287                 vector<int>               &feedId2_,
00288                 vector<int>               &dataDescId_,
00289                 int                       processorId_,
00290                 vector<int>               &fieldId_,
00291                 vector<double>            &interval_,
00292                 vector<double>            &exposure_,
00293                 vector<double>            &timeCentroid_,
00294                 int                       scanNumber_,
00295                 int                       arrayId_,
00296                 int                       observationId_,
00297                 vector<int>               &stateId_,
00298                 vector<double>            &uvw_,
00299                 vector<vector<unsigned int> >      &dataShape_,
00300                 vector<float *>           &data_,
00301                 vector<unsigned int>      &flag_,
00302                 vector<double>            &weight_,
00303                 vector<double>            &sigma_);
00304   
00305 
00306                
00307   int  addDataDescription(int spectral_window_id_,
00308                           int polarizarion_id_);
00309 
00310   int  addUniqueDataDescription(int spectral_window_id_,
00311                                 int polarizarion_id_);
00312 
00313   int  exists(char *path);
00314   String msPath();
00315 
00316 
00317   void addFeed(int      antenna_id_,
00318                int      feed_id_,
00319                int      spectral_window_id_,
00320                double   time_,
00321                double   interval_,
00322                int      num_receptors_,
00323                int      beam_id_,
00324                vector<double> &   beam_offset_,
00325                vector<std::string> & pol_type_,
00326                vector<std::complex<float> > & polarization_response_,
00327                vector<double>&   position_,  // Must be a 3 elements vector !!!
00328                vector<double>&   receptor_angle_);
00329   
00330   void addField( const string&                  name_,
00331                  const string&                  code_,
00332                  double                         time_,
00333                  int                            num_poly_,
00334                  vector<vector<double> >&       delay_dir_,
00335                  vector<vector<double> >&       phase_dir_,
00336                  vector<vector<double> >&       reference_dir_,
00337                  const string&                  direction_code_,
00338                  int                            source_id_);
00339 
00340   void updateEphemerisIdInField(vector<pair<int, int> >& idxEphemerisId_v);
00341 
00342   void addFlagCmd(double        time_,
00343                   double        interval_,
00344                   const string& type_,
00345                   const string& reason_,
00346                   int           level_,
00347                   int           severity_,
00348                   int           applied_,
00349                   string&       command_);
00350 
00351   void addHistory( double               time_,
00352                    int                  observation_id_,
00353                    const string&        message_,
00354                    const string&        priority_,
00355                    const string&        origin_,
00356                    int                  object_id_,
00357                    const string&        application_,
00358                    const string&        cli_command_,
00359                    const string&        app_parms_ );
00360 
00361   void addObservation(const string&             telescopeName_,
00362                       double                    startTime_,
00363                       double                    endTime_,
00364                       const string&             observer_,
00365                       const vector<string>&     log_,
00366                       const string&             schedule_type_,
00367                       const vector<string>&     schedule_,
00368                       const string&             project_,
00369                       double                    release_date_);
00370 
00371   void addPointingSlice(unsigned int                  n_row_,
00372                         vector<int>&                  antenna_id_,
00373                         vector<double>&               time_,
00374                         vector<double>&               interval_,
00375                         vector<double>&               direction_,
00376                         vector<double>&               target_,
00377                         vector<double>&               pointing_offset_,
00378                         vector<double>&               encoder_,
00379                         vector<bool>&                 tracking_,
00380                         bool                          overTheTopExists4All_,
00381                         vector<bool>&                 v_overTheTop_,
00382                         vector<s_overTheTop>&         v_s_overTheTop_);
00383 
00384   int  addPolarization(int num_corr_,
00385                        vector<int>& corr_type_,
00386                        vector<int>& corr_product_);
00387 
00388   int addUniquePolarization(int num_corr_,
00389                             //                      const vector<Stokes::StokesTypes>& corr_type_,
00390                             const vector<int>& corr_type_,
00391                             const vector<int>& corr_product_);
00392 
00393   void addProcessor(string& type_,
00394                     string& sub_type_,
00395                     int  type_id_,
00396                     int  mode_id_);
00397 
00398   void addSource(int             source_id_,
00399                  double          time_,
00400                  double          interval_,
00401                  int             spectral_window_id_,
00402                  int             num_lines_,
00403                  string&         name_,
00404                  int             calibration_group_,
00405                  string&         code_,
00406                  vector<double>& direction_,
00407                  string&         direction_code_,
00408                  vector<double>& position_,
00409                  vector<double>& proper_motion_,
00410                  vector<string>& transition_,
00411                  vector<double>& rest_frequency_,
00412                  vector<double>& sysvel_);
00413                  
00414   int  addSpectralWindow(int                    num_chan_,
00415                          const string&          name_,
00416                          double                 ref_frequency_,
00417                          const vector<double>&  chan_freq_,
00418                          const vector<double>&  chan_width_,
00419                          int                    meas_freq_ref_,
00420                          const vector<double>&  effective_bw_,
00421                          const vector<double>&  resolution_,
00422                          double                 total_bandwidth_,
00423                          int                    net_sideband_,
00424                          int                    bbc_no_,
00425                          int                    if_conv_chain_,
00426                          int                    freq_group_,
00427                          const string&          freq_group_name_,
00428                          int                    num_assoc_,
00429                          const vector<int>&     assoc_sp_id_,
00430                          const vector<string>&  assoc_nature_);
00431 
00432   int  addUniqueState(bool sig_,
00433                       bool ref_,
00434                       double cal_,
00435                       double load_,
00436                       unsigned int sub_scan_,
00437                       string& obs_mode_,
00438                       bool flag_row_);
00439   
00440   
00441   void addState(bool    sig_,
00442                 bool    ref_,
00443                 double  cal_,
00444                 double  load_,
00445                 int     sub_scan_,
00446                 string& obs_mode_);
00447   
00448   void addSysCal(int    antenna_id,
00449                  int    feed_id,
00450                  int    spectral_window_id,
00451                  double time_,
00452                  double interval_,
00453                  int    numReceptor_,
00454                  int    numChan_,
00455                  pair<bool, vector<float> >& tcal_spectrum_pair,
00456                  pair<bool, bool>&           tcal_flag_pair,
00457                  pair<bool, vector<float> >& trx_spectrum_pair,
00458                  pair<bool, bool>&           trx_flag_pair,
00459                  pair<bool, vector<float> >& tsky_spectrum_pair,
00460                  pair<bool, bool>&           tsky_flag_pair,
00461                  pair<bool, vector<float> >& tsys_spectrum_pair,
00462                  pair<bool, bool>&           tsys_flag_pair,
00463                  pair<bool, vector<float> >& tant_spectrum_pair,
00464                  pair<bool, bool>&           tant_flag_pair,
00465                  pair<bool, vector<float> >& tant_tsys_spectrum_pair,
00466                  pair<bool, bool>&           tant_tsys_flag_pair);
00467 
00468  void addWeather(int                            antenna_id_,
00469                   double                        time_,
00470                   double                        interval_,
00471                   const pair<bool, float>&      pressure_opt_,
00472                   const pair<bool, float>&      relHumidity_opt_,
00473                   const pair<bool, float>&      temperature_opt_,
00474                   const pair<bool, float>&      windDirection_opt_,
00475                   const pair<bool, float>&      windSpeed_opt_,
00476                   const pair<bool, float>&      dewPoint_opt_,
00477                   int                           wx_station_id_,
00478                   vector<double>&               wx_station_position_);
00479 
00491   void addCalDevice(int                         antennaId,
00492                     int                         feedId,
00493                     int                         spectralWindowId,
00494                     double                      time,
00495                     double                      interval,
00496                     unsigned int                numCalLoad,
00497                     vector<string>              calloadNames,
00498                     unsigned int                numReceptor,
00499                     vector<vector<float> >&     calEff,
00500                     vector<vector<float> >&     noiseCal,
00501                     vector<double >&            temperatureLoad);
00502 
00525   void addSysPower(int                  antennaId,
00526                    int                  feedId,
00527                    int                  spectralWindowId,
00528                    double               time,
00529                    double               interval,
00530                    unsigned int         numReceptor,
00531                    vector<float>&       switchedPowerDifference,
00532                    vector<float>&       switchedPowerSum,
00533                    vector<float>&       requantizerGain); 
00534 
00535   void addSysPowerSlice(unsigned int    nRow,
00536                         vector<int>&    antennaId,
00537                         vector<int>&    spectralWindowId,
00538                         vector<int>&    feedId,
00539                         vector<double>& time,
00540                         vector<double>& interval,
00541                         unsigned int    numReceptor,
00542                         vector<float>&  switchedPowerDifference,
00543                         vector<float>&  switchedPowerSum,
00544                         vector<float>&  requantizerGain);
00545 
00546   void end(double time_);
00547 };
00548 #endif
00549   
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1