A robot sensor report can show a small spread even if the logger captured very few usable readings. That matters when a reviewer compares channels during the same test window. In this example, the interquartile range for a channel with one valid reading is zero. The count tells the reviewer why that value provides no evidence about variation across the window.

Keep the quality mask beside the measurement

The interquartile range, or IQR, subtracts the 25th percentile from the 75th percentile. Each row in the fixture is a sample time and each column is one sensor channel. Calculating along axis 0 gives one IQR per channel. This fixture treats both NaNs and infinities as invalid, then uses the same finite-value mask to report the count and select readings for the statistic. SciPy's NaN omission handles the NaNs after the conversion.

import numpy as np

from scipy.stats import iqr

samples = np.array([

[1, 10, 20],

[2, np.nan, np.nan],

[3, np.inf, np.nan],

[4, 14, np.nan],

[5, 16, np.nan],

], dtype=float)

finite = np.isfinite(samples)

valid_count = finite.sum(axis=0)

clean = np.where(finite, samples, np.nan)

spread = iqr(

clean, axis=0, nan_policy="omit", interpolation="linear",

)

reportable = np.where(valid_count >= 3, spread, np.nan)

assert valid_count.tolist() == [5, 3, 1]

assert np.allclose(spread, [2, 3, 0])

assert np.allclose(reportable, [2, 3, np.nan], equal_nan=True)

SciPy 1.18.1 and NumPy 2.5.5 produced the expected counts and ranges. The complete channel has an IQR of 2. The second channel retains readings of 10, 14, and 16, which give an IQR of 3 with linear interpolation. The third channel has only the reading of 20. Its two quartiles coincide, so the raw result is zero. The report suppresses that result under this fixture's minimum of three finite samples. That threshold is an example of a reporting rule. Choose a minimum that matches the test protocol and expected coverage.

Distinguish a missing statistic from a steady channel

Export the count, the expected number of samples, the statistic, and the reason when the statistic is withheld. This lets a reviewer distinguish an under-sampled channel from one with several identical valid readings. If missing readings cluster around motion or impact, a finite count can still hide gaps in the part of the test that matters. Retain sample times or a coverage summary so the reviewer can tell which portions contributed.

Sources

SciPy iqr reference for interpolation, reduction axes, and NaN handling

https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.iqr.html

NumPy isfinite reference for identifying finite values

https://numpy.org/doc/stable/reference/generated/numpy.isfinite.html