Closed yumengch closed 3 years ago
I feel like the combo
unpack_uqs
andalign_col
are too complicated. I will have a look at it after this, to see if I can simplify them.
Here are my changes to improve tabulation of results.
https://github.com/nansencenter/DAPPER/compare/cd47cd0..e9c5535
Note that there are further improvements in the output of tests/test_data.py
.
The main implementation changes are
align_col
no longer relies on tabulate. Instead it does the decimal-point alignment itself. This avoids roundabout pre/post-processing.align_col
to unpack_uqs
.uq
s are extracted by unpack_uqs
.xp_process.py:xpSpace.print:make_cols
Great work, Patrick!
Some comments:
str
type values to uq.val
and uq.prec
leads to error in uq.__str__
. I'm not sure if it is necessary to safeguard uq.__str__
for the val
and prec
types. If this problem is limited within unpack_uq
, I think we can simply ignore this.unpack_uqs
:
>>> import numpy as np
>>> from dapper.tools.rounding import UncertainQtty as UQ
>>> from dapper.stats import unpack_uqs, align_col
# setup uq_list
>>> vals = np.array([0.43085084, 0.9192679 , 0.87700933, 2., 0.1])
>>> precs = np.array([0.08460475, 0.76110353, 0.001, 1.45934142, 1.35481388])
>>> uq_list = [UQ(val, prec) for val, prec in zip(vals, precs)]
# default unpack_uq
>>> unpack_uqs(uq_list, decimals=None)
{'val': ['0.43', '0.9', '0.877', '2', '0'], 'prec': ['0.08', '0.8', '0.001', '1', '1']}
# specify decimals
>>> unpack_uqs(uq_list, decimals=4)
{'val': [0.4309, 0.9193, 0.877, 2.0, 0.1], 'prec': [0.0846, 0.7611, 0.001, 1.4593, 1.3548]}
# check None array for TODO 3
>>> col = unpack_uqs(np.array([None, None, None]), decimals=None)
>>> align_col(['rand']+col['val'])
['rand', '␣␣␣␣', '␣␣␣␣', '␣␣␣␣']
>>> align_col(['1s']+col['prec'])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'prec'
It is worth noting two special cases:
-- 0.87700933 ± 0.001
and 2.0 ± 1.0
don't generate 0.8770±0.0010
and 2.0000±1.0000
when I specify decimals=4
. This is again an issue of necessity to padding 0
s for truncated values.
-- Regarding your TODO 3: validate
, the combination of unpack_uq
and align_col
in the xp_process
should be fine, but may have error in tabulate_avrgs
, but I'm not so sure if tabulate_avrgs
needs to deal with such input.
Many thanks for the comments.
If this problem is limited within
unpack_uq
, I think we can simply ignore this.
It is contained within, yes, thanks to deepcopy
. However, I changed this to vars(uq).copy()
the most recent commit, which is maybe more explicit/safe solution.
don't generate
0.8770±0.0010
and2.0000±1.0000
when I specifydecimals=4
Fixed in the latest commit. This fix was simple now that we don't have to worry about tabulate
truncating zeros.
Regarding your TODO 3: validate
This is now gone, I believe. Not sure if a similar issue could exist. But it seems good enough for now.
It looks great now. Thanks.
Aim
Add bib and demo for VL20
Resolve issue #40
Potential issue
preprocess
inalign_col
needed?0.03
now0.030
based onprec
thoughprec
is not shown. I feel this is correct.