sciform 0.28.1__tar.gz → 0.29.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. {sciform-0.28.1 → sciform-0.29.0}/CHANGELOG.rst +134 -3
  2. {sciform-0.28.1 → sciform-0.29.0}/PKG-INFO +2 -15
  3. {sciform-0.28.1 → sciform-0.29.0}/README.rst +1 -14
  4. sciform-0.29.0/docs/source/examples.rst +252 -0
  5. {sciform-0.28.1 → sciform-0.29.0}/docs/source/fsml.rst +8 -8
  6. {sciform-0.28.1 → sciform-0.29.0}/docs/source/options.rst +31 -17
  7. {sciform-0.28.1 → sciform-0.29.0}/docs/source/usage.rst +25 -20
  8. {sciform-0.28.1 → sciform-0.29.0}/examples/fit_plot_with_sciform.py +4 -3
  9. {sciform-0.28.1 → sciform-0.29.0}/src/sciform/format_options.py +34 -32
  10. {sciform-0.28.1 → sciform-0.29.0}/src/sciform/format_utils.py +1 -1
  11. {sciform-0.28.1 → sciform-0.29.0}/src/sciform/formatting.py +5 -2
  12. {sciform-0.28.1 → sciform-0.29.0}/src/sciform/fsml.py +1 -1
  13. {sciform-0.28.1 → sciform-0.29.0}/src/sciform/scinum.py +1 -1
  14. {sciform-0.28.1 → sciform-0.29.0}/src/sciform.egg-info/PKG-INFO +2 -15
  15. {sciform-0.28.1 → sciform-0.29.0}/tests/test_val_unc_formatter.py +46 -0
  16. {sciform-0.28.1 → sciform-0.29.0}/tests/test_val_unc_fsml.py +4 -4
  17. sciform-0.28.1/docs/source/examples.rst +0 -111
  18. {sciform-0.28.1 → sciform-0.29.0}/.flake8 +0 -0
  19. {sciform-0.28.1 → sciform-0.29.0}/.github/workflows/python-package.yml +0 -0
  20. {sciform-0.28.1 → sciform-0.29.0}/.github/workflows/python-publish.yml +0 -0
  21. {sciform-0.28.1 → sciform-0.29.0}/.gitignore +0 -0
  22. {sciform-0.28.1 → sciform-0.29.0}/.readthedocs.yaml +0 -0
  23. {sciform-0.28.1 → sciform-0.29.0}/LICENSE +0 -0
  24. {sciform-0.28.1 → sciform-0.29.0}/docs/Makefile +0 -0
  25. {sciform-0.28.1 → sciform-0.29.0}/docs/make.bat +0 -0
  26. {sciform-0.28.1 → sciform-0.29.0}/docs/requirements.txt +0 -0
  27. {sciform-0.28.1 → sciform-0.29.0}/docs/source/_static/css/custom.css +0 -0
  28. {sciform-0.28.1 → sciform-0.29.0}/docs/source/api.rst +0 -0
  29. {sciform-0.28.1 → sciform-0.29.0}/docs/source/conf.py +0 -0
  30. {sciform-0.28.1 → sciform-0.29.0}/docs/source/exp replacement.rst +0 -0
  31. {sciform-0.28.1 → sciform-0.29.0}/docs/source/index.rst +0 -0
  32. {sciform-0.28.1 → sciform-0.29.0}/docs/source/project.rst +0 -0
  33. {sciform-0.28.1 → sciform-0.29.0}/examples/data/fit_data.json +0 -0
  34. {sciform-0.28.1 → sciform-0.29.0}/examples/fit_plot_no_sciform.py +0 -0
  35. {sciform-0.28.1 → sciform-0.29.0}/examples/outputs/fit_plot_no_sciform.png +0 -0
  36. {sciform-0.28.1 → sciform-0.29.0}/examples/outputs/fit_plot_no_sciform_table.txt +0 -0
  37. {sciform-0.28.1 → sciform-0.29.0}/examples/outputs/fit_plot_with_sciform.png +0 -0
  38. {sciform-0.28.1 → sciform-0.29.0}/examples/outputs/fit_plot_with_sciform_table.txt +0 -0
  39. {sciform-0.28.1 → sciform-0.29.0}/examples/requirements.txt +0 -0
  40. {sciform-0.28.1 → sciform-0.29.0}/pyproject.toml +0 -0
  41. {sciform-0.28.1 → sciform-0.29.0}/requirements.txt +0 -0
  42. {sciform-0.28.1 → sciform-0.29.0}/setup.cfg +0 -0
  43. {sciform-0.28.1 → sciform-0.29.0}/src/sciform/__init__.py +0 -0
  44. {sciform-0.28.1 → sciform-0.29.0}/src/sciform/formatter.py +0 -0
  45. {sciform-0.28.1 → sciform-0.29.0}/src/sciform/grouping.py +0 -0
  46. {sciform-0.28.1 → sciform-0.29.0}/src/sciform/modes.py +0 -0
  47. {sciform-0.28.1 → sciform-0.29.0}/src/sciform/prefix.py +0 -0
  48. {sciform-0.28.1 → sciform-0.29.0}/src/sciform.egg-info/SOURCES.txt +0 -0
  49. {sciform-0.28.1 → sciform-0.29.0}/src/sciform.egg-info/dependency_links.txt +0 -0
  50. {sciform-0.28.1 → sciform-0.29.0}/src/sciform.egg-info/top_level.txt +0 -0
  51. {sciform-0.28.1 → sciform-0.29.0}/tests/test_config.py +0 -0
  52. {sciform-0.28.1 → sciform-0.29.0}/tests/test_float_formatter.py +0 -0
  53. {sciform-0.28.1 → sciform-0.29.0}/tests/test_float_fsml.py +0 -0
  54. {sciform-0.28.1 → sciform-0.29.0}/tests/test_invalid_options.py +0 -0
  55. {sciform-0.28.1 → sciform-0.29.0}/tests/test_print.py +0 -0
  56. {sciform-0.28.1 → sciform-0.29.0}/tests/test_sci_num_and_sci_num_unc.py +0 -0
