universal_devkit.utils package

Submodules

universal_devkit.utils.utils module

universal_devkit.utils.utils.convert_list_to_dict(data_list: list, using_key: str)[source]

Converts a list of dictionaries to a dictionary using the value of a specific key in each object as the indentifier

Parameters
  • data_list (list) – the list of dictionaries

  • using_key (str) – the key to use to identify each dictionary

Returns

a dictionary form of the list

Return type

dict

universal_devkit.utils.utils.create_token()[source]

Generates a 32 character unique identifier

Returns

unique identifier

Return type

str

universal_devkit.utils.utils.get_all_non_hidden_files(data_directory, exclude=[])[source]
universal_devkit.utils.utils.get_closest_match(sorted_list, query_number)[source]

Source: https://stackoverflow.com/a/12141511

Parameters: - sorted_list: a sorted list of numbers to search through - query_number: the number to search for

Returns: The closest value in sorted_list to query_number. If two numbers are equally close, return the smallest number.

universal_devkit.utils.utils.get_existing_token(data_list, json_path, match_key, token_key)[source]

Takes a list of dictionaries and tries to assign the [token_key] value passed on matching existing data in the JSON file using the [match_key].

For example, you can use this to find the sensor tokens to use for the calibrated sensor data.

Parameters
  • data_list (list(dict)) – list of dictionaries to add the keys to. Will modify this list

  • json_path (str) – path to the JSON file

  • match_key (str) – the key to use to match up values

  • token_key (str) – the key the matched token should be stored to

Returns

updated list of dictionaries

Return type

list(dict)

universal_devkit.utils.utils.get_file_extension(file_path: str)[source]

Gets the extension of a file.

Example:

>>> get_file_stem_name("/home/user/Downloads/repo/test.txt")
"txt"
Parameters

file_path (str) – the path to extract the extension from

Returns

the extension of the file

Return type

str

universal_devkit.utils.utils.get_file_stem_name(file_path: str)[source]

Gets the stem of a file path.

Example:

>>> get_file_stem_name("/home/user/Downloads/repo/test.txt")
"test"
Parameters

file_path (str) – the path to extract the stem from

Returns

the stem of the file

Return type

str

universal_devkit.utils.utils.get_full_path_to_file(root_data_dir: str, relative_file_path: str)[source]

Gets the path to a file given the path to the root data directory and a path relative to the root of the data directory

Parameters
  • root_data_dir (str) – the path to the root directory of the dataset

  • relative_file_path (str) – a path relative to the root directory of the dataset

Returns

the full path to the file

Return type

str

universal_devkit.utils.utils.get_immediate_directories(directory_path)[source]

Gets the immediate sub-directories within a directory

Parameters

directory_path (str) – path to the directory

Returns

list of sub-directories

Return type

list(str)

universal_devkit.utils.utils.get_timestamp(imu_dict)[source]

The timestamp of a message does not necessarily equal the timestamp in the message’s header. The header timestamp is more accurate and the timestamp of the message just corresponds to whenever the bag received the message and saved it.

Parameters

imu_dict (dict) – dictionary of a single IMU reading

Returns

a string timestamp to use for this IMU message. Uses the header timestamp

Return type

str

universal_devkit.utils.utils.merge_json_lists(path_a, path_b)[source]

Merge two JSON files with lists

Parameters
  • path_a (str) – path to JSON file A

  • path_b (str) – path to JSON file B

Returns

list of data with B’s data added to the end of A

Return type

list

universal_devkit.utils.utils.read_json(path)[source]

Loads a dictionary from a JSON file

Parameters

path (str) – path to a JSON file

Returns

dictionary loaded from JSON

Return type

dict

universal_devkit.utils.utils.remove_key_from_dicts(data_list, key)[source]

Remove a certain key from a list of dictionaries

Parameters
  • data_list (list(dict)) – list of dictionaries. This will get modified

  • key (str) – string to remove

universal_devkit.utils.utils.write_json(data, path)[source]

Writes data to a JSON file

Parameters
  • data (any) – data to write

  • path (str) – path to save the JSON file to

Module contents

universal_devkit.utils.create_token()[source]

Generates a 32 character unique identifier

Returns

unique identifier

Return type

str

universal_devkit.utils.read_json(path)[source]

Loads a dictionary from a JSON file

Parameters

path (str) – path to a JSON file

Returns

dictionary loaded from JSON

Return type

dict