Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Result table tabulate #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Result table tabulate #1

wants to merge 3 commits into from

Conversation

jagerber48
Copy link
Owner

@jagerber48 jagerber48 commented Jan 31, 2024

Description

In this PR I demonstrate how the report table code can be updated using tabulate. The major advantage of tabulate is that the person writing the code to present the table doesn't need to think about whitespace at all*. They simply make a data array acceptable to tabulate (e.g list of lists or list of dicts) and pass it into the tabulate function with nice user options available.

For demonstration purposes I drop usage of gformat to show how the table would look without strict lining up of the left- and right-most decimal places across rows. I also use uncertainties ufloat to format the value/uncertainty pairs describing the variable values.

printfuncs.py was not totally reworked. Only enough code was reworked to affect the example_fit_with_bounds.py example script.

*Strictly speaking I did need to include an indent_string_block function to allow me to have the tables be "nested" under their respective heading. It would be nice if tabulate had a "left pad" feature that did this internally.

Type of Changes
  • Bug fix
  • New feature
  • Refactoring / maintenance
  • Documentation / examples
Tested on
Verification

Have you

  • included docstrings that follow PEP 257?
  • referenced existing Issue and/or provided relevant link to mailing list?
  • verified that existing tests pass locally?
  • verified that the documentation builds locally?
  • squashed/minimized your commits and written descriptive commit messages?
  • added or updated existing tests to cover the changes?
  • updated the documentation and/or added an entry to the release notes (doc/whatsnew.rst)?
  • added an example?

@jagerber48
Copy link
Owner Author

Old fit results:

[[Fit Statistics]]
    # fitting method   = leastsq
    # function evals   = 79
    # data points      = 1500
    # variables        = 4
    chi-square         = 11301.3646
    reduced chi-square = 7.55438813
    Akaike info crit   = 3037.18756
    Bayesian info crit = 3058.44044
[[Variables]]
    amp:     13.8904759 +/- 0.24410753 (1.76%) (init = 13), model_value = 14
    period:  5.44026387 +/- 0.01416106 (0.26%) (init = 2), model_value = 5.4321
    shift:   0.12464389 +/- 0.02414210 (19.37%) (init = 0), model_value = 0.12345
    decay:   0.00996363 +/- 2.0275e-04 (2.03%) (init = 0.02), model_value = 0.01
[[Correlations]] 
  +----------+----------+----------+----------+----------+
  | Variable | amp      | period   | shift    | decay    |
  +----------+----------+----------+----------+----------+
  | amp      | +1.0000  | -0.0700  | -0.0870  | +0.5757  |
  | period   | -0.0700  | +1.0000  | +0.7999  | -0.0404  |
  | shift    | -0.0870  | +0.7999  | +1.0000  | -0.0502  |
  | decay    | +0.5757  | -0.0404  | -0.0502  | +1.0000  |
  +----------+----------+----------+----------+----------+

New fit results:

[[Fit Statistics]]
    ------------------  ----------
    # fitting method    leastsq
    # function evals    79
    # data points       1500
    # variables         4
    chi-square          11301.3646
    reduced chi-square  7.5544
    Akaike info crit    3037.1876
    Bayesian info crit  3058.4404
    ------------------  ----------
[[Variables]]
     Name          Value          Percent Uncertainty    Constraint    Init Val    Model Val
    ------  -------------------  ---------------------  ------------  ----------  -----------
     amp    (1.389+/-0.024)e+01          1.76%              Vary          13          14
    period  (5.440+/-0.014)e+00          0.26%              Vary          2         5.4321
    shift    (1.25+/-0.24)e-01          19.37%              Vary          0         0.12345
    decay    (9.96+/-0.20)e-03           2.03%              Vary         0.02        0.01
[[Correlations]] 
    ┌────────┬─────────┬──────────┬─────────┬─────────┐
    │        │ amp     │ period   │ shift   │ decay   │
    ├────────┼─────────┼──────────┼─────────┼─────────┤
    │ amp    │ +1.0000 │ -0.0700  │ -0.0870 │ +0.5757 │
    ├────────┼─────────┼──────────┼─────────┼─────────┤
    │ period │ -0.0700 │ +1.0000  │ +0.7999 │ -0.0404 │
    ├────────┼─────────┼──────────┼─────────┼─────────┤
    │ shift  │ -0.0870 │ +0.7999  │ +1.0000 │ -0.0502 │
    ├────────┼─────────┼──────────┼─────────┼─────────┤
    │ decay  │ +0.5757 │ -0.0404  │ -0.0502 │ +1.0000 │
    └────────┴─────────┴──────────┴─────────┴─────────┘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant