pyuncertainnumber.characterisation.utils ======================================== .. py:module:: pyuncertainnumber.characterisation.utils Classes ------- .. autoapisummary:: pyuncertainnumber.characterisation.utils.EnhancedJSONEncoder pyuncertainnumber.characterisation.utils.PBAEncoder pyuncertainnumber.characterisation.utils.UNEncoder Functions --------- .. autoapisummary:: pyuncertainnumber.characterisation.utils.save2Vis pyuncertainnumber.characterisation.utils.tranform_ecdf pyuncertainnumber.characterisation.utils.pl_pcdf pyuncertainnumber.characterisation.utils.pl_ecdf pyuncertainnumber.characterisation.utils.to_database pyuncertainnumber.characterisation.utils.cd_root_dir pyuncertainnumber.characterisation.utils.sgnumber pyuncertainnumber.characterisation.utils.initial_list_checking pyuncertainnumber.characterisation.utils.bad_list_checking pyuncertainnumber.characterisation.utils.PlusMinus_parser pyuncertainnumber.characterisation.utils.parser4 pyuncertainnumber.characterisation.utils.percentage_finder pyuncertainnumber.characterisation.utils.percentage_converter pyuncertainnumber.characterisation.utils.get_concise_repr pyuncertainnumber.characterisation.utils.array2list pyuncertainnumber.characterisation.utils.entries_to_remove Module Contents --------------- .. py:function:: save2Vis(figname) a shortcut function to save plot to visualization dir .. note:: We simply assume that every repo will have a 'visulizations' dir under the root directory .. py:function:: tranform_ecdf(s, display=False, **kwargs) plot the CDF return the quantile :param s: sample .. py:function:: pl_pcdf(dist: type[scipy.stats.rv_continuous | scipy.stats.rv_discrete], ax=None, title=None, **kwargs) .. py:function:: pl_ecdf(s, ax=None, return_value=False, **kwargs) plot the empirical CDF given samples :param s: sample which can be either raw data or deviates as a representation of dist construct :type s: array-like .. py:function:: to_database(dict_list, db_name, col_name) .. py:function:: cd_root_dir(depth=0) .. py:function:: sgnumber(user_input: str) -> list significant digits representation number plus or minus its significant-digit imprecision .. py:function:: initial_list_checking(text) detects if a string representation of a list .. py:function:: bad_list_checking(text) detects if a syntactically wrong specification of a list .. py:function:: PlusMinus_parser(txt) .. py:function:: parser4(text) .. py:function:: percentage_finder(txt) .. py:function:: percentage_converter(txt) convert a percentage into a float number .. note:: force only 1 percentage .. py:class:: EnhancedJSONEncoder(*, 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` a template for jsonify general (dataclass) object #TODO Interval object in not json serializable .. py:method:: default(o) Implement this method in a subclass such that it returns a serializable object for ``o``, or calls the base implementation (to raise a ``TypeError``). For example, to support arbitrary iterators, you could implement default like this:: def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return super().default(o) .. py:class:: PBAEncoder(*, 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` a bespoke JSON encoder for the PBA object .. py:method:: default(o) Implement this method in a subclass such that it returns a serializable object for ``o``, or calls the base implementation (to raise a ``TypeError``). For example, to support arbitrary iterators, you could implement default like this:: def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return super().default(o) .. py:class:: UNEncoder(*, 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` a bespoke JSON encoder for the UncertainNumber object .. note:: - Currently I'm treating the JSON data represent of a UN object the same as the __repr__ method. But this can be changed later on to show more explicitly the strucutre of pbox or distribution # TODO prettify the JSON output to be explicit e.g. 'essence': 'interval', 'interval_initialisation': [2, 3] to shown as 'interval' with lower end and upper end distribution to shown as the type and parameters; e.g. 'distribution': 'normal', 'parameters': [2, 3] .. py:method:: default(o) Implement this method in a subclass such that it returns a serializable object for ``o``, or calls the base implementation (to raise a ``TypeError``). For example, to support arbitrary iterators, you could implement default like this:: def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return super().default(o) .. py:function:: get_concise_repr(a_dict) .. py:function:: array2list(a_dict) convert an array from a dictionary into a list .. py:function:: entries_to_remove(remove_entries, the_dict)