Esempio n. 1
0
def params(mps):
    s = Html()
    with table(s):
        # header
        with tr(s, style=backgrounds[0]):
            s += "<td/>"
            with th(s, title="Variable name"):
                s += "Name"
            with th(s, title="Value of parameter"):
                s += "Value"
            with th(s, title="Hesse error"):
                s += "Hesse Error"
            with th(s, title="Minos lower error"):
                s += "Minos Error-"
            with th(s, title="Minos upper error"):
                s += "Minos Error+"
            with th(s, title="Lower limit of the parameter"):
                s += "Limit-"
            with th(s, title="Upper limit of the parameter"):
                s += "Limit+"
            with th(s, title="Is the parameter fixed in the fit"):
                s += "Fixed"

        mes = mps.merrors

        # body
        for i, mp in enumerate(mps):
            if mes and mp.name in mes:
                me = mes[mp.name]
                v, e, mem, mep = format_numbers(mp.value, mp.error, me.lower,
                                                me.upper)
            else:
                e, v = format_numbers(mp.error, mp.value)
                mem = ''
                mep = ''
            with tr(s, style=backgrounds[(i + 1) % 2]):
                with td(s):
                    s += str(i)
                with td(s):
                    s += mp.name
                with td(s):
                    s += v
                with td(s):
                    s += e
                with td(s):
                    s += mem
                with td(s):
                    s += mep
                with td(s):
                    s += '%.3G' % mp.lower_limit if mp.lower_limit is not None else ''
                with td(s):
                    s += '%.3G' % mp.upper_limit if mp.upper_limit is not None else ''
                with td(s):
                    s += 'yes' if mp.is_fixed else (
                        'CONST' if mp.is_const else '')
    return str(s)
Esempio n. 2
0
def params(mps):    
    s = Html()
    with table(s):
        # header
        with tr(s, style=backgrounds[0]):
            s += "<td/>"
            with th(s, title="Variable name"):
                s += "Name"
            with th(s, title="Value of parameter"):
                s += "Value"
            with th(s, title="Hesse error"):
                s += "Hesse Error"
            with th(s, title="Minos lower error"):
                s += "Minos Error-"
            with th(s, title="Minos upper error"):
                s += "Minos Error+"
            with th(s, title="Lower limit of the parameter"):
                s += "Limit-"
            with th(s, title="Upper limit of the parameter"):
                s += "Limit+"
            with th(s, title="Is the parameter fixed in the fit"):
                s += "Fixed"

        mes = mps.merrors

        # body
        for i, mp in enumerate(mps):
            if mes and mp.name in mes:
                me = mes[mp.name]
                v, e, mem, mep = format_numbers(mp.value, mp.error, me.lower, me.upper)
            else:
                e, v = format_numbers(mp.error, mp.value)
                mem = ''
                mep = ''
            with tr(s, style=backgrounds[(i + 1) % 2]):
                with td(s):
                    s += str(i)
                with td(s):
                    s += mp.name
                with td(s):
                    s += v
                with td(s):
                    s += e
                with td(s):
                    s += mem
                with td(s):
                    s += mep
                with td(s):
                    s += '%.3G' % mp.lower_limit if mp.lower_limit is not None else ''
                with td(s):
                    s += '%.3G' % mp.upper_limit if mp.upper_limit is not None else '' 
                with td(s):
                    s += 'yes' if mp.is_fixed else ('CONST' if mp.is_const else '')
    return str(s)
Esempio n. 3
0
def matrix(m):
    is_correlation = True
    for i in range(len(m)):
        if m[i][i] != 1.0:
            is_correlation = False
            break

    if not is_correlation:
        n = len(m)
        args = []
        for mi in m:
            for mj in mi:
                args.append(mj)
        nums = format_numbers(*args)

    grad = Gradient(
        (-1.0, 120.0, 120.0, 250.0),
        (0.0, 250.0, 250.0, 250.0),
        (1.0, 250.0, 100.0, 100.0),
    )

    s = Html()
    with table(s):
        with tr(s):
            s += "<td/>\n"
            for v in m.names:
                with th(s):
                    s += v
        for i, v in enumerate(m.names):
            with tr(s):
                with th(s):
                    s += v
                for j in range(len(m.names)):
                    val = m[i][j]
                    if is_correlation:
                        if i == j:
                            with td(s):
                                s += " 1.00"
                        else:
                            color = grad.rgb(val)
                            with td(s, style="background-color:" + color):
                                s += "%5.2f" % val
                    else:
                        if i == j:
                            with td(s):
                                s += nums[n * i + j]
                        else:
                            color = grad.rgb(val / (m[i][i] * m[j][j])**0.5)
                            with td(s, style="background-color:" + color):
                                s += nums[n * i + j]

    return str(s)
