Changeset 2459 for branches


Ignore:
Timestamp:
04/09/12 18:49:51 (12 years ago)
Author:
Kana Sugimoto
Message:

merged Takeshi's fix to asapgrid and STGrid class form trunk

Location:
branches/hpc33
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/hpc33/python/asapgrid.py

    r2397 r2459  
    105105        numerical value and unit, e.g. '0.5arcmin', or numerical value.
    106106        If those values are specified as numerical value, their units
    107         will be assumed to 'arcmin'. If which of those is not specified,
     107        will be assumed to 'arcsec'. If which of those is not specified,
    108108        it will be set to the same value as the other. If none of them
    109109        are specified, it will be determined from map extent and number
     
    130130        """
    131131        if not isinstance( cellx, str ):
    132             cellx = '%sarcmin'%(cellx)
     132            cellx = '%sarcsec'%(cellx)
    133133        if not isinstance( celly, str ):
    134             celly = '%sarcmin'%(celly)
     134            celly = '%sarcsec'%(celly)
    135135        self.gridder._defineimage( nx, ny, cellx, celly, center )
    136136
     
    145145           'box': 1 pixel
    146146           'sf': 3 pixels
    147            'gauss': 3 pixels (width is used as HWHM)
     147           'gauss': 1 pixel (width is used as HWHM)
    148148
    149149        func -- Function type ('box', 'sf', 'gauss').
     
    265265        idx = 0
    266266        d0 = s.get_direction( 0 ).split()[-1]
    267         while ( s.get_direction(self.npol*idx).split()[-1] == d0 ): 
     267        while ( s.get_direction(self.npol*idx) is not None \
     268                and s.get_direction(self.npol*idx).split()[-1] == d0 ):
    268269            idx += 1
    269270       
     
    276277        #print self.blc
    277278        #print self.trc
    278         incrx = s.get_directionval( self.npol )
    279         incry = s.get_directionval( self.nx*self.npol )
     279        if nrow > 1:
     280            incrx = s.get_directionval( self.npol )
     281            incry = s.get_directionval( self.nx*self.npol )
     282        else:
     283            incrx = [0.0,0.0]
     284            incry = [0.0,0.0]
    280285        self.cellx = abs( self.blc[0] - incrx[0] )
    281286        self.celly = abs( self.blc[1] - incry[1] )
     
    287292        else:
    288293            opt = 'pol %s'%(pol)
    289         if chan < 0:
     294        if type(chan) is list:
     295            opt += ', averaged over channel %s-%s'%(chan[0],chan[1])
     296        elif chan < 0:
    290297            opt += ', averaged over channel'
    291298        else:
    292299            opt += ', channel %s'%(chan)
    293         data = self.getData( chan, pol )
     300        data = self.getData( chan, pol )
     301        data = numpy.fliplr( data )
    294302        title = 'Gridded Image (%s)'%(opt)
    295303        pl.figure(10)
     
    319327                    #print irow
    320328        # show image
    321         extent=[self.blc[0]-0.5*self.cellx,
    322                 self.trc[0]+0.5*self.cellx,
     329        extent=[self.trc[0]+0.5*self.cellx,
     330                self.blc[0]-0.5*self.cellx,
    323331                self.blc[1]-0.5*self.celly,
    324332                self.trc[1]+0.5*self.celly]
     333        deccorr = 1.0/numpy.cos(0.5*(self.blc[1]+self.trc[1]))
    325334        pl.imshow(data,extent=extent,origin='lower',interpolation='nearest')
    326335        pl.colorbar()
    327336        pl.xlabel('R.A. [rad]')
    328337        pl.ylabel('Dec. [rad]')
     338        ax = pl.axes()
     339        ax.set_aspect(deccorr)
    329340        pl.title( title )
    330341
     
    359370
    360371    def getData( self, chan=-1, pol=-1 ):
    361         if chan == -1:
     372        if type(chan) == list:
     373            spectra = self.__chanAverage(start=chan[0],end=chan[1])
     374        elif chan == -1:
    362375            spectra = self.__chanAverage()
    363376        else:
     
    370383        return retval
    371384
    372     def __chanAverage( self ):
     385    def __chanAverage( self, start=-1, end=-1 ):
    373386        s = scantable( self.outfile, average=False )
    374387        nrow = s.nrow()
     
    376389        irow = 0
    377390        sp = [0 for i in xrange(self.nchan)]
     391        if start < 0:
     392            start = 0
     393        if end < 0:
     394            end = self.nchan
    378395        for i in xrange(nrow/self.npol):
    379396            for ip in xrange(self.npol):
    380                 sp = s._getspectrum( irow )
     397                sp = s._getspectrum( irow )[start:end]
    381398                spectra[ip,i] = numpy.mean( sp )
    382399                irow += 1
     400           
    383401        return spectra
    384402
  • branches/hpc33/src/STGrid.cpp

    r2398 r2459  
    1 #include <iostream>
    2 #include <fstream>
    3 #include <cfloat>
    4 
     1//
     2// C++ Implementation: STGrid
     3//
     4// Description:
     5//
     6//
     7// Author: Takeshi Nakazato <takeshi.nakazato@nao.ac.jp>, (C) 2011
     8//
     9// Copyright: See COPYING file that comes with this distribution
     10//
     11//
    512#include <casa/BasicSL/String.h>
    613#include <casa/Arrays/Vector.h>
    7 #include <casa/Arrays/Matrix.h>
    8 #include <casa/Arrays/Cube.h>
    914#include <casa/Arrays/ArrayMath.h>
    10 #include <casa/Arrays/ArrayIter.h>
    1115#include <casa/Quanta/Quantum.h>
    1216#include <casa/Quanta/QuantumHolder.h>
     
    1620#include <tables/Tables/Table.h>
    1721#include <tables/Tables/TableRecord.h>
     22#include <tables/Tables/TableRow.h>
    1823#include <tables/Tables/ExprNode.h>
    1924#include <tables/Tables/ScalarColumn.h>
    2025#include <tables/Tables/ArrayColumn.h>
    21 #include <tables/Tables/TableIter.h>
     26#include <tables/Tables/TableCopy.h>
    2227
    2328#include <measures/Measures/MDirection.h>
    2429
    25 #include <MathUtils.h>
     30#include "MathUtils.h"
     31#include <atnf/PKSIO/SrcType.h>
    2632
    2733#include "STGrid.h"
     
    407413  selectData() ;
    408414  t1 = mathutil::gettimeofday_sec() ;
    409   os << "selectData: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
     415  os << LogIO::DEBUGGING << "selectData: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
    410416
    411417  setupGrid() ;
     
    640646  setConvFunc( common.convFunc ) ;
    641647  t1 = mathutil::gettimeofday_sec() ;
    642   os << "setConvFunc: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
     648  os << LogIO::DEBUGGING << "setConvFunc: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
    643649
    644650  // for performance check
     
    681687    os << "end table " << ifile << LogIO::POST ;   
    682688  }
    683   os << "initPol: elapsed time is " << eInitPol << " sec." << LogIO::POST ;
    684   os << "getData: elapsed time is " << eGetData_-eToInt-eGetWeight << " sec." << LogIO::POST ;
    685   os << "toPixel: elapsed time is " << eToPixel_ << " sec." << LogIO::POST ;
    686   os << "ggridsd: elapsed time is " << eGGridSD_ << " sec." << LogIO::POST ;
    687   os << "toInt: elapsed time is " << eToInt << " sec." << LogIO::POST ;
    688   os << "getWeight: elapsed time is " << eGetWeight << " sec." << LogIO::POST ;
     689  os << LogIO::DEBUGGING << "initPol: elapsed time is " << eInitPol << " sec." << LogIO::POST ;
     690  os << LogIO::DEBUGGING << "getData: elapsed time is " << eGetData_-eToInt-eGetWeight << " sec." << LogIO::POST ;
     691  os << LogIO::DEBUGGING << "toPixel: elapsed time is " << eToPixel_ << " sec." << LogIO::POST ;
     692  os << LogIO::DEBUGGING << "ggridsd: elapsed time is " << eGGridSD_ << " sec." << LogIO::POST ;
     693  os << LogIO::DEBUGGING << "toInt: elapsed time is " << eToInt << " sec." << LogIO::POST ;
     694  os << LogIO::DEBUGGING << "getWeight: elapsed time is " << eGetWeight << " sec." << LogIO::POST ;
    689695 
    690696  delete chanMap ;
     
    790796  setConvFunc( common.convFunc ) ;
    791797  t1 = mathutil::gettimeofday_sec() ;
    792   os << "setConvFunc: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
     798  os << LogIO::DEBUGGING << "setConvFunc: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
    793799
    794800  // for performance check
     
    831837    os << "end table " << ifile << LogIO::POST ;   
    832838  }
    833   os << "initPol: elapsed time is " << eInitPol << " sec." << LogIO::POST ;
    834   os << "getData: elapsed time is " << eGetData_-eToInt-eGetWeight << " sec." << LogIO::POST ;
    835   os << "toPixel: elapsed time is " << eToPixel_ << " sec." << LogIO::POST ;
    836   os << "ggridsd2: elapsed time is " << eGGridSD_ << " sec." << LogIO::POST ;
    837   os << "toInt: elapsed time is " << eToInt << " sec." << LogIO::POST ;
    838   os << "getWeight: elapsed time is " << eGetWeight << " sec." << LogIO::POST ;
     839  os << LogIO::DEBUGGING << "initPol: elapsed time is " << eInitPol << " sec." << LogIO::POST ;
     840  os << LogIO::DEBUGGING << "getData: elapsed time is " << eGetData_-eToInt-eGetWeight << " sec." << LogIO::POST ;
     841  os << LogIO::DEBUGGING << "toPixel: elapsed time is " << eToPixel_ << " sec." << LogIO::POST ;
     842  os << LogIO::DEBUGGING << "ggridsd2: elapsed time is " << eGGridSD_ << " sec." << LogIO::POST ;
     843  os << LogIO::DEBUGGING << "toInt: elapsed time is " << eToInt << " sec." << LogIO::POST ;
     844  os << LogIO::DEBUGGING << "getWeight: elapsed time is " << eGetWeight << " sec." << LogIO::POST ;
    839845 
    840846  delete chanMap ;
     
    855861              common.clipCMax ) ;
    856862  t1 = mathutil::gettimeofday_sec() ;
    857   os << "clipMinMax: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
     863  os << LogIO::DEBUGGING << "clipMinMax: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
    858864//   os << "AFTER CLIPPING" << LogIO::POST ;
    859865//   os << "gdataArrC=" << common.gdataArrC << LogIO::POST ;
     
    960966  }
    961967  else
    962     ptab_ = tab_( tab_.col("POLNO") == (uInt)ipol ) ;
     968    ptab_ = tab_( tab_.col("POLNO") == pollist_[ipol] ) ;
    963969
    964970  attach( ptab_ ) ;
     
    9961002  data_.putStorage( gwgt_p, b2 ) ;
    9971003  t1 = mathutil::gettimeofday_sec() ;
    998   os << "setData: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
     1004  os << LogIO::DEBUGGING << "setData: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
    9991005}
    10001006
     
    11111117  }
    11121118  cellx_ = qcellx.getValue( "rad" ) ;
     1119  // DEC correction
     1120  cellx_ /= cos( center_[1] ) ;
    11131121  celly_ = qcelly.getValue( "rad" ) ;
     1122  //os << "cellx_=" << cellx_ << ", celly_=" << celly_ << ", cos("<<center_(1)<<")=" << cos(center_(1)) << LogIO::POST ;
    11141123  if ( nx_ < 0 ) {
    11151124    if ( wx == 0.0 ) {
     
    11561165  Int ifno = ifno_ ;
    11571166  tableList_.resize( nfile_ ) ;
    1158   if ( ifno == -1 ) {
     1167  if ( ifno_ == -1 ) {
    11591168    Table taborg( infileList_[0] ) ;
    11601169    ROScalarColumn<uInt> ifnoCol( taborg, "IFNO" ) ;
    1161     ifno = ifnoCol( 0 ) ;
     1170    ifno_ = ifnoCol( 0 ) ;
    11621171    os << LogIO::WARN
    1163        << "IFNO is not given. Using default IFNO: " << ifno << LogIO::POST ;
     1172       << "IFNO is not given. Using default IFNO: " << ifno_ << LogIO::POST ;
    11641173  }
    11651174  for ( uInt i = 0 ; i < nfile_ ; i++ ) {
    11661175    Table taborg( infileList_[i] ) ;
    11671176    TableExprNode node ;
    1168     if ( isMultiIF( taborg ) ) {
     1177    if ( ifno != -1 || isMultiIF( taborg ) ) {
    11691178      os << "apply selection on IFNO" << LogIO::POST ;
    1170       node = taborg.col("IFNO") == ifno ;
     1179      node = taborg.col("IFNO") == ifno_ ;
    11711180    }
    11721181    if ( scanlist_.size() > 0 ) {
     
    11801189      tableList_[i] = taborg( node ) ;
    11811190    }
    1182     os << "tableList_[" << i << "].nrow()=" << tableList_[i].nrow() << LogIO::POST ;
     1191    os << LogIO::DEBUGGING << "tableList_[" << i << "].nrow()=" << tableList_[i].nrow() << LogIO::POST ;
    11831192    if ( tableList_[i].nrow() == 0 ) {
    11841193      os << LogIO::SEVERE
    1185          << "No corresponding rows for given selection: IFNO " << ifno ;
     1194         << "No corresponding rows for given selection: IFNO " << ifno_ ;
    11861195      if ( scanlist_.size() > 0 )
    11871196        os << " SCANNO " << scanlist_ ;
     
    15651574    // to take into account Gaussian tail
    15661575    if ( convSupport_ < 0 )
    1567       convSupport_ = 12 ; // 3 * 4
     1576      convSupport_ = 4 ; // 1 * 4
    15681577    else {
    15691578      convSupport_ = userSupport_ * 4 ;
     
    16501659
    16511660  t1 = mathutil::gettimeofday_sec() ;
    1652   os << "saveData: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
     1661  os << LogIO::DEBUGGING << "saveData: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
     1662
     1663  fillMainColumns( tab ) ;
    16531664
    16541665  return outfile_ ;
     
    16601671  t.deepCopy( name, Table::New, False, t.endianFormat(), True ) ;
    16611672  tab = Table( name, Table::Update ) ;
    1662 }
    1663 
    1664 }
     1673  // 2012/02/13 TN
     1674  // explicitly copy subtables since no rows including subtables are
     1675  // copied by Table::deepCopy with noRows=True
     1676  TableCopy::copySubTables( tab, t ) ;
     1677}
     1678
     1679void STGrid::fillMainColumns( Table &tab )
     1680{
     1681  // values for fill
     1682  Table t( infileList_[0], Table::Old ) ;
     1683  Table tsel = t( t.col( "IFNO" ) == (uInt)ifno_, 1 ) ;
     1684  ROTableRow row( tsel ) ;
     1685  row.get( 0 ) ;
     1686  const TableRecord &rec = row.record() ;
     1687  uInt freqId = rec.asuInt( "FREQ_ID" ) ;
     1688  uInt molId = rec.asuInt( "MOLECULE_ID" ) ;
     1689  uInt tcalId = rec.asuInt( "TCAL_ID" ) ;
     1690  uInt focusId = rec.asuInt( "FOCUS_ID" ) ;
     1691  uInt weatherId = rec.asuInt( "WEATHER_ID" ) ;
     1692  String srcname = rec.asString( "SRCNAME" ) ;
     1693  String fieldname = rec.asString( "FIELDNAME" ) ;
     1694  Vector<Float> defaultTsys( 1, 1.0 ) ;
     1695  // @todo how to set flagtra for gridded spectra?
     1696  Vector<uChar> flagtra = rec.asArrayuChar( "FLAGTRA" ) ;
     1697  flagtra = (uChar)0 ;
     1698  Float opacity = rec.asFloat( "OPACITY" ) ;
     1699  Double srcvel = rec.asDouble( "SRCVELOCITY" ) ;
     1700  Vector<Double> srcpm = rec.asArrayDouble( "SRCPROPERMOTION" ) ;
     1701  Vector<Double> srcdir = rec.asArrayDouble( "SRCDIRECTION" ) ;
     1702  Vector<Double> scanrate = rec.asArrayDouble( "SCANRATE" ) ;
     1703  Double time = rec.asDouble( "TIME" ) ;
     1704  Double interval = rec.asDouble( "INTERVAL" ) ;
     1705
     1706  // fill columns
     1707  Int nrow = tab.nrow() ;
     1708  ScalarColumn<uInt> scannoCol( tab, "SCANNO" ) ;
     1709  ScalarColumn<uInt> ifnoCol( tab, "IFNO" ) ;
     1710  ScalarColumn<uInt> freqIdCol( tab, "FREQ_ID" ) ;
     1711  ScalarColumn<uInt> molIdCol( tab, "MOLECULE_ID" ) ;
     1712  ScalarColumn<uInt> tcalidCol( tab, "TCAL_ID" ) ;
     1713  ScalarColumn<Int> fitidCol( tab, "FIT_ID" ) ;
     1714  ScalarColumn<uInt> focusidCol( tab, "FOCUS_ID" ) ;
     1715  ScalarColumn<uInt> weatheridCol( tab, "WEATHER_ID" ) ;
     1716  ArrayColumn<uChar> flagtraCol( tab, "FLAGTRA" ) ;
     1717  ScalarColumn<uInt> rflagCol( tab, "FLAGROW" ) ;
     1718  ArrayColumn<Float> tsysCol( tab, "TSYS" ) ;
     1719  ScalarColumn<String> srcnameCol( tab, "SRCNAME" ) ;
     1720  ScalarColumn<String> fieldnameCol( tab, "FIELDNAME" ) ;
     1721  ScalarColumn<Int> srctypeCol( tab, "SRCTYPE" ) ;
     1722  ScalarColumn<Float> opacityCol( tab, "OPACITY" ) ;
     1723  ScalarColumn<Double> srcvelCol( tab, "SRCVELOCITY" ) ;
     1724  ArrayColumn<Double> srcpmCol( tab, "SRCPROPERMOTION" ) ;
     1725  ArrayColumn<Double> srcdirCol( tab, "SRCDIRECTION" ) ;
     1726  ArrayColumn<Double> scanrateCol( tab, "SCANRATE" ) ;
     1727  ScalarColumn<Double> timeCol( tab, "TIME" ) ;
     1728  ScalarColumn<Double> intervalCol( tab, "INTERVAL" ) ;
     1729  for ( Int i = 0 ; i < nrow ; i++ ) {
     1730    scannoCol.put( i, (uInt)i ) ;
     1731    ifnoCol.put( i, (uInt)ifno_ ) ;
     1732    freqIdCol.put( i, freqId ) ;
     1733    molIdCol.put( i, molId ) ;
     1734    tcalidCol.put( i, tcalId ) ;
     1735    fitidCol.put( i, -1 ) ;
     1736    focusidCol.put( i, focusId ) ;
     1737    weatheridCol.put( i, weatherId ) ;
     1738    flagtraCol.put( i, flagtra ) ;
     1739    rflagCol.put( i, 0 ) ;
     1740    tsysCol.put( i, defaultTsys ) ;
     1741    srcnameCol.put( i, srcname ) ;
     1742    fieldnameCol.put( i, fieldname ) ;
     1743    srctypeCol.put( i, (Int)SrcType::PSON ) ;
     1744    opacityCol.put( i, opacity ) ;
     1745    srcvelCol.put( i, srcvel ) ;
     1746    srcpmCol.put( i, srcpm ) ;
     1747    srcdirCol.put( i, srcdir ) ;
     1748    scanrateCol.put( i, scanrate ) ;
     1749    timeCol.put( i, time ) ;
     1750    intervalCol.put( i, interval ) ;
     1751  }
     1752}
     1753
     1754}
  • branches/hpc33/src/STGrid.h

    r2398 r2459  
    195195  void initTable( uInt idx ) ;
    196196  Bool isMultiIF( Table &tab ) ;
     197  void fillMainColumns( Table &tab ) ;
    197198  static bool produceChunk(void *ctx) throw(concurrent::PCException);
    198199  static void consumeChunk(void *ctx) throw(concurrent::PCException);
Note: See TracChangeset for help on using the changeset viewer.