Skip to content

Commit

Permalink
feat(quality-control): add new field DataSpan(days)
Browse files Browse the repository at this point in the history
  • Loading branch information
chanshing committed Oct 25, 2024
1 parent 30b7a24 commit d7ce6a6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions data-dictionary.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- **StartTime**: Timestamp marking the beginning of the data recording.
- **EndTime**: Timestamp marking the end of the data recording.
- **WearTime(days)**: Total time the device was worn, expressed in days.
- **DataSpan(days)**: Time span of the data (difference between last and first timestamps).
- **NumInterrupts**: Number of interruptions in the data recording.
- **LowpassOK**: A binary indicator (1 for success, 0 for failure) showing whether the lowpass filter was applied successfully.
- **LowpassCutoff(Hz)**: The cutoff frequency in Hertz for the lowpass filter.
Expand Down
6 changes: 5 additions & 1 deletion src/actipy/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def quality_control(data, sample_rate):
:param data: A pandas.DataFrame of acceleration time-series. The index must be a DateTimeIndex.
:type data: pandas.DataFrame
:type data: pandas.DataFrame
:param sample_rate: Target sample rate (Hz) to achieve.
:type sample_rate: int or float
:return: A tuple containing the processed data and a dictionary with general information about the data.
Expand All @@ -32,6 +33,7 @@ def quality_control(data, sample_rate):
duration of valid (non-NaN) data and does not account for potential \
nonwear segments. See ``find_nonwear_segments`` and ``flag_nonwear`` to \
find and flag nonwear segments in the data.
- **DataSpan(days)**: Time span of the data (difference between last and first timestamps).
- **NumInterrupts**: The number of interruptions in the data (gaps or NaNs between samples).
- **ReadErrors**: The number of data errors (if non-increasing timestamps are found).
- **Covers24hOK**: Whether the data covers all 24 hours of the day.
Expand All @@ -46,6 +48,7 @@ def quality_control(data, sample_rate):
info['EndTime'] = None
info['NumTicks'] = 0
info['WearTime(days)'] = 0
info['DataSpan(days)'] = 0
info['NumInterrupts'] = 0
return data, info

Expand Down Expand Up @@ -77,7 +80,8 @@ def quality_control(data, sample_rate):
total_time = tdiff[tdiff < tol].sum().total_seconds()
num_interrupts = (tdiff > tol).sum()
del tdiff # we're done with this
info['WearTime(days)'] = total_time / (60 * 60 * 24) # redundant now, but might get updated later if nonwear detection is run
info['WearTime(days)'] = total_time / (60 * 60 * 24)
info['DataSpan(days)'] = (data.index[-1] - data.index[0]).total_seconds() / (60 * 60 * 24)
info['NumInterrupts'] = num_interrupts

# Check if data covers all 24 hours of the day
Expand Down
1 change: 1 addition & 0 deletions tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def test_read_device():
"EndTime": '2023-06-08 15:19:33',
"NumTicks": 1021800,
"WearTime(days)": 0.1211432638888889,
"DataSpan(days)": 0.12395172453703704,
"NumInterrupts": 1,
"Covers24hOK": 0
}
Expand Down

0 comments on commit d7ce6a6

Please sign in to comment.