@@ -1,7 +1,76 @@
1
+ This project adheres to `Semantic Versioning <https://semver.org/>`_.
2
+
3
+ ----
4
+
1
5
  Unreleased
2
6
  ----------
3
7
 
4
- * No unreleased changes.
8
+ * There are no unreleased changes
9
+
10
+ ----
11
+
12
+ 0.29.0 (2023-09-05)
13
+ -------------------
14
+
15
+ Changed
16
+ ^^^^^^^
17
+
18
+ * Previously, when using ``bracket_unc=True`` with any exponent string
19
+ (such as ``e-06``, ``μ`` or ``ppm``), the value and uncertainty were
20
+ always wrapped in parentheses, e.g. ``(1.03(25))e-06``,
21
+ ``(1.03(25)) μ`` or ``(1.03(25)) ppm``.
22
+ Now, when using ``bracket_unc=True`` with prefix or parts-per exponent
23
+ format modes, if the exponent is replaced with an alphabetic
24
+ replacement, then the value and uncertainty are no longer wrapped in
25
+ parentheses, e.g. ``1.03(25) μ`` and ``1.03(25) ppm``.
26
+ This is consistent with
27
+ `BIPM Guide Section 7.2.2 <https://www.bipm.org/documents/20126/2071204/JCGM_100_2008_E.pdf/cb0ef43f-baa5-11cf-3f85-4dcd86f77bd6#page=37>`_.
28
+ Specifically, any time ``bracket_unc=False`` the value and uncertainty
29
+ are always wrapped in parentheses, and any time notation like ``e+02``
30
+ or ``b+02`` is used to indicate the exponent then the value and
31
+ uncertainty are always wrapped in parentheses.
32
+
33
+ Fixed
34
+ ^^^^^
35
+
36
+ * Correct ``fit_plot_with_sciform.py`` example script to use new
37
+ ``exp_format=ExpFormat.PREFIX`` instead of old ``prefix_exp=True``.
38
+
39
+ Improved
40
+ ^^^^^^^^
41
+
42
+ * Documentation improvements including typos and neatening up changelog.
43
+
44
+ ----
45
+
46
+ 0.28.2 (2023-08-31)
47
+ -------------------
48
+
49
+ Improved
50
+ ^^^^^^^^
51
+
52
+ * General wording and grammar improvements throughout documentation.
53
+ * Include more usage examples in the examples documentation in addition
54
+ to referring the reader to the test suite.
55
+
56
+ Fixed
57
+ ^^^^^
58
+
59
+ * Fixed a bug when using ``pdg_sig_figs`` with uncertainties larger than
60
+ about 1000 by cleaning up ``Decimal`` math.
61
+ * Previously, when formatting using the format specification
62
+ mini-language, if the prefix exponent format flag was omitted then the
63
+ exponent format was forced to ``ExpFormat.STANDARD`` rather than
64
+ ``None``.
65
+ This meant that it was impossible, using the format specification
66
+ mini-language combined with global configuration options, to set
67
+ ``ExpFormat.PARTS_PER``.
68
+ Now when the prefix flag is omitted ``exp_format`` is set to ``None``
69
+ so that it will be populated by the global default option.
70
+ In the future a flag may be added to select "parts-per" formatting
71
+ using the format specification mini-language.
72
+
73
+ ----
5
74
 
