Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
y_new_ref[3] = y_old[0] * area_subbins[4] / area_old[0]
y_new_ref[4] = y_old[1] * area_subbins[5] / area_old[1]
y_new_ref[5] = y_old[1] * area_subbins[6] / area_old[1]
y_new_ref[5] += y_old[2] * area_subbins[7] / area_old[2]
y_new_ref[5] += y_old[3] * area_subbins[8] / area_old[3]
# call rebin function
y_new = rebin.rebin(x_old, y_old, x_new, interp_kind=3)
# mean or nominal value comparison
assert_allclose(unp.nominal_values(y_new),
unp.nominal_values(y_new_ref))
# mean or nominal value comparison
assert_allclose(unp.std_devs(y_new),
unp.std_devs(y_new_ref))
y_old_ave[1] * (x_new[3] - x_new[2]),
y_old_ave[1] * (x_old[2] - x_new[3]) +
y_old_ave[2] * (x_new[4] - x_old[2]),
y_old_ave[3] * (x_new[5] - x_old[3]) +
y_old_ave[2] * (x_old[3] - x_new[4])])
# mean or nominal value comparison
# assert_allclose(unp.nominal_values(y_new),
# unp.nominal_values(y_new_here))
# mean or nominal value comparison
assert_allclose(unp.std_devs(y_new),
unp.std_devs(y_new_here))
def test_component_extraction():
"Extracting the nominal values and standard deviations from an array"
arr = unumpy.uarray(([1, 2], [0.1, 0.2]))
assert numpy.all(unumpy.nominal_values(arr) == [1, 2])
assert numpy.all(unumpy.std_devs(arr) == [0.1, 0.2])
# unumpy matrices, in addition, should have nominal_values that
# are simply numpy matrices (not unumpy ones, because they have no
# uncertainties):
mat = unumpy.matrix(arr)
assert numpy.all(unumpy.nominal_values(mat) == [1, 2])
assert numpy.all(unumpy.std_devs(mat) == [0.1, 0.2])
assert type(unumpy.nominal_values(mat)) == numpy.matrix
def std_devs(*args):
"""
Wrapper for legacy code. Obsolete: do not use. Use ufloat
instead.
"""
import warnings
warnings.warn("uncertainties.std_devs is obsolete."
" Use uncertainties.unumpy.std_devs instead.",
DeprecationWarning,
stacklevel=2)
import uncertainties.unumpy
return uncertainties.unumpy.std_devs(*args)
def power_law_I_with_err(
f_val=1, f_err=0, g_val=g_DEFAULT, g_err=0, e=1, e1=1, e2=E_INF
):
"""Evaluate power-law flux and propagate errors."""
from uncertainties import unumpy
f = unumpy.uarray(f_val, f_err)
g = unumpy.uarray(g_val, g_err)
_I = power_law_integral_flux(f, g, e, e1, e2)
I_val = unumpy.nominal_values(_I)
I_err = unumpy.std_devs(_I)
return I_val, I_err
import uncertainties.unumpy as unumpy
c=29979245800. # speed of light in CGS
dist=dist*3.085677581e24 # Mpc -> cm
nu=10**lognu
lamb=c/nu*1e4 # cm -> micron
if llerr!=None:
lllerr=unumpy.uarray(ll,llerr)
else:
lllerr=ll
lnuerr=10**lllerr/nu
fluxerr=lnuerr/(1e-26*4.*numpy.pi*dist**2) # Lnu (erg/s/Hz) -> Fnu (mJy)
if llerr!=None:
fluxerr=unumpy.log10(fluxerr)
return numpy.log10(lamb),unumpy.nominal_values(fluxerr),unumpy.std_devs(fluxerr)
else:
return numpy.log10(lamb),numpy.log10(fluxerr)
def power_law_f_with_err(
I_val=1, I_err=0, g_val=g_DEFAULT, g_err=0, e=1, e1=1, e2=E_INF
):
"""Evaluate power-law ``dnde`` and propagate errors."""
from uncertainties import unumpy
I = unumpy.uarray(I_val, I_err)
g = unumpy.uarray(g_val, g_err)
_f = power_law_flux(I, g, e, e1, e2)
f_val = unumpy.nominal_values(_f)
f_err = unumpy.std_devs(_f)
return f_val, f_err