Python package for analyzing sensor-collected human motion data

Overview

Installation | Requirements | Usage | Contribution | Getting Help

Sensor Motion

PyPI - Python Version PyPI GitHub issues https://readthedocs.org/projects/sensormotion/badge/?version=latest https://badges.gitter.im/gitterHQ/gitter.png

Python package for analyzing sensor-collected human motion data (e.g. physical activity levels, gait dynamics).

Dedicated accelerometer devices, such as those made by Actigraph, usually bundle software for the analysis of the sensor data. In my work I often collect sensor data from smartphones and have not been able to find any comparable analysis software.

This Python package allows the user to extract human motion data, such as gait/walking dynamics, directly from accelerometer signals. Additionally, the package allows for the calculation of physical activity (PA) or moderate-to-vigorous physical activity (MVPA) counts, similar to activity count data offered by companies like Actigraph.

Installation

You can install this package using pip:

pip install sensormotion

Requirements

This package has the following dependencies, most of which are just Python packages:

  • Python 3.x
    • The easiest way to install Python is using the Anaconda distribution, as it also includes the other dependencies listed below
    • Python 2.x has not been tested, so backwards compatibility is not guaranteed
  • numpy
    • Included with Anaconda. Otherwise, install using pip (pip install numpy)
  • scipy
    • Included with Anaconda. Otherwise, install using pip (pip install scipy)
  • matplotlib
    • Included with Anaconda. Otherwise, install using pip (pip install matplotlib)

Usage

Here is brief example of extracting step-based metrics from raw vertical acceleration data:

Import the package:

import sensormotion as sm

If you have a vertical acceleration signal x, and its corresponding time signal t, we can begin by filtering the signal using a low-pass filter:

b, a = sm.signal.build_filter(frequency=10,
                              sample_rate=100,
                              filter_type='low',
                              filter_order=4)

x_filtered = sm.signal.filter_signal(b, a, signal=x)

images/filter.png

Next, we can detect the peaks (or valleys) in the filtered signal, which gives us the time and value of each detection. Optionally, we can include a plot of the signal and detected peaks/valleys:

peak_times, peak_values = sm.peak.find_peaks(time=t, signal=x_filtered,
                                             peak_type='valley',
                                             min_val=0.6, min_dist=30,
                                             plot=True)

images/peak_detection.png

From the detected peaks, we can then calculate step metrics like cadence and step time:

cadence = sm.gait.cadence(time=t, peak_times=peak_times, time_units='ms')
step_mean, step_sd, step_cov = sm.gait.step_time(peak_times=peak_times)

Physical activity counts and intensities can also be calculated from the acceleration data:

x_counts = sm.pa.convert_counts(x, time, integrate='simpson')
y_counts = sm.pa.convert_counts(y, time, integrate='simpson')
z_counts = sm.pa.convert_counts(z, time, integrate='simpson')
vm = sm.signal.vector_magnitude(x_counts, y_counts, z_counts)
categories, time_spent = sm.pa.cut_points(vm, set_name='butte_preschoolers', n_axis=3)

images/pa_counts.png

For a more in-depth tutorial, and more workflow examples, please take a look at the tutorial.

I would also recommend looking over the documentation to see other functionalities of the package.

Contribution

I work on this package in my spare time, on an "as needed" basis for my research projects. However, pull requests for bug fixes and new features are always welcome!

Please see the develop branch for the development version of the package, and check out the issues page for bug reports and feature requests.

Getting Help

You can find the full documentation for the package here

Python's built-in help function will show documentation for any module or function: help(sm.gait.step_time)

You're encouraged to post questions, bug reports, or feature requests as an issue

Alternatively, ask questions on Gitter

Comments
  • Question

    Question

    I am using sensormotion.py package for finding peaks for one of my applications. I want to know how normalized min_value (0-1) in peak.find_peaks is related to minimum detectable peak value.

    opened by vivekmahadev 2
  • I need help using this library!

    I need help using this library!

    Hi

    I'm very interested in using this library in my project. I have a test of 2min walking at 100Hz and I collect the data from accelerometer, gyro and magnetometer of an Iphone 6.

    I'm trying to use the library with my data but I could understand some things. For example this function sm.peak.find_peaks(ac_lags, ac, peak_type='peak', min_val= 0.6, min_dist=32, plot=True). What are the suitable values of min_val and min_dist parameters? Are they problem dependent? I have tried with many values and the step estimation is not correct.

    Please, could you help me?

    Best regards

    opened by ogreyesp 1
  • sm.gait.step_regularity IndexError

    sm.gait.step_regularity IndexError

    step_reg, stride_reg = sm.gait.step_regularity(ac_peak_values) File ".../python3.6/site-packages/sensormotion-1.1.0-py3.6.egg/sensormotion/gait.py", line 128, in step_regularity ac_d2 = peaks_half[2] # second dominant period i.e. a stride (left-left) sm.gait.step_regularity IndexError: index 2 is out of bounds for axis 0 with size 2

    opened by jiakang 1
  • Example: Importing from live cvs file?

    Example: Importing from live cvs file?

    opened by RandoSY 1
  • Question about step regularity

    Question about step regularity

    Hey, I'm using your package right now to generate features for a dataset. I have looked at the paper by Moe Nilssen et al. and tried to follow the steps for calculating step and stride regularity. However, I wonder why you still do the following calculation at the end:

    step_reg = ac_d1 / ac_lag0 stride_reg = ac_d2 / ac_lag0

    Can you help me with this?

    opened by vanessabin 1
Releases(1.1.4)
Owner
Simon Ho
Data Science | Machine Learning | Statistics | Gaming
Simon Ho
A pipeline that creates consensus sequences from a Nanopore reads. I

A pipeline that creates consensus sequences from a Nanopore reads. It clusters reads that are similar to each other and creates a consensus that is then identified using BLAST.

Ada Madejska 2 May 15, 2022
Analysis scripts for QG equations

qg-edgeofchaos Analysis scripts for QG equations FIle/Folder Structure eigensolvers.py - Spectral and finite-difference solvers for Rossby wave eigenf

Norman Cao 2 Sep 27, 2022
Improving your data science workflows with

Make Better Defaults Author: Kjell Wooding [email protected] This is the git re

Kjell Wooding 18 Dec 23, 2022
Pyspark Spotify ETL

This is my first Data Engineering project, it extracts data from the user's recently played tracks using Spotify's API, transforms data and then loads it into Postgresql using SQLAlchemy engine. Data

16 Jun 09, 2022
This is a tool for speculation of ancestral allel, calculation of sfs and drawing its bar plot.

superSFS This is a tool for speculation of ancestral allel, calculation of sfs and drawing its bar plot. It is easy-to-use and runing fast. What you s

3 Dec 16, 2022
A meta plugin for processing timelapse data timepoint by timepoint in napari

napari-time-slicer A meta plugin for processing timelapse data timepoint by timepoint. It enables a list of napari plugins to process 2D+t or 3D+t dat

Robert Haase 2 Oct 13, 2022
Building house price data pipelines with Apache Beam and Spark on GCP

This project contains the process from building a web crawler to extract the raw data of house price to create ETL pipelines using Google Could Platform services.

1 Nov 22, 2021
A computer algebra system written in pure Python

SymPy See the AUTHORS file for the list of authors. And many more people helped on the SymPy mailing list, reported bugs, helped organize SymPy's part

SymPy 9.9k Dec 31, 2022
A DSL for data-driven computational pipelines

"Dataflow variables are spectacularly expressive in concurrent programming" Henri E. Bal , Jennifer G. Steiner , Andrew S. Tanenbaum Quick overview Ne

1.9k Jan 03, 2023
Galvanalyser is a system for automatically storing data generated by battery cycling machines in a database

Galvanalyser is a system for automatically storing data generated by battery cycling machines in a database, using a set of "harvesters", whose job it

Battery Intelligence Lab 20 Sep 28, 2022
Bigdata Simulation Library Of Dream By Sandman Books

BIGDATA SIMULATION LIBRARY OF DREAM BY SANDMAN BOOKS ================= Solution Architecture Description In the realm of Dreaming, its ruler SANDMAN,

Maycon Cypriano 3 Jun 30, 2022
This creates a ohlc timeseries from downloaded CSV files from NSE India website and makes a SQLite database for your research.

NSE-timeseries-form-CSV-file-creator-and-SQL-appender- This creates a ohlc timeseries from downloaded CSV files from National Stock Exchange India (NS

PILLAI, Amal 1 Oct 02, 2022
Incubator for useful bioinformatics code, primarily in Python and R

Collection of useful code related to biological analysis. Much of this is discussed with examples at Blue collar bioinformatics. All code, images and

Brad Chapman 560 Jan 03, 2023
Multiple Pairwise Comparisons (Post Hoc) Tests in Python

scikit-posthocs is a Python package that provides post hoc tests for pairwise multiple comparisons that are usually performed in statistical data anal

Maksim Terpilowski 264 Dec 30, 2022
Synthetic data need to preserve the statistical properties of real data in terms of their individual behavior and (inter-)dependences

Synthetic data need to preserve the statistical properties of real data in terms of their individual behavior and (inter-)dependences. Copula and functional Principle Component Analysis (fPCA) are st

32 Dec 20, 2022
Big Data & Cloud Computing for Oceanography

DS2 Class 2022, Big Data & Cloud Computing for Oceanography Home of the 2022 ISblue Big Data & Cloud Computing for Oceanography class (IMT-A, ENSTA, I

Ocean's Big Data Mining 5 Mar 19, 2022
MDAnalysis is a Python library to analyze molecular dynamics simulations.

MDAnalysis Repository README [*] MDAnalysis is a Python library for the analysis of computer simulations of many-body systems at the molecular scale,

MDAnalysis 933 Dec 28, 2022
track your GitHub statistics

GitHub-Stalker track your github statistics 👀 features find new followers or unfollowers find who got a star on your project or remove stars find who

Bahadır Araz 34 Nov 18, 2022
Randomisation-based inference in Python based on data resampling and permutation.

Randomisation-based inference in Python based on data resampling and permutation.

67 Dec 27, 2022
Powerful, efficient particle trajectory analysis in scientific Python.

freud Overview The freud Python library provides a simple, flexible, powerful set of tools for analyzing trajectories obtained from molecular dynamics

Glotzer Group 195 Dec 20, 2022