6
75
  0.28.1 (2023-08-28)
7
76
  -------------------
@@ -17,6 +86,8 @@ Unreleased
17
86
  * Test against Python 3.11.
18
87
  * List supported Python versions in ``pyproject.toml`` classifiers.
19
88
 
89
+ ----
90
+
20
91
  0.28.0 (2023-08-27)
21
92
  -------------------
22
93
 
@@ -24,7 +95,7 @@ Unreleased
24
95
  with an ``exp_format`` option which can be configured to
25
96
  ``ExpFormat.STANDARD``, ``ExpFormat.PREFIX`` or
26
97
  ``ExpFormat.PARTS_PER``.
27
- * Previously formating a non-finite number in percent mode would always
98
+ * Previously formatting a non-finite number in percent mode would always
28
99
  display a ``'%'`` symbol, e.g. ``'(nan)%'``.
29
100
  Now the brackets and ``'%'`` symbol will be omitted unless
30
101
  ``nan_inf_exp=True``.
@@ -43,11 +114,15 @@ Unreleased
43
114
  Rounding and truncating are not properly implemented in binary mode
44
115
  yet.
45
116
 
117
+ ----
118
+
46
119
  0.27.4 (2023-08-25)
47
120
  -------------------
48
121
 
49
122
  * Setup github action to automatically build and publish on release.
50
123
 
124
+ ----
125
+
51
126
  0.27.3 (2023-08-23)
52
127
  -------------------
53
128
 
@@ -57,12 +132,16 @@ Unreleased
57
132
  ``setuptools_scm``.
58
133
  * Stopped encouraging ``import FormatOptions as Fo``.
59
134
 
135
+ ----
136
+
60
137
  0.27.2 (2023-08-20)
61
138
  -------------------
62
139
 
63
140
  * Add ``__repr__()`` for ``FormatOptions`` and
64
141
  ``RenderedFormatOptions``.
65
142
 
143
+ ----
144
+
66
145
  0.27.1 (2023-08-18)
67
146
  -------------------
68
147
 
@@ -71,6 +150,8 @@ Unreleased
71
150
  outputs which appear in the documentation.
72
151
  * Remove extra ``readthedocs.yaml`` file.
73
152
 
153
+ ----
154
+
74
155
  0.27.0 (2023-08-18)
75
156
  -------------------
76
157
 
@@ -79,6 +160,8 @@ Unreleased
79
160
  ``ndigits=AutoRound``. Furthermore, ``AutoRound`` could likely be
80
161
  confused as being an option for ``round_mode``, which it is not.
81
162
 
163
+ ----
164
+
82
165
  0.26.2 (2023-08-18)
83
166
  -------------------
84
167
 
@@ -88,11 +171,15 @@ Unreleased
88
171
  The bug is fixed by re-checking the options combinations after merging
89
172
  in the global defaults but before formatting.
90
173
 
174
+ ----
175
+
91
176
  0.26.1 (2023-08-18)
92
177
  -------------------
93
178
 
94
179
  * Add unit tests, increase test coverage.
95
180
 
181
+ ----
182
+
96
183
  0.26.0 (2023-08-15)
97
184
  -------------------
98
185
 
@@ -120,16 +207,22 @@ Unreleased
120
207
  * Better explanations of ``AutoExpVal`` and ``AutoRound`` behavior.
121
208
  * More accurate descriptions of some invalid options combinations.
122
209
 
210
+ ----
211
+
123
212
  0.25.2 (2023-08-11)
124
213
  -------------------
125
214
 
126
215
  * Update roadmap
127
216
 
217
+ ----
218
+
128
219
  0.25.1 (2023-08-10)
129
220
  -------------------
130
221
 
131
222
  * Refactor ``get_pdg_round_digit()`` into a dedicated function.
132
223
 
224
+ ----
225
+
133
226
  0.25.0 (2023-08-02)
134
227
  -------------------
135
228
 
@@ -139,6 +232,8 @@ Unreleased
139
232
  ``FormatOptions`` instances using the ``merge()`` method.
