Changeset 2818


Ignore:
Timestamp:
07/02/13 10:38:18 (11 years ago)
Author:
Malte Marquarding
Message:

Issue #291: added scantable.set_sourcename to overwrite sourcename to allow freq_align to work. Exposed 'SOURCE' averaging to python api. Added some logging to freq_align refering to the sources it aligns to

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/__init__.py

    r2649 r2818  
    5959
    6060__date__ = '$Date$'.split()[1]
    61 __version__  = 'trunk'
     61__version__  = '4.1.3a'
    6262__revision__ = get_revision()
    6363
  • trunk/python/asapmath.py

    r2754 r2818  
    9090    else:
    9191        #s = scantable(stm._average(alignedlst, mask, weight.upper(), scanav))
    92         s = scantable(stm._new_average(alignedlst, compel, mask, weight.upper(), scanav))
     92        s = scantable(stm._new_average(alignedlst, compel, mask,
     93                                       weight.upper(), scanav))
    9394    s._add_history("average_time",varlist)
    9495
  • trunk/python/scantable.py

    r2810 r2818  
    21122112    #
    21132113    @asaplog_post_dec
    2114     def average_time(self, mask=None, scanav=False, weight='tint', align=False):
     2114    def average_time(self, mask=None, scanav=False, weight='tint', align=False,
     2115                     avmode="NONE"):
    21152116        """\
    21162117        Return the (time) weighted average of a scan. Scans will be averaged
     
    21402141            align:    align the spectra in velocity before averaging. It takes
    21412142                      the time of the first spectrum as reference time.
     2143            avmode:   'SOURCE' - also select by source name -  or
     2144                      'NONE' (default). Not applicable for scanav=True or
     2145                      weight=median
    21422146
    21432147        Example::
     
    21502154        weight = weight or 'TINT'
    21512155        mask = mask or ()
    2152         scanav = (scanav and 'SCAN') or 'NONE'
     2156        scanav = (scanav and 'SCAN') or avmode.upper()
    21532157        scan = (self, )
    21542158
    21552159        if align:
    21562160            scan = (self.freq_align(insitu=False), )
     2161            asaplog.push("Note: Alignment is don on a source-by-source basis")
     2162            asaplog.push("Note: Averaging (by default) is not")
     2163            # we need to set it to SOURCE averaging here           
    21572164        s = None
    21582165        if weight.upper() == 'MEDIAN':
     
    42464253        self._add_history("set_sourcetype", varlist)
    42474254
     4255
     4256    def set_sourcename(self, name):
     4257        varlist = vars()
     4258        self._setsourcename(name)
     4259        self._add_history("set_sourcename", varlist)
     4260
    42484261    @asaplog_post_dec
    42494262    @preserve_selection
  • trunk/setup.py

    r2653 r2818  
    44
    55setup(name = PKGNAME,
    6       version = '4.1.0',
     6      version = '4.1.3a',
    77      description = 'ATNF Spectral-line Analysis Package',
    88      author = 'Malte Marquarding',
  • trunk/src/STMath.cpp

    r2695 r2818  
    27812781  MVTime mvt(refEpoch.getValue());
    27822782  String epochout = mvt.string(MVTime::YMD) + String(" (") + refEpoch.getRefString() + String(")");
    2783   os << "Aligned at reference Epoch " << epochout
     2783  os << "Aligning at reference Epoch " << epochout
    27842784     << " in frame " << MFrequency::showType(system) << LogIO::POST;
    27852785  // set up the iterator
     
    27952795  while ( !iter.pastEnd() ) {
    27962796    Table t = iter.table();
     2797    ROScalarColumn<String> snCol(t, "SRCNAME");
     2798    os << "Aligning to position of source '" << snCol(0) << "'" << LogIO::POST;
    27972799    MDirection::ROScalarColumn dirCol(t, "DIRECTION");
    27982800    TableIterator fiter(t, "FREQ_ID");
    27992801    // determine nchan from the first row. This should work as
    2800     // we are iterating over BEAMNO and IFNO    // we should have constant direction
     2802    // we are iterating over BEAMNO and IFNO   
     2803    // we should have constant direction
    28012804
    28022805    ROArrayColumn<Float> sCol(t, "SPECTRA");
     
    28132816    ScalarColumn<uInt> freqidCol(ftab, "FREQ_ID");
    28142817    // get the SpectralCoordinate for the freqid, which we are iterating over
    2815     SpectralCoordinate sC = in->frequencies().getSpectralCoordinate(freqidCol(0));
     2818    SpectralCoordinate sC = \
     2819      in->frequencies().getSpectralCoordinate(freqidCol(0));
    28162820    FrequencyAligner<Float> fa( sC, nchan, refEpoch,
    28172821                                direction, refPos, system );
     
    28262830                                                sc2.increment()[0]);
    28272831    while ( !fiter.pastEnd() ) {
     2832     
    28282833      ftab = fiter.table();
    28292834      // spectral coordinate for the current FREQ_ID
  • trunk/src/Scantable.cpp

    r2813 r2818  
    180180        table_ = TableCopy::makeEmptyMemoryTable(newname,
    181181                                                 other.table_, True);
    182       } else
     182      } else {
    183183        table_ = other.table_.copyToMemoryTable(newname);
     184      }
    184185  } else {
    185186      other.table_.deepCopy(newname, Table::New, False,
     
    450451  TableVector<Int> tabvec(table_, "SRCTYPE");
    451452  tabvec = Int(stype);
     453}
     454
     455void Scantable::setSourceName( const std::string& name )
     456{
     457  TableVector<String> tabvec(table_, "SRCNAME");
     458  tabvec = name;
    452459}
    453460
  • trunk/src/Scantable.h

    r2811 r2818  
    155155  void setSourceType(int stype);
    156156
     157  /**
     158   *
     159   * @param stype The name of the source
     160   */
     161  void setSourceName(const std::string& name);
     162
    157163
    158164  /**
     
    387393
    388394  //std::string getTime(int whichrow=-1, bool showdate=true) const;
    389   std::string getTime(int whichrow=-1, bool showdate=true, casa::uInt prec=0) const;
     395  std::string getTime(int whichrow=-1, bool showdate=true,
     396                      casa::uInt prec=0) const;
    390397  double getIntTime(int whichrow) const { return integrCol_(whichrow); }
    391398
     
    668675
    669676  std::string formatTime(const casa::MEpoch& me, bool showdate)const;
    670   std::string formatTime(const casa::MEpoch& me, bool showdate, casa::uInt prec)const;
     677  std::string formatTime(const casa::MEpoch& me, bool showdate,
     678                         casa::uInt prec)const;
    671679
    672680  /**
  • trunk/src/ScantableWrapper.h

    r2811 r2818  
    188188    { table_->setSourceType(stype); }
    189189
     190  void setSourceName(const std::string& name)
     191    { table_->setSourceName(name); }
     192
    190193  void shift(int npix)
    191194  { table_->shift(npix); }
  • trunk/src/python_Scantable.cpp

    r2791 r2818  
    137137    .def("_recalcazel", &ScantableWrapper::calculateAZEL)
    138138    .def("_setsourcetype", &ScantableWrapper::setSourceType)
     139    .def("_setsourcename", &ScantableWrapper::setSourceName)
    139140    .def("_getdirectionvec", &ScantableWrapper::getDirectionVector)
    140141    .def("_parallactify", &ScantableWrapper::parallactify)
  • trunk/test/test_scantable.py

    r2802 r2818  
    149149                          'Orion_SiO', 'Orion_SiO'])
    150150
     151    def test_set_sourcename(self):
     152        s = self.st.copy()
     153        newname = "TEST"
     154        s.set_sourcename(newname)
     155        assert_equal(s.get_sourcename(), [newname]*4)
     156
    151157    def test_get_azimuth(self):
    152158        assert_almost_equal(self.st.get_azimuth()[0], 5.628767013)
     
    194200        assert_almost_equal(q1.stats(stat='max')[0], 2.66563416)
    195201
     202
     203    def test_average_time_weight(self):
     204        weights = {'none': 236.61423,
     205                   'var' : 232.98752,
     206                   'tsys' : 236.37482,
     207                   'tint' : 236.61423,
     208                   'tintsys' : 236.37485,
     209                   'median' : 236.61423,
     210                   }
     211
     212        for k,v in weights.items():
     213            yield self.av_weight, k, v
     214
     215    def av_weight(self, weight, result):
     216        out = self.st.average_time(weight=weight)
     217        assert_almost_equals(max(out.get_spectrum(0)), result, 5)
     218
    196219    @with_setup(tempdir_setup, tempdir_teardown)
    197220    def test_save(self):
     
    203226                   (fname % 'txt', 'ASCII', False),
    204227                   ]
    205         for format in formats:
    206             yield self.save, format
     228        for fmt in formats:
     229            yield self.save, fmt
    207230
    208231    def save(self, args):
Note: See TracChangeset for help on using the changeset viewer.