Changeset 258


Ignore:
Timestamp:
01/21/05 22:31:17 (19 years ago)
Author:
mar637
Message:

*renaming all -> allaxes

  • added rcParams
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/asapmath.py

    r246 r258  
    11from scantable import scantable
     2from asap import rcParams
    23
    34def average_time(*args, **kwargs):
     
    2324    if kwargs.has_key('scanav'):
    2425       scanAv = kwargs.get('scanav')
    25 #
     26
    2627    weight = 'none'
    2728    if kwargs.has_key('weight'):
    2829       weight = kwargs.get('weight')
    29 #
     30
    3031    mask = ()
    3132    if kwargs.has_key('mask'):
    3233        mask = kwargs.get('mask')
    33 #
     34
    3435    lst = tuple(args)
    3536    from asap._asap import average as _av
     
    5657    return scantable(_quot(source, reference, preserve))
    5758
    58 def b_operate(left, right, op='add'):
     59def simple_math(left, right, op='add'):
    5960    """
    6061    Apply simple mathematical binary operations to two
     
    6667        op:            the operation: 'add' (default), 'sub', 'mul', 'div'
    6768    """
     69    if not isinstance(left,scantable) and not isinstance(right,scantable):
     70        print "Please provide two scantables as input"
     71        return
    6872    from asap._asap import b_operate as _bop
    6973    return scantable(_bop(left, right, op))
    7074
    71 def scale(scan, factor, insitu=False, all=True):
     75def scale(scan, factor, insitu=None, allaxes=None):
    7276    """
    7377    Return a scan where all spectra are scaled by the give 'factor'
     
    7579        scan:        a scantable
    7680        factor:      the scaling factor
    77         insitu:      if False (default) a new scantable is returned.
    78                      Otherwise, the scaling is done in-situ
    79         all:         if True (default) apply to all spectra. Otherwise
     81        insitu:      if False a new scantable is returned.
     82                     Otherwise, the scaling is done in-situ
     83                     The default is taken from .asaprc (False)
     84        allaxes:     if True apply to all spectra. Otherwise
     85                     apply only to the selected (beam/pol/if)spectra only.
     86                     The default is taken from .asaprc (True)
     87    """
     88    if allaxes is None: allaxes = rcParams['scantable.allaxes']
     89    if insitu is None: insitu = rcParams['insitu']
     90    if not insitu:
     91        from asap._asap import scale as _scale
     92        return scantable(_scale(scan, factor, allaxes))
     93    else:
     94        from asap._asap import scale_insitu as _scale
     95        _scale(scan, factor, allaxes)
     96        return
     97       
     98
     99def add(scan, offset, insitu=None, allaxes=None):
     100    """
     101    Return a scan where all spectra have the offset added
     102    Parameters:
     103        scan:        a scantable
     104        offset:      the offset
     105        insitu:      if False a new scantable is returned.
     106                     Otherwise, the scaling is done in-situ
     107                     The default is taken from .asaprc (False)
     108        allaxes:     if True apply to all spectra. Otherwise
    80109                     apply only to the selected (beam/pol/if)spectra only
    81     """
    82     if not insitu:
    83         from asap._asap import scale as _scale
    84         return scantable(_scale(scan, factor, all))
    85     else:
    86         from asap._asap import scale_insitu as _scale
    87         _scale(scan, factor, all)
     110                     The default is taken from .asaprc (True)
     111    """
     112    if allaxes is None: allaxes = rcParams['scantable.allaxes']
     113    if insitu is None: insitu = rcParams['insitu']
     114    if not insitu:
     115        from asap._asap import add as _add
     116        return scantable(_add(scan, offset, allaxes))
     117    else:
     118        from asap._asap import add_insitu as _add
     119        _add(scan, offset, allaxes)
    88120        return
    89121       
    90 
    91 def add(scan, offset, insitu=False, all=True):
    92     """
    93     Return a scan where all spectra have the offset added
    94     Parameters:
    95         scan:        a scantable
    96         offset:      the offset
    97         insitu:      if False (default) a new scantable is returned.
    98                      Otherwise, the addition is done in-situ
    99         all:         if True (default) apply to all spectra. Otherwise
    100                      apply only to the selected (beam/pol/if)spectra only
    101     """
    102     if not insitu:
    103         from asap._asap import add as _add
    104         return scantable(_add(scan, offset, all))
    105     else:
    106         from asap._asap import add_insitu as _add
    107         _add(scan, offset, all)
    108         return
    109        
    110 def convert_flux(scan, area, eta=1.0, insitu=False, all=True):
     122def convert_flux(scan, area, eta=1.0, insitu=None, allaxes=None):
    111123    """
    112124    Return a scan where all spectra are converted to either Jansky or Kelvin
     
    116128        area:        the illuminated area of the telescope (m**2)
    117129        eta:         The efficiency of the telescope (default 1.0)       
    118         insitu:      if False (default) a new scantable is returned.
    119                      Otherwise, the conversion is done in-situ
    120         all:         if True (default) apply to all spectra. Otherwise
     130        insitu:      if False a new scantable is returned.
     131                     Otherwise, the scaling is done in-situ
     132                     The default is taken from .asaprc (False)
     133        allaxes:         if True apply to all spectra. Otherwise
    121134                     apply only to the selected (beam/pol/if)spectra only
    122     """
     135                     The default is taken from .asaprc (True)
     136    """
     137    if allaxes is None: allaxes = rcParams['scantable.allaxes']
     138    if insitu is None: insitu = rcParams['insitu']
    123139    if not insitu:
    124140        from asap._asap import convertflux as _convert
    125         return scantable(_convert(scan, area, eta, all))
     141        return scantable(_convert(scan, area, eta, allaxes))
    126142    else:
    127143        from asap._asap import convertflux_insitu as _convert
    128         _convert(scan, area, eta, all)
    129         return
    130 
    131 def gain_el(scan, poly=None, filename="", method="linear", insitu=False, all=True):
     144        _convert(scan, area, eta, allaxes)
     145        return
     146
     147def gain_el(scan, poly=None, filename="", method="linear", insitu=None, allaxes=None):
    132148    """
    133149    Return a scan after applying a gain-elevation correction. The correction
     
    140156    Parameters:
    141157        scan:        a scantable
    142         poly:        Polynomial coefficients (default None) to compute a gain-elevation
    143                      correction as a function of elevation (in degrees).
     158        poly:        Polynomial coefficients (default None) to compute a
     159                     gain-elevation correction as a function of
     160                     elevation (in degrees).
    144161        filename:    The name of an ascii file holding correction factors.
    145162                     The first row of the ascii file must give the column
    146163                     names and these MUST include columns
    147                      "ELEVATION" (degrees) and "FACTOR" (multiply data by this) somewhere.
    148                      The second row must give the data type of the column. Use 'R' for
    149                      Real and 'I' for Integer.  An example file would be:
     164                     "ELEVATION" (degrees) and "FACTOR" (multiply data by this)
     165                     somewhere.
     166                     The second row must give the data type of the column. Use
     167                     'R' for Real and 'I' for Integer.  An example file
     168                     would be:
    150169
    151170                     TIME ELEVATION FACTOR
     
    159178        method:      Interpolation method when correcting from a table. Values
    160179                     are  "nearest", "linear" (default), "cubic" and "spline"
    161         insitu:      if False (default) a new scantable is returned.
    162                      Otherwise, the conversion is done in-situ
    163         all:         if True (default) apply to all spectra. Otherwise
    164                      apply only to the selected (beam/pol/if)spectra only
    165     """
     180        insitu:      if False a new scantable is returned.
     181                     Otherwise, the scaling is done in-situ
     182                     The default is taken from .asaprc (False)
     183        allaxes:         if True apply to all spectra. Otherwise
     184                     apply only to the selected (beam/pol/if) spectra only
     185                     The default is taken from .asaprc (True)
     186    """
     187    if allaxes is None: allaxes = rcParams['scantable.allaxes']
    166188    if poly is None:
    167189       poly = ()
     190    if insitu is None: insitu = rcParams['insitu']
    168191    if not insitu:
    169192        from asap._asap import gainel as _gainEl
    170         return scantable(_gainEl(scan, poly, filename, method, all))
     193        return scantable(_gainEl(scan, poly, filename, method, allaxes))
    171194    else:
    172195        from asap._asap import gainel_insitu as _gainEl
    173         _gainEl(scan, poly, filename, method, all)
     196        _gainEl(scan, poly, filename, method, allaxes)
    174197        return
    175198       
    176 def opacity(scan, tau, insitu=False, all=True):
     199def opacity(scan, tau, insitu=None, allaxes=None):
    177200    """
    178201    Return a scan after applying an opacity correction.
     
    181204        tau:         Opacity from which the correction factor is exp(tau*ZD)
    182205                     where ZD is the zenith-distance
    183         insitu:      if False (default) a new scantable is returned.
    184                      Otherwise, the conversion is done in-situ
    185         all:         if True (default) apply to all spectra. Otherwise
     206        insitu:      if False a new scantable is returned.
     207                     Otherwise, the scaling is done in-situ
     208                     The default is taken from .asaprc (False)
     209        allaxes:     if True apply to all spectra. Otherwise
    186210                     apply only to the selected (beam/pol/if)spectra only
    187     """
     211                     The default is taken from .asaprc (True)
     212    """
     213    if allaxes is None: allaxes = rcParams['scantable.allaxes']
     214    if insitu is None: insitu = rcParams['insitu']
    188215    if not insitu:
    189216        from asap._asap import opacity as _opacity
    190         return scantable(_opacity(scan, tau, all))
     217        return scantable(_opacity(scan, tau, allaxes))
    191218    else:
    192219        from asap._asap import opacity_insitu as _opacity
    193         _opacity(scan, tau, all)
     220        _opacity(scan, tau, allaxes)
    194221        return
    195222       
    196 def bin(scan, width=5, insitu=False):
     223def bin(scan, width=5, insitu=None):
    197224    """
    198225    Return a scan where all spectra have been binned up
    199226        width:       The bin width (default=5) in pixels
    200         insitu:      if False (default) a new scantable is returned.
    201                      Otherwise, the addition is done in-situ
    202     """
     227        insitu:      if False a new scantable is returned.
     228                     Otherwise, the scaling is done in-situ
     229                     The default is taken from .asaprc (False)
     230    """
     231    if insitu is None: insitu = rcParams['insitu']
    203232    if not insitu:
    204233        from asap._asap import bin as _bin
     
    209238        return
    210239
    211 def average_pol(scan, mask=None, insitu=False):
     240def average_pol(scan, mask=None, insitu=None):
    212241    """
    213242    Average the Polarisations together.
     
    217246                     averaging will be applied. The output will have all
    218247                     specified points masked.
    219         insitu:      If False (default) a new scantable is returned.
    220                      Otherwise, the averaging is done in-situ
     248        insitu:      if False a new scantable is returned.
     249                     Otherwise, the scaling is done in-situ
     250                     The default is taken from .asaprc (False)
    221251    Example:
    222252        polav = average_pols(myscan)
     
    224254    if mask is None:
    225255        mask = ()
     256    if insitu is None: insitu = rcParams['insitu']
    226257    if not insitu:
    227258        from asap._asap import averagepol as _avpol
     
    232263        return
    233264   
    234 def smooth(scan, kernel="hanning", width=5.0, insitu=False, all=True):
     265def smooth(scan, kernel="hanning", width=5.0, insitu=None, allaxes=None):
    235266    """
    236267    Smooth the spectrum by the specified kernel (conserving flux).
     
    244275                    For 'gaussian' it is the Full Width Half
    245276                    Maximum. For 'boxcar' it is the full width.
    246         insitu:     If False (default) a new scantable is returned.
     277        insitu:     if False a new scantable is returned.
    247278                    Otherwise, the scaling is done in-situ
    248         all:        If True (default) apply to all spectra. Otherwise
     279                    The default is taken from .asaprc (False)
     280        allaxes:    If True (default) apply to all spectra. Otherwise
    249281                    apply only to the selected (beam/pol/if)spectra only
     282                    The default is taken from .asaprc (True)
    250283    Example:
    251284         none
    252285    """
     286    if allaxes is None: allaxes = rcParams['scantable.allaxes']
     287    if insitu is None: insitu = rcParams['insitu']
    253288    if not insitu:
    254289        from asap._asap import smooth as _smooth
    255         return scantable(_smooth(scan,kernel,width,all))
     290        return scantable(_smooth(scan,kernel,width,allaxes))
    256291    else:
    257292        from asap._asap import smooth_insitu as _smooth
    258         _smooth(scan,kernel,width,all)
     293        _smooth(scan,kernel,width,allaxes)
    259294        return
    260295   
    261 def poly_baseline(scan, mask=None, order=0):
     296def poly_baseline(scan, mask=None, order=0, insitu=None):
    262297    """
    263298    Return a scan which has been baselined (all rows) by a polynomial.
     
    266301        mask:    an optional mask
    267302        order:   the order of the polynomial (default is 0)
     303        insitu:      if False a new scantable is returned.
     304                     Otherwise, the scaling is done in-situ
     305                     The default is taken from .asaprc (False)
    268306    Example:
    269307        # return a scan baselined by a third order polynomial,
     
    279317    f.set_scan(scan, mask)
    280318    f.set_function(poly=order)   
    281     sf = f.auto_fit()
     319    sf = f.auto_fit(insitu)
    282320    return sf
Note: See TracChangeset for help on using the changeset viewer.