You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/extend/features.rst
+62-17
Original file line number
Diff line number
Diff line change
@@ -11,36 +11,81 @@ Extend features
11
11
Your new features therefore may not work within different setups. To make your features available to the community and integrated to gaitalytics,
12
12
please consider :ref:`contributing <Development>` to the project and our staff will take care of the integration.
13
13
14
-
Before you start creating new features, you should think about the following questions:
14
+
To implement new feature algorithms you need to define a new class inheriting :class:`gaitalytics.features.PointDependentFeature`.
15
+
This class internally loops though each cycle and context ('left' and 'right') and calculates the feature for each point in the cycle and calls the :meth:`gaitalytics.features.CycleFeaturesCalculation._calculate` method.
16
+
With implementing :meth:`gaitalytics.features.CycleFeaturesCalculation._calculate` in your class you can add new functionalities.
15
17
16
-
- Will my feature be calculated for each gait cycle?
17
-
- Are all the needed markers defined through the :ref:`mappings <Config Mapping>`?
18
+
.. code-block:: python
18
19
19
-
If you have answered all the questions, you can start creating your new feature.
20
+
from gaitalytics.features import PointDependentFeature
20
21
21
-
Class inheritance
22
-
-----------------
22
+
classNewFeature(PointDependentFeature):
23
23
24
-
With with your answers in mind, you can now decide which class you want to inherit from. The following classes are available in the library:
Through parameter `cycle` you can access the data of the current cycle and calculate your feature, including the data of the current cycle and the context ('left' or 'right').
29
+
As return the framework expects an xarray DataArray object.
29
30
30
-
The following flowchart will help you to decide which class you should inherit from:
31
+
Helping functions
32
+
-----------------
31
33
32
-
.. mermaid::
34
+
To help you with the implementation of new features, gaitalytics provides a set of helper functions handle framework specific restrictions.
33
35
34
-
flowchart LR
35
-
A{Per cycle?}---|Yes|B{Mapped markers?}
36
-
A---|No|FeatureCalculation
37
-
B---|Yes|PointDependentFeature
38
-
B---|No|CycleFeaturesCalculation
36
+
Markers & Analogs
37
+
^^^^^^^^^^^^^^^^^
38
+
If your planning to use markers or analogs which are mapped by Gaitalytics (:class:`gaitalytics.mapping.MappedMarkers`) you can use the following helper functions:
39
+
:meth:`gaitalytics.features.PointDependentFeature._get_marker_data`. This function returns the data of the mapped marker for the current cycle.
39
40
41
+
.. hint::
42
+
Getting the data for the sacrum marker is handled as a special case. Since Gaitalytics allows either a single sacrum marker or a sacrum marker or two posterior pelvis markers, the method :meth:`gaitalytics.features.PointDependentFeature._get_sacrum_marker` will handle the logic to extract jut a sacrum marker.
40
43
..
41
44
45
+
If you want to use markers or analogs which are not mapped by Gaitalytics, you can find the data in the `cycle` xarray object.
46
+
Be aware that approach is not generalized and may not work with different marker models. Therefore, it is recommended to use the mapped markers whenever possible.
47
+
Future efforts will be made to generalize this approach.
48
+
49
+
Event timings
50
+
^^^^^^^^^^^^^
51
+
Ease the work with event timings in a cycle the :meth:`gaitalytics.features.PointDependentFeature.get_event_times` function can be used to extract the event timings for the current cycle.
52
+
53
+
54
+
Vectors
55
+
^^^^^^^
56
+
It is often necessary to obtain progression vectors or sagittal plane vectors. To help you with this, gaitalytics provides the following helper functions:
The expected return value of the feature calculation is an xarray DataArray object in a specific format.
64
+
To help you with the creation of this object, gaitalytics provides the following helper functions:
65
+
66
+
- :meth:`gaitalytics.features.CycleFeaturesCalculation._create_result_from_dict` to create a DataArray object from a dictionary.
67
+
- :meth:`gaitalytics.features.CycleFeaturesCalculation._flatten_features` to flatten an xarray DataArray object.
68
+
69
+
Including your feature
70
+
----------------------
71
+
72
+
To include your feature in the calculation of the gait metrics, you need to add it to the parameters of your :func:`gaitalytics.api.calculate_features` call.
0 commit comments