Skip to content

Commit

Permalink
lint, use mode None instead of -1
Browse files Browse the repository at this point in the history
  • Loading branch information
cwhanse committed Apr 9, 2024
1 parent 1f7a0d6 commit e4e2219
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
24 changes: 12 additions & 12 deletions docs/examples/snow-detection/snow-mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,9 @@ def wrapper(voltage, current, temp_cell, effective_irradiance,
modeled_power_cols = [c for c in data.columns if "Modeled Power" in c]

col = 1
l = loss_cols[col]
m = mode_cols[col]
p = modeled_power_cols[col]
los = loss_cols[col]
mod = mode_cols[col]
pwr = modeled_power_cols[col]

# Color intervals by mode
cmap = {0: 'r',
Expand All @@ -614,7 +614,7 @@ def wrapper(voltage, current, temp_cell, effective_irradiance,
fig, ax = plt.subplots(figsize=(10, 10))
date_form = DateFormatter("%m/%d")
ax.xaxis.set_major_formatter(date_form)
temp = data[~data[m].isna()]
temp = data[~data[mod].isna()]

# Plot each day individually so we are not exaggerating losses
days_mapped = temp.index.map(lambda x: x.date())
Expand All @@ -623,17 +623,17 @@ def wrapper(voltage, current, temp_cell, effective_irradiance,

for d in days:
temp_grouped = grouped.get_group(d)
ax.plot(temp_grouped[p], c='k', ls='--')
ax.plot(temp_grouped[p]- temp_grouped[l], c='k')
ax.fill_between(temp_grouped.index, temp_grouped[p] - temp_grouped[l],
temp_grouped[p], color='k', alpha=0.2)
ax.plot(temp_grouped[pwr], c='k', ls='--')
ax.plot(temp_grouped[pwr] - temp_grouped[los], c='k')
ax.fill_between(temp_grouped.index, temp_grouped[pwr] - temp_grouped[los],
temp_grouped[pwr], color='k', alpha=0.2)

chng_pts = np.ravel(np.where(temp_grouped[m].values[:-1]
- temp_grouped[m].values[1:] != 0))
chng_pts = np.ravel(np.where(temp_grouped[mod].values[:-1]
- temp_grouped[mod].values[1:] != 0))

if len(chng_pts) == 0:
ax.axvspan(temp_grouped.index[0], temp_grouped.index[-1],
color=cmap[temp_grouped.at[temp_grouped.index[-1], m]],
color=cmap[temp_grouped.at[temp_grouped.index[-1], mod]],
alpha=0.05)
else:
set1 = np.append([0], chng_pts)
Expand All @@ -643,7 +643,7 @@ def wrapper(voltage, current, temp_cell, effective_irradiance,
my_index = temp_grouped.index[start:end]
ax.axvspan(
temp_grouped.index[start], temp_grouped.index[end],
color=cmap[temp_grouped.at[temp_grouped.index[end], m]],
color=cmap[temp_grouped.at[temp_grouped.index[end], mod]],
alpha=0.05)

# Add different colored intervals to legend
Expand Down
10 changes: 5 additions & 5 deletions pvanalytics/features/snow.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def get_transmission(measured_e_e, modeled_e_e, i_mp):


def categorize_old(vmp_ratio, transmission, voltage, min_dcv,
threshold_vratio, threshold_transmission):
threshold_vratio, threshold_transmission):

"""
Categorizes electrical behavior into a snow-related mode.
Expand Down Expand Up @@ -262,7 +262,7 @@ def categorize(vmp_ratio, transmission, voltage, min_dcv,
50th Photovoltaic Specialists Conference (PVSC), San Juan, PR, USA,
2023, pp. 1-5, :doi:`10.1109/PVSC48320.2023.10360065`.
"""
mode = np.zeros_like(voltage)
mode = np.zeros_like(voltage, dtype=int)

umin = voltage > min_dcv # necessary for all modes except 0
uvr = np.where(vmp_ratio > threshold_vratio, 3, 1)
Expand All @@ -271,6 +271,6 @@ def categorize(vmp_ratio, transmission, voltage, min_dcv,
mode = umin * (uvr + utrans)

# preserve nan
mode[np.isnan(vmp_ratio) | np.isnan(transmission)] = -1
return mode
mode[np.isnan(vmp_ratio) | np.isnan(transmission)] = None

return mode
4 changes: 2 additions & 2 deletions pvanalytics/tests/features/test_snow.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def test_categorize():
threshold_vratio = 0.7
threshold_transmission = 0.6
# np.nan, vr<thres, vr<thres, vr=thres, vr>thres, vr>thres, vr<thres
# vo>thres, vo>thres, vo>thres, vo>thres, vo>thres, vo>thres, vo<thres
# tr<thres, np.nan, tr>thres, tr<thres, tr<thres, tr<thres, tr>thres
# vo>thres, vo>thres, vo>thres, vo>thres, vo>thres, vo>thres, vo<thres
# tr<thres, np.nan, tr>thres, tr<thres, tr<thres, tr<thres, tr>thres
expected = np.array([np.nan, np.nan, 2, 2, 2, 4, 0])
result = snow.categorize(vmp_ratio, transmission, voltage, min_dcv,
threshold_vratio, threshold_transmission)
Expand Down

0 comments on commit e4e2219

Please sign in to comment.