Changeset 4a96b8b in sasview for sansutil/err1d.py


Ignore:
Timestamp:
Apr 27, 2012 9:37:14 AM (13 years ago)
Author:
Mathieu Doucet <doucetm@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
507c68f
Parents:
7d6351e
Message:

Pep-8-ification

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sansutil/err1d.py

    r4025019 r4a96b8b  
    11# This program is public domain 
    2  
    32""" 
    43Error propogation algorithms for simple arithmetic 
     
    87integers, so be sure to create them with floating point inputs. 
    98""" 
    10  
    11  
    129from __future__ import division  # Get true division 
    1310import numpy 
    1411 
    15 def div(X,varX, Y,varY): 
     12 
     13def div(X, varX, Y, varY): 
    1614    """Division with error propagation""" 
    1715    # Direct algorithm: 
     
    2826    return Z, varZ 
    2927 
    30 def mul(X,varX, Y,varY): 
     28 
     29def mul(X, varX, Y, varY): 
    3130    """Multiplication with error propagation""" 
    3231    # Direct algorithm: 
     
    4342    return Z, varZ 
    4443 
    45 def sub(X,varX, Y, varY): 
     44 
     45def sub(X, varX, Y, varY): 
    4646    """Subtraction with error propagation""" 
    4747    Z = X - Y 
     
    4949    return Z, varZ 
    5050 
    51 def add(X,varX, Y,varY): 
     51 
     52def add(X, varX, Y, varY): 
    5253    """Addition with error propagation""" 
    5354    Z = X + Y 
     
    5556    return Z, varZ 
    5657 
    57 def exp(X,varX): 
     58 
     59def exp(X, varX): 
    5860    """Exponentiation with error propagation""" 
    5961    Z = numpy.exp(X) 
    6062    varZ = varX * Z**2 
    61     return Z,varZ 
     63    return Z, varZ 
    6264 
    63 def log(X,varX): 
     65 
     66def log(X, varX): 
    6467    """Logarithm with error propagation""" 
    6568    Z = numpy.log(X) 
    6669    varZ = varX / X**2 
    67     return Z,varZ 
     70    return Z, varZ 
    6871 
    6972# Confirm this formula before using it 
     
    7477# 
    7578 
    76 def pow(X,varX,n): 
     79 
     80def pow(X, varX, n): 
    7781    """X**n with error propagation""" 
    7882    # Direct algorithm 
     
    8185    # Indirect algorithm to minimize intermediates 
    8286    Z = X**n 
    83     varZ = varX/X 
     87    varZ = varX / X 
    8488    varZ /= X 
    8589    varZ *= Z 
     
    8892    return Z, varZ 
    8993 
    90 def div_inplace(X,varX, Y,varY): 
     94 
     95def div_inplace(X, varX, Y, varY): 
    9196    """In-place division with error propagation""" 
    9297    # Z = X/Y 
     
    98103    del T   # may want to use T[:] = Y for vectors 
    99104    T = Y   # reuse T for Y 
    100     T **=2     # T now has Y**2 
     105    T ** = 2     # T now has Y**2 
    101106    varX /= T  # varX now has varZ 
    102     return X,varX 
     107    return X, varX 
    103108 
    104 def mul_inplace(X,varX, Y,varY): 
     109 
     110def mul_inplace(X, varX, Y, varY): 
    105111    """In-place multiplication with error propagation""" 
    106112    # Z = X * Y 
     
    114120    varX += T  # varX now has varZ 
    115121    X *= Y     # X now has Z 
    116     return X,varX 
     122    return X, varX 
    117123 
    118 def sub_inplace(X,varX, Y, varY): 
     124 
     125def sub_inplace(X, varX, Y, varY): 
    119126    """In-place subtraction with error propagation""" 
    120127    # Z = X - Y 
     
    122129    X -= Y 
    123130    varX += varY 
    124     return X,varX 
     131    return X, varX 
    125132 
    126 def add_inplace(X,varX, Y,varY): 
     133 
     134def add_inplace(X, varX, Y, varY): 
    127135    """In-place addition with error propagation""" 
    128136    # Z = X + Y 
     
    130138    X += Y 
    131139    varX += varY 
    132     return X,varX 
     140    return X, varX 
    133141 
    134 def pow_inplace(X,varX,n): 
     142 
     143def pow_inplace(X, varX, n): 
    135144    """In-place X**n with error propagation""" 
    136145    # Direct algorithm 
     
    141150    varX /= X     # varX now has varX/X**2 
    142151    X **= n       # X now has Z = X**n 
    143     varX *= X      
     152    varX *= X 
    144153    varX *= X     # varX now has varX/X**2 * Z**2 
    145154    varX *= n**2  # varX now has varZ 
    146     return X,varX 
     155    return X, varX 
Note: See TracChangeset for help on using the changeset viewer.