Skip to content

Commit dcb6a69

Browse files
committed
!asdf
1 parent 070d639 commit dcb6a69

File tree

4 files changed

+102
-5
lines changed

4 files changed

+102
-5
lines changed

docs/sphinx/source/conf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
'sphinx_gallery.gen_gallery',
5353
'sphinx_toggleprompt',
5454
]
55+
extensions.append("sphinx_remove_toctrees")
56+
57+
remove_from_toctrees = ["reference/**", "user_guide/forecasts*"]
5558

5659
napoleon_use_rtype = False # group rtype on same line together with return
5760

docs/sphinx/source/user_guide/storage.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -422,11 +422,6 @@ load/battery/grid, from battery to load and from grid to load/system:
422422
plt.close()
423423
424424
425-
.. note:: The :py:func:`~pvlib.flow.self_consumption_ac_battery` function
426-
allows you to define the AC-DC losses, if you would rather avoid the default
427-
values.
428-
429-
430425
While the self-consumption with AC-connected battery use case imposes many
431426
restrictions to the power flow, it still allows some flexibility to decide when
432427
to allow charging and discharging. If you wanted to simulate a use case where

pvlib/powerflow.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,56 @@ def self_consumption_ac_battery(generation, load, battery, model):
7777
return final_state, df
7878

7979

80+
def self_consumption_dc_battery(
81+
ac_generation,
82+
ac_clipping,
83+
inverter_efficiency,
84+
inverter_max_output_power_w,
85+
load,
86+
battery,
87+
model,
88+
):
89+
"""
90+
Calculate the power flow for a self-consumption use case with an
91+
AC-connected battery. It assumes the system is connected to the grid.
92+
93+
Parameters
94+
----------
95+
generation : Series
96+
The input generation profile. [W]
97+
load : Series
98+
The input load profile. [W]
99+
battery : dict
100+
The battery parameters.
101+
model : str
102+
The battery model to use.
103+
104+
Returns
105+
-------
106+
DataFrame
107+
The resulting power flow provided by the system, the grid and the
108+
battery into the system, grid, battery and load. [W]
109+
"""
110+
df = self_consumption(ac_generation, load)
111+
charging = (df["System to grid"] + ac_clipping) / inverter_efficiency
112+
discharging = df["Grid to load"]
113+
discharging = min(discharging, inverter_max_output_power_w - ac_generation)
114+
discharging /= inverter_efficiency
115+
dispatch = discharging - charging
116+
final_state, results = model(battery, dispatch)
117+
df["System to battery"] = -results["Power"].loc[results["Power"] < 0]
118+
df["System to battery"] = df["System to battery"].fillna(0.0)
119+
df["System to grid"] -= df["System to battery"] * inverter_efficiency
120+
df["Battery to load"] = results["Power"].loc[results["Power"] > 0]
121+
df["Battery to load"] = df["Battery to load"].fillna(0.0)
122+
df["Battery to load"] *= inverter_efficiency
123+
df["Grid to load"] -= df["Battery to load"]
124+
df["Grid"] = df[["Grid to system", "Grid to load"]].sum(
125+
axis=1, skipna=False
126+
)
127+
return final_state, df
128+
129+
80130
def self_consumption_ac_battery_custom_dispatch(
81131
df, dispatch, battery, model, ac_dc_loss=4, dc_ac_loss=4
82132
):
@@ -122,3 +172,50 @@ def self_consumption_ac_battery_custom_dispatch(
122172
axis=1, skipna=False
123173
)
124174
return final_state, df
175+
176+
177+
def self_consumption_dc_battery_custom_dispatch(
178+
df, dispatch, battery, model, ac_dc_loss=4, dc_ac_loss=4
179+
):
180+
"""
181+
Calculate the power flow for a self-consumption use case with an
182+
AC-connected battery and a custom dispatch series. It assumes the system is
183+
connected to the grid.
184+
185+
Parameters
186+
----------
187+
df : DataFrame
188+
The self-consumption power flow solution. [W]
189+
dispatch : Series
190+
The battery model to use.
191+
battery : dict
192+
The battery parameters.
193+
model : str
194+
The battery model to use.
195+
ac_dc_loss : float
196+
The fixed loss when converting AC to DC (i.e.: charging). [%]
197+
dc_ac_loss : float
198+
The fixed loss when converting DC to AC (i.e.: discharging). [%]
199+
200+
Returns
201+
-------
202+
DataFrame
203+
The resulting power flow provided by the system, the grid and the
204+
battery into the system, grid, battery and load. [W]
205+
"""
206+
final_state, results = model(battery, dispatch)
207+
df = df.copy()
208+
df["System to battery"] = -results["Power"]
209+
df["System to battery"].loc[df["System to battery"] < 0] = 0.0
210+
df["System to battery"] = df[["System to battery", "System to grid"]].min(
211+
axis=1
212+
)
213+
df["System to grid"] -= df["System to battery"]
214+
df["Battery to load"] = results["Power"]
215+
df["Battery to load"].loc[df["Battery to load"] < 0] = 0.0
216+
df["Battery to load"] = df[["Battery to load", "Grid to load"]].min(axis=1)
217+
df["Grid to load"] -= df["Battery to load"]
218+
df["Grid"] = df[["Grid to system", "Grid to load"]].sum(
219+
axis=1, skipna=False
220+
)
221+
return final_state, df

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[tool.black]
2+
line-length = 79

0 commit comments

Comments
 (0)