Example #1
0
def test_legacy_code():

    "Test of legacy functions"
    
    arr_def = ([1, 2], [0.1, 0.01])

    # uarray, nominal_values, std_devs from the uncertainties module
    # (not the uncertainties.unumpy module):
    arr = uncertainties.array_u(arr_def)  # Warning is normal
    assert numpy.all(uncertainties.nominal_values(arr) == arr_def[0])  # Warning is normal
    assert numpy.all(uncertainties.std_devs(arr) == arr_def[1])  # Warning is normal
Example #2
0
def ratio13 ( mx, mxErr, lag=0, dnu_mean=0):
	""" 
	Given a frequency matrix and errors calculates the ratio r13
	and propagates errors.
    """

	(Nn, Nl) = np.shape(mx)
	r13    = np.zeros((1,Nn-1))
	r13Err = np.zeros((1,Nn-1))
	r13.fill(None)      # values that can't be calculated are NaN

	for n in range(0,Nn-1):
		if (mx[n,1] and mx[n-1+lag,3] and mx[n+1,0] and mx[n,0]
		    and (mx[n+1,0]-mx[n,0] < 1.5*dnu_mean) ):     
        		a = un.ufloat( (mx[n,1], mxErr[n,1]) )
        		b = un.ufloat( (mx[n-1+lag,3], mxErr[n-1+lag,3]) )
        		c = un.ufloat( (mx[n+1,0], mxErr[n+1,0]) )
        		d = un.ufloat( (mx[n,0], mxErr[n,0]) )
        
        		result = (a-b) / (10.*(c-d))
        		r13[0,n]    = un.nominal_values(result)
        		r13Err[0,n] = un.std_dev(result)

	return r13, r13Err
Example #3
0
def ratio02 ( mx , mxErr, lag02=0, lag01=0, dnu_mean=0):
	""" 
	Given a frequency matrix and errors calculates the ratio r02
	and propagates errors.
    """

	(Nn, Nl) = np.shape(mx)
	r02    = np.zeros((1,Nn-1))
	r02Err = np.zeros((1,Nn-1))
	r02.fill(None)      # values that can't be calculated are NaN

	for n in range(0,Nn-1):
		if (mx[n,0] != 0. and mx[n-1+lag02,2] != 0. and mx[n,1] != 0. and mx[n-1,1] != 0.
	        and n-1 >= 0 and n-1+lag02 >= 0
	        and (mx[n,1]-mx[n-1,1] < 1.5*dnu_mean)):
        		a = un.ufloat( (mx[n,0], mxErr[n,0]) )
        		b = un.ufloat( (mx[n-1+lag02,2], mxErr[n-1+lag02,2]) )
        		c = un.ufloat( (mx[n,1], mxErr[n,1]) )
        		d = un.ufloat( (mx[n-1,1], mxErr[n-1,1]) )
        		result = (a-b) / (6.*(c-d))
        		r02[0,n]    = un.nominal_values(result)
        		r02Err[0,n] = un.std_dev(result)

	return r02, r02Err