-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathcumulative-energy-simple-avg-check.py
More file actions
72 lines (60 loc) · 2.33 KB
/
cumulative-energy-simple-avg-check.py
File metadata and controls
72 lines (60 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""
Cumulative Energy via Average Difference
=======================================
Check and correct energy series for cumulative energy via average differencing.
"""
# %%
# AC energy data streams are often cumulative, meaning they increase
# over time. These energy streams need to be corrected into a form
# that resembles regular, non-cumulative data. This process involves
# applying a percent threshold to the average difference in subsequent values
# to check if the data is always increasing. If it passes,
# that check, then the data stream is cumulative and it can be corrected
# via average differencing.
import pandas as pd
import matplotlib.pyplot as plt
from pvanalytics.quality import energy
import pathlib
import pvanalytics
# %%
# First, read in the ac energy data. This data set contains one week of
# 10-minute ac energy data.
pvanalytics_dir = pathlib.Path(pvanalytics.__file__).parent
energy_file = pvanalytics_dir / 'data' / 'system_10004_ac_energy.csv'
data = pd.read_csv(energy_file)
energy_series = data['ac_energy_inv_16425']
# %%
# Now check if the energy time series is cumulative via average differencing.
# This is done using the
# :py:func:`pvanalytics.quality.energy.cumulative_energy_avg_diff_check`
# function.
is_cumulative = energy.cumulative_energy_avg_diff_check(energy_series)
# %%
# If the energy series is cumulative,, then it can be converted to
# non-cumulative energy series via average differencing.
corrected_energy_series = 0.5 * \
(energy_series.diff().shift(-1) + energy_series.diff())
# %%
# Plot the original, cumulative energy series.
data.plot(x="local_measured_on", y='ac_energy_inv_16425')
plt.title("Cumulative Energy Series")
plt.xticks(rotation=45)
plt.xlabel("Datetime")
plt.ylabel("AC Energy (kWh)")
plt.tight_layout()
plt.show()
# %%
# Plot the corrected, non-cumulative energy series.
corrected_energy_df = pd.DataFrame({
"local_measured_on": data["local_measured_on"],
"corrected_ac_energy_inv_16425": corrected_energy_series})
corrected_energy_df = corrected_energy_df[
corrected_energy_df["corrected_ac_energy_inv_16425"] >= 0]
corrected_energy_df.plot(x="local_measured_on",
y="corrected_ac_energy_inv_16425")
plt.title("Corrected, Non-cumulative Energy Series")
plt.xticks(rotation=45)
plt.xlabel("Datetime")
plt.ylabel("AC Energy (kWh)")
plt.tight_layout()
plt.show()