Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 0.14.1 #142

Merged
merged 15 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
intersphinx_mapping = {
"python": ("https://docs.python.org/dev", None),
"numpy": ("https://numpy.org/doc/stable/", None),
"scipy": ("https://docs.scipy.org/doc/scipy/reference", None),
"scipy": ('https://docs.scipy.org/doc/scipy', None),
"pandas": ("https://pandas.pydata.org/pandas-docs/stable", None),
}

Expand Down
2 changes: 1 addition & 1 deletion docs/ref/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ SKDH Reference
io
preprocessing
features
context
sleep
activity
gait
gait_old
sit2stand
utility
ambulation
2 changes: 1 addition & 1 deletion docs/src/research.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Peer Reviewed Journal Articles Using SKDH
=========================================

- W. Lin et al., “Can Gait Characteristics Be Represented by Physical Activity Measured with Wrist-Worn Accelerometers?,” Sensors, vol. 23, no. 20, Art. no. 20, Jan. 2023, doi: 10.3390/s23208542.
- W. Lin et al., "SciKit Digital Health Package for Accelerometry-Measured Physical Activity: Comparisons to Existing Solutions and Investigations of Age Effects in Healthy Adults", In Preperation
- W. Lin et al., "SciKit Digital Health Package for Accelerometry-Measured Physical Activity: Comparisons to Existing Solutions and Investigations of Age Effects in Healthy Adults", Front. Digit. Health, 26 Nov. 2023, doi: 10.3389/fdgth.2023.1321086
- J. Di et al., "Wearable Accelerometers as An Innovative Approach to Monitor Physical Activity and Gait in Children and Adolescents", In Preparation
- P. Sheriff et al., "In-Clinic and Natural Gait Observations (I-CAN-GO) an Observational Low-Interventional Master Protocol to Validate Gait and Physical Activity in Adults", In Preparation
- N. Camerlingo et al., "Measuring gait parameters from a chest-worn accelerometer in healthy individuals: a validation study", In Preparation
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project(
'scikit-digital-health',
'c',
version: '0.14.0',
version: '0.14.1',
license: 'MIT',
meson_version: '>=1.1',
)
Expand Down
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ classifiers = [
"Development Status :: 4 - Beta",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
Expand All @@ -51,7 +49,7 @@ classifiers = [
requires-python = ">=3.6"
dependencies = [
"numpy>=1.17.2",
"scipy>=1.3.1",
"scipy>=1.12.0",
"pandas>=1.0.0",
"lightgbm>=2.3.0",
"pywavelets",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
numpy>=1.17.2
scipy>=1.3.1
scipy>=1.12.0
pandas>=0.23.4
lightgbm>=2.3.0
pywavelets
Expand Down
10 changes: 7 additions & 3 deletions src/skdh/activity/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
Lukas Adamowicz
Copyright (c) 2021. Pfizer Inc. All rights reserved.
"""
import warnings

from numpy import maximum, abs, repeat, arctan, sqrt, pi
from numpy.linalg import norm
from scipy.signal import butter, sosfiltfilt
Expand Down Expand Up @@ -38,9 +40,11 @@ def metric_anglez(accel, wlen, *args, **kwargs):
anglez : numpy.ndarray
(N, ) array of angles between accelerometer z axis and horizontal plane in degrees.
"""
anglez = arctan(accel[:, 2] / sqrt(accel[:, 0] ** 2 + accel[:, 1] ** 2)) * (
180 / pi
)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", message="divide by zero encountered in divide")
anglez = arctan(accel[:, 2] / sqrt(accel[:, 0] ** 2 + accel[:, 1] ** 2)) * (
180 / pi
)
return moving_mean(anglez, wlen, wlen)


Expand Down
2 changes: 1 addition & 1 deletion src/skdh/gait/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

.. currentmodule:: skdh.gait

Pipeline gait processing
Pipeline Gait Processing
------------------------

.. autosummary::
Expand Down
2 changes: 1 addition & 1 deletion src/skdh/gait/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class GaitLumbar(BaseProcess):
- `btype`: band
- `output`: sos - NOTE that this will always be set/overriden

See :scipy-signal:func:`scipy.signal.butter` for full options.
See :func:`scipy.signal.butter` for full options.
ic_prom_factor : float, optional
[:meth:`skdh.gaitv3.substeps.ApCwtGaitEvents`] Factor multiplied by the
standard deviation of the CWT coefficients to obtain a minimum prominence
Expand Down
2 changes: 1 addition & 1 deletion src/skdh/gait/substeps/s1_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class PreprocessGaitBout(BaseProcess):
- `btype`: band
- `output`: sos - NOTE that this will always be set/overriden

See :scipy-signal:func:`scipy.signal.butter` for full options.
See :func:`scipy.signal.butter` for full options.
"""

def __init__(
Expand Down
15 changes: 14 additions & 1 deletion src/skdh/io/apdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class ReadApdmH5(BaseProcess):
sensor_location : str
Sensor location to get data from. Looks at the `Label 0` key to find the
desired sensor.
localize_timestamps : bool, optional
Convert timestamps to local time from UTC. Default is True. Uses APDM's
timezone offset attribute for the sensor being extracted.
gravity_acceleration : float, optional
Acceleration due to gravity. Used to convert values to units of `g`.
Default is 9.81 m/s^2.
Expand All @@ -46,10 +49,11 @@ class ReadApdmH5(BaseProcess):
- Sternum
"""

def __init__(self, sensor_location, gravity_acceleration=9.81, ext_error="warn"):
def __init__(self, sensor_location, localize_timestamps=True, gravity_acceleration=9.81, ext_error="warn"):
super().__init__(
# kwargs
sensor_location=sensor_location,
localize_timestamps=localize_timestamps,
gravity_acceleration=gravity_acceleration,
ext_error=ext_error,
)
Expand All @@ -59,6 +63,7 @@ def __init__(self, sensor_location, gravity_acceleration=9.81, ext_error="warn")
else:
raise ValueError("`ext_error` must be one of 'raise', 'warn', 'skip'.")

self.localize_time = localize_timestamps
self.sens = sensor_location
self.g = gravity_acceleration

Expand Down Expand Up @@ -113,4 +118,12 @@ def predict(self, *, file, **kwargs):
res[self._gyro] = f["Sensors"][sid]["Gyroscope"][()]
res[self._temp] = f["Sensors"][sid]["Temperature"][()]

# if we are converting to local time
if self.localize_time:
offset_hours = float(f['Sensors'][sid]['Configuration'].attrs["Timezone Offset"])
# convert to seconds
offset_sec = offset_hours * 3600.0

res[self._time] += offset_sec

return res
2 changes: 1 addition & 1 deletion src/skdh/io/axivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def predict(self, *, file, **kwargs):
super().predict(expect_days=False, expect_wear=False, file=file, **kwargs)

# read the file
fs, n_bad_samples, imudata, ts, temperature = read_axivity(file)
fs, n_bad_samples, imudata, ts, temperature = read_axivity(str(file))

# end = None if n_bad_samples == 0 else -n_bad_samples
end = None
Expand Down
2 changes: 1 addition & 1 deletion src/skdh/io/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def handle_timestamp_inconsistency(df, fill_gaps, accel_col_names, accel_in_g, g
t_delta = to_timedelta(t_delta, unit="s")

# add the time delta so that we have unique timestamps
df["_datetime_"] += t_delta
df.loc[:, "_datetime_"] += t_delta

# check if we are filling gaps or not
if fill_gaps:
Expand Down
2 changes: 1 addition & 1 deletion src/skdh/io/geneactiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def predict(self, *, file, **kwargs):
super().predict(expect_days=False, expect_wear=False, file=file, **kwargs)

# read the file
n_max, fs, acc, time, light, temp = read_geneactiv(file)
n_max, fs, acc, time, light, temp = read_geneactiv(str(file))

results = {
self._time: time[:n_max],
Expand Down
8 changes: 4 additions & 4 deletions tests/io/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def predict(self, *, test_input=None, **kwargs):

@fixture
def gnactv_file(path_tests):
return str(path_tests / "io" / "data" / "gnactv_sample.bin")
return path_tests / "io" / "data" / "gnactv_sample.bin"


@fixture
Expand All @@ -63,7 +63,7 @@ def gnactv_truth(path_tests):

@fixture
def ax3_file(path_tests):
return str(path_tests / "io" / "data" / "ax3_sample.cwa")
return path_tests / "io" / "data" / "ax3_sample.cwa"


@fixture
Expand All @@ -78,7 +78,7 @@ def ax3_truth(path_tests):

@fixture
def ax6_file(path_tests):
return str(path_tests / "io" / "data" / "ax6_sample.cwa")
return path_tests / "io" / "data" / "ax6_sample.cwa"


@fixture
Expand All @@ -93,7 +93,7 @@ def ax6_truth(path_tests):

@fixture
def apdm_file(path_tests):
return str(path_tests / "io" / 'data' / "apdm_sample.h5")
return path_tests / "io" / 'data' / "apdm_sample.h5"


@fixture
Expand Down
4 changes: 2 additions & 2 deletions tests/io/test_apdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

class TestApdmReader:
def test(self, apdm_file):
res = ReadApdmH5("Lumbar", gravity_acceleration=9.81).predict(file=apdm_file)
res = ReadApdmH5("Lumbar", localize_timestamps=True, gravity_acceleration=9.81).predict(file=apdm_file)

lumbar_sens = "XI-010284"
with h5py.File(apdm_file) as f:
acc = f["Sensors"][lumbar_sens]["Accelerometer"][()] / 9.81
time = f["Sensors"][lumbar_sens]["Time"][()] / 1e6 # to seconds
time = f["Sensors"][lumbar_sens]["Time"][()] / 1e6 - 4 * 3600 # to seconds, convert to local
gyro = f["Sensors"][lumbar_sens]["Gyroscope"][()]
temp = f["Sensors"][lumbar_sens]["Temperature"][()]

Expand Down
Loading