:py:mod:`mlair.helpers.helpers` =============================== .. py:module:: mlair.helpers.helpers .. autoapi-nested-parse:: Collection of different help functions. Module Contents --------------- Functions ~~~~~~~~~ .. autoapisummary:: mlair.helpers.helpers.unpack mlair.helpers.helpers.make_keras_pickable mlair.helpers.helpers.to_list mlair.helpers.helpers.sort_like mlair.helpers.helpers.dict_to_xarray mlair.helpers.helpers.float_round mlair.helpers.helpers.relative_round mlair.helpers.helpers.get_order mlair.helpers.helpers.remove_items mlair.helpers.helpers.select_from_dict mlair.helpers.helpers.extract_value mlair.helpers.helpers.is_xarray mlair.helpers.helpers.convert2xrda mlair.helpers.helpers.filter_dict_by_value mlair.helpers.helpers.str2bool mlair.helpers.helpers.squeeze_coords Attributes ~~~~~~~~~~ .. autoapisummary:: mlair.helpers.helpers.__author__ mlair.helpers.helpers.__date__ .. py:data:: __author__ :annotation: = Lukas Leufen, Felix Kleinert .. py:data:: __date__ :annotation: = 2019-10-21 .. py:function:: unpack(model, training_config, weights) .. py:function:: make_keras_pickable() .. py:function:: to_list(obj: Any) -> List Transform given object to list if obj is not already a list. Sets are also transformed to a list. :param obj: object to transform to list :return: list containing obj, or obj itself (if obj was already a list) .. py:function:: sort_like(list_obj: list, sorted_obj: list) Sort elements of list_obj as ordered in sorted_obj. Length of sorted_obj as allowed to be higher than length of list_obj, but must contain at least all objects of list_obj. Will raise AssertionError, if not all elements of list_obj are also in sorted_obj. Also it is required for list_obj and sorted_obj to have only unique elements. :param list_obj: list to sort :param sorted_obj: list to use ordering from :return: sorted list .. py:function:: dict_to_xarray(d: Dict, coordinate_name: str) -> xarray.DataArray Convert a dictionary of 2D-xarrays to single 3D-xarray. The name of new coordinate axis follows . :param d: dictionary with 2D-xarrays :param coordinate_name: name of the new created axis (2D -> 3D) :return: combined xarray .. py:function:: float_round(number: float, decimals: int = 0, round_type: Callable = math.ceil) -> float Perform given rounding operation on number with the precision of decimals. :param number: the number to round :param decimals: numbers of decimals of the rounding operations (default 0 -> round to next integer value) :param round_type: the actual rounding operation. Can be any callable function like math.ceil, math.floor or python built-in round operation. :return: rounded number with desired precision .. py:function:: relative_round(x: float, sig: int, ceil=False, floor=False) -> float Round small numbers according to given "significance". Example: relative_round(0.03112, 2) -> 0.031, relative_round(0.03112, 1) -> 0.03 :params x: number to round :params sig: "significance" to determine number of decimals :return: rounded number .. py:function:: get_order(x: float) Get order of number (as power of 10) .. py:function:: remove_items(obj: Union[List, Dict, Tuple], items: Any) Remove item(s) from either list, tuple or dictionary. :param obj: object to remove items from (either dictionary or list) :param items: elements to remove from obj. Can either be a list or single entry / key :return: object without items .. py:function:: select_from_dict(dict_obj: dict, sel_list: Any, remove_none: bool = False, filter_cond: bool = True) -> dict Extract all key values pairs whose key is contained in the sel_list. Does not perform a check if all elements of sel_list are keys of dict_obj. Therefore, the number of pairs in the returned dict is always smaller or equal to the number of elements in the sel_list. If `filter_cond` is given, this method either return the parts of the input dictionary that are included or not in `sel_list`. .. py:function:: extract_value(encapsulated_value) .. py:function:: is_xarray(arr) -> bool Returns True if arr is xarray.DataArray or xarray.Dataset. :param arr: variable in question :type arr: Any :return: :rtype: bool .. py:function:: convert2xrda(arr: Union[xarray.DataArray, xarray.Dataset, numpy.ndarray, int, float], use_1d_default: bool = False, **kwargs) -> Union[xarray.DataArray, xarray.Dataset] Converts np.array, int or float object to xarray.DataArray. If a xarray.DataArray or xarray.Dataset is passed, returns that unchanged. :param arr: :type arr: xr.DataArray, xr.Dataset, np.ndarray, int, float :param use_1d_default: :type use_1d_default: bool :param kwargs: Any additional kwargs which are accepted by xr.DataArray() :type kwargs: :return: :rtype: xr.DataArray, xr.DataSet .. py:function:: filter_dict_by_value(dictionary: dict, filter_val: Any, filter_cond: bool) -> dict Filter dictionary by its values. :param dictionary: dict to filter :param filter_val: search only for key value pair with a value equal to filter_val :param filter_cond: indicate to use either all dict entries that fulfil the filter_val criteria (if `True`) or that do not match the criteria (if `False`) :returns: a filtered dict with either matching or non-matching elements depending on the `filter_cond` .. py:function:: str2bool(v) .. py:function:: squeeze_coords(d) Look for unused coords and remove them. Does only work for xarray DataArrays.