MSFitsOutput.h

Go to the documentation of this file.
00001 //# MSFitsOutput.h:  Write a MeasurementSet to a random group uvfits file
00002 //# Copyright (C) 1996,1997,1998,1999,2000,2001,2003
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This program is free software; you can redistribute it and/or modify
00006 //# it under the terms of the GNU General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or
00008 //# (at your option) any later version.
00009 //#
00010 //# This program is distributed in the hope that it will be useful,
00011 //# but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 //# GNU General Public License for more details.
00014 //# 
00015 //# You should have received a copy of the GNU General Public License
00016 //# along with this program; if not, write to the Free Software
00017 //# Foundation, Inc., 675 Mass 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: MSFitsOutput.h 21521 2014-12-10 08:06:42Z gervandiepen $
00027 
00028 #ifndef MS_MSFITSOUTPUT_H
00029 #define MS_MSFITSOUTPUT_H
00030 
00031 #include <casacore/casa/BasicSL/String.h>
00032 #include <casacore/casa/Quanta/Quantum.h>
00033 #include <casacore/ms/MeasurementSets/MeasurementSet.h>
00034 
00035 #include <casacore/casa/aips.h>
00036 
00037 namespace casacore {
00038 
00039 //# Forward Declarations
00040 class FitsOutput;
00041 template<class T> class ScalarColumn;
00042 class Table;
00043 template<class T> class Block;
00044 template<class T> class Vector;
00045 
00046 // <summary>
00047 // Write a MeasurementSet to a random group uvfits file.
00048 // </summary>
00049 
00050 class MSFitsOutput {
00051 public:
00052     //  @param fitsfile      Output filename
00053     //  @param ms            input
00054     //  @param column        specifies which "data" column to write
00055     //                       ("observed", "calibrated", "model")
00056     MSFitsOutput(
00057         const String& fitsfile, const MeasurementSet& ms,
00058         const String& column
00059     );
00060 
00061     //  @param startchan     1st channel
00062     //  @param nchan         # of channels
00063     //  @param stepchan      # of channels to stride by
00064     //  @param avgchan       average every N channels
00065     void setChannelInfo(
00066         Int startChan, Int nchan, Int stepChan, Int avgChan
00067     );
00068 
00069     //  @param writeSysCal   whether to write the system calibration table
00070     void setWriteSysCal(Bool writeSysCal);
00071 
00072     //  @param asMultiSource If true a multi-source UVFits file is written.
00073     void setAsMultiSource(Bool asMultiSource);
00074 
00075     //  @param combineSpw    If true it attempts to write the spectral windows as
00076     //                       IFs.  This is necessary for many aips tasks, and
00077     //                       for difmap.
00078     void setCombineSpw(Bool combineSpw);
00079 
00080     //  @param writeStation  If true uses pad instead of antenna names.
00081     void setWriteStation(Bool writeStation);
00082 
00083     void setSensitivity(Double sensitivity);
00084 
00085     //  @param padWithFlags  If true and combineSpw==true, fill spws with flags
00086     //                       as needed to fit the IF structure.  Does not yet
00087     //                       support spws with different shapes.
00088     void setPadWitFlags(Bool padWithFlags);
00089 
00090     void setFieldNumber(uInt fieldNumber);
00091 
00092     //  @param overwrite     overwrite existing file?
00093     void setOverwrite(Bool overwrite);
00094 
00095     // write the uvfits file.
00096     void write() const;
00097 
00098     // Convert a MeasurementSet to random group UVFITS.
00099     //  @param fitsfile      Output filename
00100     //  @param ms            input
00101     //  @param column        specifies which "data" column to write
00102     //                       ("observed", "calibrated", "model")
00103     //  @param startchan     1st channel
00104     //  @param nchan         # of channels
00105     //  @param stepchan      # of channels to stride by
00106     //  @param writeSysCal   whether to write the system calibration table
00107     //  @param asMultiSource If true a multi-source UVFits file is written.
00108     //  @param combineSpw    If true it attempts to write the spectral windows as
00109     //                       IFs.  This is necessary for many aips tasks, and
00110     //                       for difmap.
00111     //  @param writeStation  If true uses pad instead of antenna names.
00112     //  @param sensitivity
00113     //  @param padWithFlags  If true and combineSpw==true, fill spws with flags
00114     //                       as needed to fit the IF structure.  Does not yet
00115     //                       support spws with different shapes.
00116     //  @param avgchan       average every N channels
00117     //  @param overwrite     overwrite existing file?
00118     static Bool writeFitsFile(
00119         const String& fitsfile, const MeasurementSet& ms,
00120         const String& column, Int startchan=0,
00121         Int nchan=1, Int stepchan=1,
00122         Bool writeSysCal = False,
00123         Bool asMultiSource = False, Bool combineSpw=False,
00124         Bool writeStation=False, Double sensitivity=1.0,
00125         const Bool padWithFlags=false, Int avgchan=1,
00126         uInt fieldNumber=0, Bool overwrite=False
00127     );
00128 
00129 private:
00130     const String _fitsfile, _column;
00131     const MeasurementSet _ms;
00132     Int _startChan, _nchan, _stepChan, _avgChan;
00133     Bool _writeSysCal, _asMultiSource, _combineSpw,
00134         _writeStation, _padWithFlags, _overwrite;
00135     Double _sensitivity;
00136     uInt _fieldNumber;
00137 
00138 
00139     // Write the main table.
00140     //    @param refPixelFreq
00141     //    @param refFreq
00142     //    @param chanbw
00143     //    @param outFITSFile
00144     //    @param rawms
00145     //    @param column         data column to write
00146     //    @param spwidMap       spwidMap[inp_spw] = output_spw, if inp_spw is selected
00147     //                                              -1 otherwise.
00148     //    @param nrspw          # of selected spws.
00149     //    @param startchan      First channel
00150     //    @param nchan          # of channels
00151     //    @param stepchan       channel stride
00152     //    @param fieldidMap     fieldidMap[inp_fld] = output_fld, if inp_fld is selected
00153     //                                                -1 otherwise.
00154     //    @param asMultiSource  If true, write a multisource UVFITS file.
00155     //    @param combineSpw     If true, export the spectral window(s) as IF(s).
00156     //    @param padWithFlags   If true && combineSpw==true, pad the spws with
00157     //                          flags as necessary to fit the IF structure.
00158     //    @param avgchan        average every N channels
00159     FitsOutput* _writeMain(
00160         Int& refPixelFreq, Double& refFreq,
00161         Double& chanbw, const String& outFITSFile,
00162         const Block<Int>& spwidMap, Int nrspw,
00163         const Block<Int>& fieldidMap,
00164         Bool asMultiSource
00165     ) const;
00166 
00167     // Write the FQ table.
00168     // If combineSpw is True, all spectral-windows are written in one
00169     // row of the FITS table.
00170     static Bool writeFQ(FitsOutput *output, const MeasurementSet& ms,
00171         const Block<Int>& spwidMap, Int nrspw,
00172         Double refFreq, Int refPixelFreq,
00173         Double chanbw, Bool combineSpw,
00174         Int chanstart = 0, Int nchan = -1, Int chanstep = 1,
00175         Int avgchan = 1
00176     );
00177 
00178     // Write the AN table.
00179     static Bool writeAN(
00180         FitsOutput *output, const MeasurementSet& ms,
00181         Double refFreq, Bool writeStation
00182     );
00183 
00184     // Write the SU table.
00185     static Bool writeSU(
00186         FitsOutput *output, const MeasurementSet& ms,
00187         const Block<Int>& fieldidMap, Int nrfield,
00188                 const Block<Int>& spwidMap, Int nrspw
00189     );
00190 
00191     // Write the TY table.
00192     static Bool writeTY(
00193         FitsOutput *output, const MeasurementSet& ms,
00194         const Table& syscal, const Block<Int>& spwidMap,
00195         uInt nrif, Bool combineSpw
00196     );
00197 
00198     // Write the GC table.
00199     static Bool writeGC(
00200         FitsOutput *output, const MeasurementSet& ms,
00201         const Table& syscal, const Block<Int>& spwidMap,
00202         uInt nrif, Bool combineSpw, Double sensitivity,
00203         Int refPixelFreq, Double refFreq, Double chanbw
00204     );
00205 
00206     // Write the WX table.
00207     static Bool writeWX(FitsOutput *output, const MeasurementSet& ms);
00208 
00209     // Convert time to day and fraction.
00210     static void timeToDay(Int& day, Double& dayFraction, Double time);
00211 
00212     // Get the time and hourangle from the MS at the given row.
00213     // It uses the field-id and observation-id to calculate the hourangle.
00214     static void getStartHA (
00215         Double& startTime, Double& startHA,
00216         const MeasurementSet& ms, uInt rownr
00217     );
00218 
00219     // Discern the antenna numbers that go into UVFITS
00220     static void handleAntNumbers(const MeasurementSet& ms,Vector<Int>& antnumbers);
00221 
00222     // Handle the SYSCAL table.
00223     // It skips the entries not needed and sorts it in the correct order.
00224     static Table handleSysCal (
00225         const MeasurementSet& ms,
00226         const Vector<Int>& spwids, Bool isSubset
00227     );
00228 
00229     // Determine which ids are selected in the main table
00230     // (used for fields and spectral-window).
00231     //    @param map    (Really an output here, not an input.)
00232     //                  spwidMap[inp_id] = output_id, if inp_id is selected
00233     //                                     -1 otherwise.
00234     //    @param selids (Really an output here, not an input.)
00235     //                  A list of the selected input IDs.
00236     //    @param allids (Really is an input, not an output!)
00237     //                  IDs to consider.
00238     //    @return number of selected IDs in allids
00239 
00240     static Int _makeIdMap(
00241         Block<Int>& map, Vector<Int>& selids,
00242         const Vector<Int>& allids
00243     );
00244 
00245     // Find the end of a group of rows with the same
00246     // time(_centroid) (within 0.25 * ininterval(rownr)),
00247     // baseline #,
00248     // and, if asMultiSource, field ID.
00249     //    @param rownr          Row # to start from.
00250     //    @param nrow           # of rows in the columns.
00251     //    @param nif            # of IFs
00252     //    @param timec          time(_centroid) col
00253     //    @param ininterval     used to set tolerance on changes in timec.
00254     //    @param ant1           ID of baseline's antenna 1.
00255     //    @param ant2           ID of baseline's antenna 2.
00256     //    @param asMultiSource  If false, treat fieldid as unattached + prone to segfault
00257     //    @param fieldid
00258     //    @return Last row # with the same time, baseline, and apparent field as rownr.
00259     //    @warning Assumes that the columns are sorted by time(_centroid), ant1,
00260     //             ant2 (, field, DDID).
00261     static uInt get_tbf_end(
00262         const uInt rownr, const uInt nrow, const uInt nif,
00263         const ScalarColumn<Double>& timec,
00264         const ScalarColumn<Double>& ininterval,
00265         const ScalarColumn<Int>& ant1,
00266         const ScalarColumn<Int>& ant2,
00267         const Bool asMultiSource,
00268         const ScalarColumn<Int>& fieldid
00269     );
00270 
00271     static void _checkReceptorAngles(
00272         const Vector<Quantity>& ra0, Vector<Quantity>& ra1, Int antnum
00273     );
00274 };
00275 
00276 } //# NAMESPACE CASACORE - END
00277 
00278 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1