Skip to main content

This project contains code to generate activity counts from accelerometer data.

Project description

agcounts

Tests

A python package for extracting actigraphy counts from accelerometer data.

Install

pip install agcounts

Test

Download test data:

curl -L https://github.com/actigraph/agcounts/files/8247896/GT3XPLUS-AccelerationCalibrated-1x8x0.NEO1G75911139.2000-01-06-13-00-00-000-P0000.sensor.csv.gz --output data.csv.gz

Run a simple test

import pandas as pd
import numpy as np
from agcounts.extract import get_counts


def get_counts_csv(
    file,
    freq: int,
    epoch: int,
    fast: bool = True,
    verbose: bool = False,
    time_column: str = None,
):
    if verbose:
        print("Reading in CSV", flush=True)
    raw = pd.read_csv(file, skiprows=0)
    if time_column is not None:
        ts = raw[time_column]
        ts = pd.to_datetime(ts)
        time_freq = str(epoch) + "S"
        ts = ts.dt.round(time_freq)
        ts = ts.unique()
        ts = pd.DataFrame(ts, columns=[time_column])
    raw = raw[["X", "Y", "Z"]]
    if verbose:
        print("Converting to array", flush=True)
    raw = np.array(raw)
    if verbose:
        print("Getting Counts", flush=True)
    counts = get_counts(raw, freq=freq, epoch=epoch, fast=fast, verbose=verbose)
    del raw
    counts = pd.DataFrame(counts, columns=["Axis1", "Axis2", "Axis3"])
    counts["AC"] = (
        counts["Axis1"] ** 2 + counts["Axis2"] ** 2 + counts["Axis3"] ** 2
    ) ** 0.5
    ts = ts[0 : counts.shape[0]]
    if time_column is not None:
        counts = pd.concat([ts, counts], axis=1)
    return counts


def convert_counts_csv(
    file,
    outfile,
    freq: int,
    epoch: int,
    fast: bool = True,
    verbose: bool = False,
    time_column: str = None,
):
    counts = get_counts_csv(
        file, freq=80, epoch=60, verbose=True, time_column=time_column
    )
    counts.to_csv(outfile, index=False)
    return counts


counts = get_counts_csv("data.csv.gz", freq=80, epoch=60)
counts = convert_counts_csv(
    "data.csv.gz",
    outfile="counts.csv.gz",
    freq=80,
    epoch=60,
    verbose=True,
    time_column="HEADER_TIMESTAMP",
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agcounts-0.2.5.tar.gz (21.5 kB view details)

Uploaded Source

Built Distribution

agcounts-0.2.5-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file agcounts-0.2.5.tar.gz.

File metadata

  • Download URL: agcounts-0.2.5.tar.gz
  • Upload date:
  • Size: 21.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0 CPython/3.10.12 Linux/6.5.0-1025-azure

File hashes

Hashes for agcounts-0.2.5.tar.gz
Algorithm Hash digest
SHA256 93e1a171c4a9460a6fcc397e82c7a7529c062fb26f6c1f487bcb6bc86da72fb6
MD5 39729b1c234c545a4d8a28d760a8aa8d
BLAKE2b-256 1d57f48612c3726c8b55810234513ce5ba5511e430d0e23cd4455b4fafc82c7d

See more details on using hashes here.

File details

Details for the file agcounts-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: agcounts-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0 CPython/3.10.12 Linux/6.5.0-1025-azure

File hashes

Hashes for agcounts-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 20184537203c74d6fc101888a6f40f07f33e7d8cd82fcf39de3ae779b16b1459
MD5 adc2490220f4825e5fcc76aff66b0d42
BLAKE2b-256 6f32261843a68c2ab19243f7416fbf32cd43496a520031bfbfd14259932a0a90

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page