Skip to main content

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",
)

Metadata

Release files for agcounts 0.2.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agcounts 0.2.6
File Size Uploaded
agcounts-0.2.6.tar.gz 21.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for agcounts 0.2.6
File Interpreter ABI Platform
agcounts-0.2.6-py3-none-any.whl Python 3 none any Details

Total release size: 43.5 kB

Release files / agcounts-0.2.6.tar.gz

Download URL agcounts-0.2.6.tar.gz
Size 21.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b973aff2055ec1e18eb24166b5f61df65b19e9458518cfef2cec80f1074ee0d8
BLAKE2b-256 checksum
How to use checksums
dfc60628bfc4a8766d0a3e633b190c6b6f8b635d6ae329324cf64e83f7e32965
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.0 CPython/3.10.12 Linux/6.5.0-1025-azure

Release files / agcounts-0.2.6-py3-none-any.whl

Download URL agcounts-0.2.6-py3-none-any.whl
Size 21.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bce7a2b35b0357397d42bc1989f4364a109a6634c931cbdd34497a3b22a6069c
BLAKE2b-256 checksum
How to use checksums
f2fe963ac893e3298ee4bd74679e54bc951e18d144d36724e3557c6e22bea60a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.0 CPython/3.10.12 Linux/6.5.0-1025-azure

Release history Release notifications | RSS feed

This release

0.2.6 This release

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.7

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page