Base
parse_int_list(value, format_func=lambda x: str(x), all_values=None)
Takes in a value or list of values e.g. [1, 2, 3] and converts it into a list of strings where
each string has the format given by format_func e.g. ['1', '2', '3'] for the default case.
There are three string options for value:
value='x:y', will return all integers betweenxandyinclusive.value='firstX'will return first X values ofall_values.value='firstY'will return first Y values ofall_values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Union[str, int, List]
|
Variable to convert into list of strings |
required |
format_func
|
Callable
|
How to format each integer within the string. |
lambda x: str(x)
|
all_values
|
Optional[List]
|
List of all possible integers, must be provided if |
None
|
Returns:
| Type | Description |
|---|---|
List
|
List, where each integer in |
Source code in climdyn_tools/utils/base.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
round_any(x, base, round_type='round')
Rounds x to the nearest multiple of base with the rounding done according to round_type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Union[float, ndarray]
|
Number or array to round. |
required |
base
|
float
|
Rounds |
required |
round_type
|
str
|
One of the following, indicating how to round
|
'round'
|
Returns:
| Type | Description |
|---|---|
Union[float, ndarray]
|
Rounded version of |
Example
round_any(3, 5) = 5
round_any(3, 5, 'floor') = 0
Source code in climdyn_tools/utils/base.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
split_list_max_n(lst, n)
Split lst into balanced chunks with at most n elements each.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lst
|
Union[List, ndarray]
|
List to split. |
required |
n
|
int
|
Maximum number of elements in each chunk of |
required |
Returns:
| Type | Description |
|---|---|
List
|
List of |
Source code in climdyn_tools/utils/base.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 | |