From 5b98d98f8d9bf5c9e50f0ef89200909142805836 Mon Sep 17 00:00:00 2001 From: fjosw Date: Tue, 18 Jan 2022 13:00:46 +0000 Subject: [PATCH] Documentation updated --- docs/pyerrors/input/json.html | 73 +++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/docs/pyerrors/input/json.html b/docs/pyerrors/input/json.html index ef9559e3..09fa0f4e 100644 --- a/docs/pyerrors/input/json.html +++ b/docs/pyerrors/input/json.html @@ -88,6 +88,7 @@ import warnings from ..obs import Obs from ..covobs import Covobs +from ..correlators import Corr from .. import version as pyerrorsversion @@ -253,6 +254,18 @@ d['cdata'] = cdata return d + def write_Corr_to_dict(my_corr): + front_padding = next(i for i, j in enumerate(my_corr.content) if np.all(j)) + back_padding_start = front_padding + next((i for i, j in enumerate(my_corr.content[front_padding:]) if not np.all(j)), my_corr.T) + dat = write_Array_to_dict(np.array(my_corr.content[front_padding:back_padding_start])) + dat['type'] = 'Corr' + corr_meta_data = str(front_padding) + '|' + str(my_corr.T - back_padding_start) + '|' + str(my_corr.tag) + if 'tag' in dat.keys(): + dat['tag'].append(corr_meta_data) + else: + dat['tag'] = [corr_meta_data] + return dat + if not isinstance(ol, list): ol = [ol] @@ -273,6 +286,10 @@ d['obsdata'].append(write_List_to_dict(io)) elif isinstance(io, np.ndarray): d['obsdata'].append(write_Array_to_dict(io)) + elif isinstance(io, Corr): + d['obsdata'].append(write_Corr_to_dict(io)) + else: + raise Exception("Unkown datatype.") jsonstring = json.dumps(d, indent=indent, cls=my_encoder, ensure_ascii=False) @@ -454,6 +471,22 @@ ret[-1].tag = taglist[i] return np.reshape(ret, layout) + def get_Corr_from_dict(o): + taglist = o.get('tag') + corr_meta_data = taglist[-1].split('|') + padding_front = int(corr_meta_data[0]) + padding_back = int(corr_meta_data[1]) + corr_tag = corr_meta_data[2] + tmp_o = o + tmp_o['tag'] = taglist[:-1] + if len(tmp_o['tag']) == 0: + del tmp_o['tag'] + dat = get_Array_from_dict(tmp_o) + my_corr = Corr(list(dat), padding_front=padding_front, padding_back=padding_back) + if corr_tag != 'None': + my_corr.tag = corr_tag + return my_corr + json_dict = json.loads(json_string) prog = json_dict.get('program', '') @@ -480,6 +513,10 @@ ol.append(get_List_from_dict(io)) elif io['type'] == 'Array': ol.append(get_Array_from_dict(io)) + elif io['type'] == 'Corr': + ol.append(get_Corr_from_dict(io)) + else: + raise Exception("Unkown datatype.") if full_output: retd = {} @@ -708,6 +745,18 @@ d['cdata'] = cdata return d + def write_Corr_to_dict(my_corr): + front_padding = next(i for i, j in enumerate(my_corr.content) if np.all(j)) + back_padding_start = front_padding + next((i for i, j in enumerate(my_corr.content[front_padding:]) if not np.all(j)), my_corr.T) + dat = write_Array_to_dict(np.array(my_corr.content[front_padding:back_padding_start])) + dat['type'] = 'Corr' + corr_meta_data = str(front_padding) + '|' + str(my_corr.T - back_padding_start) + '|' + str(my_corr.tag) + if 'tag' in dat.keys(): + dat['tag'].append(corr_meta_data) + else: + dat['tag'] = [corr_meta_data] + return dat + if not isinstance(ol, list): ol = [ol] @@ -728,6 +777,10 @@ d['obsdata'].append(write_List_to_dict(io)) elif isinstance(io, np.ndarray): d['obsdata'].append(write_Array_to_dict(io)) + elif isinstance(io, Corr): + d['obsdata'].append(write_Corr_to_dict(io)) + else: + raise Exception("Unkown datatype.") jsonstring = json.dumps(d, indent=indent, cls=my_encoder, ensure_ascii=False) @@ -976,6 +1029,22 @@ If True, the output is a gzipped json. If False, the output is a json file. ret[-1].tag = taglist[i] return np.reshape(ret, layout) + def get_Corr_from_dict(o): + taglist = o.get('tag') + corr_meta_data = taglist[-1].split('|') + padding_front = int(corr_meta_data[0]) + padding_back = int(corr_meta_data[1]) + corr_tag = corr_meta_data[2] + tmp_o = o + tmp_o['tag'] = taglist[:-1] + if len(tmp_o['tag']) == 0: + del tmp_o['tag'] + dat = get_Array_from_dict(tmp_o) + my_corr = Corr(list(dat), padding_front=padding_front, padding_back=padding_back) + if corr_tag != 'None': + my_corr.tag = corr_tag + return my_corr + json_dict = json.loads(json_string) prog = json_dict.get('program', '') @@ -1002,6 +1071,10 @@ If True, the output is a gzipped json. If False, the output is a json file. ol.append(get_List_from_dict(io)) elif io['type'] == 'Array': ol.append(get_Array_from_dict(io)) + elif io['type'] == 'Corr': + ol.append(get_Corr_from_dict(io)) + else: + raise Exception("Unkown datatype.") if full_output: retd = {}