pySIMSalabim 1__tar.gz → 1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pysimsalabim-1 → pysimsalabim-1.2}/PKG-INFO +7 -4
- {pysimsalabim-1 → pysimsalabim-1.2}/README.md +4 -1
- pysimsalabim-1.2/pySIMsalabim/aux_funcs/addons.py +187 -0
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/experiments/JV_steady_state.py +13 -1
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/experiments/hysteresis.py +188 -19
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/experiments/impedance.py +216 -112
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/install/get_SIMsalabim.py +2 -2
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/utils/general.py +9 -2
- {pysimsalabim-1/pySIMSalabim.egg-info → pysimsalabim-1.2/pySIMsalabim.egg-info}/PKG-INFO +7 -4
- {pysimsalabim-1/pySIMSalabim.egg-info → pysimsalabim-1.2/pySIMsalabim.egg-info}/SOURCES.txt +5 -5
- {pysimsalabim-1 → pysimsalabim-1.2}/setup.py +3 -3
- pysimsalabim-1/pySIMsalabim/aux_funcs/addons.py +0 -55
- {pysimsalabim-1 → pysimsalabim-1.2}/LICENSE +0 -0
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/__init__.py +0 -0
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/aux_funcs/SCLC_funcs.py +0 -0
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/aux_funcs/__init__.py +0 -0
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/experiments/CV.py +0 -0
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/experiments/EQE.py +0 -0
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/experiments/__init__.py +0 -0
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/experiments/imps.py +0 -0
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/install/__init__.py +0 -0
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/install/compile_simsalabim.py +0 -0
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/install/get_gnu_parallel.py +0 -0
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/plots/__init__.py +0 -0
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/plots/band_diagram.py +0 -0
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/plots/plot_def.py +0 -0
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/plots/plot_functions.py +0 -0
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/tests/__init__.py +0 -0
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/tests/test_CV.py +0 -0
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/tests/test_EQE.py +0 -0
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/tests/test_IMPS.py +0 -0
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/tests/test_JV.py +0 -0
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/tests/test_hyst.py +0 -0
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/tests/test_impedance.py +0 -0
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/utils/__init__.py +0 -0
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/utils/clean_up.py +0 -0
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/utils/device_parameters.py +0 -0
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/utils/parallel_sim.py +0 -0
- {pysimsalabim-1 → pysimsalabim-1.2}/pySIMsalabim/utils/utils.py +0 -0
- {pysimsalabim-1/pySIMSalabim.egg-info → pysimsalabim-1.2/pySIMsalabim.egg-info}/dependency_links.txt +0 -0
- {pysimsalabim-1/pySIMSalabim.egg-info → pysimsalabim-1.2/pySIMsalabim.egg-info}/requires.txt +0 -0
- {pysimsalabim-1/pySIMSalabim.egg-info → pysimsalabim-1.2/pySIMsalabim.egg-info}/top_level.txt +0 -0
- {pysimsalabim-1 → pysimsalabim-1.2}/setup.cfg +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
|
-
Name:
|
|
3
|
-
Version: 1
|
|
2
|
+
Name: pySIMsalabim
|
|
3
|
+
Version: 1.2
|
|
4
4
|
Home-page: https://github.com/kostergroup/pySIMsalabim
|
|
5
|
-
Download-URL: https://github.com/kostergroup/pySIMsalabim/v1.tar.gz
|
|
5
|
+
Download-URL: https://github.com/kostergroup/pySIMsalabim/v1.02.tar.gz
|
|
6
6
|
Author: Vincent M. Le Corre, Sander Heester, L. Jan Anton Koster
|
|
7
7
|
Author-email:
|
|
8
8
|
License: GPLv3
|
|
@@ -26,7 +26,9 @@ Provides-Extra: dev
|
|
|
26
26
|
Requires-Dist: pytest; extra == "dev"
|
|
27
27
|
Requires-Dist: twine; extra == "dev"
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
<img src="./docs/logo/pySIMsalabim_logo.png" alt="pySIMsalabim logo" width="100px">
|
|
30
|
+
|
|
31
|
+
# pySIMsalabim
|
|
30
32
|
|
|
31
33
|
## Description
|
|
32
34
|
**pySIMsalabim** is a Python package used to interface drift-diffusion simulator [SIMsalabim](https://github.com/kostergroup/SIMsalabim) with Python. It provides many useful tools to set up and run simulations, as well as to analyze and visualize the results.
|
|
@@ -34,6 +36,7 @@ Requires-Dist: twine; extra == "dev"
|
|
|
34
36
|
## Authors
|
|
35
37
|
* [Vincent M. Le Corre](https://github.com/VMLC-PV)
|
|
36
38
|
* [Sander Heester](https://github.com/sheester)
|
|
39
|
+
* [Fransien Elhorst](https://github.com/Fransien-Elhorst)
|
|
37
40
|
* [L. Jan Anton Koster](https://github.com/kostergroup)
|
|
38
41
|
|
|
39
42
|
## Institutions
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
<img src="./docs/logo/pySIMsalabim_logo.png" alt="pySIMsalabim logo" width="100px">
|
|
2
|
+
|
|
3
|
+
# pySIMsalabim
|
|
2
4
|
|
|
3
5
|
## Description
|
|
4
6
|
**pySIMsalabim** is a Python package used to interface drift-diffusion simulator [SIMsalabim](https://github.com/kostergroup/SIMsalabim) with Python. It provides many useful tools to set up and run simulations, as well as to analyze and visualize the results.
|
|
@@ -6,6 +8,7 @@
|
|
|
6
8
|
## Authors
|
|
7
9
|
* [Vincent M. Le Corre](https://github.com/VMLC-PV)
|
|
8
10
|
* [Sander Heester](https://github.com/sheester)
|
|
11
|
+
* [Fransien Elhorst](https://github.com/Fransien-Elhorst)
|
|
9
12
|
* [L. Jan Anton Koster](https://github.com/kostergroup)
|
|
10
13
|
|
|
11
14
|
## Institutions
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"""Useful helper functions for pySIMsalabim"""
|
|
2
|
+
######### Package Imports #########################################################################
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
from scipy import stats,constants
|
|
6
|
+
|
|
7
|
+
## Physics constants
|
|
8
|
+
q = constants.value(u'elementary charge')
|
|
9
|
+
eps_0 = constants.value(u'electric constant')
|
|
10
|
+
kb = constants.value(u'Boltzmann constant in eV/K')
|
|
11
|
+
|
|
12
|
+
######### Function Definitions ####################################################################
|
|
13
|
+
|
|
14
|
+
def sci_notation(number, sig_fig=2):
|
|
15
|
+
"""Make proper scientific notation for graphs
|
|
16
|
+
|
|
17
|
+
Parameters
|
|
18
|
+
----------
|
|
19
|
+
number : float
|
|
20
|
+
Number to put in scientific notation.
|
|
21
|
+
|
|
22
|
+
sig_fig : int, optional
|
|
23
|
+
Number of significant digits (Defaults = 2).
|
|
24
|
+
|
|
25
|
+
Returns
|
|
26
|
+
-------
|
|
27
|
+
output : str
|
|
28
|
+
String containing the number in scientific notation
|
|
29
|
+
"""
|
|
30
|
+
if sig_fig != -1:
|
|
31
|
+
if number == 0:
|
|
32
|
+
output = '0'
|
|
33
|
+
else:
|
|
34
|
+
ret_string = "{0:.{1:d}e}".format(number, sig_fig)
|
|
35
|
+
a,b = ret_string.split("e")
|
|
36
|
+
if int(b) >= 0:
|
|
37
|
+
b = int(b) #removed leading "+" and strips leading zeros too.
|
|
38
|
+
c = ''
|
|
39
|
+
else:
|
|
40
|
+
b = abs(int(b))
|
|
41
|
+
c = u"\u207B" # superscript minus sign
|
|
42
|
+
SUP = str.maketrans("0123456789", "⁰¹²³⁴⁵⁶⁷⁸⁹")
|
|
43
|
+
b = str(b).translate(SUP)
|
|
44
|
+
output =a + ' x 10' + c + b
|
|
45
|
+
else:
|
|
46
|
+
if number == 0:
|
|
47
|
+
output = '0'
|
|
48
|
+
else:
|
|
49
|
+
ret_string = "{0:.{1:d}e}".format(number, 0)
|
|
50
|
+
a,b = ret_string.split("e")
|
|
51
|
+
b = int(b) #removed leading "+" and strips leading zeros too.
|
|
52
|
+
if int(b) >= 0:
|
|
53
|
+
b = int(b) #removed leading "+" and strips leading zeros too.
|
|
54
|
+
c = ''
|
|
55
|
+
else:
|
|
56
|
+
b = abs(int(b))
|
|
57
|
+
c = u"\u207B" # superscript minus sign
|
|
58
|
+
SUP = str.maketrans("0123456789", "⁰¹²³⁴⁵⁶⁷⁸⁹")
|
|
59
|
+
#SUB = str.maketrans("0123456789", "₀₁₂₃₄₅₆₇₈₉")
|
|
60
|
+
b = str(b).translate(SUP)
|
|
61
|
+
output = '10' + c + b
|
|
62
|
+
return output
|
|
63
|
+
|
|
64
|
+
def get_Jsc(Volt,Curr):
|
|
65
|
+
"""Get the short-circuit current (Jsc) from solar cell JV-curve by interpolating the current at 0 V
|
|
66
|
+
|
|
67
|
+
Parameters
|
|
68
|
+
----------
|
|
69
|
+
Volt : 1-D sequence of floats
|
|
70
|
+
Array containing the voltages.
|
|
71
|
+
|
|
72
|
+
Curr : 1-D sequence of floats
|
|
73
|
+
Array containing the current-densities.
|
|
74
|
+
|
|
75
|
+
Returns
|
|
76
|
+
-------
|
|
77
|
+
Jsc : float
|
|
78
|
+
Short-circuit current value
|
|
79
|
+
"""
|
|
80
|
+
Jsc_dumb = np.interp(0, Volt, Curr)
|
|
81
|
+
return Jsc_dumb
|
|
82
|
+
|
|
83
|
+
def get_Voc(Volt,Curr):
|
|
84
|
+
"""Get the Open-circuit voltage (Voc) from solar cell JV-curve by interpolating the Voltage when the current is 0
|
|
85
|
+
|
|
86
|
+
Parameters
|
|
87
|
+
----------
|
|
88
|
+
Volt : 1-D sequence of floats
|
|
89
|
+
Array containing the voltages.
|
|
90
|
+
|
|
91
|
+
Curr : 1-D sequence of floats
|
|
92
|
+
Array containing the current-densities.
|
|
93
|
+
|
|
94
|
+
Returns
|
|
95
|
+
-------
|
|
96
|
+
Voc : float
|
|
97
|
+
Open-circuit voltage value
|
|
98
|
+
"""
|
|
99
|
+
Voc_dumb = np.interp(0, Curr, Volt)
|
|
100
|
+
return Voc_dumb
|
|
101
|
+
|
|
102
|
+
def get_FF(Volt,Curr):
|
|
103
|
+
"""Get the fill factor (FF) from solar cell JV-curve by calculating the maximum power point
|
|
104
|
+
|
|
105
|
+
Parameters
|
|
106
|
+
----------
|
|
107
|
+
Volt : 1-D sequence of floats
|
|
108
|
+
Array containing the voltages.
|
|
109
|
+
|
|
110
|
+
Curr : 1-D sequence of floats
|
|
111
|
+
Array containing the current-densities.
|
|
112
|
+
|
|
113
|
+
Returns
|
|
114
|
+
-------
|
|
115
|
+
FF : float
|
|
116
|
+
Fill factor value
|
|
117
|
+
"""
|
|
118
|
+
power = []
|
|
119
|
+
Volt_oc = get_Voc(Volt,Curr)
|
|
120
|
+
Curr_sc = get_Jsc(Volt,Curr)
|
|
121
|
+
for i,j in zip(Volt,Curr):
|
|
122
|
+
if (i < Volt_oc and j > Curr_sc):
|
|
123
|
+
power.append(i*j)
|
|
124
|
+
power_max = min(power)
|
|
125
|
+
FF_dumb = power_max/(Volt_oc*Curr_sc)
|
|
126
|
+
return abs(FF_dumb)
|
|
127
|
+
|
|
128
|
+
def get_PCE(Volt,Curr,suns=1):
|
|
129
|
+
"""Get the power conversion efficiency (PCE) from solar cell JV-curve
|
|
130
|
+
|
|
131
|
+
Parameters
|
|
132
|
+
----------
|
|
133
|
+
Volt : 1-D sequence of floats
|
|
134
|
+
Array containing the voltages.
|
|
135
|
+
|
|
136
|
+
Curr : 1-D sequence of floats
|
|
137
|
+
Array containing the current-densities.
|
|
138
|
+
|
|
139
|
+
Returns
|
|
140
|
+
-------
|
|
141
|
+
PCE : float
|
|
142
|
+
Power conversion efficiency value.
|
|
143
|
+
"""
|
|
144
|
+
Voc_dumb = get_Voc(Volt,Curr)
|
|
145
|
+
Jsc_dumb = get_Jsc(Volt, Curr)
|
|
146
|
+
FF_dumb = get_FF(Volt, Curr)
|
|
147
|
+
PCE_dumb = Voc_dumb*Jsc_dumb*FF_dumb/(10*suns) # to get it in % when Jsc is in A/m2 and Voc in V
|
|
148
|
+
return abs(PCE_dumb)
|
|
149
|
+
|
|
150
|
+
def get_ideality_factor(suns,Vocs,T=295):
|
|
151
|
+
"""Returns ideality factor from suns-Voc data linear fit of Voc = (nIF/Vt)*log(suns) + intercept
|
|
152
|
+
|
|
153
|
+
Parameters
|
|
154
|
+
----------
|
|
155
|
+
suns : 1-D sequence of floats
|
|
156
|
+
Array containing the intensity in sun.
|
|
157
|
+
|
|
158
|
+
Vocs : 1-D sequence of floats
|
|
159
|
+
Array containing the open-circuit voltages.
|
|
160
|
+
|
|
161
|
+
T : float optional
|
|
162
|
+
Temperature in Kelvin (Default = 295 K).
|
|
163
|
+
|
|
164
|
+
Returns
|
|
165
|
+
-------
|
|
166
|
+
nIF : float
|
|
167
|
+
Ideality factor value.
|
|
168
|
+
|
|
169
|
+
intercept : float
|
|
170
|
+
Intercept of the regression line.
|
|
171
|
+
|
|
172
|
+
rvalue : float
|
|
173
|
+
Correlation coefficient.
|
|
174
|
+
|
|
175
|
+
pvalue : float
|
|
176
|
+
Two-sided p-value for a hypothesis test whose null hypothesis is
|
|
177
|
+
that the slope is zero, using Wald Test with t-distribution of
|
|
178
|
+
the test statistic.
|
|
179
|
+
|
|
180
|
+
stderr : float
|
|
181
|
+
Standard error of the estimated gradient.
|
|
182
|
+
"""
|
|
183
|
+
Vt = kb*T
|
|
184
|
+
suns = np.log(suns)
|
|
185
|
+
slope_d, intercept_d, r_value_d, p_value_d, std_err_d = stats.linregress(suns,Vocs)
|
|
186
|
+
nIF = slope_d/Vt
|
|
187
|
+
return nIF,intercept_d, r_value_d**2, p_value_d, std_err_d
|
|
@@ -159,8 +159,20 @@ def run_SS_JV(simss_device_parameters, session_path, JV_file_name = 'JV.dat', va
|
|
|
159
159
|
results.append(result.returncode)
|
|
160
160
|
msg_list.append(message)
|
|
161
161
|
|
|
162
|
+
# check if results is a list of CompletedProcess objects
|
|
163
|
+
|
|
164
|
+
if isinstance(results, list) :
|
|
165
|
+
if len(results) > 0 and not isinstance(results[0], subprocess.CompletedProcess):
|
|
166
|
+
pass
|
|
167
|
+
else:
|
|
168
|
+
if len(results) > 0 and isinstance(results[0], tuple) and all(isinstance(res[0], subprocess.CompletedProcess) for res in results):
|
|
169
|
+
# Extract the return codes from the CompletedProcess objects
|
|
170
|
+
results = [res[0].returncode for res in results]
|
|
171
|
+
# Check if all simulations were successful
|
|
162
172
|
if all([res == 0 for res in results]):
|
|
163
173
|
return 0, 'All JV simulations completed successfully'
|
|
174
|
+
elif all([(res == 0 or res == 95) for res in results]):
|
|
175
|
+
return 0, 'All JV simulations completed successfully, but some had some points that did not converge'
|
|
164
176
|
else:
|
|
165
177
|
return results, msg_list
|
|
166
178
|
|
|
@@ -256,4 +268,4 @@ if __name__ == "__main__":
|
|
|
256
268
|
else:
|
|
257
269
|
if results != 0:
|
|
258
270
|
for i, msg in enumerate(message):
|
|
259
|
-
print(f'G_frac: {G_fracs[i]} - {msg}')
|
|
271
|
+
print(f'G_frac: {G_fracs[i]} - {msg}')
|
|
@@ -5,6 +5,7 @@ import os,sys
|
|
|
5
5
|
import numpy as np
|
|
6
6
|
import pandas as pd
|
|
7
7
|
import matplotlib.pyplot as plt
|
|
8
|
+
from scipy.integrate import trapezoid
|
|
8
9
|
# import pySIMsalabim
|
|
9
10
|
## Import pySIMsalabim, if not successful, add the parent directory to the system path
|
|
10
11
|
try :
|
|
@@ -239,11 +240,13 @@ def create_tVG_hysteresis(session_path, Vmin, Vmax, scan_speed, direction, steps
|
|
|
239
240
|
|
|
240
241
|
return retval, msg
|
|
241
242
|
|
|
242
|
-
def plot_hysteresis_JV(path2file = 'tj.dat'):
|
|
243
|
+
def plot_hysteresis_JV(session_path, path2file = 'tj.dat'):
|
|
243
244
|
"""Plot the hysteresis JV curve
|
|
244
245
|
|
|
245
246
|
Parameters
|
|
246
247
|
----------
|
|
248
|
+
session_path : string
|
|
249
|
+
working directory for zimt
|
|
247
250
|
path2file : string
|
|
248
251
|
Path to the tj file
|
|
249
252
|
|
|
@@ -254,7 +257,7 @@ def plot_hysteresis_JV(path2file = 'tj.dat'):
|
|
|
254
257
|
|
|
255
258
|
"""
|
|
256
259
|
# Read the data from tj-file
|
|
257
|
-
data_tj = pd.read_csv(path2file, sep=r'\s+')
|
|
260
|
+
data_tj = pd.read_csv(os.path.join(session_path,path2file), sep=r'\s+')
|
|
258
261
|
|
|
259
262
|
fig, ax = plt.subplots()
|
|
260
263
|
pars = {'Jext' : 'Simulation'} #'$J_{ext}$'}
|
|
@@ -267,6 +270,7 @@ def plot_hysteresis_JV(path2file = 'tj.dat'):
|
|
|
267
270
|
plot_type = plt.plot
|
|
268
271
|
|
|
269
272
|
ax = utils_plot.plot_result(data_tj, pars, list(pars.keys()), par_x, xlabel, ylabel, xscale, yscale, title, ax, plot_type)
|
|
273
|
+
plt.tight_layout() # make it fit in the window
|
|
270
274
|
|
|
271
275
|
return ax
|
|
272
276
|
|
|
@@ -509,6 +513,156 @@ def Compare_Exp_Sim_JV(session_path, expJV_Vmin_Vmax, expJV_Vmax_Vmin, rms_mode,
|
|
|
509
513
|
|
|
510
514
|
return rms
|
|
511
515
|
|
|
516
|
+
def calc_hysteresis_index(session_path, tj_file_name = 'tj.dat', tVG_file_ame='tVG.txt', plot_hyst_index = False):
|
|
517
|
+
"""
|
|
518
|
+
Calculate the hysteresis index from the simulated JV curve using the difference area between the forward and backward scan
|
|
519
|
+
|
|
520
|
+
Parameters
|
|
521
|
+
----------
|
|
522
|
+
session_path : string
|
|
523
|
+
working directory for zimt
|
|
524
|
+
tj_file_name : string
|
|
525
|
+
Name of the tj file
|
|
526
|
+
tVG_file_ame : string
|
|
527
|
+
Name of the tVG file
|
|
528
|
+
plot_hyst_index : bool
|
|
529
|
+
If True, plot the JV curves with the normalisation and difference area
|
|
530
|
+
|
|
531
|
+
Returns
|
|
532
|
+
-------
|
|
533
|
+
float
|
|
534
|
+
Hysteresis index
|
|
535
|
+
"""
|
|
536
|
+
|
|
537
|
+
sign_dum = 0 # dummy value for sign change in voltage array
|
|
538
|
+
|
|
539
|
+
# Read data from files. tj file for the JV curve and tVG file to get all possible voltage steps.
|
|
540
|
+
# This is needed as not all voltages might be present in the tj file.
|
|
541
|
+
data_tj = pd.read_csv(os.path.join(session_path,tj_file_name), sep=r'\s+')
|
|
542
|
+
data_tVG = pd.read_csv(os.path.join(session_path,tVG_file_ame), sep=r'\s+')
|
|
543
|
+
|
|
544
|
+
# Store Vinput, Vext and Jext in arrays
|
|
545
|
+
Vinput = np.array(data_tVG['Vext'])
|
|
546
|
+
Vext = np.array(data_tj['Vext'])
|
|
547
|
+
Jext = np.array(data_tj['Jext'])
|
|
548
|
+
|
|
549
|
+
# Find the min and max values of Vext and Jext to span the normalisation area
|
|
550
|
+
Jmin = min(Jext)
|
|
551
|
+
Jmax = max(Jext)
|
|
552
|
+
Vmin = min(Vext)
|
|
553
|
+
Vmax = max(Vext)
|
|
554
|
+
|
|
555
|
+
# As the forward and backward scan are in the same array,
|
|
556
|
+
# we need to find the point where the JV curve changes direction, i.e. the turning point and split into two seperate arrays
|
|
557
|
+
# Vext,Jext array
|
|
558
|
+
diff = np.diff(Vext)
|
|
559
|
+
sign_change = np.where(np.diff(np.sign(diff)))
|
|
560
|
+
|
|
561
|
+
if len(sign_change[0]) == 0:
|
|
562
|
+
print('Hysteresis index could not be calculated. No sign change in the voltage array')
|
|
563
|
+
return 0
|
|
564
|
+
elif len(sign_change[0]) ==2:
|
|
565
|
+
# Check if they are consecutive. If so, we might just be missing the 'flip'' point, as it could have not converged, so we need to correct for this.
|
|
566
|
+
if sign_change[0][1] - sign_change[0][0] == 1:
|
|
567
|
+
idx_change = sign_change[0][0] + 2
|
|
568
|
+
sign_dum = 1
|
|
569
|
+
else:
|
|
570
|
+
print('Hysteresis index could not be calculated. Multiple sign changes in the voltage array')
|
|
571
|
+
return 0
|
|
572
|
+
elif len(sign_change[0]) > 2:
|
|
573
|
+
print('Hysteresis index could not be calculated. Multiple sign changes in the voltage array')
|
|
574
|
+
return 0
|
|
575
|
+
else:
|
|
576
|
+
# Need to correct for the index change between Vinput and the sign_change array
|
|
577
|
+
idx_change = sign_change[0][0] + 2
|
|
578
|
+
|
|
579
|
+
# split the Vext and Jext arrays into two arrays
|
|
580
|
+
Vext_1 = Vext[:idx_change]
|
|
581
|
+
Jext_1 = Jext[:idx_change]
|
|
582
|
+
Vext_2 = Vext[idx_change:]
|
|
583
|
+
Jext_2 = Jext[idx_change:]
|
|
584
|
+
|
|
585
|
+
if sign_dum != 1:
|
|
586
|
+
# append the last value of the first array to the first position of the second array to be able to include the turning point
|
|
587
|
+
Vext_2 = np.insert(Vext_2,0,Vext_1[-1])
|
|
588
|
+
Jext_2 = np.insert(Jext_2,0,Jext_1[-1])
|
|
589
|
+
|
|
590
|
+
# Vinput array
|
|
591
|
+
diff = np.diff(Vinput)
|
|
592
|
+
sign_change = np.where(np.diff(np.sign(diff)))
|
|
593
|
+
|
|
594
|
+
if len(sign_change[0]) == 0:
|
|
595
|
+
print('Hysteresis index could not be calculated. No sign change in the voltage array')
|
|
596
|
+
return 0
|
|
597
|
+
elif len(sign_change[0]) > 1:
|
|
598
|
+
print('Hysteresis index could not be calculated.. Multiple sign changes in the voltage array')
|
|
599
|
+
return 0
|
|
600
|
+
else:
|
|
601
|
+
# Need to correct for the index change between Vinput and the sign_change array
|
|
602
|
+
sign_change_Vinput = sign_change[0][0] + 2
|
|
603
|
+
|
|
604
|
+
# We only need one of the arrays, as we will only use this as a reference
|
|
605
|
+
Vinput_1 = Vinput[:sign_change_Vinput]
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
# To calculate the difference area between the two curves, we need to reverse the order of the second arrays to match the order of the applied voltage
|
|
609
|
+
# reverse the second array
|
|
610
|
+
Vext_2 = Vext_2[::-1]
|
|
611
|
+
Jext_2 = Jext_2[::-1]
|
|
612
|
+
|
|
613
|
+
# Create empty arrays to store the final V,J values
|
|
614
|
+
Vfinal = []
|
|
615
|
+
Jfinal_1 = []
|
|
616
|
+
Jfinal_2 = []
|
|
617
|
+
|
|
618
|
+
# Loop over Vinput and check if the voltage exist in both V arrays
|
|
619
|
+
# If it does, add the current to the corresponding J array, else we cannot use it so we discard it
|
|
620
|
+
for i in range(len(Vinput_1)):
|
|
621
|
+
if (Vinput_1[i] in Vext_1) and (Vinput_1[i] in Vext_2):
|
|
622
|
+
# Get the index of the voltage in the corresponding V arrays
|
|
623
|
+
idx1 = np.where(Vext_1 == Vinput_1[i])[0][0]
|
|
624
|
+
idx2 = np.where(Vext_2 == Vinput_1[i])[0][0]
|
|
625
|
+
|
|
626
|
+
# Append the values to the final arrays
|
|
627
|
+
Vfinal.append(Vext_1[idx1])
|
|
628
|
+
Jfinal_1.append(Jext_1[idx1])
|
|
629
|
+
Jfinal_2.append(Jext_2[idx2])
|
|
630
|
+
|
|
631
|
+
# Calculate the hysteresis index
|
|
632
|
+
hysteresis_index_num = abs(trapezoid(np.abs(np.array(Jfinal_1) - np.array(Jfinal_2)),Vfinal)) # Use abs around trapezoid to avoid negative values when Vfinal is flipped
|
|
633
|
+
hysteresis_index_denom = (Jmax - Jmin) * (Vmax - Vmin)
|
|
634
|
+
hysteresis_index = hysteresis_index_num / hysteresis_index_denom
|
|
635
|
+
|
|
636
|
+
if plot_hyst_index == True:
|
|
637
|
+
|
|
638
|
+
# Plot JV traces together with normalisation and difference area
|
|
639
|
+
fig, ax = plt.subplots()
|
|
640
|
+
|
|
641
|
+
# Normalisation area
|
|
642
|
+
ax.vlines(x = Vmin,ymin = Jmin, ymax = Jmax, color='#919191',linestyles='dashed',label='Normalisation area')
|
|
643
|
+
ax.vlines(x = Vmax,ymin = Jmin, ymax = Jmax, color='#919191',linestyles='dashed')
|
|
644
|
+
ax.hlines(y = Jmin,xmin = Vmin, xmax = Vmax, color='#919191',linestyles='dashed')
|
|
645
|
+
ax.hlines(y = Jmax,xmin = Vmin, xmax = Vmax, color='#919191',linestyles='dashed')
|
|
646
|
+
|
|
647
|
+
# Difference area
|
|
648
|
+
ax.fill_between(Vfinal,Jfinal_1,Jfinal_2, color='#b1f997',label='Difference area')
|
|
649
|
+
|
|
650
|
+
# JV traces
|
|
651
|
+
ax.plot(Vfinal,Jfinal_2,label='Backward', color='r', linewidth=4)
|
|
652
|
+
ax.plot(Vfinal,Jfinal_1,label='Forward', color = 'b', linewidth=4)
|
|
653
|
+
|
|
654
|
+
ax.set_xlabel('$V_{ext}$ [V]')
|
|
655
|
+
ax.set_ylabel('$J_{ext}$ [Am$^{-2}$]')
|
|
656
|
+
|
|
657
|
+
# Reverse the legend order. Curves should be listed first, then norm/diff area.
|
|
658
|
+
handles, labels = ax.get_legend_handles_labels()
|
|
659
|
+
ax.legend(handles[::-1], labels[::-1],framealpha=1, loc='center left', bbox_to_anchor=(0.07, 0.75))
|
|
660
|
+
plt.tight_layout()
|
|
661
|
+
|
|
662
|
+
plt.show()
|
|
663
|
+
|
|
664
|
+
return hysteresis_index
|
|
665
|
+
|
|
512
666
|
def Hysteresis_JV(zimt_device_parameters, session_path, UseExpData, scan_speed, direction, G_frac, tVG_name='tVG.txt', tj_name = 'tj.dat',varFile='none',
|
|
513
667
|
run_mode=False, Vmin=0.0, Vmax=0.0, steps =0, expJV_Vmin_Vmax='', expJV_Vmax_Vmin='',rms_mode='lin', **kwargs ):
|
|
514
668
|
"""Create a tVG file and perform a JV hysteresis experiment.
|
|
@@ -556,8 +710,8 @@ def Hysteresis_JV(zimt_device_parameters, session_path, UseExpData, scan_speed,
|
|
|
556
710
|
Output object of with returncode and console output of the simulation
|
|
557
711
|
string
|
|
558
712
|
Return message to display on the UI, for both success and failed
|
|
559
|
-
|
|
560
|
-
|
|
713
|
+
dict
|
|
714
|
+
Dictionary containing the special output values of the simulation. In this case, the rms error ('rms') and the hysteresis index ('hyst_index')
|
|
561
715
|
"""
|
|
562
716
|
|
|
563
717
|
UUID = kwargs.get('UUID', '') # Check if the user wants to add a UUID to the tj file name
|
|
@@ -599,7 +753,10 @@ def Hysteresis_JV(zimt_device_parameters, session_path, UseExpData, scan_speed,
|
|
|
599
753
|
varFile = os.path.join(session_path, varFile)
|
|
600
754
|
# varFile = 'none' # we don't use a var file for the hysteresis JV simulation
|
|
601
755
|
|
|
756
|
+
# Init output_vals rms & hyst_index
|
|
602
757
|
rms = 0.0
|
|
758
|
+
hyst_index = 0.0
|
|
759
|
+
|
|
603
760
|
if UseExpData == 1:
|
|
604
761
|
# When fitting to experimental data, create a tVG file where Vext is the same as the voltages in the experimental JV file
|
|
605
762
|
if os.path.exists(os.path.join(session_path, expJV_Vmin_Vmax)) and os.path.exists(os.path.join(session_path, expJV_Vmax_Vmin)):
|
|
@@ -633,9 +790,17 @@ def Hysteresis_JV(zimt_device_parameters, session_path, UseExpData, scan_speed,
|
|
|
633
790
|
if result.returncode == 0 or result.returncode == 95:
|
|
634
791
|
if UseExpData == 1:
|
|
635
792
|
rms = Compare_Exp_Sim_JV(session_path, expJV_Vmin_Vmax, expJV_Vmax_Vmin, rms_mode, direction, tj_name)
|
|
793
|
+
hyst_index = calc_hysteresis_index(session_path, tj_name, tVG_name)
|
|
794
|
+
else:
|
|
795
|
+
message = message
|
|
796
|
+
|
|
636
797
|
result = result.returncode
|
|
798
|
+
|
|
799
|
+
# Put all the output values in a dictionary to be returned.
|
|
800
|
+
# By putting it in a dictionary we can add any number of values without breaking return arguments
|
|
801
|
+
output_vals = {'rms': rms, 'hyst_index': hyst_index}
|
|
637
802
|
|
|
638
|
-
return result, message,
|
|
803
|
+
return result, message, output_vals
|
|
639
804
|
|
|
640
805
|
## Running the function as a standalone script
|
|
641
806
|
if __name__ == "__main__":
|
|
@@ -646,7 +811,7 @@ if __name__ == "__main__":
|
|
|
646
811
|
UseExpData = 0 # integer, if 1 read experimental data
|
|
647
812
|
Vmin = 0 # lower voltage boundary
|
|
648
813
|
Vmax = 1.15 # upper voltage boundary
|
|
649
|
-
steps =
|
|
814
|
+
steps = 200 # Number of voltage steps
|
|
650
815
|
expJV_Vmin_Vmax = 'od05_f.txt' # Forward (direction=1)/Backward (direction=-1) JV scan file
|
|
651
816
|
expJV_Vmax_Vmin = 'od05_b.txt' # Backward (direction=1)/Forward (direction=-1) JV scan file
|
|
652
817
|
|
|
@@ -655,9 +820,10 @@ if __name__ == "__main__":
|
|
|
655
820
|
|
|
656
821
|
zimt_device_parameters = 'simulation_setup.txt'
|
|
657
822
|
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
823
|
+
tVGFile = 'tVG.txt'
|
|
824
|
+
tJFile = 'tj.dat'
|
|
825
|
+
varFile = 'none'
|
|
826
|
+
|
|
661
827
|
# UUID = str(uuid.uuid4()) # Add a UUID to the simulation
|
|
662
828
|
UUID = ''
|
|
663
829
|
|
|
@@ -706,7 +872,7 @@ if __name__ == "__main__":
|
|
|
706
872
|
|
|
707
873
|
# Define mappings for keys and variables
|
|
708
874
|
key_action_map = {
|
|
709
|
-
'
|
|
875
|
+
'zimt_device_parameters': lambda val: {'zimt_device_parameters': val},
|
|
710
876
|
'scan_speed': lambda val: {'scan_speed': float(val)},
|
|
711
877
|
'direction': lambda val: {'direction': int(val)},
|
|
712
878
|
'G_frac': lambda val: {'G_frac': float(val)},
|
|
@@ -716,8 +882,9 @@ if __name__ == "__main__":
|
|
|
716
882
|
'steps': lambda val: {'steps': int(val)},
|
|
717
883
|
'expJV_Vmin_Vmax': lambda val: {'expJV_Vmin_Vmax': val},
|
|
718
884
|
'expJV_Vmax_Vmin': lambda val: {'expJV_Vmax_Vmin': val},
|
|
719
|
-
'
|
|
720
|
-
'
|
|
885
|
+
'tVGFile': lambda val: {'tVGFile': val},
|
|
886
|
+
'tJFile': lambda val: {'tJFile': val},
|
|
887
|
+
'varFile': lambda val: {'varFile': val},
|
|
721
888
|
'UUID': lambda val: {'UUID': val},
|
|
722
889
|
}
|
|
723
890
|
|
|
@@ -732,17 +899,19 @@ if __name__ == "__main__":
|
|
|
732
899
|
cmd_pars.extend({'par': key, 'val': value} for key, value in cmd_pars_dict.items())
|
|
733
900
|
|
|
734
901
|
if UseExpData == 1:
|
|
735
|
-
result, message,
|
|
902
|
+
result, message, output_vals = Hysteresis_JV(zimt_device_parameters, session_path, UseExpData, scan_speed, direction, G_frac, tVG_name = tVGFile, tj_name = tJFile,
|
|
736
903
|
run_mode = False, expJV_Vmin_Vmax = expJV_Vmin_Vmax, expJV_Vmax_Vmin = expJV_Vmax_Vmin, rms_mode = rms_mode, cmd_pars = cmd_pars, UUID=UUID)
|
|
737
904
|
else:
|
|
738
|
-
result, message,
|
|
905
|
+
result, message, output_vals = Hysteresis_JV(zimt_device_parameters, session_path, UseExpData, scan_speed, direction, G_frac, tVG_name = tVGFile, tj_name = tJFile,
|
|
739
906
|
run_mode = False, Vmin=Vmin, Vmax=Vmax, steps =steps, rms_mode = rms_mode, cmd_pars = cmd_pars, UUID=UUID)
|
|
740
|
-
|
|
907
|
+
|
|
741
908
|
if result == 0 or result == 95:
|
|
742
909
|
if UseExpData == 1:
|
|
743
|
-
print('Rms-value: ', "{:.5f}".format(round(rms, 5)))
|
|
744
|
-
|
|
745
|
-
|
|
910
|
+
print('Rms-value: ', "{:.5f}".format(round(output_vals['rms'], 5)))
|
|
911
|
+
|
|
912
|
+
print(f'hyst-index: {output_vals["hyst_index"]:.3f}')
|
|
913
|
+
|
|
914
|
+
ax = plot_hysteresis_JV(session_path, tJFile)
|
|
746
915
|
if UseExpData == 1:
|
|
747
916
|
JVExp = concatJVs(session_path, expJV_Vmin_Vmax, expJV_Vmax_Vmin, direction)
|
|
748
917
|
ax.scatter(JVExp.Vext, JVExp.Jext, label='Experimental', color='r')
|
|
@@ -750,4 +919,4 @@ if __name__ == "__main__":
|
|
|
750
919
|
ax.legend()
|
|
751
920
|
plt.show()
|
|
752
921
|
else:
|
|
753
|
-
print('Convergence issues, no plot is printed')
|
|
922
|
+
print(message) #'Convergence issues, no plot is printed')
|
|
@@ -113,87 +113,44 @@ def create_tVG_SS(V_0, G_frac, tVG_name, session_path):
|
|
|
113
113
|
|
|
114
114
|
return retval, msg
|
|
115
115
|
|
|
116
|
+
def create_tVG_tolDens(V_0, del_V, ini_timeFactor, f_min, f_max, G, tVG_name, session_path):
|
|
117
|
+
""" Creates the tVG file for the steady state simulation with only t 0 and V_0
|
|
116
118
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
# DataFrame
|
|
130
|
-
# Pandas dataFrame containing the time, voltage, current density and numerical error in the current density of the tj_file
|
|
131
|
-
# """
|
|
132
|
-
|
|
133
|
-
# data = pd.read_csv(os.path.join(session_path,tj_file_name), sep=r'\s+')
|
|
134
|
-
|
|
135
|
-
# return data
|
|
136
|
-
|
|
137
|
-
# def get_integral_bounds(data, f_min=1e-2, f_max=1e6, f_steps=20):
|
|
138
|
-
# """ Determine integral bounds in the time domain, used to compute the conductance and capacitance
|
|
139
|
-
|
|
140
|
-
# Parameters
|
|
141
|
-
# ----------
|
|
142
|
-
# data : dataFrame
|
|
143
|
-
# Pandas dataFrame containing the time, voltage, current density and numerical error in the current density of the tj_file
|
|
144
|
-
# f_min : float
|
|
145
|
-
# Minimum frequency
|
|
146
|
-
# f_max : float
|
|
147
|
-
# Maximum frequency
|
|
148
|
-
# f_steps : float
|
|
149
|
-
# Frequency steps
|
|
150
|
-
|
|
151
|
-
# Returns
|
|
152
|
-
# -------
|
|
153
|
-
# list
|
|
154
|
-
# List of array indices that will be used in the plotting
|
|
155
|
-
# """
|
|
156
|
-
|
|
157
|
-
# # Total number of time points
|
|
158
|
-
# numTimePoints = len(data['t'])
|
|
159
|
-
|
|
160
|
-
# # Check which time index corresponds to 1/fmax. We call this istart:
|
|
161
|
-
# istart = -1
|
|
162
|
-
# for i in range(numTimePoints):
|
|
163
|
-
# if math.isclose(data['t'][i], 1/f_max, rel_tol = 2/f_steps): #note: don't use == to compare 2 floating points!
|
|
164
|
-
# istart = i
|
|
165
|
-
|
|
166
|
-
# # Starting time point could not be found.
|
|
167
|
-
# if istart == -1:
|
|
168
|
-
# msg = 'Could not find a time that corresponds to the highest frequency.'
|
|
169
|
-
# return -1, msg
|
|
170
|
-
|
|
171
|
-
# # print('Found istart: ', istart)
|
|
172
|
-
|
|
173
|
-
# # ifin: last index we should plot, corresponds to time = 1/f_min:
|
|
174
|
-
# ifin = numTimePoints - 1
|
|
119
|
+
Parameters
|
|
120
|
+
----------
|
|
121
|
+
V_0 : float
|
|
122
|
+
Voltage at t=0
|
|
123
|
+
del_V : float
|
|
124
|
+
Voltage step that is applied after t=0
|
|
125
|
+
G_frac : float
|
|
126
|
+
Fractional light intensity
|
|
127
|
+
tVG_name : string
|
|
128
|
+
Name of the tVG file
|
|
129
|
+
session_path : string
|
|
130
|
+
Path of the simulation folder for this session
|
|
175
131
|
|
|
176
|
-
|
|
177
|
-
|
|
132
|
+
Returns
|
|
133
|
+
-------
|
|
134
|
+
string
|
|
135
|
+
A message to indicate the result of the process
|
|
136
|
+
"""
|
|
178
137
|
|
|
179
|
-
#
|
|
138
|
+
del_t = ini_timeFactor/f_max # t_1 = 0 s + del_t
|
|
180
139
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
140
|
+
tVG_lines = ('t\tVext\tG_frac\n'
|
|
141
|
+
f'0\t{V_0+del_V}\t{G:.3e}\n'
|
|
142
|
+
f'0\t{V_0}\t{G:.3e}\n'
|
|
143
|
+
f'{del_t}\t{V_0+del_V}\t{G:.3e}\n')
|
|
185
144
|
|
|
186
|
-
#
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
# isToPlot.append(i) # add the index to our array
|
|
145
|
+
# Write the tVG lines to the tVG file
|
|
146
|
+
with open(os.path.join(session_path,tVG_name), 'w') as file:
|
|
147
|
+
file.write(tVG_lines)
|
|
190
148
|
|
|
191
|
-
#
|
|
192
|
-
|
|
149
|
+
# tVG file is created, message a success
|
|
150
|
+
msg = 'Success'
|
|
151
|
+
retval = 0
|
|
193
152
|
|
|
194
|
-
|
|
195
|
-
# msg = 'Success'
|
|
196
|
-
# return isToPlot, msg
|
|
153
|
+
return retval, msg
|
|
197
154
|
|
|
198
155
|
def calc_impedance_limit_time(I, errI, time, VStep, imax):
|
|
199
156
|
"""Fourier Decomposition formula which computes the impedance at frequency freq (Hz) and its complex error
|
|
@@ -304,20 +261,6 @@ def calc_impedance(data, del_V, isToPlot,session_path,zimt_device_parameters,Rse
|
|
|
304
261
|
errC = np.empty(numFreqPoints)
|
|
305
262
|
errG = np.empty(numFreqPoints)
|
|
306
263
|
|
|
307
|
-
|
|
308
|
-
# We need to know the series and shunt resistance to calculate the impedance correctly later on
|
|
309
|
-
# dev_val,lyrs_dum = load_device_parameters(session_path, zimt_device_parameters)
|
|
310
|
-
# for i in dev_val[zimt_device_parameters]:
|
|
311
|
-
# if i[0] == 'Contacts':
|
|
312
|
-
# contacts = i
|
|
313
|
-
# break
|
|
314
|
-
|
|
315
|
-
# for i in contacts[1:]:
|
|
316
|
-
# if i[1] == 'R_series':
|
|
317
|
-
# Rseries = float(i[2])
|
|
318
|
-
# elif i[1] == 'R_shunt':
|
|
319
|
-
# Rshunt = float(i[2])
|
|
320
|
-
|
|
321
264
|
for i in range(numFreqPoints):
|
|
322
265
|
imax=isToPlot[i]
|
|
323
266
|
freq[i], Z[i], errZ[i] = calc_impedance_limit_time(data['Jext'], data['errJ'], data['t'], del_V, imax)
|
|
@@ -412,7 +355,7 @@ def get_impedance(data, f_min, f_max, f_steps, del_V, session_path, output_file,
|
|
|
412
355
|
store_impedance_data(session_path, freq, ReZ, ImZ, errZ, C, G, errC, errG, output_file)
|
|
413
356
|
|
|
414
357
|
msg = 'Success'
|
|
415
|
-
return 0,msg
|
|
358
|
+
return 0, msg
|
|
416
359
|
else:
|
|
417
360
|
# Failed to determine integral bounds, exit with the error message
|
|
418
361
|
return -1, msg
|
|
@@ -534,6 +477,110 @@ def plot_impedance(session_path, output_file='freqZ.dat'):
|
|
|
534
477
|
# Capacitance plot
|
|
535
478
|
Capacitance_plot(session_path,output_file)
|
|
536
479
|
|
|
480
|
+
|
|
481
|
+
def get_tolDens(zimt_device_parameters, session_path, f_min, f_max, V_0, G_frac, del_V, run_mode, tVG_name, tj_name, varFile, ini_timeFactor, dum_str, cmd_pars):
|
|
482
|
+
"""
|
|
483
|
+
Calculate the tolerance of the density solver, to ensure a reliable impedance spectrum
|
|
484
|
+
|
|
485
|
+
Parameters
|
|
486
|
+
----------
|
|
487
|
+
zimt_device_parameters : string
|
|
488
|
+
Name of the zimt device parameters file
|
|
489
|
+
session_path : string
|
|
490
|
+
Working directory for zimt
|
|
491
|
+
f_min : float
|
|
492
|
+
Minimum frequency
|
|
493
|
+
f_max : float
|
|
494
|
+
Maximum frequency
|
|
495
|
+
V_0 : float
|
|
496
|
+
Voltage at t=0
|
|
497
|
+
G_frac : float
|
|
498
|
+
Fractional light intensity
|
|
499
|
+
del_V : float
|
|
500
|
+
Voltage step
|
|
501
|
+
run_mode : bool
|
|
502
|
+
Indicate whether the script is in 'web' mode (True) or standalone mode (False). Used to control the console output
|
|
503
|
+
tVG_name : string
|
|
504
|
+
Name of the tVG file
|
|
505
|
+
tj_name : string
|
|
506
|
+
Name of the tj file
|
|
507
|
+
varFile : string
|
|
508
|
+
Name of the var file
|
|
509
|
+
ini_timeFactor : float
|
|
510
|
+
Constant defining the size of the initial timestep
|
|
511
|
+
dum_str : string
|
|
512
|
+
dummy string with UUID string to append to the file names
|
|
513
|
+
cmd_pars : list
|
|
514
|
+
List of dictionaries with the command line parameters
|
|
515
|
+
|
|
516
|
+
Returns
|
|
517
|
+
-------
|
|
518
|
+
integer
|
|
519
|
+
Return code of the simulation, 0 if successful, -1 if one of the steps failed else the return code of the simulation
|
|
520
|
+
string
|
|
521
|
+
Return message to display on the UI in case of failure
|
|
522
|
+
float
|
|
523
|
+
Tolerance of the density solver. If failed, returns None
|
|
524
|
+
"""
|
|
525
|
+
|
|
526
|
+
# Determine J(t=0), J(t=∞), and J_dis to get the maximum allowed tolerance of the density solver to retrieve a
|
|
527
|
+
# reliable impedance spectrum, where tolDens = J(t=∞) - J(t=0) / J_displacement
|
|
528
|
+
result, message = create_tVG_tolDens(V_0, del_V, ini_timeFactor, f_min, f_max, G_frac, tVG_name, session_path)
|
|
529
|
+
|
|
530
|
+
if result == 0:
|
|
531
|
+
# In order for zimt to converge, set absolute tolerance of Poisson solver small enough
|
|
532
|
+
tolPois = 10**(math.floor(math.log10(abs(del_V)))-5)
|
|
533
|
+
|
|
534
|
+
tolDens_test = str(1e-10)
|
|
535
|
+
# Define mandatory options for ZimT to run well with impedance:
|
|
536
|
+
tolDens_args = [{'par':'dev_par_file','val':zimt_device_parameters},
|
|
537
|
+
{'par':'tVGFile','val':tVG_name},
|
|
538
|
+
{'par':'tolPois','val':str(tolPois)},
|
|
539
|
+
{'par':'tolDens','val':tolDens_test},
|
|
540
|
+
{'par':'limitDigits','val':'0'},
|
|
541
|
+
{'par':'currDiffInt','val':'2'},
|
|
542
|
+
{'par':'tJFile','val':tj_name},
|
|
543
|
+
{'par':'varFile','val':varFile},
|
|
544
|
+
{'par':'logFile','val':'log'+dum_str+'.txt'}]
|
|
545
|
+
|
|
546
|
+
if cmd_pars is not None:
|
|
547
|
+
tolDens_args = update_cmd_pars(tolDens_args, cmd_pars)
|
|
548
|
+
|
|
549
|
+
result, message = utils_gen.run_simulation('zimt', tolDens_args, session_path, run_mode)
|
|
550
|
+
|
|
551
|
+
if result.returncode == 0 or result.returncode == 95:
|
|
552
|
+
data = read_tj_file(session_path, tj_file_name=tj_name)
|
|
553
|
+
try:
|
|
554
|
+
J_0 = data['Jext'][1]
|
|
555
|
+
J_inf = data['Jext'][0]
|
|
556
|
+
J_dis = abs(data['Jext'][2] - J_0)
|
|
557
|
+
except KeyError as key:
|
|
558
|
+
if key == 0:
|
|
559
|
+
message = f"J_inf does not exist in the tolDens tJ-file"
|
|
560
|
+
elif key == 1:
|
|
561
|
+
message = f"J_0 does not exist in the tolDens tJ-file"
|
|
562
|
+
elif key == 2:
|
|
563
|
+
message = f"J_spike does not exist in the tolDens tJ-file"
|
|
564
|
+
return -1, message, None
|
|
565
|
+
|
|
566
|
+
# tolDens cannot be larger than 1E-6
|
|
567
|
+
tolDens = min(abs(J_inf - J_0) / J_dis * 1e-4, 1e-6)
|
|
568
|
+
|
|
569
|
+
# tolDens cannot be smaller than 1E-12
|
|
570
|
+
tolDens = max(tolDens, 1e-12)
|
|
571
|
+
else:
|
|
572
|
+
return result.returncode, message, None
|
|
573
|
+
|
|
574
|
+
# Remove the tVG and tJ files as they are not needed anymore
|
|
575
|
+
os.remove(os.path.join(session_path,tVG_name))
|
|
576
|
+
os.remove(os.path.join(session_path,tj_name))
|
|
577
|
+
|
|
578
|
+
else:
|
|
579
|
+
message = "Computing tolDens was unsuccesful"
|
|
580
|
+
return -1, message, None
|
|
581
|
+
|
|
582
|
+
return 0, '', tolDens
|
|
583
|
+
|
|
537
584
|
def run_impedance_simu(zimt_device_parameters, session_path, f_min, f_max, f_steps, V_0, G_frac = 1, del_V = 0.01, run_mode = False, tVG_name='tVG.txt', output_file = 'freqZ.dat', tj_name = 'tj.dat', varFile ='none', ini_timeFactor=1e-3, timeFactor=1.02, **kwargs):
|
|
538
585
|
"""Create a tVG file and run ZimT with impedance device parameters
|
|
539
586
|
|
|
@@ -615,10 +662,54 @@ def run_impedance_simu(zimt_device_parameters, session_path, f_min, f_max, f_ste
|
|
|
615
662
|
varFile = os.path.join(session_path,varFile)
|
|
616
663
|
# varFile = 'none' # we don't use a var file for the hysteresis JV simulation
|
|
617
664
|
|
|
665
|
+
##############################################################################
|
|
666
|
+
# If the voltage is set to Voc, firstly compute its value
|
|
667
|
+
if V_0 == 'oc':
|
|
668
|
+
# Create tVG
|
|
669
|
+
result, message = create_tVG_SS(V_0, G_frac, tVG_name, session_path)
|
|
670
|
+
|
|
671
|
+
# Check if tVG file is created
|
|
672
|
+
if result == 0:
|
|
673
|
+
# In order for zimt to converge, set absolute tolerance of Poisson solver small enough
|
|
674
|
+
tolPois = 10**(math.floor(math.log10(abs(del_V)))-4)
|
|
675
|
+
|
|
676
|
+
# Define mandatory options for ZimT to run well with impedance:
|
|
677
|
+
Impedance_SS_args = [{'par':'dev_par_file','val':zimt_device_parameters},
|
|
678
|
+
{'par':'tVGFile','val':tVG_name},
|
|
679
|
+
{'par':'tolPois','val':str(tolPois)},
|
|
680
|
+
{'par':'limitDigits','val':'0'},
|
|
681
|
+
{'par':'currDiffInt','val':'2'},
|
|
682
|
+
{'par':'tJFile','val':tj_name},
|
|
683
|
+
{'par':'varFile','val':varFile},
|
|
684
|
+
{'par':'logFile','val':'log'+dum_str+'.txt'}
|
|
685
|
+
]
|
|
686
|
+
|
|
687
|
+
if turnoff_autoTidy:
|
|
688
|
+
Impedance_SS_args.append({'par':'autoTidy','val':'0'})
|
|
689
|
+
|
|
690
|
+
if cmd_pars is not None:
|
|
691
|
+
Impedance_SS_args = update_cmd_pars(Impedance_SS_args, cmd_pars)
|
|
692
|
+
|
|
693
|
+
if threadsafe:
|
|
694
|
+
result, message = utils_gen.run_simulation_filesafe('zimt', Impedance_SS_args, session_path, run_mode)
|
|
695
|
+
else:
|
|
696
|
+
result, message = utils_gen.run_simulation('zimt', Impedance_SS_args, session_path, run_mode)
|
|
697
|
+
|
|
698
|
+
if result.returncode == 0 or result.returncode == 95:
|
|
699
|
+
data = read_tj_file(session_path, tj_file_name=tj_name)
|
|
700
|
+
|
|
701
|
+
V_0 = data['Vext'][0]
|
|
702
|
+
else:
|
|
703
|
+
message = "Computing the value of Voc led to the following error: " + message
|
|
704
|
+
return result.returncode, message
|
|
705
|
+
else:
|
|
706
|
+
V_0 = float(V_0)
|
|
707
|
+
|
|
708
|
+
##############################################################################
|
|
618
709
|
# The simulations with Rseries and Rshunt often do not converge, so we first run a steady state simulation to get the internal voltage and then run the impedance simulation with Rseries = 0 and Rshunt = -Rshunt. We will correct the impedance afterwards. This is a workaround to improve the convergence of the impedance simulation that should remain accurate to estimate the impedance.
|
|
619
|
-
#
|
|
710
|
+
# Default values for Rseries and Rshunt
|
|
620
711
|
Rseries = 0
|
|
621
|
-
Rshunt = -
|
|
712
|
+
Rshunt = -1 # Negative values are used for Rshunt in SIMsalabim to indicate infinite Rshunt
|
|
622
713
|
|
|
623
714
|
# Do the steady state simulation to calculate the internal voltage in case of series resistance
|
|
624
715
|
# Create tVG
|
|
@@ -691,10 +782,15 @@ def run_impedance_simu(zimt_device_parameters, session_path, f_min, f_max, f_ste
|
|
|
691
782
|
return result, message
|
|
692
783
|
|
|
693
784
|
# remove the Rseries and Rshunt from cmd_pars
|
|
694
|
-
if
|
|
695
|
-
cmd_pars
|
|
696
|
-
|
|
697
|
-
|
|
785
|
+
if cmd_pars is not None:
|
|
786
|
+
cmd_pars = [dictionary for dictionary in cmd_pars if dictionary['par'] not in ('R_series', 'R_shunt')]
|
|
787
|
+
|
|
788
|
+
# Calculate the tolerance of the density solver
|
|
789
|
+
result, message, tolDens = get_tolDens(zimt_device_parameters, session_path, f_min, f_max, V_0, G_frac, del_V, run_mode, tVG_name, tj_name, varFile, ini_timeFactor, dum_str, cmd_pars)
|
|
790
|
+
|
|
791
|
+
if result != 0:
|
|
792
|
+
# Failed to calculate the tolerance of the density solver, return the error message
|
|
793
|
+
return result, message
|
|
698
794
|
|
|
699
795
|
# Do the impedance simulation
|
|
700
796
|
# Create tVG
|
|
@@ -709,6 +805,7 @@ def run_impedance_simu(zimt_device_parameters, session_path, f_min, f_max, f_ste
|
|
|
709
805
|
Impedance_args = [{'par':'dev_par_file','val':zimt_device_parameters},
|
|
710
806
|
{'par':'tVGFile','val':tVG_name},
|
|
711
807
|
{'par':'tolPois','val':str(tolPois)},
|
|
808
|
+
{'par':'tolDens','val':str(tolDens)},
|
|
712
809
|
{'par':'limitDigits','val':'0'},
|
|
713
810
|
{'par':'currDiffInt','val':'2'},
|
|
714
811
|
{'par':'tJFile','val':tj_name},
|
|
@@ -716,7 +813,7 @@ def run_impedance_simu(zimt_device_parameters, session_path, f_min, f_max, f_ste
|
|
|
716
813
|
{'par':'logFile','val':'log'+dum_str+'.txt'},
|
|
717
814
|
# We remove Rseries and Rshunt as the simulation is either to converge that way, we will correct the impedance afterwards
|
|
718
815
|
{'par':'R_series','val':str(0)},
|
|
719
|
-
{'par':'R_shunt','val':str(-
|
|
816
|
+
{'par':'R_shunt','val':str(-1)}]
|
|
720
817
|
|
|
721
818
|
if turnoff_autoTidy:
|
|
722
819
|
Impedance_args.append({'par':'autoTidy','val':'0'})
|
|
@@ -743,9 +840,9 @@ def run_impedance_simu(zimt_device_parameters, session_path, f_min, f_max, f_ste
|
|
|
743
840
|
if __name__ == "__main__":
|
|
744
841
|
## Manual Impedance input parameters. These are overwritten by command line arguments if provided
|
|
745
842
|
f_min = 1e-2 # org 1e-2
|
|
746
|
-
f_max =
|
|
843
|
+
f_max = 1e6 # org 1e6
|
|
747
844
|
f_steps = 20 # org 20
|
|
748
|
-
V_0 =
|
|
845
|
+
V_0 = 0.6 # Float or 'oc' for the open-circuit voltage
|
|
749
846
|
del_V = 1e-2 # org 1e-2
|
|
750
847
|
G_frac = 1
|
|
751
848
|
|
|
@@ -754,9 +851,10 @@ if __name__ == "__main__":
|
|
|
754
851
|
|
|
755
852
|
zimt_device_parameters = 'simulation_setup.txt'
|
|
756
853
|
|
|
757
|
-
|
|
758
|
-
|
|
854
|
+
tVGFile = 'tVG.txt'
|
|
855
|
+
tJFile = 'tj.dat'
|
|
759
856
|
output_name = 'freqZ.dat'
|
|
857
|
+
varFile = 'none'
|
|
760
858
|
|
|
761
859
|
# UUID = str(uuid.uuid4()) # Add a UUID to the simulation
|
|
762
860
|
UUID = ''
|
|
@@ -764,7 +862,7 @@ if __name__ == "__main__":
|
|
|
764
862
|
# Not user input
|
|
765
863
|
ini_timeFactor = 1e-3 # Initial timestep factor, org 1e-3
|
|
766
864
|
timeFactor = 1.02 # Increase in timestep every step to reduce the amount of datapoints necessary, use value close to 1 as this is best! Org 1.02
|
|
767
|
-
run_mode =
|
|
865
|
+
run_mode = False # Show verbose output in console
|
|
768
866
|
|
|
769
867
|
############## Command line arguments ##############
|
|
770
868
|
## Notes
|
|
@@ -774,7 +872,7 @@ if __name__ == "__main__":
|
|
|
774
872
|
## - Special arguments
|
|
775
873
|
## - sp : string
|
|
776
874
|
## - The session path, i.e. the working directory for the simulation
|
|
777
|
-
## -
|
|
875
|
+
## - zimt_device_parameters : string
|
|
778
876
|
## - The name of the zimt simulation setup parameters file
|
|
779
877
|
## - UUID : string
|
|
780
878
|
## - An UUID to add to the simulation (output)
|
|
@@ -811,18 +909,24 @@ if __name__ == "__main__":
|
|
|
811
909
|
|
|
812
910
|
# Define mappings for keys and variables
|
|
813
911
|
key_action_map = {
|
|
814
|
-
'
|
|
912
|
+
'zimt_device_parameters': lambda val: {'zimt_device_parameters': val},
|
|
815
913
|
'f_min': lambda val: {'f_min': float(val)},
|
|
816
914
|
'f_max': lambda val: {'f_max': float(val)},
|
|
817
915
|
'f_steps': lambda val: {'f_steps': int(val)},
|
|
818
|
-
'V_0': lambda val: {'V_0':
|
|
916
|
+
'V_0': lambda val: {'V_0': val},
|
|
819
917
|
'del_V': lambda val: {'del_V': float(val)},
|
|
820
918
|
'G_frac': lambda val: {'G_frac': float(val)},
|
|
821
|
-
'
|
|
822
|
-
'
|
|
823
|
-
'
|
|
919
|
+
'tVGFile': lambda val: {'tVGFile': val},
|
|
920
|
+
'tJFile': lambda val: {'tJFile': val},
|
|
921
|
+
'varFile': lambda val: {'varFile': val},
|
|
922
|
+
'output_name': lambda val: {'output_name': val},
|
|
824
923
|
'UUID': lambda val: {'UUID': val},
|
|
825
|
-
}
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
# Use exactly the same names as in SIMsalabim and as the Manual input parameters,
|
|
927
|
+
# if not than the tVG file name is not updated if putting e.g. "-tVGFile tVG_1.txt" in the command line in the terminal.
|
|
928
|
+
# Instead two tVG files names are defined one from the manual input parameters and one from the command line wherefore
|
|
929
|
+
# SIMsalabim gives the error "invalid input"
|
|
826
930
|
|
|
827
931
|
for key in list(cmd_pars_dict.keys()): # Use list to avoid modifying the dictionary while iterating
|
|
828
932
|
if key in key_action_map:
|
|
@@ -835,12 +939,12 @@ if __name__ == "__main__":
|
|
|
835
939
|
cmd_pars.extend({'par': key, 'val': value} for key, value in cmd_pars_dict.items())
|
|
836
940
|
|
|
837
941
|
## Run impedance spectroscopy
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
output_file = output_name, tj_name = tj_name,ini_timeFactor=ini_timeFactor, timeFactor=timeFactor, cmd_pars=cmd_pars, UUID=UUID)
|
|
942
|
+
result, message = run_impedance_simu(zimt_device_parameters, session_path, f_min, f_max, f_steps, V_0, G_frac, del_V, run_mode=run_mode, tVG_name=tVGFile,
|
|
943
|
+
output_file=output_name, tj_name=tJFile, varFile=varFile, ini_timeFactor=ini_timeFactor, timeFactor=timeFactor, cmd_pars=cmd_pars, UUID=UUID)
|
|
841
944
|
|
|
842
945
|
# Make the impedance plots
|
|
843
|
-
|
|
946
|
+
calc_Voc_output_string = 'Computing the value of Voc led to the following error:'
|
|
947
|
+
if result == 0 or (result.returncode == 95 and calc_Voc_output_string not in message):
|
|
844
948
|
plot_impedance(session_path, os.path.basename(output_name))
|
|
845
949
|
else:
|
|
846
950
|
print(message)
|
|
@@ -297,8 +297,8 @@ def install_SIMsalabim(cwd, folder_name='kostergroup-SIMsalabim-',verbose=False)
|
|
|
297
297
|
os.system('fpc zimt.pas')
|
|
298
298
|
os.chdir(cwd)
|
|
299
299
|
|
|
300
|
-
|
|
301
|
-
|
|
300
|
+
if verbose:
|
|
301
|
+
print('SIMsalabim programs have been compiled successfully!')
|
|
302
302
|
|
|
303
303
|
else:
|
|
304
304
|
# fpc version requirement not met
|
|
@@ -118,7 +118,11 @@ def construct_cmd(sim_type, cmd_pars):
|
|
|
118
118
|
for i in cmd_pars:
|
|
119
119
|
# When specified, the device parameter file must be placed first, as is required by SIMsalabim
|
|
120
120
|
if i['par'] == 'dev_par_file':
|
|
121
|
-
|
|
121
|
+
if os.name == 'nt':
|
|
122
|
+
# Add the device parameters file as " -dev_par_file "dev_par_file"
|
|
123
|
+
args_single = ' "' + i['val']+ '"'
|
|
124
|
+
else:
|
|
125
|
+
args_single = ' ''' + i['val']+ ' '''
|
|
122
126
|
cmd_line = cmd_line + args_single
|
|
123
127
|
# After the dev_par_file key had been found once, stop the loop. If more than one dev_par_file is specified, the rest are ignored.
|
|
124
128
|
break
|
|
@@ -127,7 +131,10 @@ def construct_cmd(sim_type, cmd_pars):
|
|
|
127
131
|
for i in cmd_pars:
|
|
128
132
|
if i['par'] != 'dev_par_file':
|
|
129
133
|
# Add each parameter as " -par_name par_value"
|
|
130
|
-
|
|
134
|
+
if os.name == 'nt': #add "" to the parameter name if on Windows
|
|
135
|
+
args_single = ' -"' + i['par'] + '" "' + i['val'] + '"'
|
|
136
|
+
else:
|
|
137
|
+
args_single = ' -' +i['par'] + ' ' + i['val']
|
|
131
138
|
cmd_line = cmd_line + args_single
|
|
132
139
|
|
|
133
140
|
return cmd_line
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
|
-
Name:
|
|
3
|
-
Version: 1
|
|
2
|
+
Name: pySIMsalabim
|
|
3
|
+
Version: 1.2
|
|
4
4
|
Home-page: https://github.com/kostergroup/pySIMsalabim
|
|
5
|
-
Download-URL: https://github.com/kostergroup/pySIMsalabim/v1.tar.gz
|
|
5
|
+
Download-URL: https://github.com/kostergroup/pySIMsalabim/v1.02.tar.gz
|
|
6
6
|
Author: Vincent M. Le Corre, Sander Heester, L. Jan Anton Koster
|
|
7
7
|
Author-email:
|
|
8
8
|
License: GPLv3
|
|
@@ -26,7 +26,9 @@ Provides-Extra: dev
|
|
|
26
26
|
Requires-Dist: pytest; extra == "dev"
|
|
27
27
|
Requires-Dist: twine; extra == "dev"
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
<img src="./docs/logo/pySIMsalabim_logo.png" alt="pySIMsalabim logo" width="100px">
|
|
30
|
+
|
|
31
|
+
# pySIMsalabim
|
|
30
32
|
|
|
31
33
|
## Description
|
|
32
34
|
**pySIMsalabim** is a Python package used to interface drift-diffusion simulator [SIMsalabim](https://github.com/kostergroup/SIMsalabim) with Python. It provides many useful tools to set up and run simulations, as well as to analyze and visualize the results.
|
|
@@ -34,6 +36,7 @@ Requires-Dist: twine; extra == "dev"
|
|
|
34
36
|
## Authors
|
|
35
37
|
* [Vincent M. Le Corre](https://github.com/VMLC-PV)
|
|
36
38
|
* [Sander Heester](https://github.com/sheester)
|
|
39
|
+
* [Fransien Elhorst](https://github.com/Fransien-Elhorst)
|
|
37
40
|
* [L. Jan Anton Koster](https://github.com/kostergroup)
|
|
38
41
|
|
|
39
42
|
## Institutions
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
LICENSE
|
|
2
2
|
README.md
|
|
3
3
|
setup.py
|
|
4
|
-
pySIMSalabim.egg-info/PKG-INFO
|
|
5
|
-
pySIMSalabim.egg-info/SOURCES.txt
|
|
6
|
-
pySIMSalabim.egg-info/dependency_links.txt
|
|
7
|
-
pySIMSalabim.egg-info/requires.txt
|
|
8
|
-
pySIMSalabim.egg-info/top_level.txt
|
|
9
4
|
pySIMsalabim/__init__.py
|
|
5
|
+
pySIMsalabim.egg-info/PKG-INFO
|
|
6
|
+
pySIMsalabim.egg-info/SOURCES.txt
|
|
7
|
+
pySIMsalabim.egg-info/dependency_links.txt
|
|
8
|
+
pySIMsalabim.egg-info/requires.txt
|
|
9
|
+
pySIMsalabim.egg-info/top_level.txt
|
|
10
10
|
pySIMsalabim/aux_funcs/SCLC_funcs.py
|
|
11
11
|
pySIMsalabim/aux_funcs/__init__.py
|
|
12
12
|
pySIMsalabim/aux_funcs/addons.py
|
|
@@ -4,8 +4,8 @@ with open("README.md", "r") as fh:
|
|
|
4
4
|
long_description = fh.read()
|
|
5
5
|
|
|
6
6
|
setuptools.setup(
|
|
7
|
-
name="
|
|
8
|
-
version="v1",
|
|
7
|
+
name="pySIMsalabim", # Replace with your own username
|
|
8
|
+
version="v1.02",
|
|
9
9
|
author="Vincent M. Le Corre, Sander Heester, L. Jan Anton Koster",
|
|
10
10
|
author_email="",
|
|
11
11
|
description="",
|
|
@@ -13,7 +13,7 @@ setuptools.setup(
|
|
|
13
13
|
long_description_content_type="text/markdown",
|
|
14
14
|
license='GPLv3',
|
|
15
15
|
url="https://github.com/kostergroup/pySIMsalabim",
|
|
16
|
-
download_url="https://github.com/kostergroup/pySIMsalabim/v1.tar.gz",
|
|
16
|
+
download_url="https://github.com/kostergroup/pySIMsalabim/v1.02.tar.gz",
|
|
17
17
|
packages=setuptools.find_packages(),
|
|
18
18
|
readme = "README.md",
|
|
19
19
|
keywords=['Drift-diffusion', 'semiconductor', 'solar cells'],
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"""Useful helper functions for pySIMsalabim"""
|
|
2
|
-
######### Package Imports #########################################################################
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
######### Function Definitions ####################################################################
|
|
6
|
-
|
|
7
|
-
def sci_notation(number, sig_fig=2):
|
|
8
|
-
"""Make proper scientific notation for graphs
|
|
9
|
-
|
|
10
|
-
Parameters
|
|
11
|
-
----------
|
|
12
|
-
number : float
|
|
13
|
-
Number to put in scientific notation.
|
|
14
|
-
|
|
15
|
-
sig_fig : int, optional
|
|
16
|
-
Number of significant digits (Defaults = 2).
|
|
17
|
-
|
|
18
|
-
Returns
|
|
19
|
-
-------
|
|
20
|
-
output : str
|
|
21
|
-
String containing the number in scientific notation
|
|
22
|
-
"""
|
|
23
|
-
if sig_fig != -1:
|
|
24
|
-
if number == 0:
|
|
25
|
-
output = '0'
|
|
26
|
-
else:
|
|
27
|
-
ret_string = "{0:.{1:d}e}".format(number, sig_fig)
|
|
28
|
-
a,b = ret_string.split("e")
|
|
29
|
-
if int(b) >= 0:
|
|
30
|
-
b = int(b) #removed leading "+" and strips leading zeros too.
|
|
31
|
-
c = ''
|
|
32
|
-
else:
|
|
33
|
-
b = abs(int(b))
|
|
34
|
-
c = u"\u207B" # superscript minus sign
|
|
35
|
-
SUP = str.maketrans("0123456789", "⁰¹²³⁴⁵⁶⁷⁸⁹")
|
|
36
|
-
b = str(b).translate(SUP)
|
|
37
|
-
output =a + ' x 10' + c + b
|
|
38
|
-
else:
|
|
39
|
-
if number == 0:
|
|
40
|
-
output = '0'
|
|
41
|
-
else:
|
|
42
|
-
ret_string = "{0:.{1:d}e}".format(number, 0)
|
|
43
|
-
a,b = ret_string.split("e")
|
|
44
|
-
b = int(b) #removed leading "+" and strips leading zeros too.
|
|
45
|
-
if int(b) >= 0:
|
|
46
|
-
b = int(b) #removed leading "+" and strips leading zeros too.
|
|
47
|
-
c = ''
|
|
48
|
-
else:
|
|
49
|
-
b = abs(int(b))
|
|
50
|
-
c = u"\u207B" # superscript minus sign
|
|
51
|
-
SUP = str.maketrans("0123456789", "⁰¹²³⁴⁵⁶⁷⁸⁹")
|
|
52
|
-
#SUB = str.maketrans("0123456789", "₀₁₂₃₄₅₆₇₈₉")
|
|
53
|
-
b = str(b).translate(SUP)
|
|
54
|
-
output = '10' + c + b
|
|
55
|
-
return output
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pysimsalabim-1/pySIMSalabim.egg-info → pysimsalabim-1.2/pySIMsalabim.egg-info}/dependency_links.txt
RENAMED
|
File without changes
|
{pysimsalabim-1/pySIMSalabim.egg-info → pysimsalabim-1.2/pySIMsalabim.egg-info}/requires.txt
RENAMED
|
File without changes
|
{pysimsalabim-1/pySIMSalabim.egg-info → pysimsalabim-1.2/pySIMsalabim.egg-info}/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|