From ad54866a040931cbdcc685bfe0a46fd1f3078392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9=20=D0=9F=D1=83?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2?= Date: Mon, 28 Nov 2022 01:54:15 +0300 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=B8?= =?UTF-8?q?=D0=BB(=D0=B0)=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B2=20'Pro?= =?UTF-8?q?ject'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project/analize.py | 38 +++++++++++++++++++++++++++++++++++++ Project/rw_device_params.py | 33 ++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 Project/analize.py create mode 100644 Project/rw_device_params.py 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