diff --git a/Project/analize.py b/Project/analize.py new file mode 100644 index 0000000..9a30643 --- /dev/null +++ b/Project/analize.py @@ -0,0 +1,38 @@ +from scipy.optimize import curve_fit +from numpy import linspace + +from numpy import tanh +from scipy.constants import e, k + + +import pandas as pd + + +# Global variables + +new_U = linspace(-25, 25, 1000) + + +# Function for approximation + + +def function_IU(U, I_n, T_e): + return I_n * tanh(e*U/2/k/T_e) + +# Find the best fit params of In and Te + + +def find_FitParams(data_I, data_U): + popt, pcov = curve_fit(function_IU, data_U, data_I, p0=[0, 50000]) + return popt, pcov + +# Returns pandas.DataFrame with approximated Current and Voltage values + + +def getApproxValues(data): + data = data.sort_values(by=['U']) + popt, pcov = find_FitParams(data['I'], data['U']) + df = pd.DataFrame() + df['U'] = new_U + df['I'] = function_IU(df['U'], *popt) + return df diff --git a/Project/rw_device_params.py b/Project/rw_device_params.py new file mode 100644 index 0000000..bf44fb0 --- /dev/null +++ b/Project/rw_device_params.py @@ -0,0 +1,33 @@ +# Dict for all devices params + +all_params = {'func': 0, 'status': 1, 'name': 2, + 'id': 3, 'type_of_connection': 4, 'baud_rate': 5} + +# Read device params from .dat device file + + +def read_device_params(name): + file = open('data/{}.dat'.format(name), 'r') + params = file.readline().split() + file.close() + return params + +# Change device params in .dat device file + + +def write_device_params(name, param, value): + + try: + file = open('data/{}.dat'.format(name), 'r+') + params = file.readline().split() + if value != '': + params[all_params[param]] = str(value) + else: + params[all_params[param]] = 'none' + file.seek(0) + file.truncate() + file.write(' '.join(params)) + file.close() + + except IndexError: + print('ErrorType = FileError: File.dat for this device does not exist') \ No newline at end of file