General Helper Functions

class aurora.general_helper_functions.DotDict[source]

Bases: dict

Helper function for debugging, casts a dict so that its values can be accessed via dict.key as well as dict[“key”]

Usage: dot_dict = DotDict(basic_dict)

Methods

clear()

copy()

fromkeys(iterable[, value])

Create a new dictionary with keys from iterable and values set to value.

get(key[, default])

Return the value for key if key is in the dictionary, else default.

items()

keys()

pop(k[,d])

If key is not found, d is returned if given, otherwise KeyError is raised

popitem(/)

Remove and return a (key, value) pair as a 2-tuple.

setdefault(key[, default])

Insert key with a value of default if key is not in the dictionary.

update([E, ]**F)

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()

aurora.general_helper_functions.count_lines(file_name)[source]

acts like wc -l in unix, raise FileNotFoundError: if file_name does not exist.

Parameters:

file_name (str or pathlib.Path) – The file to apply line counting to

Returns:

num_lines – Number of lines present in fileName or -1 if file does not exist

Return type:

int

aurora.general_helper_functions.execute_command(cmd, **kwargs)[source]

Executes command in terminal from script.

Parameters:
  • cmd (str) – command to exectute from a terminal

  • kwargs – exec_dir (str): the directory from which to execute

  • kwargs – no_exception: suppress output if exception

  • exit_status0 is good, otherwise there is some problem

Note

When executing rm * this crashes if the directory we are removing from is empty

Note

if you can you should probably use execute_subprocess() instead

aurora.general_helper_functions.execute_subprocess(cmd, **kwargs)[source]
Parameters:
  • cmd (string) – command as it would be typed in a terminal

  • kwargs

aurora.general_helper_functions.get_test_path()[source]
aurora.general_helper_functions.save_to_mat(data, variable_name, filename)[source]

Example Usage: x = X.to_array(dim=”channel”) save_to_mat(x.data, “x”, “x.mat”)

Reading into matlab or Octave: tmp = load(“x.mat”); data = tmp.x;

Parameters:
  • data (numpy array) – the data to save to file. its fine if this is complex-valued.

  • variable_name (string) – The name that we use to reference the variable within the struct in the matfile.

  • filename (string) – The filepath to output