Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
image: python:3.9

pages:
stage: deploy
script:
- python setup.py install
- pip install -U sphinx
- pip install -U sphinx-rtd-theme
- sphinx-build -b html ./docs public
artifacts:
paths:
- public
only:
- master
3 changes: 2 additions & 1 deletion docs/_static/0/basecase/Visualize_and_Export.html
Original file line number Diff line number Diff line change
Expand Up @@ -15030,7 +15030,8 @@ <h3 id="Playing-with-data-frames:-profiles-and-time-series">Playing with data fr
<div class="jp-InputPrompt jp-InputArea-prompt">In&nbsp;[27]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="CodeMirror cm-s-jupyter">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">df</span><span class="p">[[</span><span class="s1">&#39;distance&#39;</span><span class="p">]]</span><span class="o">.</span><span class="n">iplot</span><span class="p">()</span>
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">fig_dist</span> <span class="o">=</span> <span class="n">px</span><span class="o">.</span><span class="n">line</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="s2">&quot;distance&quot;</span><span class="p">,</span> <span class="n">title</span><span class="o">=</span><span class="s2">&quot;distance&quot;</span><span class="p">)</span>
<span class="n">fig_dist</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>

</div>
Expand Down
1 change: 0 additions & 1 deletion docs/requirements.readthedocs.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
appdirs
plotly
cufflinks
zenodo-get
pyyaml
pandas
Expand Down
109 changes: 63 additions & 46 deletions emobpy/availability.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,49 @@
logger = get_logger(__name__)


@jit(nopython=True)
def _charging_cap_numba(state_is_driving, consumption, charging_cap, t, battery_capacity):
"""
Berechnet die angepasste charging_cap-Spalte (0 wo keine Lademöglichkeit).
state_is_driving[i] == 1 bedeutet state == 'driving'.
"""
n = consumption.shape[0]
out_cap = np.empty_like(charging_cap)
for i in range(n):
out_cap[i] = charging_cap[i]
flag = False
cumcons = 0.0
cumchrg = 0.0
for i in range(n):
if flag:
if state_is_driving[i]:
if cumcons != 0 and cumchrg == 0:
cumcons += consumption[i]
if cumcons < battery_capacity * 0.50:
out_cap[i] = 0.0
cumchrg = 0.0
else:
cumchrg += charging_cap[i] * t
cumcons = 0.0
else:
cumchrg += charging_cap[i] * t
if cumchrg > battery_capacity * 0.5:
cumchrg = 0.0
cumcons = 0.001
else:
flag = False
elif state_is_driving[i]:
flag = True
cumcons = consumption[i]
if cumcons < battery_capacity * 0.65:
out_cap[i] = 0.0
cumchrg = 0.0
else:
cumchrg = charging_cap[i] * t
cumcons = 0.0
return out_cap


################################################################
# These functions are for grid availability profile creation ###
################################################################
Expand Down Expand Up @@ -439,20 +482,19 @@ def _fill_rows(self):
self.dt = pd.DataFrame(columns=self.db.columns)
self.dt.loc[:, "hh"] = np.arange(0, self.hours, self.t)

# Start New version, which works for 1s-based profiles:
temp_timeseries = [round(num*3600) for num in self.dt["hh"]]
temp_db = [round(num*3600) for num in self.db["hr"]]
temp_intersection_list = list(set(temp_timeseries).intersection(temp_db))

self.idx = []
for i in temp_intersection_list:
self.idx.append(temp_timeseries.index(i))
self.idx = np.sort(self.idx).tolist()
# End new version
# Vektorisiert (wie in mobility._fill_rows): Index-Suche mit NumPy
temp_ts = np.round(self.dt["hh"].values * 3600).astype(np.int64)
temp_db = np.round(self.db["hr"].values * 3600).astype(np.int64)
order = np.argsort(temp_ts)
sorted_ts = temp_ts[order]
pos = np.searchsorted(sorted_ts, temp_db)
idx = order[pos]
sorted_by_idx = np.argsort(idx)
self.idx = idx[sorted_by_idx].tolist()

