{"record":{"id":"a90e08df08334a25","repo":"ruvnet/RuView","slug":"outlier-threshold-must-be-positive","errorCode":null,"errorMessage":"outlier_threshold must be positive","messagePattern":"outlier_threshold must be positive","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"archive/v1/src/core/phase_sanitizer.py","lineNumber":72,"sourceCode":"            config: Configuration to validate\n            \n        Raises:\n            ValueError: If configuration is invalid\n        \"\"\"\n        required_fields = ['unwrapping_method', 'outlier_threshold', 'smoothing_window']\n        missing_fields = [field for field in required_fields if field not in config]\n        \n        if missing_fields:\n            raise ValueError(f\"Missing required configuration: {missing_fields}\")\n        \n        # Validate unwrapping method\n        valid_methods = ['numpy', 'scipy', 'custom']\n        if config['unwrapping_method'] not in valid_methods:\n            raise ValueError(f\"Invalid unwrapping method: {config['unwrapping_method']}. Must be one of {valid_methods}\")\n        \n        # Validate thresholds\n        if config['outlier_threshold'] <= 0:\n            raise ValueError(\"outlier_threshold must be positive\")\n        \n        if config['smoothing_window'] <= 0:\n            raise ValueError(\"smoothing_window must be positive\")\n    \n    def unwrap_phase(self, phase_data: np.ndarray) -> np.ndarray:\n        \"\"\"Unwrap phase data to remove discontinuities.\n        \n        Args:\n            phase_data: Wrapped phase data (2D array)\n            \n        Returns:\n            Unwrapped phase data\n            \n        Raises:\n            PhaseSanitizationError: If unwrapping fails\n        \"\"\"\n        try:\n            if self.unwrapping_method == 'numpy':","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/ruvnet/RuView/blob/4685618388a5e49fad5b3005806f3bdd6a7c25c3/archive/v1/src/core/phase_sanitizer.py#L54-L90","documentation":"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.","triggerScenarios":"Constructing PhaseSanitizer with outlier_threshold=0, a negative number, or 0.0. Example: PhaseSanitizer({'unwrapping_method': 'numpy', 'outlier_threshold': 0, 'smoothing_window': 5}).","commonSituations":"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.","solutions":["Set outlier_threshold to a positive value; 3.0 (three-sigma) is the standard starting point.","If disabling outlier removal is the goal, set enable_outlier_removal=False and keep a positive threshold value.","Guard computed thresholds: `threshold = abs(threshold) or 3.0` before construction.","Check the config file for a mistyped 0 or a missing decimal point (e.g. 0 instead of 0.5)."],"exampleFix":"# before\nconfig = {'unwrapping_method': 'numpy', 'outlier_threshold': 0, 'smoothing_window': 5}\n# intent: no outlier removal\n\n# after\nconfig = {'unwrapping_method': 'numpy', 'outlier_threshold': 3.0,\n          'smoothing_window': 5, 'enable_outlier_removal': False}","handlingStrategy":"validation","validationCode":"threshold = float(config.get('outlier_threshold', 0))\nif threshold <= 0:\n    if not config.get('enable_outlier_removal', True):\n        threshold = 3.0  # disable via flag, keep valid threshold\n    else:\n        threshold = 3.0  # default sigma\nconfig['outlier_threshold'] = threshold","typeGuard":null,"tryCatchPattern":"try:\n    sanitizer = PhaseSanitizer(config)\nexcept ValueError as e:\n    if 'outlier_threshold must be positive' in str(e):\n        config['outlier_threshold'] = 3.0\n        sanitizer = PhaseSanitizer(config)\n    else:\n        raise","preventionTips":["Store thresholds as positive sigma values (3.0 is the standard).","Use enable_outlier_removal=False to disable; never encode disablement as 0.","Validate config-file numbers with a lint pass before deployment."],"tags":["config","validation","phase-sanitizer","outliers"],"backgroundTag":null,"analyzedSha":"4685618388a5e49fad5b3005806f3bdd6a7c25c3","analyzedAt":"2026-08-16T06:09:40.886Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}