graphnet.data.extractors.icecube.utilities.collections module

Utility methods for manipulating python-type collections of data.

graphnet.data.extractors.icecube.utilities.collections.flatten_nested_dictionary(obj, parent_key, separator)[source]

Flatten a nested dictionary to a dictionary with non-dict values.

Example

d = {“a”: {“b”: 1}, “c”: 2} flatten_nested_dictionary(d) >>> {“a__b”: 1, “c”: 2}

Parameters:
  • obj (Union[Dict, Any]) – The object that should be flattened, if applicable.

  • parent_key (str, default: '') – The combined name of the parent key(s) containing obj.

  • separator (str, default: '__') – The string used to concatenate nester parent keys.

Return type:

Union[Dict, Any]

graphnet.data.extractors.icecube.utilities.collections.serialise(obj)[source]

Serialise the necessary keys in obj to JSON for saving to file.

It is typically not possible to save nested collections (lists, dicts) to file. Therefore, if obj is, e.g., a list of lists, we need to serialise each element in the outer list to JSON (i.e., convert it to a JSON- formatted string) in order to be able to save obj to file. It will then be possible to de-serialise corresponding elements when reading them from file.

Return type:

Union[Dict, Any]

Parameters:

obj (Dict | Any)

graphnet.data.extractors.icecube.utilities.collections.transpose_list_of_dicts(array)[source]

Transpose a list of dicts to a dict of lists.

Return type:

Dict[str, List[Any]]

Parameters:

array (List[Dict[str, Any]])