Muscat.Containers.Tags module¶
- class Tag(tagname)[source]¶
Bases:
object
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) None [source]¶
Add id or ids to the list of tags more memory is allocated if needed
- Parameters:
tid (MuscatIndex 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, unique=False)[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
unique (bool) – if unique is True then the input is assumed to have no double entries
- UnFrozen()¶
- class Tags[source]¶
Bases:
object
Storage to hold many 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, an Exception is raised
- DeleteTags(tagNames: List[str])[source]¶
Ensure that tags with the names in the tagNames are deleted
- Parameters:
tagNames (str or List[str]) – tagname of a List of tagNames
- Merge(other: Tags)[source]¶
Merge the other tags into this
- Parameters:
other (Tags) – _description_, by default None
- 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
- View() Tags [source]¶
return a copy of this object recursively, numpy arrays are view to the original ones but with the flags.writeable = False
- Returns:
a view of Tags
- Return type: