ruvnet/RuView · error · ValueError

smoothing_window must be positive

Error message

smoothing_window must be positive

What it means

Raised by PhaseSanitizer._validate_config when smoothing_window is present but <= 0. The window is the length (in samples) of the smoothing filter applied to phase; zero or negative lengths are rejected because convolution with such kernels is undefined. Validation happens in __init__, before any data is touched.

Source

Thrown at archive/v1/src/core/phase_sanitizer.py:75

            ValueError: If configuration is invalid
        """
        required_fields = ['unwrapping_method', 'outlier_threshold', 'smoothing_window']
        missing_fields = [field for field in required_fields if field not in config]
        
        if missing_fields:
            raise ValueError(f"Missing required configuration: {missing_fields}")
        
        # Validate unwrapping method
        valid_methods = ['numpy', 'scipy', 'custom']
        if config['unwrapping_method'] not in valid_methods:
            raise ValueError(f"Invalid unwrapping method: {config['unwrapping_method']}. Must be one of {valid_methods}")
        
        # Validate thresholds
        if config['outlier_threshold'] <= 0:
            raise ValueError("outlier_threshold must be positive")
        
        if config['smoothing_window'] <= 0:
            raise ValueError("smoothing_window must be positive")
    
    def unwrap_phase(self, phase_data: np.ndarray) -> np.ndarray:
        """Unwrap phase data to remove discontinuities.
        
        Args:
            phase_data: Wrapped phase data (2D array)
            
        Returns:
            Unwrapped phase data
            
        Raises:
            PhaseSanitizationError: If unwrapping fails
        """
        try:
            if self.unwrapping_method == 'numpy':
                return self._unwrap_numpy(phase_data)
            elif self.unwrapping_method == 'scipy':
                return self._unwrap_scipy(phase_data)

View on GitHub (pinned to 4685618388)

Solutions

  1. Set smoothing_window to a positive odd integer such as 5 or 7 (odd lengths avoid phase shift in symmetric filters).
  2. To disable smoothing, set enable_smoothing=False and keep a positive window value.
  3. Guard computed windows: `smoothing_window = max(1, computed)` or skip sanitization until enough samples exist.
  4. Verify the units: it is a sample count, not seconds.

Example fix

# before
config = {'unwrapping_method': 'numpy', 'outlier_threshold': 3.0, 'smoothing_window': 0}

# after
config = {'unwrapping_method': 'numpy', 'outlier_threshold': 3.0,
          'smoothing_window': 5, 'enable_smoothing': False}  # if disabling was the intent
Defensive patterns

Strategy: validation

Validate before calling

window = int(config.get('smoothing_window', 0))
if window < 1:
    window = 5 if config.get('enable_smoothing', True) else 5  # keep valid; flag controls behavior
config['smoothing_window'] = window

Try / catch

try:
    sanitizer = PhaseSanitizer(config)
except ValueError as e:
    if 'smoothing_window must be positive' in str(e):
        config['smoothing_window'] = 5
        sanitizer = PhaseSanitizer(config)
    else:
        raise

Prevention

When it happens

Trigger: Constructing PhaseSanitizer with smoothing_window=0 or negative, e.g. PhaseSanitizer({'unwrapping_method': 'numpy', 'outlier_threshold': 3.0, 'smoothing_window': 0}).

Common situations: 0 placeholder never replaced; window derived as `int(duration * rate)` with a zero factor; disabling intent (use enable_smoothing=False instead); config sweeps that include 0; window computed from buffer length on cold start when the buffer is empty.

Related errors


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