:py:mod:`nessai.utils.io` ========================= .. py:module:: nessai.utils.io .. autoapi-nested-parse:: Utilities related to loading files, saving files etc. .. !! processed by numpydoc !! Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: nessai.utils.io.NessaiJSONEncoder Functions ~~~~~~~~~ .. autoapisummary:: nessai.utils.io.is_jsonable nessai.utils.io.safe_file_dump nessai.utils.io.save_live_points .. py:function:: is_jsonable(x) Check if an object is JSON serialisable. Based on: https://stackoverflow.com/a/53112659 :Parameters: **x** : obj Object to check :Returns: bool Boolean that indicates if the object is JSON serialisable. .. !! processed by numpydoc !! .. py:class:: NessaiJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None) Bases: :py:obj:`json.JSONEncoder` Class to encode numpy arrays and other non-serialisable objects. Based on: https://stackoverflow.com/a/57915246. .. rubric:: Examples This class should be used in the ``cls`` argument:: with open(filename, 'w') as wf: json.dump(d, wf, indent=4, cls=NessaiJSONEncoder) .. !! processed by numpydoc !! .. py:method:: default(self, obj) Method that returns a serialisable object .. !! processed by numpydoc !! .. py:function:: safe_file_dump(data, filename, module, save_existing=False) Safely dump data to a .pickle file. See Bilby for the original impletmentation: https://git.ligo.org/michael.williams/bilby/-/blob/master/bilby/core/utils.py :Parameters: **data** Data to dump. **filename** : str The file to dump to. **module** : {pickle, dill} The python module to use. **save_existing** : bool, optional If true move the existing file to .old. .. !! processed by numpydoc !! .. py:function:: save_live_points(live_points, filename) Save live points to a file using JSON. Live points are converted to a dictionary and then saved. :Parameters: **live_points** : ndarray Live points to save. **filename** : str File to save to. .. !! processed by numpydoc !!