mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-05-14 19:43:41 +02:00
Added dictionary output of json input routine: It is possible to import and export any structure that is JSON serializable as description (or Obs.tag)
This commit is contained in:
parent
d7c2f125fe
commit
5937a519d7
2 changed files with 50 additions and 19 deletions
|
@ -9,6 +9,8 @@ def test_jsonio():
|
|||
o2 = pe.pseudo_Obs(0.5, .1, 'two|r1')
|
||||
o3 = pe.pseudo_Obs(0.5, .1, 'two|r2')
|
||||
o4 = pe.merge_obs([o2, o3])
|
||||
otag = 'This has been merged!'
|
||||
o4.tag = otag
|
||||
do = o - .2 * o4
|
||||
|
||||
o5 = pe.pseudo_Obs(0.8, .1, 'two|r2')
|
||||
|
@ -17,7 +19,7 @@ def test_jsonio():
|
|||
arr = np.array([o3, o5])
|
||||
mat = np.array([[pe.pseudo_Obs(1.0, .1, 'mat'), pe.pseudo_Obs(0.3, .1, 'mat')], [pe.pseudo_Obs(0.2, .1, 'mat'), pe.pseudo_Obs(2.0, .4, 'mat')]])
|
||||
|
||||
ol = [do, testl, mat, arr, np.array([o])]
|
||||
ol = [o4, do, testl, mat, arr, np.array([o])]
|
||||
fname = 'test_rw'
|
||||
|
||||
jsonio.dump_to_json(ol, fname, indent=1)
|
||||
|
@ -30,8 +32,18 @@ def test_jsonio():
|
|||
if isinstance(ol[i], pe.Obs):
|
||||
o = ol[i] - rl[i]
|
||||
assert(o.is_zero())
|
||||
assert(ol[i].tag == rl[i].tag)
|
||||
or1 = np.ravel(ol[i])
|
||||
or2 = np.ravel(rl[i])
|
||||
for j in range(len(or1)):
|
||||
o = or1[j] - or2[j]
|
||||
assert(o.is_zero())
|
||||
|
||||
description = {'I': {'Am': {'a': 'nested dictionary!'}}}
|
||||
jsonio.dump_to_json(ol, fname, indent=1, gz=False, description=description)
|
||||
|
||||
rl = jsonio.load_json(fname, gz=False, full_output=True)
|
||||
|
||||
assert(description == rl['description'])
|
||||
|
||||
os.remove(fname + '.json')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue