bencher.utils
Module Contents
Functions
|
From a dictionary of kwargs, return a hashable representation (tuple) that is always the same for the same inputs and retains the order of the input arguments. e.g, {x=1,y=2} -> (1,2) and {y=2,x=1} -> (1,2). This is used so that keywords arguments can be hashed and converted the the tuple keys that are used for holomaps |
|
Convenience method for making a named tuple |
|
Given an xarray dataset and kwargs of key value pairs of coordinate values, return a dictionary of the nearest coordinate name value pair that was found in the dataset |
|
|
|
A hash function that avoids the PYTHONHASHSEED 'feature' which returns a different hash value each time the program is run |
|
Given a string of lowercase words, capitalise them |
|
Given a snake_case string return a CamelCase string |
|
Uses the golden angle to generate colors programmatically with minimum overlap between colors. |
|
|
|
|
|
|
|
|
|
|
|
|
|
Take an object and turn it into a list if its not already a list |
|
|
|
- bencher.utils.hmap_canonical_input(dic: dict) tuple
From a dictionary of kwargs, return a hashable representation (tuple) that is always the same for the same inputs and retains the order of the input arguments. e.g, {x=1,y=2} -> (1,2) and {y=2,x=1} -> (1,2). This is used so that keywords arguments can be hashed and converted the the tuple keys that are used for holomaps
- Parameters:
dic (dict) – dictionary with keyword arguments and values in any order
- Returns:
values of the dictionary always in the same order and hashable
- Return type:
tuple
- bencher.utils.make_namedtuple(class_name: str, **fields) collections.namedtuple
Convenience method for making a named tuple
- Parameters:
class_name (str) – name of the named tuple
- Returns:
a named tuple with the fields as values
- Return type:
namedtuple
- bencher.utils.get_nearest_coords(dataset: xarray.Dataset, collapse_list=False, **kwargs) dict
Given an xarray dataset and kwargs of key value pairs of coordinate values, return a dictionary of the nearest coordinate name value pair that was found in the dataset
- Parameters:
ds (xr.Dataset) – dataset
- Returns:
nearest coordinate name value pair that matches the input coordinate name value pairs.
- Return type:
dict
- bencher.utils.get_nearest_coords1D(val: Any, coords) Any
- bencher.utils.hash_sha1(var: any) str
A hash function that avoids the PYTHONHASHSEED ‘feature’ which returns a different hash value each time the program is run
- bencher.utils.capitalise_words(message: str)
Given a string of lowercase words, capitalise them
- Parameters:
message (str) – lower case string
- Returns:
capitalised string
- Return type:
_type_
- bencher.utils.un_camel(camel: str) str
Given a snake_case string return a CamelCase string
- Parameters:
camel (str) – camelcase string
- Returns:
uncamelcased string
- Return type:
str
- bencher.utils.int_to_col(int_val, sat=0.5, val=0.95, alpha=-1) tuple[float, float, float]
Uses the golden angle to generate colors programmatically with minimum overlap between colors. https://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/
- Parameters:
int_val (_type_) – index of an object you want to color, this is mapped to hue in HSV
sat (float, optional) – saturation in HSV. Defaults to 0.5.
val (float, optional) – value in HSV. Defaults to 0.95.
alpha (int, optional) – transparency. If -1 then only RGB is returned, if 0 or greater, RGBA is returned. Defaults to -1.
- Returns:
either RGB or RGBA vector
- Return type:
tuple[float, float, float] | tuple[float, float, float, float]
- bencher.utils.lerp(value, input_low: float, input_high: float, output_low: float, output_high: float)
- bencher.utils.color_tuple_to_css(color: tuple[float, float, float]) str
- bencher.utils.gen_path(filename, folder, suffix)
- bencher.utils.gen_video_path(video_name: str = 'vid', extension: str = '.webm') str
- bencher.utils.gen_image_path(image_name: str = 'img', filetype='.png') str
- bencher.utils.callable_name(any_callable: Callable[Ellipsis, Any]) str
- bencher.utils.listify(obj) list
Take an object and turn it into a list if its not already a list
- bencher.utils.get_name(var)
- bencher.utils.params_to_str(param_list: List[param.Parameter])