Esempio n. 4
0
def merror(me):
    mel, meu = format_numbers(me.lower, me.upper)
    s = Html()
    with table(s):
        with tr(s):
            with th(s, title="Parameter name"):
                s += me.name
            with td(s,
                    colspan="2",
                    style=good(me.is_valid, True),
                    align="center"):
                s += 'Valid' if me.is_valid else 'Invalid'
        with tr(s):
            with td(s, title="Lower and upper minos error of the parameter"):
                s += "Error"
            with td(s):
                s += mel
            with td(s):
                s += meu
        with tr(s):
            with td(s, title="Validity of lower/upper minos error"):
                s += "Valid"
            with td(s, style=good(me.lower_valid, True)):
                s += "%s" % me.lower_valid
            with td(s, style=good(me.upper_valid, True)):
                s += "%s" % me.upper_valid
        with tr(s):
            with td(s, title="Did scan hit limit of any parameter?"):
                s += "At Limit"
            with td(s, style=good(me.at_lower_limit, False)):
                s += "%s" % me.at_lower_limit
            with td(s, style=good(me.at_upper_limit, False)):
                s += "%s" % me.at_upper_limit
        with tr(s):
            with td(s, title="Did scan hit function call limit?"):
                s += "Max FCN"
            with td(s, style=good(me.at_lower_max_fcn, False)):
                s += "%s" % me.at_lower_max_fcn
            with td(s, style=good(me.at_upper_max_fcn, False)):
                s += "%s" % me.at_upper_max_fcn
        with tr(s):
            with td(s, title="New minimum found when doing scan?"):
                s += "New Min"
            with td(s, style=good(me.lower_new_min, False)):
                s += "%s" % me.lower_new_min
            with td(s, style=good(me.upper_new_min, False)):
                s += "%s" % me.upper_new_min
    return str(s)
Esempio n. 5
0
def matrix(m):
    is_correlation = True
    for i in range(len(m)):
        if m[i][i] != 1.0:
            is_correlation = False
            break

    if not is_correlation:
        n = len(m)
        args = []
        for mi in m:
            for mj in mi:
                args.append(mj)
        nums = format_numbers(*args)

    s = Html()
    with table(s):
        with tr(s):
            s += "<td/>\n"
            for v in m.names:
                with th(s):
                    s += v
        for i, v in enumerate(m.names):
            with tr(s):
                with th(s):
                    s += v
                for j in range(len(m.names)):
                    val = m[i][j]
                    if is_correlation:
                        if i == j:
                            with td(s):
                                s += "1.00"                        
                        else:
                            color = Gradient.rgb_color_for(val)
                            with td(s, style="background-color:"+color):
                                s += "%.2f" % val
                    else:
                        if i == j:
                            with td(s):
                                s += nums[n*i + j]
                        else:
                            color = Gradient.rgb_color_for(val / (m[i][i] * m[j][j]) ** 0.5)
                            with td(s, style="background-color:"+color):
                                s += nums[n*i + j]

    return str(s)
