crrlpy.utils module

Some utilities for python.

crrlpy.utils.alphanum_key(s)[source]

Turn a string into a list of string and number chunks.

Parameters:

s – String

Returns:

List with strings and integers.

Return type:

list

Example:

>>> alphanum_key('z23a')
['z', 23, 'a']
crrlpy.utils.best_match_indx(value, array)[source]

Searchs for the index of the closest entry to value inside an array.

Parameters:
  • value (float) – Value to find inside the array.

  • array (list or numpy.array) – List to search for the given value.

Returns:

Best match index for the value inside array.

Return type:

float

Example:

>>> a = [1,2,3,4]
>>> best_match_indx(3, a)
2
crrlpy.utils.best_match_indx_tol(value, array, tol)[source]

Searchs for the best match to a value inside an array given a tolerance.

Parameters:
  • value (float) – Value to find inside the array.

  • tol (float) – Tolerance for match.

  • array (numpy.array) – List to search for the given value.

Returns:

Best match for val inside array.

Return type:

float

crrlpy.utils.best_match_value(value, array)[source]

Searchs for the closest ocurrence of value in array.

Parameters:
  • value (float) – Value to find inside the array.

  • array (list or numpy.array) – List to search for the given value.

Returns:

Best match for the value inside array.

Return type:

float.

Example:

>>> a = [1,2,3,4]
>>> best_match_value(3.5, a)
3
crrlpy.utils.factors(n)[source]

Decomposes a number into its factors. :param n: Number to decompose. :type n: int :return: List of values into which n can be decomposed. :rtype: list

crrlpy.utils.flatten_list(list)[source]
crrlpy.utils.get_max_sep(array)[source]

Get the maximum element separation in an array.

Parameters:
arrayarray

Array where the maximum separation is wanted.

Returns:
max_sepfloat

The maximum separation between the elements in array.

Examples

>>> import numpy as np
>>> x = np.array([1,2,3,4,5,7])
>>> get_max_sep(x)
2
crrlpy.utils.get_min_sep(array)[source]

Get the minimum element separation in an array.

Parameters:
arrayarray

Array where the minimum separation is wanted.

Returns:
max_sepfloat

The minimum separation between the elements in array.

Examples

>>> import numpy as np
>>> x = np.array([1,2,3,4,5,7])
>>> get_min_sep(x)
1
crrlpy.utils.myround(x, base=5)[source]
crrlpy.utils.natural_sort(list)[source]

Sort the given list in the way that humans expect. Sorting is done in place.

Parameters:

list (list) – List to sort.

Example:

>>> my_list = ['spec_3', 'spec_4', 'spec_1']
>>> natural_sort(my_list)
>>> my_list
['spec_1', 'spec_3', 'spec_4']
crrlpy.utils.path_leaf(path)[source]

Taken from: https://stackoverflow.com/questions/8384737/extract-file-name-from-path-no-matter-what-the-os-path-format

crrlpy.utils.pow_notation(number, sig_fig=2)[source]

Converts a number to scientific notation keeping sig_fig signitifcant figures.

crrlpy.utils.sci_notation(number, sig_fig=2)[source]

Converts a number to scientific notation keeping sig_fig signitifcant figures.

crrlpy.utils.str2bool(str)[source]

Converts a string to a boolean value. The conversion is case insensitive.

Parameters:

str (string) – string to convert.

Returns:

True if str is one of: “yes”, “y”, “true”, “t” or “1”.

Return type:

bool

crrlpy.utils.text_slope_match_line(text, x, y, line, dindx=1)[source]
crrlpy.utils.tryint(str)[source]

Returns an integer if str can be represented as one.

Parameters:

str (string) – String to check.

Returns:

True is str can be cast to an int.

Return type:

int

crrlpy.utils.update_text_slopes()[source]