Changeset 2574


Ignore:
Timestamp:
06/21/12 15:00:20 (13 years ago)
Author:
Takeshi Nakazato
Message:

New Development: No

JIRA Issue: Yes CAS-4105

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: sdmath unit test

Put in Release Notes: No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Unified behavior of scantable operation with scalar, 1-d array,
and 2-d array. Result of the operation (+,-,*,/) is returned as
new scantable. Returned scantable refers new table if sd.rcParamsinsitu
is False while it refers the same table as input scantable if
sd.rcParamsinsitu is True. For the later case, input scantable will
be modified. If sd.rcParamsscantable.storage is 'disk', it means
that original scantable (on disk) will be modified so that those
functions must be used with care.

In task level (sdmath and sdscale), we take care to keep original table
unchanged so the users don't need to worry about that as long as they
are working on task level.


Location:
trunk/python
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/asapmath.py

    r2538 r2574  
    10221022             Otherwise, the array operation is done in-sitsu.
    10231023    """
     1024    if insitu is None: insitu = rcParams['insitu']
    10241025    nrow = scan.nrow()
    10251026    s = None
  • trunk/python/scantable.py

    r2541 r2574  
    34703470    @asaplog_post_dec
    34713471    def __add__(self, other):
    3472         varlist = vars()
     3472        """
     3473        implicit on all axes and on Tsys
     3474        """
     3475        varlist = vars()
     3476        s = self.__op( other, "ADD" )
     3477        s._add_history("operator +", varlist)
     3478        return s
     3479
     3480    @asaplog_post_dec
     3481    def __sub__(self, other):
     3482        """
     3483        implicit on all axes and on Tsys
     3484        """
     3485        varlist = vars()
     3486        s = self.__op( other, "SUB" )
     3487        s._add_history("operator -", varlist)
     3488        return s
     3489
     3490    @asaplog_post_dec
     3491    def __mul__(self, other):
     3492        """
     3493        implicit on all axes and on Tsys
     3494        """
     3495        varlist = vars()
     3496        s = self.__op( other, "MUL" ) ;
     3497        s._add_history("operator *", varlist)
     3498        return s
     3499
     3500
     3501    @asaplog_post_dec
     3502    def __div__(self, other):
     3503        """
     3504        implicit on all axes and on Tsys
     3505        """
     3506        varlist = vars()
     3507        s = self.__op( other, "DIV" )
     3508        s._add_history("operator /", varlist)
     3509        return s
     3510
     3511    @asaplog_post_dec
     3512    def __op( self, other, mode ):
    34733513        s = None
    34743514        if isinstance(other, scantable):
    3475             s = scantable(self._math._binaryop(self, other, "ADD"))
     3515            s = scantable(self._math._binaryop(self, other, mode))
    34763516        elif isinstance(other, float):
    3477             s = scantable(self._math._unaryop(self, other, "ADD", False))
     3517            if other == 0.0:
     3518                raise ZeroDivisionError("Dividing by zero is not recommended")
     3519            s = scantable(self._math._unaryop(self, other, mode, False))
    34783520        elif isinstance(other, list) or isinstance(other, numpy.ndarray):
    34793521            if isinstance(other[0], list) \
    34803522                    or isinstance(other[0], numpy.ndarray):
    34813523                from asapmath import _array2dOp
    3482                 s = _array2dOp( self.copy(), other, "ADD", False )
     3524                s = _array2dOp( self, other, mode, False )
    34833525            else:
    3484                 s = scantable( self._math._arrayop( self.copy(), other,
    3485                                                     "ADD", False ) )
     3526                s = scantable( self._math._arrayop( self, other,
     3527                                                    mode, False ) )
    34863528        else:
    34873529            raise TypeError("Other input is not a scantable or float value")
    3488         s._add_history("operator +", varlist)
    3489         return s
    3490 
    3491     @asaplog_post_dec
    3492     def __sub__(self, other):
    3493         """
    3494         implicit on all axes and on Tsys
    3495         """
    3496         varlist = vars()
    3497         s = None
    3498         if isinstance(other, scantable):
    3499             s = scantable(self._math._binaryop(self, other, "SUB"))
    3500         elif isinstance(other, float):
    3501             s = scantable(self._math._unaryop(self, other, "SUB", False))
    3502         elif isinstance(other, list) or isinstance(other, numpy.ndarray):
    3503             if isinstance(other[0], list) \
    3504                     or isinstance(other[0], numpy.ndarray):
    3505                 from asapmath import _array2dOp
    3506                 s = _array2dOp( self.copy(), other, "SUB", False )
    3507             else:
    3508                 s = scantable( self._math._arrayop( self.copy(), other,
    3509                                                     "SUB", False ) )
    3510         else:
    3511             raise TypeError("Other input is not a scantable or float value")
    3512         s._add_history("operator -", varlist)
    3513         return s
    3514 
    3515     @asaplog_post_dec
    3516     def __mul__(self, other):
    3517         """
    3518         implicit on all axes and on Tsys
    3519         """
    3520         varlist = vars()
    3521         s = None
    3522         if isinstance(other, scantable):
    3523             s = scantable(self._math._binaryop(self, other, "MUL"))
    3524         elif isinstance(other, float):
    3525             s = scantable(self._math._unaryop(self, other, "MUL", False))
    3526         elif isinstance(other, list) or isinstance(other, numpy.ndarray):
    3527             if isinstance(other[0], list) \
    3528                     or isinstance(other[0], numpy.ndarray):
    3529                 from asapmath import _array2dOp
    3530                 s = _array2dOp( self.copy(), other, "MUL", False )
    3531             else:
    3532                 s = scantable( self._math._arrayop( self.copy(), other,
    3533                                                     "MUL", False ) )
    3534         else:
    3535             raise TypeError("Other input is not a scantable or float value")
    3536         s._add_history("operator *", varlist)
    3537         return s
    3538 
    3539 
    3540     @asaplog_post_dec
    3541     def __div__(self, other):
    3542         """
    3543         implicit on all axes and on Tsys
    3544         """
    3545         varlist = vars()
    3546         s = None
    3547         if isinstance(other, scantable):
    3548             s = scantable(self._math._binaryop(self, other, "DIV"))
    3549         elif isinstance(other, float):
    3550             if other == 0.0:
    3551                 raise ZeroDivisionError("Dividing by zero is not recommended")
    3552             s = scantable(self._math._unaryop(self, other, "DIV", False))
    3553         elif isinstance(other, list) or isinstance(other, numpy.ndarray):
    3554             if isinstance(other[0], list) \
    3555                     or isinstance(other[0], numpy.ndarray):
    3556                 from asapmath import _array2dOp
    3557                 s = _array2dOp( self.copy(), other, "DIV", False )
    3558             else:
    3559                 s = scantable( self._math._arrayop( self.copy(), other,
    3560                                                     "DIV", False ) )
    3561         else:
    3562             raise TypeError("Other input is not a scantable or float value")
    3563         s._add_history("operator /", varlist)
    35643530        return s
    35653531
Note: See TracChangeset for help on using the changeset viewer.