-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
30 lines (25 loc) · 799 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""Common utility functions
"""
import os
import sys
import matplotlib as mpl
import matplotlib.pyplot as plt
if sys.version <= "3.7":
try:
from collections.abc import OrderedDict
except ImportError:
from collections import OrderedDict
else:
OrderedDict = dict
def obj_attr_cat_to_int(objects:OrderedDict, category:str) -> OrderedDict:
"""Map objects' categorical attributes to int
:param objects: all objects to be processed
:param category: category keyword in attributes
:param: a map from category keyword to int
"""
categories = [objects[_id][category] for _id in objects]
int_map = OrderedDict.fromkeys(categories)
# fill in color id by enumeration
for i, c in enumerate(int_map):
int_map[c] = i
return int_map