Skip to content

Commit 42487e0

Browse files
committed
Merge branch 'main' into feature/issue-160/replace-arparse-with-typer
2 parents 6ef1abd + 88896ef commit 42487e0

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

src/wristpy/processing/analytics.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,9 @@ def _find_periods(
301301

302302

303303
def _fill_false_blocks(boolean_array: np.ndarray, gap_block: int) -> np.ndarray:
304-
"""Helper function to fill gaps in SPT window that are less than gap_blocks.
304+
"""Helper function to fill gaps in any window that are less than gap_blocks.
305305
306-
We find the first non-zero in the sleep_idx_array, if there are none ,
306+
We find the first non-zero in the boolean_array, if there are none ,
307307
we return the initial array.
308308
We then iterate over the array and count every zero between ones
309309
(skipping the leading zeros),
@@ -314,7 +314,7 @@ def _fill_false_blocks(boolean_array: np.ndarray, gap_block: int) -> np.ndarray:
314314
gap_block: the length of the gap that needs to be filled.
315315
316316
Returns:
317-
A numpy array with 1s, typically for identified SPT windows.
317+
A booelan numpy array where true, typically, idicates the SPT windows.
318318
"""
319319
n_zeros = 0
320320
first_one_idx = next(
@@ -417,12 +417,15 @@ def sleep_cleanup(
417417

418418
sleep = _sleep_windows_as_measurement(nonwear_measurement.time, sleep_windows)
419419

420-
filtered_sleep = sleep.measurements - nonwear_measurement.measurements
420+
filtered_sleep = np.logical_and(
421+
sleep.measurements,
422+
np.logical_not(nonwear_measurement.measurements.astype(bool)),
423+
)
421424
cleaned_sleep = np.logical_not(
422425
_fill_false_blocks(np.logical_not(filtered_sleep), num_samples_15min)
423426
)
424427

425-
return models.Measurement(time=sleep.time, measurements=cleaned_sleep.astype(int))
428+
return models.Measurement(time=sleep.time, measurements=cleaned_sleep)
426429

427430

428431
def _sleep_windows_as_measurement(
@@ -440,17 +443,17 @@ def _sleep_windows_as_measurement(
440443
instances of the SleepWindow class.
441444
442445
Returns:
443-
A new Measurement instance with the sleep values.
446+
A new Measurement instance with the sleep values, as a booleans.
444447
"""
445448
logger.debug("Converting sleep windows to measurement.")
446449

447-
sleep_value = np.zeros(len(ref_measurement_time), dtype=int)
450+
sleep_value = np.zeros(len(ref_measurement_time), dtype=bool)
448451

449452
for sw in sleep_windows:
450453
if sw.onset is not None and sw.wakeup is not None:
451454
time_mask = (ref_measurement_time >= sw.onset) & (
452455
ref_measurement_time <= sw.wakeup
453456
)
454-
sleep_value[time_mask] = 1
457+
sleep_value[time_mask] = True
455458

456459
return models.Measurement(time=ref_measurement_time, measurements=sleep_value)

0 commit comments

Comments
 (0)