Missing-Event Gap Filling¶
biosigpy.hrv.fillgaps ¶
Iterative reconstruction of missing events in ordered time series.
FillGapsResult ¶
Bases: NamedTuple
Named, unpackable result of :func:fillgaps.
Attributes:
| Name | Type | Description |
|---|---|---|
tn | ndarray | Corrected event timestamps in seconds. Every original timestamp is preserved exactly and reconstructed timestamps may be inserted. |
dtn | ndarray | Successive corrected intervals in seconds. An interval spanning an unresolved gap is represented by |
Source code in src/biosigpy/hrv/fillgaps.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
fillgaps ¶
fillgaps(tk: ArrayLike, gap_detection_factor: float = 1.5, correction_upper_factor: float = 1.15, correction_lower_factor: float = 0.75, minimum_interval: float = 0.5, max_gap_duration: float = 10.0, debug: bool = False) -> FillGapsResult
Reconstruct missing event timestamps inside locally detected gaps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tk | array_like | Non-empty, finite, strictly increasing event timestamps in seconds. The series must already have undergone any desired false-positive removal. | required |
gap_detection_factor | float | Positive factor applied to the local adaptive baseline for detection. | 1.5 |
correction_upper_factor | float | Upper factor used to accept reconstructed intervals. | 1.15 |
correction_lower_factor | float | Lower factor used to detect over-insertion. | 0.75 |
minimum_interval | float | Non-negative absolute interval boundary in seconds. | 0.5 |
max_gap_duration | float | Positive maximum gap duration attempted for reconstruction, in seconds. | 10.0 |
debug | bool | When true, show the current gaps and every reconstruction attempt in an interactive figure. Accepted attempts are green, rejected attempts are red, and execution waits for a key press or mouse click after each attempt. The figure closes when processing finishes. | False |
Returns:
| Type | Description |
|---|---|
FillGapsResult | Named result containing corrected timestamps |
Raises:
| Type | Description |
|---|---|
TypeError | If a numeric input is non-numeric or complex. |
ValueError | If timestamps, parameter values, or factor relationships violate the Biosiglib contract. |
Notes
This function never calls :func:biosigpy.hrv.removefp implicitly. The recommended explicit preprocessing sequence is removefp(tk) followed by fillgaps(cleaned_tk). Normal calls have no plotting or other GUI side effects. Interactive inspection is enabled only by debug=True and requires Matplotlib with an interactive backend.
Examples:
>>> from biosigpy.hrv import fillgaps
>>> result = fillgaps([0, 1, 2, 4, 5, 6])
>>> result.tn
array([0., 1., 2., 3., 4., 5., 6.])
Source code in src/biosigpy/hrv/fillgaps.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |