digital-markers 0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. digital_markers-0.1/.github/workflows/publish.yml +46 -0
  2. digital_markers-0.1/.github/workflows/test.yml +28 -0
  3. digital_markers-0.1/.gitignore +18 -0
  4. digital_markers-0.1/LICENSE +17 -0
  5. digital_markers-0.1/PKG-INFO +310 -0
  6. digital_markers-0.1/README.md +273 -0
  7. digital_markers-0.1/pyproject.toml +31 -0
  8. digital_markers-0.1/src/digital_markers/__init__.py +13 -0
  9. digital_markers-0.1/src/digital_markers/context.py +13 -0
  10. digital_markers-0.1/src/digital_markers/exertion/__init__.py +5 -0
  11. digital_markers-0.1/src/digital_markers/exertion/markers.py +510 -0
  12. digital_markers-0.1/src/digital_markers/gait/__init__.py +5 -0
  13. digital_markers-0.1/src/digital_markers/gait/bouts.py +88 -0
  14. digital_markers-0.1/src/digital_markers/gait/markers.py +266 -0
  15. digital_markers-0.1/src/digital_markers/gait/spectral.py +21 -0
  16. digital_markers-0.1/src/digital_markers/gait/steps.py +44 -0
  17. digital_markers-0.1/src/digital_markers/location/__init__.py +5 -0
  18. digital_markers-0.1/src/digital_markers/location/distance.py +24 -0
  19. digital_markers-0.1/src/digital_markers/location/home.py +130 -0
  20. digital_markers-0.1/src/digital_markers/location/markers.py +360 -0
  21. digital_markers-0.1/src/digital_markers/location/staypoints.py +241 -0
  22. digital_markers-0.1/src/digital_markers/preprocessing/__init__.py +5 -0
  23. digital_markers-0.1/src/digital_markers/preprocessing/wear.py +104 -0
  24. digital_markers-0.1/src/digital_markers/requirements.py +8 -0
  25. digital_markers-0.1/src/digital_markers/results.py +14 -0
  26. digital_markers-0.1/src/digital_markers/routine/__init__.py +5 -0
  27. digital_markers-0.1/src/digital_markers/routine/markers.py +1078 -0
  28. digital_markers-0.1/tests/test_context.py +9 -0
  29. digital_markers-0.1/tests/test_exertion.py +507 -0
  30. digital_markers-0.1/tests/test_gait.py +129 -0
  31. digital_markers-0.1/tests/test_import.py +29 -0
  32. digital_markers-0.1/tests/test_location.py +95 -0
  33. digital_markers-0.1/tests/test_routine.py +107 -0
  34. digital_markers-0.1/tests/test_wear.py +50 -0
