Applying CIMAP to gait analysis
Here is an example of how to use the CIMAP algorithm, no data are needed from you since the code uses a dataset freely available in the GitHub repository. More specifically, the CIMAP algorithm will be applied to study muscle activation patterns acquired from a healthy subject during overground walking at self-selected speed.
Importing libraries
Be sure you have installed the latest stable release of the algorithm using the command
`pip install CIMAP`
command. through the bash shell or command prompt. You can check the release’s information using the command`pip show CIMAP`
. Then, you can import the library and set the input file path as follows:# Import of the library import CIMAP # Import of the library for the visualization of the graphical elements import matplotlib.pyplot as plt input_file = ".\\example_data\\Dataset.csv"Notice that is possible to easily run the CIMAP algorithm without directly calling all of the CIMAP functions by using the function
run_algorithm()
.
Dataset preparation and pre-processing
First, the
data_reading()
function is used to open and format the input data according to the Documentation section. Within thedata_reading()
function, theintervals()
function is used to extract muscle activation onset and offset (i.e., the beginning and the end of each muscle activation, respectively) time instants. Then, theremoveaddints()
function is called to remove outliers (i.e., cycles characterized by always ON or always OFF activation patterns). Further details on the outliers removal process can be found in the study by Rosati et al. [1].>>> s,muscles = CIMAP.data_reading(input_file = input_file) Input dataset loaded successfully >>> s = CIMAP.remove_add_ints(s) Pre-processing successfully performedPre-processed muscle activation intervals can be graphically investigated using the
actplot()
andmodality_distribution()
functions. Theactplot()
function represents the pre-processed muscle activation intervals over time for each acquired muscle and side, separately. If you are interested in a specific muscle, the target property of theactplot()
function can be used to set the muscle to be represented. As an example, only the muscle activation intervals extracted from the left and right Lateral Gastrocnemius (LGS) muscle are represented.# Plot muscle activation intervals >>> CIMAP.act_plot(s,target = 'LGS') # Command to display all open figures >>> plt.show(block = False)
Cycles are then divided into several sub-datasets grouping together cycles showing the same number of muscle activations within the cycle (called modalities).
# Division of the cycles by modality >>> muscles = CIMAP.modality_division(s,muscles) Cycles successfully divided into modalities
The modality_distribution()
function, instead, can be used to represent the muscle activation patterns distributions. If you are interested in a specific muscle, the target property of the modality_distribution()
function can be used to set the muscle to be represented. As an example, only the histogram of the muscle activation patterns extracted from the left and right Lateral Gastrocnemius (LGS) muscle are represented.
# Plot muscle activation patterns distributions >>> CIMAP.modality_distribution(s,target = 'LGS') # Command to display all open figures >>> plt.show(block = False)
Agglomerative Hierarchical Clustering
Agglomerative hierarchical clustering is applied to each sub-dataset, separately. Using the
dendrograms()
function, two different dendrograms are computed: the first one using the Manhattan distance metric and the second one using the Chebychev distance metric. Then, the cutoff point for each of the two dendrograms and the best clustering results are chosen using thecuts()
function. Further details on the identification of the cutoff point and the selection of the best clustering results can be found in the Documentation section.# Building dendrograms >>> muscles = CIMAP.dendrograms(muscles) Dendrograms building completed # Choice of the best clustering results >>> muscles = CIMAP.cuts(muscles) Best clustering result chosenClustering results can be graphically represented through the
dendroplot()
andclustersplot()
function plots the hierarchical tree of each computed modality. Clusters obtained after the selection of the optimal cutoff point are represented in different colours. If you are interested in a specific muscle, the target property of thedendroplot()
function can be used to set the muscle to be represented. As an example, only the clustering results computed from the left and right Lateral Gastrocnemius (LGS) muscle are represented.# Dendrogram representation >>> CIMAP.dendro_plot(muscles,target = 'LGS') # Command to display all open figures >>> plt.show(block = False)
The clustersplot()
function, instead, can be used to show the original muscle activation intervals grouped in clusters and divided by modality. results of clustering representing the activation intervals group in each cluster divided by modality. The color property of the clustersplot()
function can be used to have a color map consistent with the one represented using the dendroplot()
function. If you are interested in a specific muscle, the target property of the clustersplot()
function can be used to set the muscle to be represented. As an example, only the clustering results computed from the left and right Lateral Gastrocnemius (LGS) muscle are represented.
# Obtain the output of the algorithm >>> cimap_output = CIMAP.algorithm_output(s,muscles) Output dictionary created # Plot muscle activation intervals grouped in clusters and divided by modality >>> CIMAP.clusters_plot(cimap_output,target = 'LGS', color = True) # Command to display all open figures >>> plt.show(block = False)
Data saving
Finally, to save the output data, the
resultsaver()
function should be used. This function has the property input_file set equal to “None” by default. When called, it will open a window that allows you to select a folder where to save the results.# Save clustering results >>> CIMAP.result_saver(cimap_output) Please insert the name of the file containing the results: results_file Results savedAll the code presented in this tutorial will work as in the example if you copy and paste it into your Python IDE.
References
[1]. S. Rosati, C. Castagneri, V. Agostini, M. Knaflitz, and G. Balestra, Muscle contractions in cyclic movements: Optimization of CIMAP algorithm, 2017, doi: 10.1109/EMBC.2017.8036762.