BasicTools.Containers.Tags module
- class BasicTools.Containers.Tags.Tag(tagname)[source]
Bases:
BaseOutputObjectA Tag is an object to store a name and ids. internals it has a buffer to easily fill the content incrementally.
- AddToTag(tid: int | Collection)[source]
Add id or ids to the list of tags more memory is allocated if needed
- Parameters:
tid (PBasicIndexType or Iterable) – the id or ids to added to the tag.
- Allocate(allocationSize: int)[source]
Allocate the memory for n objects the user is responsible of filling each individual position. Internally numpy.resize is used.
- Parameters:
l (int) – the number of element to allocate
- Copy() Tag[source]
Create a copy of this Tag
- Returns:
a Tag with the same name and a copy of the ids
- Return type:
- GetIds() np.ndarray[source]
Return the Ids in the tag
- Returns:
_description_
- Return type:
np.ndarray
- GetIdsAsMask(totalNumberOfObjects: int = 0, output: np.ndarray = None, erase: bool = True) np.ndarray[source]
Generate a numpy array of dtype=bool of size totalNumberOfObjects with the indexes of this as True
if output is not None, this array will be uses as output.
- Parameters:
totalNumberOfObjects (int, optional) – total number of Objects to allocate the output This argument is not compatible with the output argument by default None
output (bool, optional) – output array for work in place This argument is not compatible with the totalNumberOfObjects by default None
erase (bool, optional) – set all values to False before working on output, by default True
- Returns:
Array of bool
- Return type:
np.ndarray
- IsFrozen()
- Merge(other: Tag)[source]
Merge the other tag into this
- Parameters:
other (Tag, optional) – _description_, by default None
- SetId(pos: int, idd: int)[source]
Set the value of the id in the position pos. The user is responsible to allocate the memory first
- Parameters:
pos (int) – position
idd (int) – the value
- SetIds(ids: ArrayLike)[source]
Set the ids of this tag, a copy is made and a RemoveDoubles is executed to ensure ids are present only once. old data is lost.
- Parameters:
ids (ArrayLike) – the list of ids
- UnFrozen()
- class BasicTools.Containers.Tags.Tags[source]
Bases:
BaseOutputObjectStorage to hold tag : It has a Dict like interface Propagate some function to every tag Functions to create and delete tag
- Copy() Tags[source]
Make a new copy of the tag containers.
- Returns:
A copy containing copies of each tag.
- Return type:
- CreateTag(name: str, errorIfAlreadyCreated: bool | None = True) Tag[source]
Create a new tag with the name “name” and return it
- Parameters:
name (str) – Name of the tag to be created
errorIfAlreadyCreated (Optional[bool], optional) – If False and a tag with the same name exit, then this tag is returned , by default True
- Returns:
Tag with the name : name
- Return type:
- Raises:
Exception – If errorIfAlreadyCreated is True and the tag already exist, a Exception is raised
- DeleteTags(tagNames: List[str])[source]
Ensure that tags with the names in the tagNames are deleted
- Parameters:
tagNames (List[str]) – List of tagnames
- RenameTag(name: str, newName: str, noError: bool | None = False)[source]
Rename a tag if exist, nonError controls if a exception is raised
- Parameters:
name (str) – Name of the tag to change the name
newName (str) – New name
noError (Optional[bool], optional) – Option to silently do nothing if no tag exist with name “name” , by default False
- Raises:
Exception – if noError is False (default) a Exception is raised if a tag with the name “name” does not exist