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
This is an analysis and prediction project for house prices in King County, USA based on certain features of the house

This is a project for analysis and estimation of House Prices in King County USA The .csv file contains the data of the house and the .ipynb file con

Amit Prakash 1 Jan 21, 2022
A project consists in a set of assignements corresponding to a BI process: data integration, construction of an OLAP cube, qurying of a OPLAP cube and reporting.

TennisBusinessIntelligenceProject - A project consists in a set of assignements corresponding to a BI process: data integration, construction of an OLAP cube, qurying of a OPLAP cube and reporting.

carlo paladino 1 Jan 02, 2022
Python Package for DataHerb: create, search, and load datasets.

The Python Package for DataHerb A DataHerb Core Service to Create and Load Datasets.

DataHerb 4 Feb 11, 2022
Python Library for learning (Structure and Parameter) and inference (Statistical and Causal) in Bayesian Networks.

pgmpy pgmpy is a python library for working with Probabilistic Graphical Models. Documentation and list of algorithms supported is at our official sit

pgmpy 2.2k Dec 25, 2022
Analyse the limit order book in seconds. Zoom to tick level or get yourself an overview of the trading day.

Analyse the limit order book in seconds. Zoom to tick level or get yourself an overview of the trading day. Correlate the market activity with the Apple Keynote presentations.

2 Jan 04, 2022
BasstatPL is a package for performing different tabulations and calculations for descriptive statistics.

BasstatPL is a package for performing different tabulations and calculations for descriptive statistics. It provides: Frequency table constr

Angel Chavez 1 Oct 31, 2021
Show you how to integrate Zeppelin with Airflow

Introduction This repository is to show you how to integrate Zeppelin with Airflow. The philosophy behind the ingtegration is to make the transition f

Jeff Zhang 11 Dec 30, 2022
Python package for analyzing behavioral data for Brain Observatory: Visual Behavior

Allen Institute Visual Behavior Analysis package This repository contains code for analyzing behavioral data from the Allen Brain Observatory: Visual

Allen Institute 16 Nov 04, 2022
Hg002-qc-snakemake - HG002 QC Snakemake

HG002 QC Snakemake To Run Resources and data specified within snakefile (hg002QC

Juniper A. Lake 2 Feb 16, 2022
The OHSDI OMOP Common Data Model allows for the systematic analysis of healthcare observational databases.

The OHSDI OMOP Common Data Model allows for the systematic analysis of healthcare observational databases.

Bell Eapen 14 Jan 02, 2023
A data analysis using python and pandas to showcase trends in school performance.

A data analysis using python and pandas to showcase trends in school performance. A data analysis to showcase trends in school performance using Panda

Jimmy Faccioli 0 Sep 07, 2021
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
Clean and reusable data-sciency notebooks.

KPACUBO KPACUBO is a set Jupyter notebooks focused on the best practices in both software development and data science, namely, code reuse, explicit d

Matvey Morozov 1 Jan 28, 2022
Recommendations from Cramer: On the show Mad-Money (CNBC) Jim Cramer picks stocks which he recommends to buy. We will use this data to build a portfolio

Backtesting the "Cramer Effect" & Recommendations from Cramer Recommendations from Cramer: On the show Mad-Money (CNBC) Jim Cramer picks stocks which

Gábor Vecsei 12 Aug 30, 2022
Desafio proposto pela IGTI em seu bootcamp de Cloud Data Engineer

Desafio Modulo 4 - Cloud Data Engineer Bootcamp - IGTI Objetivos Criar infraestrutura como código Utuilizando um cluster Kubernetes na Azure Ingestão

Otacilio Filho 4 Jan 23, 2022
Option Pricing Calculator using the Binomial Pricing Method (No Libraries Required)

Binomial Option Pricing Calculator Option Pricing Calculator using the Binomial Pricing Method (No Libraries Required) Background A derivative is a fi

sammuhrai 1 Nov 29, 2021
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
A program that uses an API and a AI model to get info of sotcks

Stock-Market-AI-Analysis I dont mind anyone using this code but please give me credit A program that uses an API and a AI model to get info of stocks

1 Dec 17, 2021
Analyzing Covid-19 Outbreaks in Ontario

My group and I took Covid-19 outbreak statistics from ontario, and analyzed them to find different patterns and future predictions for the virus

Vishwaajeeth Kamalakkannan 0 Jan 20, 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