self.mixed = self.repeats_str + self.repeats_float + self.fixed + self.copied
for r in self.mixed:
self.val = self.db[r].values.tolist()
self.val = self.db[r].values[sorted_by_idx]
self.dt.loc[self.idx, r] = self.val
self.dt.loc[self.totalrows - 1, "state"] = self.db["state"].iloc[-1]
self.dt.loc[self.totalrows - 1, "hr"] = self.dt["hh"][self.totalrows - 1]
Expand All @@ -464,7 +506,7 @@ def _fill_rows(self):
for sm in self.same:
self.dt.loc[:, sm] = self.db[sm].values.tolist()[0]
for cal in self.calc:
self.dt.loc[:, cal] = self.dt["hh"].apply(lambda x: x % 24)
self.dt.loc[:, cal] = self.dt["hh"].values % 24
self.dt.loc[:, "count"] = self.dt.groupby(["hr", "state"])[
"consumption"
].transform("count")
Expand All @@ -474,40 +516,15 @@ def _fill_rows(self):
self.dt.loc[:, "distance"] = (
self.dt.loc[:, "distance"] / self.dt.loc[:, "count"]
)
# convert this section to numba
flag = False
for i, row in self.dt.iterrows():
if flag:
if row["state"] == "driving":
flag = True
if self.cumcons != 0 and self.cumchrg == 0:
self.cumcons += row["consumption"]
if self.cumcons < self.battery_capacity * 0.50:
self.dt.loc[i, "charging_cap"] = 0
self.dt.loc[i, "charging_point"] = "none"
self.cumchrg = 0
else:
self.cumchrg += row["charging_cap"] * self.t
self.cumcons = 0
else:
self.cumchrg += row["charging_cap"] * self.t
if self.cumchrg > self.battery_capacity * 0.5:
self.cumchrg = 0
self.cumcons += 0.001
else:
pass
else:
flag = False
elif row["state"] == "driving":
flag = True
self.cumcons = row["consumption"]
if self.cumcons < self.battery_capacity * 0.65:
self.dt.loc[i, "charging_cap"] = 0
self.dt.loc[i, "charging_point"] = "none"
self.cumchrg = 0
else:
self.cumchrg = row["charging_cap"] * self.t
self.cumcons = 0
state_is_driving = (self.dt["state"] == "driving").values.astype(np.float64)
consumption_arr = self.dt["consumption"].values.astype(np.float64)
charging_cap_arr = self.dt["charging_cap"].values.astype(np.float64)
new_cap = _charging_cap_numba(
state_is_driving, consumption_arr, charging_cap_arr,
self.t, self.battery_capacity,
)
self.dt.loc[:, "charging_cap"] = new_cap
self.dt.loc[self.dt["charging_cap"] == 0, "charging_point"] = "none"

def run(self):
"""
Expand Down
12 changes: 7 additions & 5 deletions emobpy/charging.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,13 @@ def run(self):
self._clean()
return None
self.numpy_array3 = self.profile[['state']].values.T
self.arraystringstate = self.numpy_array3[0]
self.arraystringstate = self.numpy_array3[0].astype(str)
self.arraycodestate = np.array([self.states.index(s) for s in self.arraystringstate])
self.numpy_array2 = self.profile[['consumption', 'charging_cap']].values.T
self.arrayconsumption = self.numpy_array2[0].astype(np.float64)
self.arraychargingcap = self.numpy_array2[1].astype(np.float64)
self.results = self._immediate(self.pointcode, self.charging_eff, self.battery_capacity, self.soc_init,
self.arraycodestate, *self.numpy_array2, self.t)
self.arraycodestate, self.arrayconsumption, self.arraychargingcap, self.t)
self.profile.loc[:, 'actual_soc'] = self.results[0]
self.profile.loc[:, 'charge_battery'] = self.results[1]
self.profile.loc[:, 'charge_grid'] = self.results[2]
Expand All @@ -157,7 +159,7 @@ def run(self):
self._clean()
return None
self.numpy_array3 = self.profile[['state', 'consumption', 'charging_cap']].values.T
self.arraystringstate = self.numpy_array3[0]
self.arraystringstate = self.numpy_array3[0].astype(str)
self.arraycodestate = np.array([self.states.index(s) for s in self.arraystringstate])
self.arrayconsumption = self.numpy_array3[1].astype(np.float64)
self.arraychargingcap = self.numpy_array3[2].astype(np.float64)
Expand All @@ -173,7 +175,7 @@ def run(self):
self.point = self.op_list[5]

self.numpy_array4 = self.profile[['state', 'consumption', 'charging_cap', 'hh']].values.T
self.arraystringstate = self.numpy_array4[0]
self.arraystringstate = self.numpy_array4[0].astype(str)
self.arraycodestate = np.array([self.states.index(s) for s in self.arraystringstate])
try:
self.drivingcode = self.states.index('driving')
Expand Down Expand Up @@ -595,4 +597,4 @@ def save_profile(self, folder, description=' '):
display_all()
except:
pass
return None
return None
Loading