Extend pipelines/steps/adjust_uncertainty_column_in_nas_file.py to handle list of variables.

This commit is contained in:
2025-05-27 09:53:12 +02:00
parent 38fe2b8774
commit f3f830487e
2 changed files with 103 additions and 49 deletions

View File

@ -93,8 +93,28 @@ def generate_missing_value_code(max_val, num_decimals):
return missing_code
def compute_uncertainty_estimate(x,x_err):
return ((0.5*x_err)**2+(0.5*x)**2)**0.5
import math
import numpy as np
def compute_uncertainty_estimate(x, x_err):
"""
Computes uncertainty estimate: sqrt((0.5 * x_err)^2 + (0.5 * x)^2)
for scalar inputs. Prints errors if inputs are invalid.
"""
try:
x = float(x)
x_err = float(x_err)
if math.isnan(x) or math.isnan(x_err):
print(f"Warning: One or both inputs are NaN -> x: {x}, x_err: {x_err}")
return np.nan
return math.sqrt((0.5 * x_err)**2 + (0.5 * x)**2)
except (ValueError, TypeError) as e:
print(f"Error computing uncertainty for x: {x}, x_err: {x_err} -> {e}")
return np.nan
def generate_error_dataframe(df: pd.DataFrame, datetime_var):