ATCAFiller.h

Go to the documentation of this file.
00001 //# ATCAFiller.h: Definition for ATCA filler 
00002 //# Copyright (C) 2004
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id: ATCAFiller.h,v 1.6 2004/12/13 04:44:35 mwiering Exp $
00027 
00028 #ifndef ATNF_ATCAFILLER_H
00029 #define ATNF_ATCAFILLER_H
00030 
00031 //# Includes
00032 #include <casa/aips.h>
00033 #include <casa/Arrays/Matrix.h>
00034 #include <casa/Logging/LogIO.h>
00035 #include <tables/DataMan/TiledDataStManAccessor.h>
00036 #include <ms/MeasurementSets/MeasurementSet.h>
00037 #include <ms/MeasurementSets/MSColumns.h>
00038 
00039 #include <casa/namespace.h>
00040 namespace casa { //# NAMESPACE CASA - BEGIN
00041 class String;
00042 
00043 class ATCAFiller {
00044 public:
00045 
00046   // Construct the ATCAFiller
00047   ATCAFiller();
00048 
00049   ~ATCAFiller();
00050 
00051   // return the ATCA required tabledesc, this is the standard MeasurementSet
00052   // plus ATCA specific additions.
00053   static TableDesc atcaTableDesc(Bool compress);
00054 
00055   // make the ATCA specific MeasurementSet
00056   static MeasurementSet makeTable(const String& tableName, Bool compress,
00057     Bool cabb);
00058 
00059   // make the subtables with ATCA specific additions
00060   static void makeSubTables(MS& ms, Table::TableOption option, Bool cabb);
00061 
00062   // Open the measurement set and one or more RPFits files.
00063   // Opacity correction is not yet implemented - could go
00064   // in gencal or here, if gencal scheme doesn't improve
00065   Bool open(const String& msName, const Vector<String>& rpfitsFiles,
00066                   const Vector<String> & options, Int opcor=2);
00067 
00068  // Fill the measurement set
00069   Bool fill();
00070  
00071   // Select a number of fields by name.
00072   ATCAFiller & fields(const Vector<String> & fieldList);
00073 
00074   // Select a range of frequencies, lowFreq=0 => everything below higFreq,
00075   //  highFreq=0 => everything above lowFreq.
00076   ATCAFiller & freqRange(Double lowFreq, Double highFreq=0);
00077  
00078   // Select frequencies within windowWidth of specified ones.
00079   // (This selects on center-frequencies only, not channelfrequencies)
00080   ATCAFiller & frequencies(Vector<Double> freqs, Double windowWidth=1e6);
00081 
00082   // Select a range of scans to read. first=0 or 1 => start at first one,
00083   //   last=0 => read to end of file.
00084   ATCAFiller & scanRange(Int firstScan, Int lastScan=0);
00085 
00086   // Select range of channels, with optional increment.
00087   // We may want multiple channel ranges -> use matrix(3,n) for selection?
00088   ATCAFiller & chanRange(Int firstChan, Int lastChan, Int ChanInc=1);
00089 
00090   // Time range selection.
00091   ATCAFiller & timeRange(Double firstTime, Double lastTime=0);
00092 
00093   // Select the Freq (which one of the simult. freqs), 0=> no selection.
00094   // 
00095   ATCAFiller & freqSel(const Vector<Int>& spws); 
00096 
00097   // Select on bandwidth of IF 1.
00098   ATCAFiller & bandwidth1(Int bandwidth1);
00099 
00100   // Select on number of channels of IF 1
00101   ATCAFiller & numChan1(Int numchan1);
00102 
00103   // Set shadowing limit
00104   ATCAFiller & shadow(Float diam);
00105 
00106   // Deselect antennas.
00107   ATCAFiller & deselectAntenna(Vector<Int> antennas);
00108 
00109   // Smooth xy-phases with running median and 
00110   // flag data with discrepant xy-phase.
00111   ATCAFiller & xyPhaseSmooth(Int window=9, Double tolerance=10.0);
00112 
00113   // Smooth Tsys values with running median and recalibrate the data.
00114   ATCAFiller & tsysSmooth(Int window=9);
00115   
00116   // Set percentage of channels to flag at band edges
00117   ATCAFiller & edge(Float edge);
00118 
00119 private:
00120   //# disallow all these
00121   //ATCAFiller();
00122   ATCAFiller(const ATCAFiller &);
00123   ATCAFiller & operator=(const ATCAFiller &);
00124 
00125   //for constructors
00126   void init();
00127 
00128   void storeHeader();
00129   void storeATCAHeader();
00130   void storeSysCal();
00131 
00132   // fill a single input file
00133   Bool fill1(const String & rpfitsname);
00134 
00135   // List the file on cout
00136   void list();
00137 
00138    // Flag data if samplerstats are bad.
00139   Bool samplerFlag(Int row, Double posNegTolerance=3.0, 
00140                    Double zeroTolerance=0.5);
00141   
00142   Int birdChan(Double refFreq, Int refChan, Double chanSpac);
00143   void reweight();
00144   void storeData();
00145   Int checkSpW(Int ifNumber,Bool log=True);
00146   void checkField();
00147   void checkObservation();
00148   // Fill the feed table (with dummy values)
00149   void fillFeedTable();
00150   void fillObservationTable();
00151   void fillMeasureReferences();
00152   Bool selected(Int ifNum);
00153   void listScan(Double & mjd, Int scan, Double ut);
00154   Bool checkCABB(const String & rpfitsname);
00155   void rfiFlag(Matrix<Bool> & flags);
00156   
00157 
00158   String atcaPosToStation(Vector<Double>& xyz);
00159   void flush();
00160   void unlock();
00161 
00162   void shadow(Int row, Bool last=False);
00163 
00164   // Constants
00165   // MaxNPol needs to agree with if_cstok in RPFITS.h
00166   enum{MaxNChan=16385, MaxNPol=4};
00167   // Data
00168   MeasurementSet atms_p;
00169   MSColumns *msc_p;
00170 
00171   // Filenames
00172   Vector<String> rpfitsFiles_p;
00173   Int opcor_p;
00174   String currentFile_p;
00175 
00176   // The following should be constant throughout the rpfits file
00177   Int nAnt_p; 
00178 
00179   // Number of scans seen; #SpWs, #fields stored sofar
00180   Int nScan_p, nSpW_p, nField_p;
00181   // #scanheaders stored, index into MS SpW and Field Tables for current data
00182   Int scanNo_p, spWId_p, fieldId_p, prev_fieldId_p, obsId_p;
00183 
00184   // Bools
00185   Bool gotAN_p; //have we got an antenna Table yet?
00186   Bool appendMode_p;
00187   Bool storedHeader_p;
00188   Bool skipScan_p;
00189   Bool skipData_p;
00190   Bool firstHeader_p;
00191   Bool listHeader_p;
00192   uInt fileSize_p;
00193   Bool eof_p;
00194   Bool birdie_p;   // flag birdie channels
00195   Bool reweight_p; // gibbs reweighting
00196   Bool noxycorr_p; // do not apply xy phase correction
00197   Bool noac_p;    // Don't load the autocorrelation data
00198   Int obsType_p; // the type of observation: 0= standard, 1= fastmosaic
00199   Bool hires_p; // transform binned data into high time res data
00200   Bool init_p; // Are we initialized yet?
00201   Bool cabb_p; // Are we reading CABB data?
00202 
00203   // rpfits data
00204   Float vis[2*MaxNPol*MaxNChan];
00205   Float weight[MaxNPol*MaxNChan];
00206   Int baseline, flg, bin, if_no, sourceno; //index into rpfits Table(not MS) 
00207   Float ut, u, v, w;
00208 
00209   // storage manager accessor
00210   TiledDataStManAccessor dataAccessor_p,sigmaAccessor_p,flagAccessor_p,
00211     flagCatAccessor_p;
00212   TiledDataStManAccessor modelDataAccessor_p,corrDataAccessor_p,imWtAccessor_p;
00213 
00214   // Column objects to access Tables
00215 
00216   // colXXX objects are ATCA specific columns in the MeasurementSet 
00217   ScalarColumn<Int> colSysCalIdAnt1, colSysCalIdAnt2;
00218   ScalarColumn<Float> colXYAmplitude,colTrackErrMax,colTrackErrRMS,
00219       colWeatherSeeMonPhase,colWeatherSeeMonRMS,colWeatherRainGauge;
00220   ScalarColumn<Int> colSamplerBits;
00221   ArrayColumn<Float> colSamplerStatsNeg, colSamplerStatsZero,
00222       colSamplerStatsPos;
00223   ArrayColumn<Float> colGTP, colSDO, colCalJy;
00224   ScalarColumn<Bool> colWeatherSeeMonFlag;
00225   // ATCA_SCAN_INFO columns & table
00226   ScalarColumn<Int> colScanInfoAntId, colScanInfoScanId, colScanInfoSpWId,
00227        colScanInfoCacal;
00228   ArrayColumn<Int> colScanInfoFine, colScanInfoCoarse, colScanInfommAtt;
00229   ArrayColumn<Float> colScanInfoSubreflector;
00230   ScalarColumn<String> colScanInfoCorrConfig, colScanInfoScanType,
00231       colScanInfoCoordType,colScanInfoPointInfo;
00232   ScalarColumn<Bool> colScanInfoLineMode;
00233   Table msScanInfo_p;
00234   Matrix<Float> pointingCorr_p;
00235   Bool newPointingCorr_p;
00236 
00237   // reference date
00238   Double mjd0_p;
00239 
00240   // variables to keep the state of the sysCal search & binning state
00241   Vector<Int> sysCalId_p;
00242   Float lastUT_p;
00243   Int lastSpWId_p;
00244   Bool gotSysCalId_p;
00245   Float lastWeatherUT_p;
00246   Int errCount_p;
00247 
00248   // Selection parameters
00249   Vector<String> fieldSelection_p;
00250   Double lowFreq_p, highFreq_p;
00251   Vector<Double> freqs_p;
00252   Double windowWidth_p;
00253   Int firstScan_p, lastScan_p;
00254   Int firstChan_p, lastChan_p;
00255   Double firstTime_p, lastTime_p;
00256   Vector<Int> spws_p;
00257   Int bandWidth1_p, numChan1_p;
00258   Vector<Int> baselines_p, antennas_p;
00259 
00260   // Track sources
00261   String sources_p;
00262   Int nsources_p;
00263   
00264   // Polarization order
00265   Matrix<Int> corrIndex_p;
00266 
00267   // Check for shadowing
00268   Float shadow_p;
00269   Float edge_p;
00270   Block<Int> rowCache_p;
00271   Int nRowCache_p;
00272   Double prevTime_p;
00273   
00274   // Flagging
00275   Bool autoFlag_p,flagScanType_p;
00276   enum {COUNT=0, FLAG, ONLINE, SCANTYPE, SYSCAL, SHADOW, NFLAG};
00277   Vector<Int> flagCount_p;
00278 
00279   // Logger
00280   LogIO os_p;
00281       
00282 };
00283 
00284 } //# NAMESPACE CASA - END
00285 
00286 
00287 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1