From 6ec9b5917390a45bfe00be24c89fe971c03d895c Mon Sep 17 00:00:00 2001 From: Julian Peters Date: Sat, 29 Apr 2023 14:52:36 +0200 Subject: [PATCH 1/2] initial commit --- errorcalc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/errorcalc.py b/errorcalc.py index 52c6d11..098f15d 100644 --- a/errorcalc.py +++ b/errorcalc.py @@ -3,7 +3,7 @@ class Error: - def __init__(self, func): + def __init__(self, func: callable): # Get the arguments of the function arg_names = inspect.getfullargspec(func).args # Define the variables as regular Python variables @@ -21,7 +21,7 @@ def __init__(self, func): f_prime = self.f.diff(variable) self.derivatives[str(variable)] = f_prime - def substitute(self, values): + def substitute(self, values: dict): derivatives_sub = [] for variable in self.variables: # Get the variable name as a string From 672239ad3eeb980d14b40d0042fc90666f3167f3 Mon Sep 17 00:00:00 2001 From: Julian Peters Date: Sat, 29 Apr 2023 15:13:13 +0200 Subject: [PATCH 2/2] basic docstrings --- errorcalc.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/errorcalc.py b/errorcalc.py index 098f15d..db25774 100644 --- a/errorcalc.py +++ b/errorcalc.py @@ -3,7 +3,24 @@ class Error: + """ Perform a error estimation of given function + and corresponding errors for the variables. """ + def __init__(self, func: callable): + """ Constructer for the Error instance. + Parameters + ---------- + func: callable + Func (e.g. a physical Law) is the function, + to which the error estimation is to be calculated. + The Arguments used in func are automatticlay extraced using + the inspect library. + + Returns + ------ + Error Instance + + """ # Get the arguments of the function arg_names = inspect.getfullargspec(func).args # Define the variables as regular Python variables @@ -36,7 +53,7 @@ def substitute(self, values: dict): derivatives_sub.append(derivative_str) return " + ".join(derivatives_sub) - def latex_out(self, values): + def latex_out(self, values: dict): latex_str = "\\begin{align*}\n" latex_str += ( " &= \\Delta " @@ -72,7 +89,7 @@ def latex_out(self, values): latex_str += f" &= \\SI{{{float(result)}}}{{}}\n" latex_str += "\\end{align*}\n\n" return latex_str - def result(self, values): + def result(self, values: dict): result = sum( [ values[delta_name][0]