Miscellany utils

Log messages

Show error and log messages.

misc_utils.log_messages.error(msg)
misc_utils.log_messages.log(msg)
misc_utils.log_messages.setLevel(level)
misc_utils.log_messages.to_file(fName)
misc_utils.log_messages.warning(msg)

Pickle utils

class misc_utils.pickle_utils.interp1dPicklable(xi, yi, **kwargs)

Bases: object

class wrapper for piecewise linear function

Staircase function

class misc_utils.staircase_function.StairCaseFunction(xi, vi, leftDefaultValue=0.0, rightDefaultValue=0.0)

Bases: object

Function defined as a series of constant values in consecutive intervals

Data structures utils

String manipulation utilities.

misc_utils.data_struct_utils.atoi(text)
misc_utils.data_struct_utils.get_closest_inlist(lst, value)

Return the number in a list that is the closest to the target value.

Parameters
  • lst – list of numbers

  • value – target value.

misc_utils.data_struct_utils.get_encoding(input_str)

Return the encoding of the the string argument.

misc_utils.data_struct_utils.get_index_closest_inlist(lst, value)

Return the index in a list that matches the closest element to the target value.

Parameters
  • lst – list of numbers.

  • value – target value.

misc_utils.data_struct_utils.get_max_lstOfLsts_by_col(lstOfLsts, col)

Return the maximun value of column ‘col’ in the list of lists ‘lstOfLsts’ (first column in list is col=0)

misc_utils.data_struct_utils.get_min_lstOfLsts_by_col(lstOfLsts, col)

Return the minimum value of column ‘col’ in the list of lists ‘lstOfLsts’ (first column in list is col=0)

misc_utils.data_struct_utils.get_number_decimal_positions(number)

Return the number of decimal positions in the number given as parameter

misc_utils.data_struct_utils.is_ascii(input_str)

Return true if the argument is an ascii string.

misc_utils.data_struct_utils.natural_keys(text)

alist.sort(key=natural_keys) sorts in human order http://nedbatchelder.com/blog/200712/human_sorting.html (See Toothy’s implementation in the comments)

misc_utils.data_struct_utils.remove_accents(input_str)

Remove the accents from the string argument.

Parameters

input_str – string to remove accents from.

misc_utils.data_struct_utils.remove_close_values(lst, tolerance)

Remove close values in a list with the specified tolerance

misc_utils.data_struct_utils.remove_duplicates_list(lst)

Return a list from lst without items duplicated

misc_utils.data_struct_utils.slugify(s)

Simplifies ugly strings into something URL-friendly. >>> print(slugify(“[Some] _ Article’s Title–“)) some-articles-title

misc_utils.data_struct_utils.sort_human(l)
misc_utils.data_struct_utils.sort_two_parallel_lists(list1, list2)

Returns list1 sorted and list2 sorted in parallel to list1. e.g.: for list1=[3,5,1,7] and

list2=[2, 4, 6, 8]

returns:

sorted_list1=[1, 3, 5, 7] sorted_list2=[6, 2, 4, 8]

misc_utils.data_struct_utils.to_unicode(input_str)

Return a unicode string from the input.

Parameters

input_str – input string.

Unit utils

misc_utils.units_utils.convert_inches(n)

Return (feet,inches,inches’ fraction) equivalent to number n of inches given as parameter, where n is a real number.

misc_utils.units_utils.feet_and_inches(n)
misc_utils.units_utils.roundLst(lst, decpl)

return a list with the values of ‘lst’ rounded to ‘decpl’ decimal places

misc_utils.units_utils.show_inches(inches, fractions)

Pretty printing of (inches,fractions) given as parameter