gaitmap.stride_segmentation.RoiStrideSegmentation#
- class gaitmap.stride_segmentation.RoiStrideSegmentation(segmentation_algorithm: StrideSegmentationAlgorithm | None = None, s_id_naming: typing_extensions.Literal[replace, prefix] = 'replace', action_method: str | None = None)[source]#
Apply any stride segmentation algorithms to specific regions of interest in a longer dataset.
In many cases it is preferable to not apply a stride segmentation algorithm to an entire dataset, but rather preselect regions of interest. These regions could be defined by some activity recognition algorithms or manually using further knowledge about the kind of recording.
This class allows you to easily loop over all specified regions of interest and call the selected stride segmentation algorithm just with the selected piece of data. The final stride list is than again concatenated over all regions of interest.
The class supports different types of input data combinations:
- Single-sensor datasets with single-sensor regions of interest
If a simple single-sensor dataset and a single-sensor region of interest is supplied, the segmentation method will be simply called for each region of interest.
- Synchronised multi-sensor dataset with single-sensor regions of interest
If a synchronised multi-sensor dataset (multi-level pandas dataframe) is passed and just a single-sensor regions of interest list, this list will be applied to all sensors. This class will handle looping the rois and looping the individual sensors will be handled by the actual segmentation algorithm.
- Multi-sensor dataset with multi-sensor regions of interest
If a multi-sensor regions of interest list is provided the entries for each sensor will be applied to respective datastreams of the dataset. In this case this class handles looping over the sensors and over the ROIs. The actual segmentation method will be called for each combination of sensor and ROI individually. All outputs will become nested dictionaries with the sensor-name at the top level. Note that sensors that do not have ROIs specified will not be processed.
For more information about the valid formats for the regions of interest list, review the datatype guide.
- Parameters:
- segmentation_algorithm
An instance of a valid segmentation algorithm with all the wanted parameters set.
- s_id_naming
Controls how the stride ids of the final stride lists are created to ensure they are unique. In case of “replace” the stride ids created by the stride segmentation algorithms per ROI are removed and replaced with an increasing numerical id. In case of “prefix” the original ids are kept and prefixed with “{roi_id}_”.
- action_method
Controls which action method of the wrapped algorithm should be called. This is only relevant, if the wrapped algorithm offers mutliple action methods. By default the primary action method is used.
- Other Parameters:
- data
The data passed to the
segmentmethod.- sampling_rate_hz
The sampling rate of the data
- regions_of_interest
The regions of interest list defining the start and the end of each region
- Attributes:
- stride_list_pd.DataFrame or Dictionary of such values
The final stride list marking the start and the end of each detected stride. It further contains a column “gsd_id” or “roi_id” (depending on the roi list used in the input) that indicates in which of the ROIs each stride was detected. The “start” and “end” values are relative to the start of the dataset (and not the individual ROIs). In case a multi-sensor ROI list was used, this will be a dictionary with one stride list per sensor. Further information about the outputs can be found in the documentation of the used segmentation algorithm.
- instances_per_roi_(Nested) Dictionary of StrideSegmentation algorithm instances
The actual instances of the stride segmentation algorithm for each ROI. They can be used to inspect further results and extract debug information. For available values review the documentation of the used stride segmentation algorithm. Remember that all values and data in these individual instances are relative to the start of each individual ROI. In case a multi-sensor ROI list was used, this will be a nested dictionary, with the sensor name as the top level and the ROI-ID as the second level.
Examples
>>> # We need our normal raw data (note that the required format might depend on the used segmentation method) and ... # And a valid region of interest list >>> data = pd.DataFrame(...) >>> roi_list = pd.DataFrame(...) >>> # Create an instance of your stride segmentation algorithm >>> from gaitmap.stride_segmentation import BarthDtw >>> dtw = BarthDtw() >>> # Now we can use the RoiStrideSegmentation to apply BarthDtw to each ROI >>> roi_seg = RoiStrideSegmentation(segmentation_algorithm=dtw) >>> roi_seg.segment(data, sampling_rate_hz=100, regions_of_interest=roi_list) >>> # Inspect the results >>> roi_seg.stride_list_ # TODO: Add example output >>> roi_seg.instances_per_roi_ {"roi_1": <BarthDtw...>, "roi_2": <BarthDtw ...>, ...}
Methods
clone()Create a new instance of the class with all parameters copied over.
from_json(json_str)Import an gaitmap object from its json representation.
get_params([deep])Get parameters for this algorithm.
segment(data, sampling_rate_hz, *[, ...])Run the segmentation on each region of interest.
set_params(**params)Set the parameters of this Algorithm.
to_json()Export the current object parameters as json.
- __init__(segmentation_algorithm: StrideSegmentationAlgorithm | None = None, s_id_naming: typing_extensions.Literal[replace, prefix] = 'replace', action_method: str | None = None) None[source]#
- clone() Self[source]#
Create a new instance of the class with all parameters copied over.
This will create a new instance of the class itself and all nested objects
- classmethod from_json(json_str: str) Self[source]#
Import an gaitmap object from its json representation.
For details have a look at the this example.
You can use the
to_jsonmethod of a class to export it as a compatible json string.- Parameters:
- json_str
json formatted string
- get_params(deep: bool = True) dict[str, Any][source]#
Get parameters for this algorithm.
- Parameters:
- deep
Only relevant if object contains nested algorithm objects. If this is the case and deep is True, the params of these nested objects are included in the output using a prefix like
nested_object_name__(Note the two “_” at the end)
- Returns:
- params
Parameter names mapped to their values.
- segment(data: DataFrame | dict[Union[collections.abc.Hashable, str], pandas.core.frame.DataFrame], sampling_rate_hz: float, *, regions_of_interest: DataFrame | dict[Union[collections.abc.Hashable, str], pandas.core.frame.DataFrame] | None = None, **kwargs) Self[source]#
Run the segmentation on each region of interest.
- Parameters:
- dataarray, single-sensor dataframe, or multi-sensor dataset
The input data. For details on the required datatypes review the class docstring.
- sampling_rate_hz
The sampling rate of the data signal.
- regions_of_interestsingle or multi-sensor regions of interest list
The regions of interest that should be used. The segmentation algorithm will be applied to each region individually
- kwargs
All keyword arguments will be passed to the segment method of the selected
segmentation_algorithm