diff --git a/docs/source/examples/validation_example.ipynb b/docs/source/examples/validation_example.ipynb index c7103b2..116bc56 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", diff --git a/impedance/preprocessing.py b/impedance/preprocessing.py index dbf0af6..9404f04 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 diff --git a/impedance/validation.py b/impedance/validation.py index 290d4a2..d6e1961 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'):