140
233
  * Minor documentation improvements.
141
234
 
235
+ ----
236
+
142
237
  0.24.0 (2023-07-30)
143
238
  -------------------
144
239
 
@@ -146,6 +241,8 @@ Unreleased
146
241
  ``ExpMode.PERCENT``.
147
242
  There is no longer a ``percent`` keyword argument.
148
243
 
244
+ ----
245
+
149
246
  0.23.0 (2023-07-29)
150
247
  -------------------
151
248
 
@@ -161,17 +258,23 @@ Unreleased
161
258
  ``SciNumUnc`` objects.
162
259
  * Change ``pyproject.toml`` description
163
260
 
261
+ ----
262
+
164
263
  0.22.2 (2023-07-27)
165
264
  -------------------
166
265
 
167
266
  * Add ``.readthedocs.yaml`` and update documentation
168
267
  ``requirements.txt`` for reproducible documentation builds.
169
268
 
269
+ ----
270
+
170
271
  0.22.1 (2023-07-27)
171
272
  -------------------
172
273
 
173
274
  * Fix a date typo in the changelog for the entry for version ``0.22.0``.
174
275
 
276
+ ----
277
+
175
278
  0.22.0 (2023-07-27)
176
279
  -------------------
177
280
 
@@ -200,6 +303,8 @@ Unreleased
200
303
  was corrected.
201
304
  * Add "under construction" message to README.
202
305
 
306
+ ----
307
+
203
308
  0.21.0 (2023-07-22)
204
309
  -------------------
205
310
 
@@ -208,7 +313,9 @@ Unreleased
208
313
  ``float`` and more reliable rounding behavior.
209
314
  * Update particle data group uncertainty rounding unit tests since edge
210
315
  cases are now handled property as a result of adopting ``Decimal``.
211
- * Minor cleanup of ``sfloat`` arithemetic functions.
316
+ * Minor cleanup of ``sfloat`` arithmetic functions.
317
+
318
+ ----
212
319
 
213
320
  0.20.1 (2023-06-24)
214
321
  -------------------
@@ -221,6 +328,8 @@ Unreleased
221
328
  ``format_float()`` and ``format_val_unc()`` directly instead of
222
329
  creating a ``Formatter`` object first.
223
330
 
331
+ ----
332
+
224
333
  0.20.0 (2023-06-22)
225
334
  -------------------
226
335
 
@@ -236,6 +345,8 @@ Unreleased
236
345
  mode: e.g. ``\text{Mi}``.
237
346
  * Link to test cases on examples page.
238
347
 
348
+ ----
349
+
239
350
  0.19.0 (2023-06-22)
240
351
  -------------------
241
352
 
@@ -243,11 +354,15 @@ Unreleased
243
354
  doc testing, and flake8 scans during github pull requests.
244
355
  * Minor flake8 cleanup
245
356
 
357
+ ----
358
+
246
359
  0.18.1 (2023-06-21)
247
360
  -------------------
248
361
 
249
362
  * Documentation improvements
250
363
 
364
+ ----
365
+
251
366
  0.18.0 (2023-06-19)
252
367
  -------------------
253
368
 
@@ -261,6 +376,8 @@ Unreleased
261
376
  * Expose ``AutoPrec`` and ``AutoExp`` sentinel classes so that users can
262
377
  explicitly indicate automatic precision and exponent selection.
263
378
 
379
+ ----
380
+
264
381
  0.17.1 (2023-06-19)
265
382
  -------------------
266
383
 
@@ -268,6 +385,8 @@ Unreleased
268
385
  including more verbose clarifying comments.
269
386
  * Minor documentation cleanup
270
387
 
388
+ ----
389
+
271
390
  0.17.0 (2023-06-19)
272
391
  -------------------
273
392
 
@@ -276,6 +395,8 @@ Unreleased
276
395
  * Fix typos in binary IEC prefixes table.
277
396
  * Fix some cross links in documentation.
278
397
 
398
+ ----
399
+
279
400
  0.16.0 (2023-06-18)
280
401
  -------------------
281
402
 
@@ -283,16 +404,22 @@ Unreleased
283
404
  * Refactor exponent string conversion.
284
405
  * Percent mode for non-finite numbers.
285
406
 
407
+ ----
408
+
286
409
  0.15.2 (2023-06-18)
287
410
  -------------------
288
411
 
289
412
  * Fix a bug involving space filling and separators.
290
413
 
