Skip to content

Commit 4c85a1e

Browse files
Merge pull request #438 from EIT-ALIVE/437_fix_pixelbreath_bug
Fix bug in pixel breath for NaN pixels
2 parents 2205fe0 + 95f59a7 commit 4c85a1e

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

eitprocessing/features/pixel_breath.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121

2222
def _return_sentinel_breath_detection() -> BreathDetection:
23-
# Returns a sential of a BreathDetection, which only exists to signal that the default value for breath_detection
23+
# Returns a sentinel of a BreathDetection, which only exists to signal that the default value for breath_detection
2424
# was used.
2525
return _SENTINEL_BREATH_DETECTION
2626

@@ -190,9 +190,13 @@ def find_pixel_breaths( # noqa: C901, PLR0912, PLR0915
190190
raise ValueError(msg)
191191

192192
for row, col in itertools.product(range(n_rows), range(n_cols)):
193+
if all_nan_mask[row, col]:
194+
# pixel has no amplitude
195+
continue
193196
mean_tiv = mean_tiv_pixel[row, col]
194197

195-
if np.std(pixel_impedance[:, row, col]) == 0:
198+
pi = np.copy(pixel_impedance[:, row, col]) # TODO: check whether copying is necessary
199+
if np.std(pi) == 0:
196200
# pixel has no amplitude
197201
continue
198202

@@ -204,7 +208,7 @@ def find_pixel_breaths( # noqa: C901, PLR0912, PLR0915
204208

205209
cd = np.copy(continuous_data.values)
206210
cd = signal.detrend(cd, type="linear")
207-
pi = np.copy(pixel_impedance[:, row, col])
211+
208212
if not np.all(np.isnan(pi)):
209213
pi = signal.detrend(pi, type="linear")
210214

tests/test_pixel_breath.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,23 @@ def none_sequence():
169169

170170
def mock_compute_pixel_parameter(mean: int):
171171
def _mock(*_args, **_kwargs) -> SparseData:
172+
n_breaths = 3
173+
n_rows, n_cols = 2, 2
174+
values = [np.full((n_rows, n_cols), mean, dtype=float) for _ in range(n_breaths)]
175+
176+
# Time must have the same length as values
177+
time = np.linspace(0, 10, n_breaths)
178+
172179
return SparseData(
173180
label="mock_sparse_data",
174181
name="Tidal impedance variation",
175182
unit=None,
176183
category="impedance difference",
177-
time=np.linspace(0, 100, 100),
184+
time=time,
178185
description="Mock tidal impedance variation",
179186
parameters={},
180187
derived_from=[],
181-
values=np.full(100, np.sign(mean)),
188+
values=values,
182189
)
183190

184191
return _mock
@@ -351,6 +358,7 @@ def test_with_data(draeger1: Sequence, timpel1: Sequence, pytestconfig: pytest.C
351358
ssequence = sequence
352359
pi = PixelBreath()
353360
eit_data = ssequence.eit_data["raw"]
361+
eit_data.pixel_impedance[:, 0, 0] = np.nan # set one pixel to NaN to test handling of NaNs
354362
cd = ssequence.continuous_data["global_impedance_(raw)"]
355363
pixel_breaths = pi.find_pixel_breaths(eit_data, cd)
356364
test_result = np.stack(pixel_breaths.values)

0 commit comments

Comments
 (0)