mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-03-16 07:10:24 +01:00
Merge pull request #101 from s-kuberski/feature/json_io
bugfix: Deltas in JSON file are now relative to o.value and not o.r_values[r_name]
This commit is contained in:
commit
a799bd1f7c
2 changed files with 13 additions and 5 deletions
|
@ -33,6 +33,7 @@ def create_json_string(ol, description='', indent=1):
|
||||||
|
|
||||||
def _gen_data_d_from_list(ol):
|
def _gen_data_d_from_list(ol):
|
||||||
dl = []
|
dl = []
|
||||||
|
No = len(ol)
|
||||||
for name in ol[0].mc_names:
|
for name in ol[0].mc_names:
|
||||||
ed = {}
|
ed = {}
|
||||||
ed['id'] = name
|
ed['id'] = name
|
||||||
|
@ -43,10 +44,11 @@ def create_json_string(ol, description='', indent=1):
|
||||||
if ol[0].is_merged.get(r_name, False):
|
if ol[0].is_merged.get(r_name, False):
|
||||||
rd['is_merged'] = True
|
rd['is_merged'] = True
|
||||||
rd['deltas'] = []
|
rd['deltas'] = []
|
||||||
|
offsets = [o.r_values[r_name] - o.value for o in ol]
|
||||||
|
deltas = np.column_stack([ol[oi].deltas[r_name] + offsets[oi] for oi in range(No)])
|
||||||
for i in range(len(ol[0].idl[r_name])):
|
for i in range(len(ol[0].idl[r_name])):
|
||||||
rd['deltas'].append([ol[0].idl[r_name][i]])
|
rd['deltas'].append([ol[0].idl[r_name][i]])
|
||||||
for o in ol:
|
rd['deltas'][-1] += deltas[i].tolist()
|
||||||
rd['deltas'][-1].append(o.deltas[r_name][i])
|
|
||||||
ed['replica'].append(rd)
|
ed['replica'].append(rd)
|
||||||
dl.append(ed)
|
dl.append(ed)
|
||||||
return dl
|
return dl
|
||||||
|
|
|
@ -33,11 +33,10 @@ def test_jsonio():
|
||||||
mat[1][0].tag = '{testt}'
|
mat[1][0].tag = '{testt}'
|
||||||
mat[1][1].tag = '[tag]'
|
mat[1][1].tag = '[tag]'
|
||||||
|
|
||||||
tt1 = pe.Obs([np.random.rand(100)], ['t|r1'], idl=[range(2, 202, 2)])
|
tt1 = pe.Obs([np.random.rand(100), np.random.rand(100)], ['t|r1', 't|r2'], idl=[range(2, 202, 2), range(22, 222, 2)])
|
||||||
tt2 = pe.Obs([np.random.rand(100)], ['t|r2'], idl=[range(2, 202, 2)])
|
|
||||||
tt3 = pe.Obs([np.random.rand(102)], ['qe'])
|
tt3 = pe.Obs([np.random.rand(102)], ['qe'])
|
||||||
|
|
||||||
tt = tt1 + tt2 + tt3
|
tt = tt1 + tt3
|
||||||
|
|
||||||
tt.tag = 'Test Obs: Ä'
|
tt.tag = 'Test Obs: Ä'
|
||||||
|
|
||||||
|
@ -63,6 +62,13 @@ def test_jsonio():
|
||||||
for j in range(len(or1)):
|
for j in range(len(or1)):
|
||||||
o = or1[j] - or2[j]
|
o = or1[j] - or2[j]
|
||||||
assert(o.is_zero())
|
assert(o.is_zero())
|
||||||
|
if isinstance(ol[i], pe.Obs):
|
||||||
|
for name in ol[i].r_values:
|
||||||
|
assert(np.isclose(ol[i].r_values[name], rl[i].r_values[name]))
|
||||||
|
elif isinstance(ol[i], list):
|
||||||
|
for j in range(len(ol[i])):
|
||||||
|
for name in ol[i][j].r_values:
|
||||||
|
assert(np.isclose(ol[i][j].r_values[name], rl[i][j].r_values[name]))
|
||||||
|
|
||||||
description = {'I': {'Am': {'a': 'nested dictionary!'}}}
|
description = {'I': {'Am': {'a': 'nested dictionary!'}}}
|
||||||
jsonio.dump_to_json(ol, fname, indent=0, gz=False, description=description)
|
jsonio.dump_to_json(ol, fname, indent=0, gz=False, description=description)
|
||||||
|
|
Loading…
Add table
Reference in a new issue