Esempio n. 6
0
def merror(me):
    mel, meu = format_numbers(me.lower, me.upper)
    s = Html()
    with table(s):
        with tr(s):
            with th(s, title="Parameter name"):
                s += me.name
            with td(s, colspan="2", style=good(me.is_valid, True), align="center"):
                s += 'Valid' if me.is_valid else 'Invalid'
        with tr(s):
            with td(s, title="Lower and upper minos error of the parameter"):
                s += "Error"
            with td(s):
                s += mel
            with td(s):
                s += meu
        with tr(s):
            with td(s, title="Validity of lower/upper minos error"):
                s += "Valid"
            with td(s, style=good(me.lower_valid, True)):
                s += "%s" % me.lower_valid
            with td(s, style=good(me.upper_valid, True)):
                s += "%s" % me.upper_valid
        with tr(s):
            with td(s, title="Did scan hit limit of any parameter?"):
                s += "At Limit"
            with td(s, style=good(me.at_lower_limit, False)):
                s += "%s" % me.at_lower_limit
            with td(s, style=good(me.at_upper_limit, False)):
                s += "%s" % me.at_upper_limit
        with tr(s):
            with td(s, title="Did scan hit function call limit?"):
                s += "Max FCN"
            with td(s, style=good(me.at_lower_max_fcn, False)):
                s += "%s" % me.at_lower_max_fcn
            with td(s, style=good(me.at_upper_max_fcn, False)):
                s += "%s" % me.at_upper_max_fcn
        with tr(s):
            with td(s, title="New minimum found when doing scan?"):
                s += "New Min" 
            with td(s, style=good(me.lower_new_min, False)):
                s += "%s" % me.lower_new_min
            with td(s, style=good(me.upper_new_min, False)):
                s += "%s" % me.upper_new_min
    return str(s)
Esempio n. 7
0
def test_format_numbers():
    assert repr_text.format_numbers(1.2567, 0.1234) == ("1.26", "0.12")
    assert repr_text.format_numbers(1.2567e3, 0.1234e3) == ("1260", "120")
    assert repr_text.format_numbers(1.2567e4, 0.1234e4) == ("1.26E4", "0.12E4")
    assert repr_text.format_numbers(1.2567e-1, 0.1234e-1) == ("0.126", "0.012")
    assert repr_text.format_numbers(1.2567e-2, 0.1234e-2) == ("1.26E-2", "0.12E-2")
    assert repr_text.format_numbers(0, 1, -1) == ("0.0", "1.0", "-1.0")
    assert repr_text.format_numbers(2, -1, 1) == ("2.0", "-1.0", "1.0")
    assert repr_text.format_numbers(2.01, -1.01, 1.01) == ("2.0", "-1.0", "1.0")
    assert repr_text.format_numbers(1.999, -0.999, 0.999) == ("2.0", "-1.0", "1.0")
    assert repr_text.format_numbers(1, 0.5, -0.5) == ("1.0", "0.5", "-0.5")
    assert repr_text.format_numbers(1.0, 1e-10) == ("1.000", "0.000")
    assert repr_text.format_numbers(1.234567e11, -1.234567e-11) == ("1.235E11", "-0.000E11")
Esempio n. 8
0
def test_format_numbers():
    assert repr_text.format_numbers(1.2567, 0.1234) == ("1.26", "0.12")
    assert repr_text.format_numbers(1.2567e3, 0.1234e3) == ("1260", "120")
    assert repr_text.format_numbers(1.2567e4, 0.1234e4) == ("1.26E4", "0.12E4")
    assert repr_text.format_numbers(1.2567e-1, 0.1234e-1) == ("0.126", "0.012")
    assert repr_text.format_numbers(1.2567e-2,
                                    0.1234e-2) == ("1.26E-2", "0.12E-2")
    assert repr_text.format_numbers(1.0, 0.0, 0.25) == ("1.00", "0.00", "0.25")
    assert repr_text.format_numbers(0, 1, -1) == (" 0.0", " 1.0", "-1.0")
    assert repr_text.format_numbers(2, -1, 1) == (" 2.0", "-1.0", " 1.0")
    assert repr_text.format_numbers(2.01, -1.01,
                                    1.01) == (" 2.0", "-1.0", " 1.0")
    assert repr_text.format_numbers(1.999, -0.999,
                                    0.999) == (" 2.0", "-1.0", " 1.0")
    assert repr_text.format_numbers(1, 0.5, -0.5) == (" 1.0", " 0.5", "-0.5")
    assert repr_text.format_numbers(1.0, 1e-10) == ("1.0", "0.0")
    assert repr_text.format_numbers(1.234567e11,
                                    -1.234567e-11) == (" 1.2E11", "-0.0E11")