From 5a0f2aa99ebf7da2ca2e9f5ede18982b91276a09 Mon Sep 17 00:00:00 2001 From: "David W.H. Swenson" Date: Wed, 19 Nov 2025 13:23:37 -0600 Subject: [PATCH 1/4] Add docstring to explain the rounding in gather --- openfecli/commands/gather.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/openfecli/commands/gather.py b/openfecli/commands/gather.py index 65da35fe0..305a0e690 100644 --- a/openfecli/commands/gather.py +++ b/openfecli/commands/gather.py @@ -50,6 +50,34 @@ def format_estimate_uncertainty( ) -> tuple[str, str]: """Truncate raw estimate and uncertainty values to the appropriate uncertainty. + The premise here is that, if you're reporting your uncertain to a + certain number of significant figures, your estimate should be reported + to the same precision. + + As an example, assume your raw estimate is 12.34567 and your raw + uncertainty is 0.0123. Say you want to report your uncertainty to 2 + significant figures. So your rounded uncertainty is 0.012. You should + report your estimate to the same precision, so your rounded estimate + should be 12.346. On the other hand, if you wanted to report your + uncertain to the first significant figure (0.01), then you should report + your estimate as 12.35. + + You need to report these to the same precision (not the same number of + significant figures) because the two numbers need to be added together. + If you report both to 2 significant figures, you'd have 12.0 +/- 0.0012, + and your actual estimate falls way outside your error bars! It has to be + the uncertainty that determines the precision of the estimate, because + if you said you had 3 significant figures in the estimate and used that + to set the precision of the uncertainty, you'd have 12.3 +/- 0.0 -- no + error at all! + + We implement this by thinking of the decimal representation as "columns" + centered on the decimal point. We get the column index of the first + non-zero number in the decimal representation of the uncertainty, and + use the fact that ``np.round`` rounds to the number of decimal places + you give it to report the estimate. The uncertainty is presented to the + desired number of significant figures. + Parameters ---------- est : float From a9913d0b767a6805cb9c6d08e1dc834b642aa395 Mon Sep 17 00:00:00 2001 From: Alyssa Travitz <31974495+atravitz@users.noreply.github.com> Date: Wed, 19 Nov 2025 11:38:13 -0800 Subject: [PATCH 2/4] Update openfecli/commands/gather.py Co-authored-by: David W.H. Swenson --- openfecli/commands/gather.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openfecli/commands/gather.py b/openfecli/commands/gather.py index 305a0e690..317612226 100644 --- a/openfecli/commands/gather.py +++ b/openfecli/commands/gather.py @@ -50,7 +50,7 @@ def format_estimate_uncertainty( ) -> tuple[str, str]: """Truncate raw estimate and uncertainty values to the appropriate uncertainty. - The premise here is that, if you're reporting your uncertain to a + The premise here is that, if you're reporting your uncertainty to a certain number of significant figures, your estimate should be reported to the same precision. From 81c2b0f0223071cc27fd6d9995b753ffd14a7548 Mon Sep 17 00:00:00 2001 From: Alyssa Travitz Date: Wed, 19 Nov 2025 11:42:07 -0800 Subject: [PATCH 3/4] formatting: one sentence per line --- openfecli/commands/gather.py | 47 ++++++++++++++---------------------- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/openfecli/commands/gather.py b/openfecli/commands/gather.py index 317612226..330143f5b 100644 --- a/openfecli/commands/gather.py +++ b/openfecli/commands/gather.py @@ -48,35 +48,24 @@ def format_estimate_uncertainty( unc: float, unc_prec: int = 1, ) -> tuple[str, str]: - """Truncate raw estimate and uncertainty values to the appropriate uncertainty. - - The premise here is that, if you're reporting your uncertainty to a - certain number of significant figures, your estimate should be reported - to the same precision. - - As an example, assume your raw estimate is 12.34567 and your raw - uncertainty is 0.0123. Say you want to report your uncertainty to 2 - significant figures. So your rounded uncertainty is 0.012. You should - report your estimate to the same precision, so your rounded estimate - should be 12.346. On the other hand, if you wanted to report your - uncertain to the first significant figure (0.01), then you should report - your estimate as 12.35. - - You need to report these to the same precision (not the same number of - significant figures) because the two numbers need to be added together. - If you report both to 2 significant figures, you'd have 12.0 +/- 0.0012, - and your actual estimate falls way outside your error bars! It has to be - the uncertainty that determines the precision of the estimate, because - if you said you had 3 significant figures in the estimate and used that - to set the precision of the uncertainty, you'd have 12.3 +/- 0.0 -- no - error at all! - - We implement this by thinking of the decimal representation as "columns" - centered on the decimal point. We get the column index of the first - non-zero number in the decimal representation of the uncertainty, and - use the fact that ``np.round`` rounds to the number of decimal places - you give it to report the estimate. The uncertainty is presented to the - desired number of significant figures. + """ + Truncate raw estimate and uncertainty values to the appropriate uncertainty. + + The premise here is that, if you're reporting your uncertainty to a certain number of significant figures, your estimate should be reported to the same precision. + + As an example, assume your raw estimate is 12.34567 and your raw uncertainty is 0.0123. + Say you want to report your uncertainty to 2 significant figures. + So your rounded uncertainty is 0.012. + You should report your estimate to the same precision, so your rounded estimate should be 12.346. + On the other hand, if you wanted to report your uncertain to the first significant figure (0.01), then you should report your estimate as 12.35. + + You need to report these to the same precision (not the same number of significant figures) because the two numbers need to be added together. + If you report both to 2 significant figures, you'd have 12.0 +/- 0.0012, and your actual estimate falls way outside your error bars! + It has to be the uncertainty that determines the precision of the estimate, because if you said you had 3 significant figures in the estimate and used that to set the precision of the uncertainty, you'd have 12.3 +/- 0.0 -- no error at all! + + We implement this by thinking of the decimal representation as "columns" centered on the decimal point. + We get the column index of the first non-zero number in the decimal representation of the uncertainty, and use the fact that ``np.round`` rounds to the number of decimal places you give it to report the estimate. + The uncertainty is presented to the desired number of significant figures. Parameters ---------- From 2681fa8ca9e4299f4a3a928e6c985c93fead2992 Mon Sep 17 00:00:00 2001 From: "David W.H. Swenson" Date: Wed, 19 Nov 2025 15:04:55 -0600 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: Alyssa Travitz <31974495+atravitz@users.noreply.github.com> --- openfecli/commands/gather.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openfecli/commands/gather.py b/openfecli/commands/gather.py index 330143f5b..34acc997c 100644 --- a/openfecli/commands/gather.py +++ b/openfecli/commands/gather.py @@ -49,7 +49,7 @@ def format_estimate_uncertainty( unc_prec: int = 1, ) -> tuple[str, str]: """ - Truncate raw estimate and uncertainty values to the appropriate uncertainty. + Round raw estimate and uncertainty values to the appropriate precision. The premise here is that, if you're reporting your uncertainty to a certain number of significant figures, your estimate should be reported to the same precision. @@ -57,7 +57,7 @@ def format_estimate_uncertainty( Say you want to report your uncertainty to 2 significant figures. So your rounded uncertainty is 0.012. You should report your estimate to the same precision, so your rounded estimate should be 12.346. - On the other hand, if you wanted to report your uncertain to the first significant figure (0.01), then you should report your estimate as 12.35. + On the other hand, if you wanted to report your uncertainty to the first significant figure (0.01), then you should report your estimate as 12.35. You need to report these to the same precision (not the same number of significant figures) because the two numbers need to be added together. If you report both to 2 significant figures, you'd have 12.0 +/- 0.0012, and your actual estimate falls way outside your error bars! @@ -65,7 +65,7 @@ def format_estimate_uncertainty( We implement this by thinking of the decimal representation as "columns" centered on the decimal point. We get the column index of the first non-zero number in the decimal representation of the uncertainty, and use the fact that ``np.round`` rounds to the number of decimal places you give it to report the estimate. - The uncertainty is presented to the desired number of significant figures. + The uncertainty is rounded to the desired number of significant figures. Parameters ----------