Read and process raw vertical accelerometry data from a lumbar sensor during gait; calculate clinical gait characteristics.
Project description
GaitPy
Read and process raw vertical accelerometry data from a sensor on the lower back during gait; calculate clinical gait characteristics.
Overview
GaitPy provides python functions to read accelerometry data from a single lumbar-mounted sensor and estimate clinical characteristics of gait.
- Device location: lower back/lumbar
- Sensing modality: Accelerometer
- Sensor data: Vertical acceleration
- Minimum sampling rate: 50Hz
Installation
GaitPy is compatible with python v3.6 on MacOSX, Windows, and Linux and is available through Anaconda.
Installation via Anaconda (recommended):
Once you have Anaconda installed, open a terminal window and create a new environment using the following command.
conda create --name my_env python=3.6
Then, activate your environment using the following command for Mac and Linux.
source activate my_env
For Windows use the following.
activate my_env
Lastly, to install GaitPy, use the following command.
conda install gaitpy
Alternatively, you can install via pip:
pip install gaitpy
You can also install GaitPy from source:
git clone https://github.com/matt002/gaitpy
cd ~/gaitpy
python setup.py install
Basic usage
GaitPy consists of the following 3 functions:
- classify_bouts: If your data consists of gait and non-gait data, run the classify_bouts function to first classify bouts of gait. If your data is solely during gait, this function is not necessary to use.
- extract_features: Extract initial contact (IC) and final contact (FC) events from your data and estimate various temporal and spatial gait features.
- plot_contacts: Plot the resulting bout detections and IC/FC events alongside your raw accelerometer signal.
GaitPy accepts a csv file or pandas dataframe that includes a column containing unix timestamps and a column containing vertical acceleration from a lumbar-mounted sensor. GaitPy makes three assumptions by default:
- Timestamps and vertical acceleration columns are labeled 'timestamps' and 'y' respectively, however this can be changed using the 'v_acc_col_name' and 'ts_col_name' arguments respectively.
- Timestamps are in Unix milliseconds and data is in meters per second squared, however this can be be changed using the 'ts_units' and 'v_acc_units' arguments respectively.
- Baseline vertical acceleration data is -9.8m/s^2 or -1g. If your baseline data is +9.8m/s^2 or +1g, set the 'flip' argument to True.
Additionally, the sample rate of your device (at least 50Hz) and height of the subject must be provided.
More details about the inputs and ouputs of each of these functions can be found in the documentation and Czech et al. 2019.
from gaitpy.gait import Gaitpy
raw_data = 'raw-data-path or pandas dataframe'
sample_rate = 128 # hertz
subject_height = 170 # centimeters
#### Create an instance of Gaitpy ####
gaitpy = Gaitpy(raw_data, # Raw data consisting of vertical acceleration from lumbar location and unix timestamps
sample_rate, # Sample rate of raw data (in Hertz)
v_acc_col_name='y', # Vertical acceleration column name
ts_col_name='timestamps', # Timestamp column name
v_acc_units='m/s^2', # Units of vertical acceleration
ts_units='ms', # Units of timestamps
flip=False) # If baseline data is at +1g or +9.8m/s^2, set flip=True
#### Classify bouts of gait - Optional (use if your data consists of gait and non-gait periods)####
gait_bouts = gaitpy.classify_bouts(result_file='/my/folder/classified_gait.h5') # File to save results to (None by default)
#### Extract gait characteristics ####
gait_features = gaitpy.extract_features(subject_height, # Subject height
subject_height_units='centimeter', # Units of subject height
result_file='/my/folder/gait_features.csv', # File to save results to (None by default)
classified_gait=gait_bouts) # Pandas Dataframe or .h5 file results of classify_bouts function (None by default)
#### Plot results of gait feature extraction ####
gaitpy.plot_contacts(gait_features, # Pandas Dataframe or .csv file results of extract_features function
result_file='/my/folder/plot_contacts.html)', # File to save results to (None by default)
show_plot=True) # Specify whether to display plot upon completion (True by default)
Running the demo
The demo file provided lets you to test whether GaitPy outputs the expected results on your system.
You may run the demo directly from a terminal window:
cd gaitpy/demo
python demo.py
You may also run the demo via a python interpreter. In a terminal window start python by typing:
python
In the interpreter window you can then import and run the demo with the following two commands:
from gaitpy.demo import demo
demo.run_demo()
The demo script will prompt you to type in a results directory. Following the run, results will be saved in the provided results directory (less than 250kB of data will be saved). Running the demo should take less than a minute, though this may vary depending on your machine.
Contributing to the project
Please help contribute to the project! See the CONTRIBUTING.md file for details.
Acknowledgements
The Digital Medicine & Translational Imaging group at Pfizer, Inc supported the development of this package.
Author
Matthew Czech
License
GaitPy is under the MIT license
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file gaitpy-1.6.1.tar.gz
.
File metadata
- Download URL: gaitpy-1.6.1.tar.gz
- Upload date:
- Size: 2.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a027ac8c11576f6c7ba70a426e3144cbe9c7a84c0339079f05e9a6c18fe9edb5 |
|
MD5 | 41f2fa8ce75bf42b66dd1a949c43c96e |
|
BLAKE2b-256 | fd88615da6b04b07cd7c5dc5178fffd8b6188d797aeaecb9ebaa2d62d465696b |
File details
Details for the file gaitpy-1.6.1-py3-none-any.whl
.
File metadata
- Download URL: gaitpy-1.6.1-py3-none-any.whl
- Upload date:
- Size: 2.3 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fed4e996aeb35c0f2172be01c77db2f45d00492b8413b584ccef13686ebe1383 |
|
MD5 | 1f1f274f8dc7dd3da9418e9faafeae06 |
|
BLAKE2b-256 | df42253b541bfcb61688056ea4cf2699f8d4a31a81beed2a4848b7056703023b |