collection¶
- class InstanceCollection(*, data=None, cfg=None, validate_on_init=True)¶
Bases:
ConfiguredDataThe base class to represent an unordered collection of instances, possibly from more than one animal.
Implements the
__getitem__and__setitem__methods to provide indexing, slicing, and dictionary-like access to the data.- Parameters:
- classmethod concatenate(*collections, copy_config=False, validate=True)¶
Concatenates multiple collections into a single one.
- Parameters:
- Return type:
Self- Returns:
The concatenated collection.
- Raises:
AssertionError – If no collections are provided, or if the configurations of the collections are not equal when validation is enabled.
ValueError – If the identity types of the collections are not compatible.
- copy(*, copy_config=False)¶
Copies the collection.
- Parameters:
copy_config (
bool, default:False) – Whether to copy the configuration.- Return type:
Self- Returns:
the copied collection.
- property data: dict[str, ndarray]¶
Property that returns the underlying data dictionary. The property can be set to update the data if the data passes validation.
- init_other(*, data, copy_config=False, validate_on_init=False)¶
Initializes a new collection from provided data with the same configuration.
- Parameters:
- Return type:
Self- Returns:
The new collection.
- select(*, timestamp=None, identity=None)¶
Selects a subset of instances based on timestamp and/or identity.
- Parameters:
- Return type:
Self- Returns:
The selected collection.
- Raises:
ValueError – If timestamp/identity selection is attempted without the corresponding keys defined in the configuration.
- select_index(index)¶
Selects a subset of the data based on the provided index. Allows indexing as in
numpy, and will return a view if possible.- Parameters:
index (
ndarray) – The indices to select.- Return type:
Self- Returns:
The selected collection.
- validate(validate)¶
Yields a context where data validation is enabled or disabled.
- validate_data(data, *, allow_duplicated_timestamps=True, allow_missing_keys=False, try_broadcasting=True, require_array_like=False)¶
Validates the input data against the specified requirements.
- Parameters:
data (
Mapping[str,ndarray|int|float|str|integer|floating]) – The data to validate.allow_duplicated_timestamps (
bool, default:True) – Whether to allow duplicated timestamps.allow_missing_keys (
bool, default:False) – Whether to allow missing keys.try_broadcasting (
bool, default:True) – Whether to try broadcasting.require_array_like (default:
False) – Whether to require array-like values.
- Returns:
If the data passed validation.
- Return type:
- Raises:
ValueError – If the data fails any of the validation checks, such as key mismatches, length mismatches, or invalid timestamp or identity data types.