Skip to content

Commit f762dcb

Browse files
Merge pull request #30 from sandialabs/iv-sim-bug
iv simulator bug fix
2 parents 5756335 + 5c231b6 commit f762dcb

File tree

2 files changed

+45
-18
lines changed

2 files changed

+45
-18
lines changed

pvops/iv/physics_utils.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import scipy
33
import math
44
from sklearn.linear_model import LinearRegression
5+
import copy
56

67

78
def calculate_IVparams(v, c):
@@ -143,10 +144,20 @@ def intersection(x1, y1, x2, y2):
143144
-------
144145
intersection coordinates
145146
"""
146-
x1 = np.asarray(x1)
147-
x2 = np.asarray(x2)
148-
y1 = np.asarray(y1)
149-
y2 = np.asarray(y2)
147+
x1 = copy.copy(np.asarray(x1))
148+
x2 = copy.copy(np.asarray(x2))
149+
y1 = copy.copy(np.asarray(y1))
150+
y2 = copy.copy(np.asarray(y2))
151+
152+
def _upsample_curve(Varr, Iarr, n_pts=1000):
153+
vmax = Varr.max()
154+
vnot = Varr.min()
155+
resol = (vmax - vnot) / n_pts
156+
v_interps = np.arange(vnot, vmax, resol)
157+
return v_interps, np.interp(v_interps, Varr, Iarr)
158+
159+
x1, y1 = _upsample_curve(x1, y1)
160+
x2, y2 = _upsample_curve(x2, y2)
150161

151162
def _rect_inter_inner(x1, x2):
152163
n1 = x1.shape[0] - 1
@@ -197,6 +208,25 @@ def _rect_inter_inner(x1, x2):
197208

198209
xy0 = T[2:, in_range]
199210
xy0 = xy0.T
211+
212+
if not len(xy0[:, 1]):
213+
import matplotlib.pyplot as plt
214+
plt.figure(figsize=(13, 8))
215+
plt.plot(x1, y1,
216+
'bo', markersize=2, label='1')
217+
plt.plot(x2, y2, 'ro',
218+
markersize=2, label='2')
219+
plt.legend()
220+
plt.xlabel('V (Volts)')
221+
plt.ylabel('I (Amps)')
222+
# plt.ylim(0, max(max(y2),max(y1)) + 2.)
223+
plt.ylim(-4, 20)
224+
plt.xlim(-13.5, max(max(x2), max(x1)) + 2.)
225+
plt.show()
226+
print("x1 = ", list(x1))
227+
print("x2 = ", list(x2))
228+
print("y1 = ", list(y1))
229+
print("y2 = ", list(y2))
200230
return xy0[:, 0], xy0[:, 1]
201231

202232

pvops/iv/simulator.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ def simulate_modules(self):
900900
"""
901901
for discrete_mod in list(self.modcells.keys()):
902902
# print(discrete_mod)
903-
print('in simulate_modules, iterating to ', discrete_mod)
903+
# print('in simulate_modules, iterating to ', discrete_mod)
904904
self.simulate_module(discrete_mod)
905905

906906
def BISHOP88_simulate_module(self, mod_key):
@@ -995,9 +995,6 @@ def PVOPS_simulate_module(self, mod_key):
995995

996996
for md_idx, modset in enumerate(self.modcells[mod_key]):
997997

998-
if show_debugging_plots:
999-
print(modset)
1000-
1001998
# Map all definitions to every possible definition-map combination
1002999
cell_defs = []
10031000
for cell_num in set(modset):
@@ -1034,11 +1031,6 @@ def PVOPS_simulate_module(self, mod_key):
10341031

10351032
for s in range(self.module_parameters['nsubstrings']):
10361033

1037-
if show_debugging_plots:
1038-
print()
1039-
print()
1040-
print(f'substring:{s}')
1041-
10421034
ivs = {}
10431035

10441036
celltypes = []
@@ -1114,7 +1106,7 @@ def find_nearest(array, value):
11141106
# Essentially Isc minus effectiveISC
11151107
delta = realisc - effective_Isc[1][0]
11161108
substr_i -= delta
1117-
else:
1109+
elif substr_i[idx_left_substr] < iter_I[idx_left_iter]:
11181110
iter_V_cutoff, iter_I_cutoff = iter_V.copy(
11191111
), iter_I.copy()
11201112

@@ -1128,6 +1120,10 @@ def find_nearest(array, value):
11281120
delta = realisc - effective_Isc[1][0]
11291121
iter_I -= delta
11301122

1123+
else:
1124+
# Equal! Doing nothing.
1125+
pass
1126+
11311127
substr_v, substr_i = add_series(
11321128
substr_v, substr_i, iter_V, iter_I)
11331129

@@ -1457,7 +1453,6 @@ def _histograms(self):
14571453
params.append(parm)
14581454
vals.append(dct[parm])
14591455

1460-
print(len(params), len(cell_ids), len(vals))
14611456
df_gp = pd.DataFrame()
14621457
df_gp['param_names'] = params
14631458
df_gp['cell_id'] = cell_ids
@@ -1500,7 +1495,7 @@ def ax_settings(ax, var_name, x_min, x_max):
15001495

15011496
cell_idx = 0
15021497
for cellid_iter in list(self.condition_dict.keys()):
1503-
print('id', cellid_iter)
1498+
# print('id', cellid_iter)
15041499
sns.kdeplot(data=df_gp[(df_gp.cell_id == cellid_iter) & (df_gp.param_names == self.acceptible_keys[i])].value,
15051500
ax=ax[i], shade=True, color=colors[cell_idx], bw=300, legend=False)
15061501
cell_idx += 1
@@ -1522,7 +1517,7 @@ def ax_settings(ax, var_name, x_min, x_max):
15221517
plt.show()
15231518
return
15241519

1525-
def visualize(self, lim=False, correct_gt=False):
1520+
def visualize(self, lim=False):
15261521
"""Run visualization suite to visualize information about the simulated curves.
15271522
"""
15281523
d = {}
@@ -1595,6 +1590,7 @@ def visualize(self, lim=False, correct_gt=False):
15951590
plt.legend(loc='center left', bbox_to_anchor=(1, 0.5))
15961591
if lim:
15971592
plt.xlim(xmin=0)
1593+
plt.ylim(ymin=0)
15981594
plt.show()
15991595

16001596
if len(self.string_cond.keys()) > 0:
@@ -1609,6 +1605,7 @@ def visualize(self, lim=False, correct_gt=False):
16091605
plt.legend(loc='center left', bbox_to_anchor=(1, 0.5))
16101606
if lim:
16111607
plt.xlim(xmin=0)
1608+
plt.ylim(ymin=0)
16121609
plt.show()
16131610

16141611
def visualize_specific_iv(self, ax=None, string_identifier=None, module_identifier=None, substring_identifier=None, cutoff=True, correct_gt=False):
@@ -1722,7 +1719,7 @@ def visualize_multiple_cells_traces(self, list_cell_identifiers, cutoff=True):
17221719
colors = sns.color_palette("hls", len(list_cell_identifiers))
17231720

17241721
for i, cell_identity in enumerate(list_cell_identifiers):
1725-
print(cell_identity)
1722+
# print(cell_identity)
17261723
if i == 0:
17271724
axs = self._vis_cell_trace(
17281725
cell_identity, colors[i], cutoff=cutoff)

0 commit comments

Comments
 (0)