Skip to content

Commit

Permalink
improve pretty print
Browse files Browse the repository at this point in the history
  • Loading branch information
bobmyhill committed Nov 12, 2024
1 parent 5ec72a4 commit 85e3cba
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions burnman/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,26 @@ def flatten(arr):
)


def pretty_print_values(popt, pcov, params):
def pretty_print_values(popt, pcov, params, extra_decimal_places=0):
"""
Takes a numpy array of parameters, the corresponding covariance matrix
and a set of parameter names and prints the parameters and
principal 1-s.d.uncertainties (np.sqrt(pcov[i][i]))
in a nice text based format.
"""
for i, p in enumerate(params):
p_rnd = round_to_n(popt[i], np.sqrt(pcov[i][i]), 1)
c_rnd = round_to_n(np.sqrt(pcov[i][i]), np.sqrt(pcov[i][i]), 1)
p_rnd = round_to_n(popt[i], np.sqrt(pcov[i][i]), 1 + extra_decimal_places)
c_rnd = round_to_n(
np.sqrt(pcov[i][i]), np.sqrt(pcov[i][i]), 1 + extra_decimal_places
)

if p_rnd != 0.0:
p_expnt = np.floor(np.log10(np.abs(p_rnd)))
else:
p_expnt = 0.0

scale = np.power(10.0, p_expnt)
nd = p_expnt - np.floor(np.log10(np.abs(c_rnd)))
nd = p_expnt - np.floor(np.log10(np.abs(c_rnd))) + extra_decimal_places
print(
"{0:s}: ({1:{4}{5}f} +/- {2:{4}{5}f}) x {3:.0e}".format(
p, p_rnd / scale, c_rnd / scale, scale, 0, (nd) / 10.0
Expand Down

0 comments on commit 85e3cba

Please sign in to comment.