cvkit.pose_estimation.data_readers package
Submodules
cvkit.pose_estimation.data_readers.cvkit_datastore module
- class CVKitDataStore3D(body_parts, path, dimensions=3)[source]
Bases:
DataStoreInterfaceImplements a datastore reader for BU-CVKit’s n-dimensional data files. Expects a csv file where all dimensions are stored in a single cell. The header should contain a single column per keypoint.
- Parameters:
body_parts – list of column names
path – path to data file
dimension – data dimension
- FLAVOR = 'CVKit3D'
Acts as an ID for the class. File with “CVKit3D” indicates that the file should be opened with
CVKitDataStore3D
- SEP = ';'
File Separator
- build_part(row, name)[source]
Build part from internal row representation
- Parameters:
row – row of a dataframe
name – Name of the part
- Returns:
PartObject
- build_skeleton(row) Skeleton[source]
Build skeleton from internal row representation.
- Parameters:
row – row of a dataframe.
- static convert_to_list(index, skeleton, threshold=0.8)[source]
Generates a list of parts for
csv.writermodule. The structure of the list depends upon output data format. The data not crossing the threshold will not be included. Can be used to convert one data flavor to another.- Parameters:
index – Target Index
skeleton – Target skeleton
threshold – Threshold for including data.
- delete_part(index, name, force_remove=False)[source]
Deletes part at given index.
- Parameters:
index – The index from which the part will be deleted.
name – Name of the target part.
force_remove – Bypass index validation.
- get_behaviour(index) list[source]
Get behaviour at given index.
- Parameters:
index – The idex of the data to be retrieved.
- Returns:
List of behaviours
- get_part(index, name) Part[source]
Get
Partobject at given index.- Parameters:
index – The index from which the data will be retrieved.
name – Name of the target body part.
- Returns:
Part
- get_part_slice(slice_indices: list, name: str) ndarray[source]
Get slice of data for given part as a Numpy array.
- Parameters:
slice_indices – List of two integers defining starting and ending point (non-inclusive) of the slice.
name – Name of the body part
- Returns:
Numpy array of dimension nxd where n is the size of the slice and d is the dimension of the data.
- save_file(path: str | None = None) None[source]
Save data to a file.
- Parameters:
path – Path of the file. If None, the file will overwrite.
- set_behaviour(index, behaviour: list) None[source]
Set behaviour data for current index.
- Parameters:
index – The index where behaviour data will be inserted.
behaviour – List of behaviours
- set_part(index, part: Part) None[source]
Set
Partobject at given index.- Parameters:
index – The index at which the data will be inserted.
part –
Partto be inserted.
- set_part_slice(slice_indices: list, name: str, data: ndarray) None[source]
Set a slice of data for given part.
- Parameters:
slice_indices – List of two integers defining starting and ending point (non-inclusive) of the slice.
name – Name of the body part
data – nxd dimensional numpy array where n is the size of the slice and d is the dimension of the data.
cvkit.pose_estimation.data_readers.datastore_interface module
- class DataStoreInterface(body_parts, path, dimension=3)[source]
Bases:
ABCInterface for data reader. This class can be implemented to integrate data files from other toolkits.
- Parameters:
body_parts – list of column names
path – path to data file
dimension – data dimension
- BEHAVIOUR_SEP = '~'
Character to separate multiple behaviours
- DIMENSIONS = 3
Dimension of the data
- FLAVOR = 'Abstract'
Acts as an ID for the class. File with “CVKit3D” indicates that the file should be opened with
CVKitDataStore3D
- MAGIC_NUMBER = -4668
Magic number to represent invalid data
- SEP = ','
File Separator
- build_empty_skeleton()[source]
Builds empty skeleton object from a pre-defined MAGIC_NUMBER.
- Returns:
Empty
Skeleton
- abstract build_part(row, name) Part[source]
Build part from internal row representation
- Parameters:
row – row of a dataframe
name – Name of the part
- Returns:
PartObject
- abstract build_skeleton(row) Skeleton[source]
Build skeleton from internal row representation.
- Parameters:
row – row of a dataframe.
- compute_data_hash()[source]
Computes a hash value of the dataframe. Used to detect changes.
- Returns:
hash value
- abstract static convert_to_list(index, skeleton, threshold=0.8)[source]
Generates a list of parts for
csv.writermodule. The structure of the list depends upon output data format. The data not crossing the threshold will not be included. Can be used to convert one data flavor to another.- Parameters:
index – Target Index
skeleton – Target skeleton
threshold – Threshold for including data.
- abstract delete_part(index, name, force_remove=False)[source]
Deletes part at given index.
- Parameters:
index – The index from which the part will be deleted.
name – Name of the target part.
force_remove – Bypass index validation.
- delete_skeleton(index)[source]
Deletes data at location pointed by the index.
- Parameters:
index – The index of the data to be deleted
- abstract get_behaviour(index) list[str][source]
Get behaviour at given index.
- Parameters:
index – The idex of the data to be retrieved.
- Returns:
List of behaviours
- get_header_rows()[source]
Generates a list of header data for
csv.writermodule. The structure of the list depends upon output data format.- Returns:
List of header data
- Return type:
list
- get_numpy(index)[source]
Generate nxd Numpy array from given index where n is number of body parts and d is the dimension. The order of data follows
DataStoreInterface.body_parts.- Parameters:
index – The index from which data will be retrieved.
- Returns:
nxd Numpy array
- abstract get_part(index, name) Part[source]
Get
Partobject at given index.- Parameters:
index – The index from which the data will be retrieved.
name – Name of the target body part.
- Returns:
Part
- abstract get_part_slice(slice_indices: list[int], name: str) ndarray[source]
Get slice of data for given part as a Numpy array.
- Parameters:
slice_indices – List of two integers defining starting and ending point (non-inclusive) of the slice.
name – Name of the body part
- Returns:
Numpy array of dimension nxd where n is the size of the slice and d is the dimension of the data.
- get_skeleton(index) Skeleton[source]
Generates and return skeleton object for the frame defined by index.
- Parameters:
index – The index number pointing to the data corresponding to the frame.
- Returns:
Skeletonobject
- part_iterator(part)[source]
Generates and iterator which yields index and corresponding
Partsequentially. Example Usage: .. highlight:: python .. code-block:: python- for index, snout in data_store.part_iterator(‘snout’):
print(index,snout)
- Parameters:
part – Target body part.
- row_iterator()[source]
Generates and iterator which yields index and corresponding
Skeletonsequentially.Example Usage:
for index, skeleton in data_store.row_iterator(): print(index,skeleton)
- save_file(path: str | None = None) None[source]
Save data to a file.
- Parameters:
path – Path of the file. If None, the file will overwrite.
- abstract set_behaviour(index, behaviour: list[str]) None[source]
Set behaviour data for current index.
- Parameters:
index – The index where behaviour data will be inserted.
behaviour – List of behaviours
- abstract set_part(index, part: Part) None[source]
Set
Partobject at given index.- Parameters:
index – The index at which the data will be inserted.
part –
Partto be inserted.
- abstract set_part_slice(slice_indices: list, name: str, data: ndarray) None[source]
Set a slice of data for given part.
- Parameters:
slice_indices – List of two integers defining starting and ending point (non-inclusive) of the slice.
name – Name of the body part
data – nxd dimensional numpy array where n is the size of the slice and d is the dimension of the data.
- set_skeleton(index, skeleton: Skeleton, force_insert=False) None[source]
Set pose data from :py:class`~cvkit.pose_estimation.skeleton.Skeleton` object at given index.
- Parameters:
index – The index at which the data will be inserted.
skeleton –
Skeletonobject containing the pose data.force_insert – By pass index validation
cvkit.pose_estimation.data_readers.deeplabcut_datastore module
- class DeeplabcutDataStore(body_parts, path, dimensions=2)[source]
Bases:
DataStoreInterfaceImplements a datastore reader for DeepLabCut compatible data files.
- Parameters:
body_parts – list of column names
path – path to data file
dimension – data dimension
- DIMENSIONS = 2
Dimension of the data
- FLAVOR = 'deeplabcut'
Acts as an ID for the class. File with “CVKit3D” indicates that the file should be opened with
CVKitDataStore3D
- build_part(row, name)[source]
Build part from internal row representation
- Parameters:
row – row of a dataframe
name – Name of the part
- Returns:
PartObject
- build_skeleton(row) Skeleton[source]
Build skeleton from internal row representation.
- Parameters:
row – row of a dataframe.
- static convert_to_list(index, skeleton, threshold=0.8)[source]
Generates a list of parts for
csv.writermodule. The structure of the list depends upon output data format. The data not crossing the threshold will not be included. Can be used to convert one data flavor to another.- Parameters:
index – Target Index
skeleton – Target skeleton
threshold – Threshold for including data.
- delete_part(index, name, force_remove=False)[source]
Deletes part at given index.
- Parameters:
index – The index from which the part will be deleted.
name – Name of the target part.
force_remove – Bypass index validation.
- get_behaviour(index) list[source]
Get behaviour at given index.
- Parameters:
index – The idex of the data to be retrieved.
- Returns:
List of behaviours
- get_part(index, name) Part[source]
Get
Partobject at given index.- Parameters:
index – The index from which the data will be retrieved.
name – Name of the target body part.
- Returns:
Part
- get_part_slice(slice_indices: list, name: str) ndarray[source]
Get slice of data for given part as a Numpy array.
- Parameters:
slice_indices – List of two integers defining starting and ending point (non-inclusive) of the slice.
name – Name of the body part
- Returns:
Numpy array of dimension nxd where n is the size of the slice and d is the dimension of the data.
- part_iterator(part)[source]
Generates and iterator which yields index and corresponding
Partsequentially. Example Usage: .. highlight:: python .. code-block:: python- for index, snout in data_store.part_iterator(‘snout’):
print(index,snout)
- Parameters:
part – Target body part.
- set_behaviour(index, behaviour) None[source]
Set behaviour data for current index.
- Parameters:
index – The index where behaviour data will be inserted.
behaviour – List of behaviours
- set_part(index, part: Part) None[source]
Set
Partobject at given index.- Parameters:
index – The index at which the data will be inserted.
part –
Partto be inserted.
- set_part_slice(slice_indices: list, name: str, data: ndarray) None[source]
Set a slice of data for given part.
- Parameters:
slice_indices – List of two integers defining starting and ending point (non-inclusive) of the slice.
name – Name of the body part
data – nxd dimensional numpy array where n is the size of the slice and d is the dimension of the data.
cvkit.pose_estimation.data_readers.flattened_datastore module
- class FlattenedDataStore(body_parts, path, dimension=3)[source]
Bases:
DataStoreInterfaceImplements a datastore reader for flattened csv files. Expects a csv file where all dimensions are flattened. The header should contain 3 consecutive columns per keypoint. Ex. Snout_1,Snout_2,Snout_3 for x,y, and z values
- Parameters:
body_parts – list of column names
path – path to data file
dimension – data dimension
- DIMENSIONS = 3
Dimension of the data
- FLAVOR = 'flattened'
Acts as an ID for the class. File with “CVKit3D” indicates that the file should be opened with
CVKitDataStore3D
- build_part(row, name)[source]
Build part from internal row representation
- Parameters:
row – row of a dataframe
name – Name of the part
- Returns:
PartObject
- build_skeleton(row) Skeleton[source]
Build skeleton from internal row representation.
- Parameters:
row – row of a dataframe.
- static convert_to_list(index, skeleton, threshold=0.8)[source]
Generates a list of parts for
csv.writermodule. The structure of the list depends upon output data format. The data not crossing the threshold will not be included. Can be used to convert one data flavor to another.- Parameters:
index – Target Index
skeleton – Target skeleton
threshold – Threshold for including data.
- delete_part(index, name, force_remove=False)[source]
Deletes part at given index.
- Parameters:
index – The index from which the part will be deleted.
name – Name of the target part.
force_remove – Bypass index validation.
- get_behaviour(index) list[source]
Get behaviour at given index.
- Parameters:
index – The idex of the data to be retrieved.
- Returns:
List of behaviours
- get_header_rows()[source]
Generates a list of header data for
csv.writermodule. The structure of the list depends upon output data format.- Returns:
List of header data
- Return type:
list
- get_part(index, name) Part[source]
Get
Partobject at given index.- Parameters:
index – The index from which the data will be retrieved.
name – Name of the target body part.
- Returns:
Part
- get_part_slice(slice_indices: list, name: str) ndarray[source]
Get slice of data for given part as a Numpy array.
- Parameters:
slice_indices – List of two integers defining starting and ending point (non-inclusive) of the slice.
name – Name of the body part
- Returns:
Numpy array of dimension nxd where n is the size of the slice and d is the dimension of the data.
- part_iterator(part)[source]
Generates and iterator which yields index and corresponding
Partsequentially. Example Usage: .. highlight:: python .. code-block:: python- for index, snout in data_store.part_iterator(‘snout’):
print(index,snout)
- Parameters:
part – Target body part.
- save_file(path: str | None = None) None[source]
Save data to a file.
- Parameters:
path – Path of the file. If None, the file will overwrite.
- set_behaviour(index, behaviour: list) None[source]
Set behaviour data for current index.
- Parameters:
index – The index where behaviour data will be inserted.
behaviour – List of behaviours
- set_part(index, part: Part) None[source]
Set
Partobject at given index.- Parameters:
index – The index at which the data will be inserted.
part –
Partto be inserted.
- set_part_slice(slice_indices: list, name: str, data: ndarray) None[source]
Set a slice of data for given part.
- Parameters:
slice_indices – List of two integers defining starting and ending point (non-inclusive) of the slice.
name – Name of the body part
data – nxd dimensional numpy array where n is the size of the slice and d is the dimension of the data.
Module contents
- convert_data_flavor(source: DataStoreInterface, target: DataStoreInterface)[source]
Converts one data flavor to another.
- Parameters:
source (
DataStoreInterface.) – Source datastore instance.target (
DataStoreInterface) – Empty target datastore instance.
- initialize_datastore_reader(body_parts, path, reader_type, dimension=3) DataStoreInterface[source]
Detects underlying class based on reader_type. And generates appropriate
DataStoreInterfacesubclass instance.- Parameters:
body_parts (list[str]) – List of body parts
path (str) – Path to the data file
reader_type (str) – A string to identify underlying data reader type. Refer to the
FLAVORattributes of each implementation.dimension (int) – Dimension of the data
- Returns:
An instance of appropriate subclass of
DataStoreInterface.- Return type: