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
CINECA molecular dynamics tutorial set

High Performance Molecular Dynamics Logging into CINECA's computer systems To logon to the M100 system use the following command from an SSH client ss

J. W. Dell 0 Mar 13, 2022
Performance analysis of predictive (alpha) stock factors

Alphalens Alphalens is a Python Library for performance analysis of predictive (alpha) stock factors. Alphalens works great with the Zipline open sour

Quantopian, Inc. 2.5k Jan 09, 2023
Hue Editor: Open source SQL Query Assistant for Databases/Warehouses

Hue Editor: Open source SQL Query Assistant for Databases/Warehouses

Cloudera 759 Jan 07, 2023
ped-crash-techvol: Texas Ped Crash Tech Volume Pack

ped-crash-techvol: Texas Ped Crash Tech Volume Pack In conjunction with the Final Report "Identifying Risk Factors that Lead to Increase in Fatal Pede

Network Modeling Center; Center for Transportation Research; The University of Texas at Austin 2 Sep 28, 2022
Dbt-core - dbt enables data analysts and engineers to transform their data using the same practices that software engineers use to build applications.

Dbt-core - dbt enables data analysts and engineers to transform their data using the same practices that software engineers use to build applications.

dbt Labs 6.3k Jan 08, 2023
InDels analysis of CRISPR lines by NGS amplicon sequencing technology for a multicopy gene family.

CRISPRanalysis InDels analysis of CRISPR lines by NGS amplicon sequencing technology for a multicopy gene family. In this work, we present a workflow

2 Jan 31, 2022
Driver Analysis with Factors and Forests: An Automated Data Science Tool using Python

Driver Analysis with Factors and Forests: An Automated Data Science Tool using Python 📊

Thomas 2 May 26, 2022
Python ELT Studio, an application for building ELT (and ETL) data flows.

The Python Extract, Load, Transform Studio is an application for performing ELT (and ETL) tasks. Under the hood the application consists of a two parts.

Schlerp 55 Nov 18, 2022
Using Data Science with Machine Learning techniques (ETL pipeline and ML pipeline) to classify received messages after disasters.

Using Data Science with Machine Learning techniques (ETL pipeline and ML pipeline) to classify received messages after disasters.

1 Feb 11, 2022
sportsdataverse python package

sportsdataverse-py See CHANGELOG.md for details. The goal of sportsdataverse-py is to provide the community with a python package for working with spo

Saiem Gilani 37 Dec 27, 2022
The lastest all in one bombing tool coded in python uses tbomb api

BaapG-Attack is a python3 based script which is officially made for linux based distro . It is inbuit mass bomber with sms, mail, calls and many more bombing

59 Dec 25, 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
Python dataset creator to construct datasets composed of OpenFace extracted features and Shimmer3 GSR+ Sensor datas

Python dataset creator to construct datasets composed of OpenFace extracted features and Shimmer3 GSR+ Sensor datas

Gabriele 3 Jul 05, 2022
a tool that compiles a csv of all h1 program stats

h1stats - h1 Program Stats Scraper This python3 script will call out to HackerOne's graphql API and scrape all currently active programs for informati

Evan 40 Oct 27, 2022
AWS Glue ETL Code Samples

AWS Glue ETL Code Samples This repository has samples that demonstrate various aspects of the new AWS Glue service, as well as various AWS Glue utilit

AWS Samples 1.2k Jan 03, 2023
Senator Trades Monitor

Senator Trades Monitor This monitor will grab the most recent trades by senators and send them as a webhook to discord. Installation To use the monito

Yousaf Cheema 5 Jun 11, 2022
Larch: Applications and Python Library for Data Analysis of X-ray Absorption Spectroscopy (XAS, XANES, XAFS, EXAFS), X-ray Fluorescence (XRF) Spectroscopy and Imaging

Larch: Data Analysis Tools for X-ray Spectroscopy and More Documentation: http://xraypy.github.io/xraylarch Code: http://github.com/xraypy/xraylarch L

xraypy 95 Dec 13, 2022
Tools for analyzing data collected with a custom unity-based VR for insects.

unityvr Tools for analyzing data collected with a custom unity-based VR for insects. Organization: The unityvr package contains the following submodul

Hannah Haberkern 1 Dec 14, 2022
Full ELT process on GCP environment.

Rent Houses Germany - GCP Pipeline Project: The goal of the project is to extract data about house rentals in Germany, store, process and analyze it u

Felipe Demenech Vasconcelos 2 Jan 20, 2022