414
+ ----
415
+
291
416
  0.15.1 (2023-06-17)
292
417
  -------------------
293
418
 
294
419
  * Changelog formatting typo.
295
420
 
421
+ ----
422
+
296
423
  0.15.0 (2023-06-17)
297
424
  -------------------
298
425
 
@@ -300,8 +427,12 @@ Unreleased
300
427
  * Forbid percent mode unless using fixed point exponent mode.
301
428
  * Add PyPi link to readme.
302
429
 
430
+ ----
431
+
303
432
  0.14.0 (2023-06-17)
304
433
  -------------------
305
434
 
306
435
  * Add Changelog.
307
436
  * Add ``unicode_pm`` option with documentation and tests.
437
+
438
+ ----
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sciform
3
- Version: 0.28.1
3
+ Version: 0.29.0
4
4
  Summary: A package for formatting numbers into scientific formatted strings.
5
5
  Author-email: Justin Gerber <justin.gerber48@gmail.com>
6
6
  Project-URL: homepage, https://github.com/jagerber48/sciform
@@ -77,7 +77,7 @@ continue to change until version ``1.0.0`` is released.
77
77
  API changes will be announced after new releases in the
78
78
  `changelog <https://sciform.readthedocs.io/en/stable/project.html#changelog>`_.
79
79
  If you have an idea or opinion about how ``sciform`` should be designed,
80
- now is a great to
80
+ now is a great time to
81
81
  `post a discussion topic <https://github.com/jagerber48/sciform/discussions>`_
82
82
  about it!
83
83
 
@@ -107,19 +107,6 @@ strings according to the selected options.
107
107
  >>> print(sform(123456.78))
108
108
  123.5e+03
109
109
 
110
- For brevity, the user may consider abbreviating ``FormatOptions`` as
111
- ``Fo``.
112
-
113
- >>> from sciform import (Formatter, FormatOptions, RoundMode,
114
- ... GroupingSeparator, ExpMode)
115
- >>> sform = Formatter(FormatOptions(
116
- ... round_mode=RoundMode.DEC_PLACE,
117
- ... ndigits=6,
118
- ... upper_separator=GroupingSeparator.SPACE,
119
- ... lower_separator=GroupingSeparator.SPACE))
120
- >>> print(sform(51413.14159265359))
121
- 51 413.141 593
122
-
123
110
  Users can also format numbers by constructing ``SciNum`` objects and
124
111
  using string formatting to format the ``SciNum`` instances according
125
112
  to a custom FSML.
@@ -60,7 +60,7 @@ continue to change until version ``1.0.0`` is released.
60
60
  API changes will be announced after new releases in the
61
61
  `changelog <https://sciform.readthedocs.io/en/stable/project.html#changelog>`_.
62
62
  If you have an idea or opinion about how ``sciform`` should be designed,
63
- now is a great to
63
+ now is a great time to
64
64
  `post a discussion topic <https://github.com/jagerber48/sciform/discussions>`_
65
65
  about it!
66
66
 
@@ -90,19 +90,6 @@ strings according to the selected options.
90
90
  >>> print(sform(123456.78))
91
91
  123.5e+03
92
92
 
93
- For brevity, the user may consider abbreviating ``FormatOptions`` as
94
- ``Fo``.
95
-
96
- >>> from sciform import (Formatter, FormatOptions, RoundMode,
97
- ... GroupingSeparator, ExpMode)
98
- >>> sform = Formatter(FormatOptions(
99
- ... round_mode=RoundMode.DEC_PLACE,
100
- ... ndigits=6,
101
- ... upper_separator=GroupingSeparator.SPACE,
102
- ... lower_separator=GroupingSeparator.SPACE))
103
- >>> print(sform(51413.14159265359))
104
- 51 413.141 593
105
-
106
93
  Users can also format numbers by constructing ``SciNum`` objects and
107
94
  using string formatting to format the ``SciNum`` instances according
108
95
  to a custom FSML.
