Smart rounding based on uncertainties
The purpose of this MR is to add a smart rounding method which rounds based on the uncertainties.
Merge request reports
Activity
Some suggestions:
- I notice there’s an absolute value for the percision value: rounding = int(np.abs(np.floor(np.log10(lowest_uncertainty))))
I think that’s a mistake, as the numpy round function handles well both negative and positive values for this number. That is, have you considered what happens when the uncertainty is more than 1? E.g. 791 Mpc should round to 790 Mpc. I think you can fix this by replacing the “abs” with a minus sign.
- I suggest some formatting so that the latex values print to the precision where they are rounded, rather than the precision that first happens to have a zero. That is, in the example, I think 6.1 should print as 6.10 in the latex output.
@jonah-kanner, thanks so much for the comments. I did not know that
np.round
accepts negative numbers! That is very useful.@jonah-kanner, I have changed the code and added some more examples to show how it now works. These are copied below:
Examples -------- >>> data = [1.234, 0.2, 0.1] >>> smart_round(data) [ 1.2 0.2 0.1] >>> data = [ ... [6.093, 0.059, 0.055], ... [6.104, 0.057, 0.052], ... [6.08, 0.056, 0.052] ... ] >>> smart_round(data) [[ 6.09 0.06 0.06] [ 6.1 0.06 0.05] [ 6.08 0.06 0.05]] >>> smart_round(data, return_latex=True) 6.09^{+0.06}_{-0.06} 6.10^{+0.06}_{-0.05} 6.08^{+0.06}_{-0.05} >>> data = [ ... [743.25, 43.6, 53.2], ... [8712.5, 21.5, 35.2], ... [196.46, 65.2, 12.5] ... ] >>> smart_round(data, return_latex_row=True) 740^{+40}_{-50} & 8710^{+20}_{-40} & 200^{+70}_{-10} >>> data = [ ... [743.25, 43.6, 53.2], ... [8712.5, 21.5, 35.2], ... [196.46, 65.2, 8.2] ... ] >>> smart_round(data, return_latex_row=True) 743^{+44}_{-53} & 8712^{+22}_{-35} & 196^{+65}_{-8}
If you are happy with this, then I will merge once the CI passes.
added 59 commits
-
cf9fed1a...28e4beaa - 58 commits from branch
master
- e53563a4 - update to master
-
cf9fed1a...28e4beaa - 58 commits from branch
ping @jonah-kanner
@charlie.hoy Thank you for doing this so quickly! This all looks very, very good to me.
One detail: In the example above, I see 2 different results for the latex output of the luminosity distance numbers. I see 743 in one row, and 740 in another. Could be a cut and paste error in the documentation?
Best, jonah
mentioned in commit 58cd22cf