The json routines for corr now have a dictionary as a tag and the entry tag of this dictionary contains the old tag.

This should be compatible with the old way of saving.
This commit is contained in:
JanNeuendorf 2022-01-28 12:21:28 +01:00
parent 0bac8a417a
commit 0098c973af

View file

@ -186,6 +186,11 @@ def create_json_string(ol, description='', indent=1):
dat['tag'].append(corr_meta_data) dat['tag'].append(corr_meta_data)
else: else:
dat['tag'] = [corr_meta_data] dat['tag'] = [corr_meta_data]
taglist = dat['tag']
dat['tag'] = {} # tag is now a dictionary, that contains the previous taglist in the key "tag"
dat['tag']['tag'] = taglist
if my_corr.prange is not None:
dat['tag']['prange'] = my_corr.prange
return dat return dat
if not isinstance(ol, list): if not isinstance(ol, list):
@ -395,7 +400,17 @@ def import_json_string(json_string, verbose=True, full_output=False):
return np.reshape(ret, layout) return np.reshape(ret, layout)
def get_Corr_from_dict(o): def get_Corr_from_dict(o):
taglist = o.get('tag') if isinstance(o.get('tag'), list): # supports the old way
taglist = o.get('tag') # This had to be modified to get the taglist from the dictionary
temp_prange = None
else:
tagdic = o.get('tag')
taglist = tagdic['tag']
if 'prange' in tagdic:
temp_prange = tagdic['prange']
else:
temp_prange = None
corr_tag = taglist[-1] corr_tag = taglist[-1]
tmp_o = o tmp_o = o
tmp_o['tag'] = taglist[:-1] tmp_o['tag'] = taglist[:-1]
@ -405,6 +420,8 @@ def import_json_string(json_string, verbose=True, full_output=False):
my_corr = Corr([None if np.isnan(o.ravel()[0].value) else o for o in list(dat)]) my_corr = Corr([None if np.isnan(o.ravel()[0].value) else o for o in list(dat)])
if corr_tag != 'None': if corr_tag != 'None':
my_corr.tag = corr_tag my_corr.tag = corr_tag
my_corr.prange = temp_prange
return my_corr return my_corr
json_dict = json.loads(json_string) json_dict = json.loads(json_string)