Skip to content
Snippets Groups Projects

Smart rounding based on uncertainties

Merged Charlie Hoy requested to merge rounding into master

The purpose of this MR is to add a smart rounding method which rounds based on the uncertainties.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • 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.
  • Author Maintainer

    @jonah-kanner, thanks so much for the comments. I did not know that np.round accepts negative numbers! That is very useful.

  • Charlie Hoy added 2 commits

    added 2 commits

    • 9bc1a370 - correcting Jonah's comments
    • 210012e8 - Merge branch 'rounding' of git.ligo.org:lscsoft/pesummary into rounding

    Compare with previous version

  • Author Maintainer

    @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.

  • Charlie Hoy added 1 commit

    added 1 commit

    Compare with previous version

  • Charlie Hoy added 59 commits

    added 59 commits

    Compare with previous version

  • @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

  • Author Maintainer

    This is ready to merge (subject to passing CI).

  • Charlie Hoy approved this merge request

    approved this merge request

  • merged

  • Charlie Hoy mentioned in commit 58cd22cf

    mentioned in commit 58cd22cf

Please register or sign in to reply
Loading