@@ -0,0 +1,46 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ permissions:
8
+ contents: read
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+
14
+ steps:
15
+ - uses: actions/checkout@v7
16
+
17
+ - uses: actions/setup-python@v7
18
+ with:
19
+ python-version: "3.14"
20
+
21
+ - name: Build package
22
+ run: |
23
+ python -m pip install --upgrade pip build
24
+ python -m build
25
+
26
+ - uses: actions/upload-artifact@v7
27
+ with:
28
+ name: python-package-distributions
29
+ path: dist/
30
+
31
+ publish:
32
+ needs: build
33
+ runs-on: ubuntu-latest
34
+ environment:
35
+ name: pypi
36
+ url: https://pypi.org/p/digital-markers
37
+ permissions:
38
+ id-token: write
39
+
40
+ steps:
41
+ - uses: actions/download-artifact@v7
42
+ with:
43
+ name: python-package-distributions
44
+ path: dist/
45
+
46
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,28 @@
1
+ name: Tests
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+
7
+ jobs:
8
+ test:
9
+ runs-on: ubuntu-latest
10
+ strategy:
11
+ fail-fast: false
12
+ matrix:
13
+ python-version: ["3.12", "3.14"]
14
+
15
+ steps:
16
+ - uses: actions/checkout@v7
17
+
18
+ - uses: actions/setup-python@v7
19
+ with:
20
+ python-version: ${{ matrix.python-version }}
21
+
22
+ - name: Install dependencies
23
+ run: |
24
+ python -m pip install --upgrade pip
25
+ python -m pip install -e ".[dev]"
26
+
27
+ - name: Run tests
28
+ run: pytest -q
@@ -0,0 +1,18 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ venv/
5
+ build/
6
+ dist/
7
+ *.egg-info/
8
+ .pytest_cache/
9
+ .coverage
10
+ htmlcov/
11
+ .ruff_cache/
12
+ .DS_Store
13
+ .vscode/
14
+ .idea/
15
+ refsrc
16
+ data/
17
+ results/
18
+ local/
@@ -0,0 +1,17 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Washington State University CASAS Lab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -0,0 +1,310 @@
1
+ Metadata-Version: 2.5
2
+ Name: digital-markers
3
+ Version: 0.1
4
+ Summary: Digital health markers derived from wearable sensor and participant data
5
+ Project-URL: Homepage, https://github.com/WSU-CASAS/digital-markers
6
+ Project-URL: Repository, https://github.com/WSU-CASAS/digital-markers
7
+ Project-URL: Issues, https://github.com/WSU-CASAS/digital-markers/issues
8
+ Author: WSU CASAS Lab
9
+ License: MIT License
10
+
11
+ Copyright (c) 2026 Washington State University CASAS Lab
12
+
13
+ Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ of this software and associated documentation files (the "Software"), to deal
15
+ in the Software without restriction, including without limitation the rights
16
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ copies of the Software, and to permit persons to whom the Software is
18
+ furnished to do so, subject to the following conditions:
19
+
20
+ The above copyright notice and this permission notice shall be included in all
21
+ copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26
+ License-File: LICENSE
27
+ Requires-Python: >=3.12
28
+ Requires-Dist: numpy
29
+ Requires-Dist: pandas
30
+ Requires-Dist: scipy
31
+ Provides-Extra: dev
32
+ Requires-Dist: build; extra == 'dev'
33
+ Requires-Dist: pytest; extra == 'dev'
34
+ Requires-Dist: pytest-cov; extra == 'dev'
35
+ Requires-Dist: ruff; extra == 'dev'
36
+ Description-Content-Type: text/markdown
37
+
38
+ # digital-markers
39
+
40
+ `digital-markers` is an open-source Python library from the CASAS Lab at
41
+ Washington State University. The package computes marker families from
42
+ wearable sensor data: exertion, gait, location, and behavioral routine.
43
+ Additional marker families will be added soon.
44
+
45
+ ## Supported markers
46
+
47
+ ### Exertion
48
+
49
+ `compute_exertion_markers` computes daily motion-only and
50
+ heart-rate-plus-motion exertion markers, with participant-level summaries.
51
+
52
+ ### Gait
53
+
54
+ `compute_gait_markers` computes daily wrist-derived walking-bout markers,
55
+ including step counts, cadence, step intervals, gait frequency, and signal
56
+ measures.
57
+
58
+ ### Location
59
+
60
+ `compute_location_markers` returns participant-level and daily location
61
+ measurements, plus home-location and staypoint tables in `details`.
62
+
63
+ ### Behavioral routine
64
+
65
+ `compute_routine_markers` computes model-free routine markers from 10 Hz motion
66
+ data using fixed acceleration thresholds. Its details include five-minute
67
+ interval, state-balance, region, and diagnostic tables.
68
+
69
+ ## Preparing participant data
70
+
71
+ The `compute_*_markers` functions accept a `ParticipantData` instance and
72
+ return a `MarkerResult`. Prepare one DataFrame for each sensor stream and use
73
+ the canonical column names below. Sensor timestamps must be parseable as
74
+ datetimes. Exertion requires the motion timestamp and, when heart rate is
75
+ provided, the heart-rate timestamp to have a Pandas datetime dtype. Gait and
76
+ routine require a datetime motion timestamp.
77
+
78
+ The package uses Pandas readers, so inputs can come from CSV or Parquet. This
79
+ CSV example assumes timestamps have no timezone or UTC offset and already
80
+ represent local wall-clock time:
81
+
82
+ ```python
83
+ import pandas as pd
84
+ from digital_markers import ParticipantData
85
+
86
+ motion = pd.read_csv("motion.csv")
87
+ motion["timestamp"] = pd.to_datetime(motion["timestamp"])
88
+
89
+ heart_rate = pd.read_csv("heart_rate.csv")
90
+ heart_rate["timestamp"] = pd.to_datetime(heart_rate["timestamp"])
91
+
92
+ location = pd.read_csv("location.csv")
93
+ location["timestamp"] = pd.to_datetime(location["timestamp"])
94
+
95
+ participant = ParticipantData(
96
+ participant_id="P001",
97
+ timezone="America/Los_Angeles",
98
+ motion=motion,
99
+ heart_rate=heart_rate,
100
+ location=location,
101
+ )
102
+ ```
103
+
104
+ For Parquet, use `pd.read_parquet("motion.parquet")` (and likewise for the
105
+ other streams; Pandas needs an optional Parquet engine such as `pyarrow`).
106
+ Parquet timestamps are often already datetimes; if a timestamp column was
107
+ stored as text, convert it with `pd.to_datetime` before calling the marker
108
+ functions. Do not infer a timezone from a naive timestamp: establish from the
109
+ source whether it represents local time or UTC. A naive local timestamp parsed
110
+ with `utc=True` is interpreted as UTC, not local time.
111
+
112
+ Use these column names:
113
+
114
+ | Stream | Required columns | Optional columns |
115
+ |---|---|---|
116
+ | `motion` | `timestamp`, `acceleration_x`, `acceleration_y`, `acceleration_z` | `rotation_rate_x`, `rotation_rate_y`, `rotation_rate_z`; routine can also use `latitude`, `longitude` |
117
+ | `heart_rate` | `timestamp`, `heart_rate` | None |
118
+ | `location` | `timestamp`, `latitude`, `longitude` | None |
119
+
120
+ Use numeric values for sensor measurements. Exertion requires all three
121
+ rotation-rate columns. Gait can run without rotation-rate columns; when
122
+ provided, supply all three. Routine can run without them, but if any rotation
123
+ column is present, all three are required. Location requires the latitude and
124
+ longitude columns, but their values may be missing on rows without a GPS fix.
125
+ Keep those rows and their timestamps: location uses them to estimate observed
126
+ recording time. Routine uses `location` coordinates when supplied, or motion
127
+ coordinates when present. Its motion input is expected at 10 Hz.
128
+
129
+ ### Timestamp and local-time guidance
130
+
131
+ Use the participant's IANA timezone (for example, `America/Los_Angeles`) as
132
+ the source of truth for local time. Keep original timestamps and their source
133
+ timezone/UTC-offset information in your stored data whenever possible. A
134
+ timezone-naive timestamp does not identify a timezone: treat it as local only
135
+ when the source confirms it is already local. If naive timestamps represent
136
+ UTC, localize them as UTC before converting; do not parse them as local time.
137
+ For example, for a CSV column known to contain UTC timestamps:
138
+
139
+ ```python
140
+ frame = pd.read_csv("motion.csv")
141
+ local_timezone = "America/Los_Angeles"
142
+ timestamps_utc = pd.to_datetime(frame["timestamp"], utc=True)
143
+ frame["timestamp"] = timestamps_utc.dt.tz_convert(local_timezone)
144
+ ```
145
+
146
+ `utc=True` is appropriate in that example only because the source is known to
147
+ be UTC (or contains explicit offsets). For naive local timestamps, use
148
+ `pd.to_datetime` without `utc=True`, as in the earlier example. If localizing
149
+ naive timestamps to a named timezone, choose an explicit policy for daylight
150
+ saving transitions: a fall-back clock change can make a local time occur twice,
151
+ and a spring-forward change can make some local times nonexistent. Pandas
152
+ defaults to raising on ambiguous or nonexistent times; resolve them using
153
+ source metadata rather than guessing.
154
+
155
+ The current marker functions do not apply one common local-time conversion:
156
+
157
+ - Routine converts timezone-aware motion and location timestamps to
158
+ `ParticipantData.timezone`, or UTC when `timezone` is omitted. Naive
159
+ timestamps are left unchanged and treated as local clock values.
160
+ - Exertion, gait, and location do not use `ParticipantData.timezone` to
161
+ convert inputs. Their daily grouping follows the timestamps as processed by
162
+ each implementation; timezone-aware inputs may therefore not align with
163
+ routine's local-day grouping.
164
+
165
+ Set `ParticipantData.timezone` for routine and ensure that motion and
166
+ heart-rate timestamps use compatible conventions for exertion. If local-day
167
+ alignment across all four marker families is essential, convert the streams
168
+ consistently before calling them and validate results around midnight and
169
+ daylight-saving transitions. Converting timezone-aware values to local time and
170
+ then removing timezone information can align ordinary local-day boundaries, but
171
+ it loses the distinction between the two occurrences of a repeated fall-back
172
+ time; routine removes duplicate motion timestamps. Retain the original
173
+ timezone-aware timestamps so that this ambiguity can be detected and handled
174
+ for the study's data.
175
+
176
+ ## Calling the marker functions
177
+
178
+ Import each function from its marker package. All functions take the same
179
+ participant object:
180
+
181
+ ```python
182
+ from digital_markers.exertion import compute_exertion_markers
183
+ from digital_markers.gait import compute_gait_markers
184
+ from digital_markers.location import compute_location_markers
185
+ from digital_markers.routine import compute_routine_markers
186
+
187
+ exertion = compute_exertion_markers(participant)
188
+ gait = compute_gait_markers(participant)
189
+ location_result = compute_location_markers(participant)
190
+ routine = compute_routine_markers(participant)
191
+ ```
192
+
193
+ Exertion requires `motion`; `heart_rate` is optional and can be omitted from
194
+ `ParticipantData` or set to `None`. Gait and routine require `motion`.
195
+ Location requires `location`; `motion` is optional and contributes timestamps
196
+ to its recorded-time calculations. Routine can use location data but does not
197
+ require it. Location and routine currently take no marker-specific keyword
198
+ arguments; routine configuration uses fixed thresholds.
199
+
200
+ ### Optional exertion arguments
201
+
202
+ Exertion defaults are suitable for typical use. The keyword-only arguments let
203
+ you customize windowing, signal filtering, and HR availability:
204
+
205
+ | Argument | Default | Purpose |
206
+ |---|---:|---|
207
+ | `time_window` | `None` | Pandas frequency string for aggregation windows; when unset, uses `window_seconds`. Keep `window_seconds` consistent when changing this frequency because it is also used in wear-time calculations. |
208
+ | `window_seconds` | `30` | Default aggregation window in seconds and the window duration used for wear-time calculations. |
209
+ | `hr_weight`, `motion_weight` | `0.3`, `0.7` | Weights for the HR and motion components of combined exertion. |
210
+ | `min_hr`, `max_hr` | `35`, `220` | Plausible HR bounds used for peak-HR reporting and HR cleaning when enabled. |
211
+ | `motion_robust_z_max`, `hr_robust_z_max` | `6.0`, `4.0` | Robust outlier cutoffs for motion and HR when signal filtering is enabled. |
212
+ | `min_motion_samples_per_window`, `min_hr_samples_per_window` | `5`, `1` | Minimum samples required to calculate each window's motion or HR measure. |
213
+ | `min_hr_values_for_markers` | `21` | Minimum valid HR samples needed to report HR-derived markers. |
214
+ | `filter_signals` | `False` | Enable robust outlier filtering for motion and HR values. |
215
+ | `use_short_smoothing` | `None` | Enable/disable rolling-median smoothing. `None` follows `filter_signals`; an explicit boolean overrides it. |
216
+ | `motion_smooth_seconds`, `hr_smooth_seconds` | `5`, `15` | Rolling-median window widths in seconds when smoothing is enabled. |
217
+
218
+ For example:
219
+
220
+ ```python
221
+ exertion = compute_exertion_markers(
222
+ participant,
223
+ window_seconds=30,
224
+ filter_signals=True,
225
+ min_hr_values_for_markers=30,
226
+ )
227
+ ```
228
+
229
+ ### Optional gait arguments
230
+
231
+ Gait accepts keyword-only parameters for sampling rate and bout detection. The
232
+ defaults are tuned for 10 Hz wrist motion; adjust them to match the sampling
233
+ rate and study protocol:
234
+
235
+ | Argument | Default | Purpose |
236
+ |---|---:|---|
237
+ | `fs` | `10.0` | Motion sampling frequency in Hz. |
238
+ | `wear_threshold` | `0.5` | Cutoff applied to the binary wear mask; the default retains samples marked worn. |
239
+ | `max_gap_factor` | `2.5` | Gap multiplier used to split discontinuous motion segments. |
240
+ | `min_steps` | `8` | Minimum steps for an accepted walking bout. |
241
+ | `min_bout_seconds` | `4.0` | Minimum walking-bout duration. |
242
+ | `max_step_gap_seconds` | `1.5` | Maximum allowed gap between detected steps. |
243
+ | `min_cadence`, `max_cadence` | `45.0`, `180.0` | Accepted cadence range in steps per minute. |
244
+ | `max_interval_cv` | `0.4` | Maximum coefficient of variation for step intervals. |
245
+ | `prominence_scale` | `0.5` | Scale factor used for step-peak prominence detection. |
246
+
247
+
248
+ ## Reading results
249
+
250
+ `MarkerResult` has `markers`, `daily`, `details`, and `metadata` attributes:
251
+
252
+ ```python
253
+ print(exertion.markers.head()) # participant-level summary
254
+ print(exertion.daily.head()) # one row per day, when provided by the marker
255
+
256
+ print(gait.daily[["date", "num_steps", "num_walking_bouts"]])
257
+ print(location_result.details["home_locations"])
258
+ print(routine.details["state_balance"])
259
+
260
+ for name, table in routine.details.items():
261
+ print(name, table.shape)
262
+ ```
263
+
264
+ `markers` contains participant-level values; `daily` contains daily
265
+ measurements when that marker provides them. Routine does not provide a `daily`
266
+ table: its five-minute records and summaries are in `details`. Use
267
+ `details.keys()` to see which additional tables are available, and inspect
268
+ `metadata` for marker-specific information such as participant ID and sampling
269
+ rate.
270
+
271
+ The tables are marker-specific. Exertion daily rows include motion-only and
272
+ HR-plus-motion exertion, peak HR, HR/motion relationships, and wear time;
273
+ participant summaries report statistics across daily measurements. Gait daily
274
+ rows include step and bout counts, walking duration, cadence, step-interval and
275
+ signal measures; participant summaries include means, standard deviations,
276
+ trends, and valid/recorded day counts. In summary column names, `mean_` denotes
277
+ the average across days, `std_` the spread, `slope_` the linear trend over time,
278
+ and `ac1_` lag-one autocorrelation when consecutive-day data is available;
279
+ exact calculations vary by marker. Location returns daily and
280
+ participant-level movement summaries, with `details["home_locations"]` and
281
+ `details["staypoints"]` for home and staypoint tables. Routine includes
282
+ `details["intervals"]`, `details["state_balance"]`, `details["regions"]`,
283
+ `details["motion_diagnostics"]`, and `details["location_diagnostics"]`.
284
+
285
+ Missing values are meaningful: a value may be unavailable because the stream
286
+ was not supplied or there were too few valid observations. In particular,
287
+ exertion's HR-derived metrics are unavailable when fewer than
288
+ `min_hr_values_for_markers` valid HR samples exist; motion-only results remain
289
+ available. Location can return empty summary tables when there are too few GPS
290
+ fixes or no recorded minutes. Check the relevant counts and detail tables
291
+ instead of replacing missing values with zero.
292
+
293
+
294
+ ## Installation
295
+
296
+ ```bash
297
+ python -m pip install digital-markers
298
+ ```
299
+
300
+ For development:
301
+
302
+ ```bash
303
+ git clone https://github.com/WSU-CASAS/digital-markers.git
304
+ cd digital-markers
305
+ python -m venv .venv
306
+ source .venv/bin/activate
307
+ python -m pip install --upgrade pip
308
+ python -m pip install -e ".[dev]"
309
+ pytest
310
+ ```