Repository navigation
Description
Describe the bug
I think you missed the shift from winter to summer time and vice versa. When comparing your SLP H0 implementation with one of our own for the year 2024, I found that up until the 30th of March the profile match almost perfectly and from 31st of March to 26th of October (included) they are off by one hour, which if I interpret this correctly indicates that you do not consider summer / winter time, right?
So basically, the SLP H0 is only applicable in countries where there is no change between summer and winter time. If applied in german context (as I did) this change should be adressed because otherwise the SLP H0 is off one hour during the summer time period.
I hope I did not miss any documentation on this, but if I did, please let me know!
To Reproduce
# %%
from demandlib import bdew
import pandas as pd
import holidays # pip install holidays
pd.options.plotting.backend = "plotly"
demandlib = bdew.ElecSlp(
year=2024,
holidays=holidays.Germany(years=2024)
).create_dynamic_h0_profile() * 100000 # scale profileso we do not have such small values
# inspect the DateTimeIndex time zone information (there is none)
print(demandlib.index.tz) # prints "None"
# plot demandlib SLP H0 from 2024-03-27 to 2024-04-03
fig1 = demandlib.loc['2024-03-27':'2024-04-03'].plot()
fig1.update_layout(
title='DemandLib SLP H0 (original DateTimeIndex)',
xaxis_title='Time',
yaxis_title='Value',
legend=dict(x=0.01, y=0.99)
)
fig1.show()
# get the peak time on 2024-03-27 (Wednesday in winter time) and 2024-04-02 (Wednesday in summer time)
peak_time_winter = demandlib.loc['2024-03-27'].idxmax()
print(f"Peak time on 2024-03-27: {peak_time_winter}")
# Prints: Peak time on 2024-04-02: 2024-04-02 19:45:00
peak_time_summer = demandlib.loc['2024-04-02'].idxmax()
print(f"Peak time on 2024-04-02: {peak_time_summer}")
# Prints: Peak time on 2024-04-02: 2024-04-02 19:45:00
# %%
# now we a apply a DateTimeIndex which is TZ-aware for Germany
dt_index = pd.date_range(start="2024-01-01", end="2025-01-01", freq="15min", tz="Europe/Berlin")
dt_index = dt_index[:len(demandlib)]
demandlib.index = dt_index
# inspect the DateTimeIndex time zone information (now we see the timezone)
print(demandlib.index.tz) # prints "Europe/Berlin"
# plot demandlib SLP H0 from 2024-03-27 to 2024-04-03
fig1 = demandlib.loc['2024-03-27':'2024-04-03'].plot()
fig1.update_layout(
title='DemandLib SLP H0 (original DateTimeIndex)',
xaxis_title='Time',
yaxis_title='Value',
legend=dict(x=0.01, y=0.99)
)
fig1.show()
# get the peak time on 2024-03-27 (Wednesday in winter time) and 2024-04-02 (Wednesday in summer time)
peak_time_winter = demandlib.loc['2024-03-27'].idxmax()
print(f"Peak time on 2024-03-27: {peak_time_winter}")
# Prints: Peak time on 2024-03-27: 2024-03-27 19:45:00+01:00
peak_time_summer = demandlib.loc['2024-04-02'].idxmax()
print(f"Peak time on 2024-04-02: {peak_time_summer}")
# Prints: Peak time on 2024-03-27: 2024-04-02 20:45:00+02:00
# now we see that the peak time on 2024-04-02 changed from 19:45:00+01:00 to 20:45:00+02:00
# but we would expect it to be 19:45:00+02:00Expected behavior
When comparing to non-holiday wednesdays between summer and winter time I would expect the evening peak to be at the same time (e.g. 19:45). Currently as the code example shows the peak in winter time is 19:45+01:00 and the peak in summer time is 20:45+02:00.
Screenshots
Activity
p-snft commentedon Aug 21, 2025
Thanks for bringing that up. Looking at our implementation, we neglect time zones and just assume local time is given. And reading through the definitions of BDEW, I assume that, eg. the value for 12 pm is the value for 12 pm independent from the day of the year. I think, the proper way to work with this is switching to timezone-aware time stamps. This would also require setting a "target" time zone for the profiles. For example, it would make sense to give a time index in UTC but demand profiles for Germany (including DST).
At the same time, in your plot it is hard to tell if the 31st of March really is one hour shorter then the other days.
In the end, I think both implementations have their problems: By neglecting DST, we do not have one hour less in spring and the additional hour in fall. Your implementation shifts the whole profile by one hour in summer, which is also not intended (or only correct if you replace the time index before using it).
PS: Technically, the profiles should only be relevant for Germany.
joemfe commentedon Aug 21, 2025
Thank you for your quick reply!
As for you comment on the plot. The 31st of March actually is one hour shorter because the clock jumps from 1:59 to 3:00. I also double checked and found that the index is correct.
I agree that the timestamps are correct if you look at each day individually in a way that for example the peak on every sunday is at 12:00 noon throughout the whole year. But if you look at the annual profile as a whole it is in my opinion not correct (especially if it is only relevant for Germany) because the shift to and from DST should also shift the profile.
My solution for now is to create a proper tz-aware index and then clip the extra hour in March and insert it in October.
Maybe if there is time you could implement a optional parameter for
create_dynamic_h0_profile()to return a Series indexed with tz-aware Timestamps in "Europe/Berlin" timezone where the shift is considered.p-snft commentedon Aug 21, 2025
Sorry, you are right. You get up one hour early in summer. What I wanted to say: in your plot, every day seems to have the same length. (Changed that in the above comment to not confuse anybody.)
Thinking about it, I now interpret your time axis as given in central European standard time, the axis of demandlib is in local time (switches from standard time to DST) but incorrectly adds/removes hours so that every day has exactly 24 hours. Probably, always returning a timezone-aware index would solve the problem you mention here. An optional parameter would be used to set a different time zone. ("Europe/Berlin" would be a meaningful standard for BDEW.)
At the same time, the new
BDEW25Profiles, accept apd.DatetimeIndex. Should we enforce timezone-aware time indexes (and possibly a parameter to offset the time series)? Seems like this was the only clean way to do it.joemfe commentedon Aug 21, 2025
I came up with a quick snippet illustrating my thoughts and also what you elaborated on in your last reply which should serve as a basis for a common understanding of my original issue.
And here is the output:
I would appreciate if you'd adress this issue in the future :)
p-snft commentedon Aug 26, 2025
Overwriting the time axis of course will produce wrong results. The time series was calculated using a time zone naive index. The only way to address the issue is by properly converting the data to a timezone-aware index (and information about the location). This would include deleting points in time that do not exist in reality (as 2:30 at the last Sunday in March) and duplicating other values (as 2:30 at the last Sunday in October).
The question is whether we should do this internally or not. I just suggested this question for the upcoming developer meeting.
joemfe commentedon Aug 26, 2025
Thanks a lot for passing on the issue 👍