ruvnet/RuView · error · ValueError

sampling_rate must be positive

Error message

sampling_rate must be positive

What it means

Raised by CSIProcessor._validate_config during __init__ when the config dict contains sampling_rate but its value is <= 0. The processor divides time axes and FFT frequencies by sampling_rate, so a zero or negative rate would corrupt every downstream computation, hence the fail-fast check.

Source

Thrown at archive/v1/src/core/csi_processor.py:111

        self._human_detections = 0
    
    def _validate_config(self, config: Dict[str, Any]) -> None:
        """Validate configuration parameters.
        
        Args:
            config: Configuration to validate
            
        Raises:
            ValueError: If configuration is invalid
        """
        required_fields = ['sampling_rate', 'window_size', 'overlap', 'noise_threshold']
        missing_fields = [field for field in required_fields if field not in config]
        
        if missing_fields:
            raise ValueError(f"Missing required configuration: {missing_fields}")
        
        if config['sampling_rate'] <= 0:
            raise ValueError("sampling_rate must be positive")
        
        if config['window_size'] <= 0:
            raise ValueError("window_size must be positive")
        
        if not 0 <= config['overlap'] < 1:
            raise ValueError("overlap must be between 0 and 1")
    
    def preprocess_csi_data(self, csi_data: CSIData) -> CSIData:
        """Preprocess CSI data for feature extraction.
        
        Args:
            csi_data: Raw CSI data
            
        Returns:
            Preprocessed CSI data
            
        Raises:
            CSIProcessingError: If preprocessing fails

View on GitHub (pinned to 4685618388)

Solutions

  1. Set sampling_rate to the true CSI sample rate in Hz (e.g. 100 for 100 packets/sec capture, or your hardware's rate such as 1000 for high-rate ESP32 captures).
  2. If the rate is computed, guard it before construction: `rate = max(rate, 1)` or assert it derives from a positive duration.
  3. Log the resolved config right before constructing CSIProcessor to catch defaults leaking in as 0.
  4. For hardware-driven rates, ensure the extractor reports a positive measured rate before instantiating the processor.

Example fix

# before
config = {'sampling_rate': 0, 'window_size': 64, 'overlap': 0.5, 'noise_threshold': 0.1}
processor = CSIProcessor(config)  # ValueError

# after
config = {'sampling_rate': 100, 'window_size': 64, 'overlap': 0.5, 'noise_threshold': 0.1}
processor = CSIProcessor(config)
Defensive patterns

Strategy: validation

Validate before calling

def is_valid_csi_config(config: dict) -> bool:
    return (
        {'sampling_rate', 'window_size', 'overlap', 'noise_threshold'} <= config.keys()
        and config['sampling_rate'] > 0
    )

Try / catch

try:
    processor = CSIProcessor(config)
except ValueError as e:
    if 'sampling_rate must be positive' in str(e):
        config['sampling_rate'] = measured_rate  # from hardware/extractor
        processor = CSIProcessor(config)
    else:
        raise

Prevention

When it happens

Trigger: Constructing CSIProcessor with sampling_rate=0, a negative number, or a value that coerces to <= 0 (e.g. 0.0, -100). Typical call: CSIProcessor({'sampling_rate': 0, 'window_size': 64, 'overlap': 0.5, 'noise_threshold': 0.1}).

Common situations: Placeholder 0 in a config template never replaced; computing rate as `n_samples / duration` when duration is misparsed; ESP32 firmware subcarrier rate config injected as 0 before hardware init; YAML that parses an empty value into 0; unit tests probing boundary values.

Related errors


AI-assisted analysis of ruvnet/RuView@4685618388 (2026-08-16). Data as JSON: /api/errors/e30ee527b13afe35. Report an issue: GitHub.