Changeset 2635


Ignore:
Timestamp:
08/08/12 17:15:19 (12 years ago)
Author:
Takeshi Nakazato
Message:

New Development: No

JIRA Issue: Yes CAS-2825

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No?

Module(s): Module Names change impacts.

Description: Describe your changes here...

Added optional plot method.


File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/edgemarker.py

    r2616 r2635  
    11from asap.scantable import scantable
    22from asap._asap import _edgemarker
    3 
     3import numpy
     4import math
     5       
    46class edgemarker:
    57    """
     
    143145        s = self.getresult()
    144146        s.save( name, overwrite=overwrite )
     147
     148    def plot( self ):
     149        """
     150        """
     151        from matplotlib import pylab as pl
     152        from asap import selector
     153        from asap._asap import srctype as st
     154        pl.clf()
     155
     156        # result as a scantable
     157        s = self.getresult()
     158
     159        # ON scan
     160        sel = selector()
     161        sel.set_types( int(st.pson) )
     162        s.set_selection( sel )
     163        diron = numpy.array( s.get_directionval() ).transpose()
     164        diron[0] = rotate( diron[0] )
     165        s.set_selection()
     166        sel.reset()
     167
     168        # OFF scan
     169        sel.set_types( int(st.psoff) )
     170        s.set_selection( sel )
     171        diroff = numpy.array( s.get_directionval() ).transpose()
     172        diroff[0] = rotate( diroff[0] )
     173        s.set_selection()
     174        sel.reset()
     175        del s
     176        del sel
     177
     178        # plot
     179        pl.ioff()
     180        ax=pl.axes()
     181        ax.set_aspect(1.0)
     182        pl.plot( diron[0], diron[1], '.', color='blue', label='ON' )
     183        pl.plot( diroff[0], diroff[1], '.', color='green', label='OFF' )
     184        [xmin,xmax,ymin,ymax] = pl.axis()
     185        pl.axis([xmax,xmin,ymin,ymax])
     186        pl.legend(loc='best',prop={'size':'small'},numpoints=1)
     187        pl.xlabel( 'R.A. [rad]' )
     188        pl.ylabel( 'Declination [rad]' )
     189        pl.title( 'edgemarker result' )
     190        pl.ion()
     191        pl.draw()
     192
     193def _0to2pi( v ):
     194    return v % (2.0*math.pi)
     195
     196def quadrant( v ):
     197    vl = _0to2pi( v )
     198    base = 0.5 * math.pi
     199    return int( vl / base )
     200
     201def quadrantList( a ):
     202    n = len(a)
     203    nquad = numpy.zeros( 4, dtype=int )
     204    for i in xrange(n):
     205        v = quadrant( a[i] )
     206        nquad[v] += 1
     207    #print nquad
     208    return nquad
     209
     210def rotate( v ):
     211    a = numpy.zeros( len(v), dtype=float )
     212    for i in xrange(len(v)):
     213        a[i] = _0to2pi( v[i] )
     214    nquad = quadrantList( a )
     215    quadList = [[],[],[],[]]
     216    rot = numpy.zeros( 4, dtype=bool )
     217    if all( nquad==0 ):
     218        print 'no data'
     219    elif all( nquad>0 ):
     220        #print 'extends in all quadrants'
     221        pass
     222    elif nquad[0]>0 and nquad[3]>0:
     223        #print 'need rotation'
     224        rot[3] = True
     225        rot[2] = nquad[1]==0 and nquad[2]>0
     226    #print rot
     227
     228    for i in xrange(len(a)):
     229        if rot[quadrant(a[i])]:
     230            a[i] -= 2*math.pi
     231    return a
Note: See TracChangeset for help on using the changeset viewer.