diff --git a/docs/pyerrors/input/json.html b/docs/pyerrors/input/json.html index 5ac66459..2d8804b7 100644 --- a/docs/pyerrors/input/json.html +++ b/docs/pyerrors/input/json.html @@ -59,6 +59,12 @@
def load_json(fname, verbose=True, gz=True, full_output=False): - """Import a list of Obs or structures containing Obs from a .json.gz file. + """Import a list of Obs or structures containing Obs from a .json(.gz) file. The following structures are supported: Obs, list, numpy.ndarray, Corr If the list contains only one element, it is unpacked from the list. @@ -1199,7 +1418,7 @@ If False, only the data is returned. -Import a list of Obs or structures containing Obs from a .json.gz file.
++ +Import a list of Obs or structures containing Obs from a .json(.gz) file.
The following structures are supported: Obs, list, numpy.ndarray, Corr If the list contains only one element, it is unpacked from the list.
@@ -1220,6 +1439,147 @@ If False, only the data is returned.+ +#   + + + def + dump_dict_to_json(od, fname, description='', indent=1, reps='DICTOBS', gz=True): ++ +++ +View Source
++ +def dump_dict_to_json(od, fname, description='', indent=1, reps='DICTOBS', gz=True): + """Export a dict of Obs or structures containing Obs to a .json(.gz) file + + Parameters + ---------- + od : dict + Dict of JSON valid structures and objects that will be exported. + At the moment, these objects can be either of: Obs, list, numpy.ndarray, Corr. + All Obs inside a structure have to be defined on the same set of configurations. + fname : str + Filename of the output file. + description : str + Optional string that describes the contents of the json file. + indent : int + Specify the indentation level of the json file. None or 0 is permissible and + saves disk space. + reps : str + Specify the structure of the placeholder in exported dict to be reps[0-9]+. + gz : bool + If True, the output is a gzipped json. If False, the output is a json file. + """ + + if not isinstance(od, dict): + raise Exception('od has to be a dictionary. Did you want to use dump_to_json?') + + infostring = ('This JSON file contains a python dictionary that has been parsed to a list of structures. ' + 'OBSDICT contains the dictionary, where Obs or other structures have been replaced by ' + '' + reps + '[0-9]+. The field description contains the additional description of this JSON file. ' + 'This file may be parsed to a dict with the pyerrors routine load_json_dict.') + + desc_dict = {'INFO': infostring, 'OBSDICT': {}, 'description': description} + ol, desc_dict['OBSDICT'] = _ol_from_dict(od, reps=reps) + + dump_to_json(ol, fname, description=desc_dict, indent=indent, gz=gz) ++ + +Export a dict of Obs or structures containing Obs to a .json(.gz) file
+ +Parameters
+ ++
+- od (dict): +Dict of JSON valid structures and objects that will be exported. +At the moment, these objects can be either of: Obs, list, numpy.ndarray, Corr. +All Obs inside a structure have to be defined on the same set of configurations.
+- fname (str): +Filename of the output file.
+- description (str): +Optional string that describes the contents of the json file.
+- indent (int): +Specify the indentation level of the json file. None or 0 is permissible and +saves disk space.
+- reps (str): +Specify the structure of the placeholder in exported dict to be reps[0-9]+.
+- gz (bool): +If True, the output is a gzipped json. If False, the output is a json file.
++ #   + + + def + load_json_dict(fname, verbose=True, gz=True, full_output=False, reps='DICTOBS'): ++ +++ +View Source
++ +def load_json_dict(fname, verbose=True, gz=True, full_output=False, reps='DICTOBS'): + """Import a dict of Obs or structures containing Obs from a .json(.gz) file. + + The following structures are supported: Obs, list, numpy.ndarray, Corr + + Parameters + ---------- + fname : str + Filename of the input file. + verbose : bool + Print additional information that was written to the file. + gz : bool + If True, assumes that data is gzipped. If False, assumes JSON file. + full_output : bool + If True, a dict containing auxiliary information and the data is returned. + If False, only the data is returned. + reps : str + Specify the structure of the placeholder in imported dict to be reps[0-9]+. + """ + indata = load_json(fname, verbose=verbose, gz=gz, full_output=True) + description = indata['description']['description'] + indict = indata['description']['OBSDICT'] + ol = indata['obsdata'] + od = _od_from_list_and_dict(ol, indict, reps=reps) + + if full_output: + indata['description'] = description + indata['obsdata'] = od + return indata + else: + return od ++ +Import a dict of Obs or structures containing Obs from a .json(.gz) file.
+ +The following structures are supported: Obs, list, numpy.ndarray, Corr
+ +Parameters
+ ++
+- fname (str): +Filename of the input file.
+- verbose (bool): +Print additional information that was written to the file.
+- gz (bool): +If True, assumes that data is gzipped. If False, assumes JSON file.
+- full_output (bool): +If True, a dict containing auxiliary information and the data is returned. +If False, only the data is returned.
+- reps (str): +Specify the structure of the placeholder in imported dict to be reps[0-9]+.
+