From 03b48401156871e303f38cdbbb4f3071f09a5d89 Mon Sep 17 00:00:00 2001 From: fjosw Date: Thu, 27 Jan 2022 14:16:55 +0000 Subject: [PATCH] Documentation updated --- docs/pyerrors/input/json.html | 66 ++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 20 deletions(-) diff --git a/docs/pyerrors/input/json.html b/docs/pyerrors/input/json.html index 1979f541..0b292cde 100644 --- a/docs/pyerrors/input/json.html +++ b/docs/pyerrors/input/json.html @@ -241,12 +241,27 @@ d['cdata'] = cdata return d + def _nan_Obs_like(obs): + samples = [] + names = [] + idl = [] + for key, value in obs.idl.items(): + samples.append([np.nan] * len(value)) + names.append(key) + idl.append(value) + my_obs = Obs(samples, names, idl) + my_obs.reweighted = obs.reweighted + my_obs.is_merged = obs.is_merged + return my_obs + 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])) + first_not_none = next(i for i, j in enumerate(my_corr.content) if np.all(j)) + dummy_array = np.empty((my_corr.N, my_corr.N), dtype=object) + dummy_array[:] = _nan_Obs_like(my_corr.content[first_not_none].ravel()[0]) + content = [o if o is not None else dummy_array for o in my_corr.content] + dat = write_Array_to_dict(np.array(content, dtype=object)) dat['type'] = 'Corr' - corr_meta_data = str(front_padding) + '|' + str(my_corr.T - back_padding_start) + '|' + str(my_corr.tag) + corr_meta_data = str(my_corr.tag) if 'tag' in dat.keys(): dat['tag'].append(corr_meta_data) else: @@ -258,7 +273,7 @@ d = {} d['program'] = 'pyerrors %s' % (pyerrorsversion.__version__) - d['version'] = '0.1' + d['version'] = '0.2' d['who'] = getpass.getuser() d['date'] = datetime.datetime.now().astimezone().strftime('%Y-%m-%d %H:%M:%S %z') d['host'] = socket.gethostname() + ', ' + platform.platform() @@ -296,6 +311,7 @@ return '\n'.join(split) jsonstring = remove_quotationmarks(jsonstring) + jsonstring = jsonstring.replace('nan', 'NaN') return jsonstring @@ -460,16 +476,13 @@ 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] + corr_tag = taglist[-1] 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=[padding_front, padding_back]) + my_corr = Corr([None if np.isnan(o.ravel()[0].value) else o for o in list(dat)]) if corr_tag != 'None': my_corr.tag = corr_tag return my_corr @@ -718,12 +731,27 @@ d['cdata'] = cdata return d + def _nan_Obs_like(obs): + samples = [] + names = [] + idl = [] + for key, value in obs.idl.items(): + samples.append([np.nan] * len(value)) + names.append(key) + idl.append(value) + my_obs = Obs(samples, names, idl) + my_obs.reweighted = obs.reweighted + my_obs.is_merged = obs.is_merged + return my_obs + 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])) + first_not_none = next(i for i, j in enumerate(my_corr.content) if np.all(j)) + dummy_array = np.empty((my_corr.N, my_corr.N), dtype=object) + dummy_array[:] = _nan_Obs_like(my_corr.content[first_not_none].ravel()[0]) + content = [o if o is not None else dummy_array for o in my_corr.content] + dat = write_Array_to_dict(np.array(content, dtype=object)) dat['type'] = 'Corr' - corr_meta_data = str(front_padding) + '|' + str(my_corr.T - back_padding_start) + '|' + str(my_corr.tag) + corr_meta_data = str(my_corr.tag) if 'tag' in dat.keys(): dat['tag'].append(corr_meta_data) else: @@ -735,7 +763,7 @@ d = {} d['program'] = 'pyerrors %s' % (pyerrorsversion.__version__) - d['version'] = '0.1' + d['version'] = '0.2' d['who'] = getpass.getuser() d['date'] = datetime.datetime.now().astimezone().strftime('%Y-%m-%d %H:%M:%S %z') d['host'] = socket.gethostname() + ', ' + platform.platform() @@ -773,6 +801,7 @@ return '\n'.join(split) jsonstring = remove_quotationmarks(jsonstring) + jsonstring = jsonstring.replace('nan', 'NaN') return jsonstring @@ -1004,16 +1033,13 @@ If True, the output is a gzipped json. If False, the output is a json file. 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] + corr_tag = taglist[-1] 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=[padding_front, padding_back]) + my_corr = Corr([None if np.isnan(o.ravel()[0].value) else o for o in list(dat)]) if corr_tag != 'None': my_corr.tag = corr_tag return my_corr