@@ -0,0 +1,252 @@
1
+ Examples
2
+ ########
3
+
4
+ .. module:: sciform
5
+ :noindex:
6
+
7
+ Test Cases
8
+ ==========
9
+
10
+ The :mod:`sciform`
11
+ `test suite <https://github.com/jagerber48/sciform/tree/main/tests>`_
12
+ contains hundreds of example formatting test cases which showcase the
13
+ many available formatting options.
14
+
15
+ Formatter
16
+ =========
17
+
18
+ Here are a small selection of examples which demonstrate some of the
19
+ available formatting options.
20
+
21
+ >>> from sciform import (FormatOptions, Formatter, ExpMode, RoundMode,
22
+ ... SignMode, GroupingSeparator, ExpFormat)
23
+ >>> num = 12345.54321
24
+ >>> sform = Formatter(FormatOptions(
25
+ ... exp_mode=ExpMode.SCIENTIFIC,
26
+ ... round_mode=RoundMode.SIG_FIG,
27
+ ... ndigits=4))
28
+ >>> print(sform(num))
29
+ 1.235e+04
30
+ >>> sform = Formatter(FormatOptions(
31
+ ... exp_mode=ExpMode.ENGINEERING,
32
+ ... round_mode=RoundMode.DEC_PLACE,
33
+ ... ndigits=10,
34
+ ... sign_mode=SignMode.SPACE,
35
+ ... superscript_exp=True))
36
+ >>> print(sform(num))
37
+ 12.3455432100×10³
38
+ >>> sform = Formatter(FormatOptions(
39
+ ... exp_mode=ExpMode.FIXEDPOINT,
40
+ ... upper_separator=GroupingSeparator.SPACE,
41
+ ... decimal_separator=GroupingSeparator.COMMA,
42
+ ... lower_separator=GroupingSeparator.UNDERSCORE,
43
+ ... sign_mode=SignMode.ALWAYS))
44
+ >>> print(sform(num))
45
+ +12 345,543_21
46
+
47
+ >>> num = 0.076543
48
+ >>> sform = Formatter(FormatOptions(
49
+ ... exp_mode=ExpMode.SCIENTIFIC,
50
+ ... exp_val=-3,
51
+ ... exp_format=ExpFormat.PARTS_PER,
52
+ ... add_ppth_form=True))
53
+ >>> print(sform(num))
54
+ 76.543 ppth
55
+ >>> sform = Formatter(FormatOptions(
56
+ ... exp_mode=ExpMode.SCIENTIFIC,
57
+ ... exp_val=-2,
58
+ ... exp_format=ExpFormat.PREFIX,
59
+ ... add_c_prefix=True))
60
+ >>> print(sform(num))
61
+ 7.6543 c
62
+ >>> sform = Formatter(FormatOptions(
63
+ ... exp_mode=ExpMode.SCIENTIFIC,
64
+ ... exp_val=-6,
65
+ ... exp_format=ExpFormat.PREFIX))
66
+ >>> print(sform(num))
67
+ 76543 μ
68
+ >>> sform = Formatter(FormatOptions(
69
+ ... exp_mode=ExpMode.PERCENT))
70
+ >>> print(sform(num))
71
+ 7.6543%
72
+
73
+ >>> num = 3141592.7
74
+ >>> unc = 1618
75
+ >>> sform = Formatter()
76
+ >>> print(sform(num, unc))
77
+ 3141593 +/- 1618
78
+ >>> sform = Formatter(FormatOptions(
79
+ ... exp_mode=ExpMode.ENGINEERING,
80
+ ... exp_format=ExpFormat.PREFIX,
81
+ ... pdg_sig_figs=True,
82
+ ... unicode_pm=True,
83
+ ... unc_pm_whitespace=False))
84
+ >>> print(sform(num, unc))
85
+ (3.1416±0.0016) M
86
+
87
+ >>> num = 314159.27
88
+ >>> unc = 1618
89
+ >>> sform = Formatter(FormatOptions(
90
+ ... exp_mode=ExpMode.ENGINEERING_SHIFTED,
91
+ ... pdg_sig_figs=True,
92
+ ... bracket_unc=True))
93
+ >>> print(sform(num, unc))
94
+ (0.3142(16))e+06
95
+
96
+ SciNum, SciNumUnc, and Global Options
97
+ =====================================
98
+
99
+ Here are a small selection of examples which demonstrate some of the
100
+ available string formatting options.
101
+ Note that many options are not available through the :ref:`fsml`, so
102
+ these options must be selected by configuring the global default options
103
+ during formatting.
104
+ Here this is done using the :class:`GlobalDefaultsContext` context
105
+ manager, but this could have been done using :func:`set_global_defaults`
106
+ instead.
107
+
108
+ >>> from sciform import SciNum, SciNumUnc, GlobalDefaultsContext
109
+ >>> snum = SciNum(12345.54321)
110
+ >>> print(f'{snum:!4e}')
111
+ 1.235e+04
112
+ >>> print(f'{snum: .10r}')
113
+ 12.3455432100e+03
114
+ >>> print(f'{snum:+s,_}')
115
+ +12 345,543_21
116
+
117
+ >>> snum = SciNum(0.076543)
118
+ >>> with GlobalDefaultsContext(FormatOptions(
119
+ ... exp_format=ExpFormat.PARTS_PER,
120
+ ... add_ppth_form=True)):
121
+ ... print(f'{snum:ex-3}')
122
+ 76.543 ppth
123
+ >>> with GlobalDefaultsContext(FormatOptions(
124
+ ... exp_format=ExpFormat.PREFIX,
125
+ ... add_c_prefix=True)):
126
+ ... print(f'{snum:ex-2}')
127
+ 7.6543 c
128
+ >>> with GlobalDefaultsContext(FormatOptions(
129
+ ... exp_mode=ExpMode.SCIENTIFIC,
130
+ ... exp_val=-6,
131
+ ... exp_format=ExpFormat.PREFIX)):
132
+ ... print(f'{snum:ex-6}')
133
+ 76543 μ
134
+ >>> print(f'{snum:%}')
135
+ 7.6543%
136
+
137
+ >>> num_unc = SciNumUnc(3141592.7, 1618)
138
+ >>> print(f'{num_unc}')
139
+ 3141593 +/- 1618
140
+ >>> with GlobalDefaultsContext(FormatOptions(
141
+ ... pdg_sig_figs=True,
142
+ ... unicode_pm=True,
143
+ ... unc_pm_whitespace=False)):
144
+ ... print(f'{num_unc:rp}')
145
+ (3.1416±0.0016) M
146
+
147
+ >>> num_unc = SciNumUnc(314159.27, 1618)
148
+ >>> with GlobalDefaultsContext(FormatOptions(
149
+ ... pdg_sig_figs=True)):
150
+ ... print(f'{num_unc:#r()}')
151
+ (0.3142(16))e+06
152
+
153
+ Plotting and Tabulating Fit Data
154
+ ================================
155
+
156
+ We are given 3 data sets:
157
+
158
+ .. collapse:: Data
159
+
160
+ .. literalinclude:: ../../examples/data/fit_data.json
161
+ :language: json
162
+
163
+ We want to perform quadratic fits to these data sets, visualize
164
+ the results, and print the best fit parameters including the uncertainty
165
+ reported by the fit routine.
166
+ For these tasks we will require the ``numpy``, ``scipy``,
167
+ ``matplotlib``, and ``tabulate`` packages.
168
+
169
+ Without ``sciform``
170
+ -------------------
171
+
172
+ Without ``sciform`` we can perform the fit and plot the data and best
173
+ fit lines and print out a table of best fit parameters and
174
+ uncertainties:
175
+
176
+ .. collapse:: Code
177
+
178
+ .. literalinclude:: ../../examples/fit_plot_no_sciform.py
179
+ :language: python
180
+
181
+ This produces the plot:
182
+
183
+ .. image:: ../../examples/outputs/fit_plot_no_sciform.png
184
+ :width: 400
185
+
186
+ And the table:
187
+
188
+ .. literalinclude:: ../../examples/outputs/fit_plot_no_sciform_table.txt
189
+ :language: python
190
+
191
+ This plot and table suffer from a number of shortcomings which impede
192
+ human readability.
193
+
194
+ - In the table, the exponents for the values and uncertainties differ,
195
+ making it hard to identify the significant digits of the value.
196
+ - The number of digits displayed for the values is not correlated with
197
+ the uncertainty for that value. For example, the ``y0`` values are
198
+ shown with precision to the 10\ :sup:`+8` place, but the uncertainty
199
+ indicates precision down to the 10\ :sup:`+3` place.
200
+ - In the table, the exponents vary from one dataset to the next. It is
201
+ hard to see these differences at a glance.
202
+ - The tick labels on the plot are illegible because each value has so
203
+ many digits.
204
+
205
+ Of course, even without :mod:`sciform`, it would be possible to make
206
+ manual adjustments to the plot and the table to improve these data
207
+ visualizations.
208
+ However, :mod:`sciform` will allow us to make the required changes in a
209
+ general and automated way.
210
+
211
+ With ``sciform``
212
+ ----------------
213
+
214
+ We can address these problems using :mod:`sciform` by:
215
+
216
+ #. Using prefix scientific notation to label the plot axes.
217
+ This will greatly reduce the number of symbols needed for each tick
218
+ value.
219
+ #. Using value/uncertainty formatting in the table to collapse the value
220
+ and error column pairs into individual columns.
221
+ This will make obvious the relative scale between the uncertainty and
222
+ the value.
223
+ Using ``sciform``, the significant digits displayed for the value
224
+ will always match the precision of the uncertainty.
225
+ We will use bracket uncertainty format.
226
+ #. Using engineering notation for the value/uncertainty in the table. This
227
+ will make the relative scale between different rows obvious.
228
+
229
+ To do this we import :mod:`sciform` and make some helper functions for
230
+ displaying the plot axes as described:
231
+
232
+ .. collapse:: Code
233
+
234
+ .. literalinclude:: ../../examples/fit_plot_with_sciform.py
235
+ :language: python
236
+
237
+ This produces the plot:
238
+
239
+ .. image:: ../../examples/outputs/fit_plot_with_sciform.png
240
+ :width: 400
241
+
242
+ and the table:
243
+
244
+ .. literalinclude:: ../../examples/outputs/fit_plot_with_sciform_table.txt
245
+ :language: python
246
+
247
+ We can see the plot and table are immediately much more legible.
248
+ Less characters are needed to communicate the data in both
249
+ visualizations.
250
+ The relative scaling of parameters between datasets and the relative
251
+ scaling between the value and uncertainty for each entry are
252
+ immediately clear.
@@ -1,6 +1,6 @@
1
1
  .. _fsml:
