IdMap¶
-
class
bosaris.
IdMap
(idmap_filename='')[source]¶ A class that stores a map between identifiers (strings). One list is called ‘leftids’ and the other ‘rightids’. The class provides methods that convert a sequence of left ids to a sequence of right ids and vice versa. If leftids or rightids contains duplicates then all occurrences are used as the index when mapping.
- Attr leftids
a list of classes in a ndarray
- Attr rightids
a list of segments in a ndarray
- Attr start
index of the first frame of the segment
- Attr stop
index of the last frame of the segment
-
filter_on_left
(idlist, keep)[source]¶ Removes some of the information in an idmap. Depending on the value of ‘keep’, the idlist indicates the strings to retain or the strings to discard.
- Parameters
idlist – an array of strings which will be compared with the leftids of the current.
keep – A boolean indicating whether idlist contains the ids to keep or to discard.
- Returns
a filtered version of the current IdMap.
-
filter_on_right
(idlist, keep)[source]¶ Removes some of the information in an idmap. Depending on the value of ‘keep’, the idlist indicates the strings to retain or the strings to discard.
- Parameters
idlist – an array of strings which will be compared with the rightids of the current IdMap.
keep – a boolean indicating whether idlist contains the ids to keep or to discard.
- Returns
a filtered version of the current IdMap.
-
map_left_to_right
(leftidlist)[source]¶ Maps an array of ids to a new array of ids using the given map. The input ids are matched against the leftids of the map and the output ids are taken from the corresponding rightids of the map.
Beware: if leftids are not unique in the IdMap, only the last value corresponding is kept
- Parameters
leftidlist – an array of strings to be matched against the leftids of the idmap. The rightids corresponding to these leftids will be returned.
- Returns
an array of strings that are the mappings of the strings in leftidlist.
-
map_right_to_left
(rightidlist)[source]¶ Maps an array of ids to a new array of ids using the given map. The input ids are matched against the rightids of the map and the output ids are taken from the corresponding leftids of the map.
Beware: if rightids are not unique in the IdMap, only the last value corresponding is kept
- Parameters
rightidlist – An array of strings to be matched against the rightids of the idmap. The leftids corresponding to these rightids will be returned.
- Returns
an array of strings that are the mappings of the strings in rightidlist.
-
merge
(idmap2)[source]¶ Merges the current IdMap with another IdMap or a list of IdMap objects..
- Parameters
idmap2 – Another Id_Map object.
- Returns
an Id_Map object that contains the information from the two input Id_Maps.
-
static
read
(input_file_name)[source]¶ Read IdMap in hdf5 format.
- Parameters
input_file_name – name of the file to read from