ruvnet/RuView · error · ValueError

outlier_threshold must be positive

Error message

outlier_threshold must be positive

What it means

Raised by PhaseSanitizer._validate_config when outlier_threshold is present but <= 0. The threshold (typically in standard deviations, e.g. 3.0) governs outlier removal on phase data; zero or negative thresholds would flag everything or nothing meaningful, so construction fails fast.

Source

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

            config: Configuration to validate
            
        Raises:
            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':

View on GitHub (pinned to 4685618388)

Solutions

  1. Set outlier_threshold to a positive value; 3.0 (three-sigma) is the standard starting point.
  2. If disabling outlier removal is the goal, set enable_outlier_removal=False and keep a positive threshold value.
  3. Guard computed thresholds: `threshold = abs(threshold) or 3.0` before construction.
  4. Check the config file for a mistyped 0 or a missing decimal point (e.g. 0 instead of 0.5).

Example fix

# before
config = {'unwrapping_method': 'numpy', 'outlier_threshold': 0, 'smoothing_window': 5}
# intent: no outlier removal

# after
config = {'unwrapping_method': 'numpy', 'outlier_threshold': 3.0,
          'smoothing_window': 5, 'enable_outlier_removal': False}
Defensive patterns

Strategy: validation

Validate before calling

threshold = float(config.get('outlier_threshold', 0))
if threshold <= 0:
    if not config.get('enable_outlier_removal', True):
        threshold = 3.0  # disable via flag, keep valid threshold
    else:
        threshold = 3.0  # default sigma
config['outlier_threshold'] = threshold

Try / catch

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

Prevention

When it happens

Trigger: Constructing PhaseSanitizer with outlier_threshold=0, a negative number, or 0.0. Example: PhaseSanitizer({'unwrapping_method': 'numpy', 'outlier_threshold': 0, 'smoothing_window': 5}).

Common situations: 0 used as a placeholder in templates; thresholds expressed as percentages (e.g. 5 meaning 5%) passed raw where a sigma value is expected, or 0 meaning auto; sign flipped when computing `threshold = mean - k*std` with negative std input; YAML empty value coerced to 0.

Related errors


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