2
2
 
3
- Format Specification Mini Language
3
+ Format Specification Mini-Language
4
4
  ##################################
5
5
 
6
6
  .. module:: sciform
@@ -14,7 +14,7 @@ configured using :class:`FormatOptions` instances, users can construct
14
14
  :class:`SciNum` or :class:`SciNumUnc` instances and format them using
15
15
  string formatting with format specification strings from the
16
16
  :mod:`sciform` format specification mini-language (FSML).
17
- This is analagous to how python :class:`int`, :class:`float`, and
17
+ This is analogous to how python :class:`int`, :class:`float`, and
18
18
  :class:`Decimal` instances can be formatted using the built-in
19
19
  `format specification mini-language <https://docs.python.org/3/library/string.html#format-specification-mini-language>`_.
20
20
  The :mod:`sciform` format specification mini-language is given by::
@@ -126,7 +126,7 @@ Further details about the options can be found at
126
126
  See :ref:`bracket_uncertainty`.
127
127
 
128
128
 
129
- Incompatibilities With Built-in Format Specification Mini Language
129
+ Incompatibilities With Built-in Format Specification Mini-Language
130
130
  ==================================================================
131
131
 
132
132
  The :mod:`sciform` FSML extends the functionality of the
@@ -158,12 +158,12 @@ for scientific formatting.
158
158
  * Inclusion of a hanging decimal point, e.g. ``123.``.
