From 0b3b191bc74e154859c625d9c141541bfd1e297e Mon Sep 17 00:00:00 2001 From: matmay Date: Thu, 23 Jan 2025 15:18:20 +0100 Subject: [PATCH 1/3] Update plot_nyquist arguments fix wrong arguments --- docs/source/examples/validation_example.ipynb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/source/examples/validation_example.ipynb b/docs/source/examples/validation_example.ipynb index c7103b2f..116bc56c 100644 --- a/docs/source/examples/validation_example.ipynb +++ b/docs/source/examples/validation_example.ipynb @@ -192,10 +192,10 @@ "ax2 = fig.add_subplot(gs[2,:])\n", "\n", "# plot original data\n", - "plot_nyquist(ax1, Z, fmt='s')\n", + "plot_nyquist(ax=ax1, Z=Z, fmt='s')\n", "\n", "# plot measurement model\n", - "plot_nyquist(ax1, meas_model.predict(f), fmt='-', scale=1e3, units='\\Omega')\n", + "plot_nyquist(ax=ax1, Z=meas_model.predict(f), fmt='-', scale=1e3, units='\\Omega')\n", "\n", "ax1.legend(['Data', 'Measurement model'], loc=2, fontsize=12)\n", "\n", @@ -330,10 +330,10 @@ "ax2 = fig.add_subplot(gs[2,:])\n", "\n", "# plot original data\n", - "plot_nyquist(ax1, Z, fmt='s')\n", + "plot_nyquist(ax=ax1, Z=Z, fmt='s')\n", "\n", "# plot measurement model\n", - "plot_nyquist(ax1, Z_linKK, fmt='-', scale=1e3, units='\\Omega')\n", + "plot_nyquist(ax=ax1, Z=Z_linKK, fmt='-', scale=1e3, units='\\Omega')\n", "\n", "ax1.legend(['Data', 'Lin-KK model'], loc=2, fontsize=12)\n", "\n", From bc299afa542d54881d7507ce0ea98801ad504f8a Mon Sep 17 00:00:00 2001 From: matmay Date: Thu, 23 Jan 2025 15:50:27 +0100 Subject: [PATCH 2/3] Update validation.py Always got an error and ChatGPT and I fought hard for this fix. Pls check if this is sensible as I don't understand enough to be sure this is a good way of fixing it. Problem was that for the eval() function np and all of the circuit_elements were not available. --- impedance/validation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/impedance/validation.py b/impedance/validation.py index 290d4a27..d6e19611 100644 --- a/impedance/validation.py +++ b/impedance/validation.py @@ -277,7 +277,7 @@ def eval_linKK(elements, ts, f): circuit_string = circuit_string.strip(',') circuit_string += '])' - return eval(circuit_string, circuit_elements) + return eval(circuit_string, {**circuit_elements, 'np': np}) def residuals_linKK(elements, ts, Z, f, residuals='real'): From cf6235ffbdfcb314420abcd1a7bbcf18cef58a94 Mon Sep 17 00:00:00 2001 From: matmay Date: Thu, 23 Jan 2025 17:55:20 +0100 Subject: [PATCH 3/3] Update preprocessing.py to also read Kolibrik Potentiostat Data --- impedance/preprocessing.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/impedance/preprocessing.py b/impedance/preprocessing.py index dbf0af6d..9404f041 100644 --- a/impedance/preprocessing.py +++ b/impedance/preprocessing.py @@ -390,6 +390,39 @@ def readCHInstruments(filename): return np.array(f), np.array(Z) +def readKolibrik(filename): + """ function for dat files from Kolibrik Potentiostats + + Parameters + ---------- + filename: string + Filename of .dat file to extract impedance data + + Returns + ------- + frequencies : np.ndarray + Array of frequencies + impedance : np.ndarray of complex numbers + Array of complex impedances + + """ + + with open(filename, 'r', encoding="utf8") as input_file: + lines = input_file.readlines() + + for i, line in enumerate(lines): + if line.find('[Data]') != -1: + start_line = i + + raw_data = lines[start_line+2:-1] + f, Z = [], [] + for line in raw_data: + each = line.split('\t') + f.append(float(each[5])) + Z.append(complex(float(each[3]), float(each[4]))) + + return np.array(f), np.array(Z) + def readCSV(filename): """ function for reading plain csv files