BasicTools.Containers.Tags module

BasicTools.Containers.Tags.CheckIntegrity()[source]
class BasicTools.Containers.Tags.Tag(tagname)[source]

Bases: BaseOutputObject

A 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

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:

Tag

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

Merge(other: Tag)[source]

Merge the other tag into this

Parameters:
  • other (Tag, optional) – _description_, by default None

  • ids (np.typing.ArrayLike, optional) – _description_, by default None

RemoveDoubles()[source]

Remove doubles and release non used memory

SetId(pos: int, idd: int)[source]

set the value of the id in the position pos

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

Parameters:

ids (ArrayLike) – the list of ids

Tighten()[source]

Release non used memory

class BasicTools.Containers.Tags.Tags[source]

Bases: BaseOutputObject

Storage to hold tag : It has a Dict like interface Propagate some function to every tag Functions to create and delete tag

AddTag(item: Tag) Tag[source]

Add a tag to the container

Parameters:

item (Tag) – The tag to be added, this tag must contain a unique name

Returns:

the Tag added

Return type:

Tag

Raises:

Exception – if a tag with the same name exist already

Copy() Tags[source]

Make a new copy of the tag containers.

Returns:

A copy containing copies of each tag.

Return type:

Tags

CreateTag(name: str, errorIfAlreadyCreated: Optional[bool] = 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:

Tag

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

RemoveDoubles()[source]

Call Tag.RemoveDoubles on every tag

RemoveEmptyTags()[source]

Remove empty tag

RenameTag(name: str, newName: str, noError: Optional[bool] = 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

Tighten()[source]

Call Tag.Tighten on every tag

items() Iterable[Tuple[str, Tag]][source]

Dict API

Returns:

_description_

Return type:

Iterable[Tuple[str,Tag]]

keys()[source]

Dict API, the keys are the names