159
159
  :mod:`sciform` never includes a hanging decimal point.
160
160
 
161
- * For :class:`float` instances, Python formatting uses a default precion
162
- of 6 for ``f``, ``F``, ``%``, ``e``, and ``E`` modes if no explicit
163
- precision (``ndigits``) is supplied.
161
+ * For :class:`float` instances, Python formatting uses a default
162
+ precision of 6 for ``f``, ``F``, ``%``, ``e``, and ``E`` modes if no
163
+ explicit precision (``ndigits``) is supplied.
164
164
  :mod:`sciform`, instead, converts :class:`float` instances into
165
165
  :class:`str` and then :class:`Decimal` so that they are displayed with
166
- as many digits as necessary "round-trip" when no ``ndigits`` is
166
+ as many digits as necessary to "round-trip" when no ``ndigits`` is
167
167
  supplied.
168
168
  E.g. ``f'{float(0.3):f}'`` yields ``0.300000`` while
169
169
  ``f'{SciNum(0.3):f}`` yields ``0.3``.
@@ -182,7 +182,7 @@ for scientific formatting.
182
182
  There is no ``0`` flag, as in the built-in FSML, that may be placed
183
183
  before the width field to indicate sign-aware zero padding.
184
184
  E.g. ``f'{float(12): =4}`` yields ``' 12'`` while
185
- ``f{SciNum(12): =4}`` yeilds ``' 12'``, fill characters are padded
185
+ ``f{SciNum(12): =4}`` yields ``' 12'``, fill characters are padded
186
186
  up to the 10\ :sup:`4` digits place.
187
187
 
188
188
  * The built-in FSML supports displaying negative zero, but also supports