Typical-day profile
The profile is 24 numbers. Each is the mean of the
A borehole pump delivers 28 percent more water this month than last month, and the manager wants to know who is using it. If the answer given is “the users”, the site buys a larger pump. If the true answer is “a broken pipe”, the larger pump only feeds the leak faster. The monthly total cannot separate the two cases, but the shape of an ordinary day can. This lesson shows how to fold weeks of readings into one typical day and one typical week, how to read base load and peak from that picture, and how to separate a slow trend from a pattern that repeats. #TimeSeries #LoadProfile #Seasonality
By the end of this lesson, you will be able to:
A borehole pump fills a village supply. A flow meter on the discharge pipe logs the flow every hour. Over 60 days the meter shows that the daily volume rose from about 78 m³ to about 100 m³. Nobody changed the pump, and nobody counted the users.
Two explanations fit the totals. More people may be drawing water: then the extra flow appears when people are awake and is nearly absent at night. Or a pipe may have failed: then water leaves through the break at every hour, including 03:00 when every tap is closed. The two cases give the same total and different shapes of day.
The same question appears on every site. A building’s energy is high on some days and low on others: is that the weather, or are some of those days Sundays? Before any model is fitted, the engineer must know what an ordinary day and an ordinary week look like.
Most site data repeats with the clock and the calendar. Water use follows the hours of the day. Office energy follows the days of the week. Cooling follows the year. In time series work, any pattern with a fixed, known period is called seasonal, even when the period is one day and has nothing to do with seasons.
A long plot of 1,440 hourly readings hides this repetition. Fold the series instead, like the days of a calendar laid on top of each other: every reading taken at 03:00 in one group, every reading at 04:00 in the next, and describe each group.
Write
Typical-day profile
The profile is 24 numbers. Each is the mean of the
A mean alone hides how much one day differs from the next, so at each hour also take the 10th and the 90th percentile of the same
Three numbers come directly from a profile.
Base load deserves attention because it runs for all 8,760 hours of the year. A base load of 1 kW costs 8,760 kWh a year.
On a real site, three things spoil a profile:
A profile is also a rule for fair comparison: compare a reading at 03:00 with other readings at 03:00, and a Tuesday with other Tuesdays. Comparing a Sunday with a Monday reports the weekend, which you already knew, and hides any real change.
To compare two months, compare their profiles hour by hour. The difference at each hour,
A constant addition lifts every hour by the same amount. A proportional rise multiplies every hour by the same factor, adding much at the peak and almost nothing at the base.
Daily totals fold in the same way, with a period of 7 days. Number the days of the week from 0 (Monday) to 6 (Sunday) and take the mean of all Mondays, all Tuesdays and so on. For many buildings, two numbers are enough: the mean of weekdays and the mean of weekend days.
A daily series with a weekly pattern jumps every Saturday. To see the slow movement under those jumps, average over exactly one full period, so that every window holds one Monday, one Tuesday and so on. The pattern then cancels, whatever its shape.
Centred moving average, odd window
For a weekly pattern in daily data,
“Centred” means that the window extends equally to both sides, so the average belongs to the middle day. A trailing average (the last 7 days) also removes the weekly pattern, but it reports the level of 3 days ago, so every turn appears late.
A centred window needs
This is not a fault of the software: the trend on the last day depends on days that have not happened yet. Programs that draw a line to the very end have guessed, usually with a shorter or one-sided window, and those last points change when new data arrives. The cost grows with the window: a 7-day window loses 3 days at each end, and a 365-day window loses 182.
With the trend known, the series can be written as three parts.
Additive decomposition
The simple method has four steps.
If the remainder is small and without shape, the calendar explains the site. If it is large, something else drives the readings, such as weather or production.
The method assumes that the pattern is stable, with the same seven values of
A fuller method called STL (Cleveland and others, 1990) allows the seasonal component to change slowly and resists outliers. It is described in the forecasting text listed in the references.
Arrange the data. Put the 1,440 readings into a table of 60 rows (days) and 24 columns (hours). Rows 0 to 34 are the first period, 35 days. Rows 35 to 59 are the second period, 25 days. ✅
Take the mean of each column. Each value of the first profile is the mean of 35 readings, and each value of the second is the mean of 25 readings. Selected hours, in m³/h:
| Hour | Days 0 to 34 | 10th | 90th | Days 35 to 59 | Difference |
|---|---|---|---|---|---|
| 0 | 0.58 | 0.48 | 0.67 | 1.49 | 0.91 |
| 3 | 0.59 | 0.47 | 0.68 | 1.50 | 0.91 |
| 6 | 4.47 | 3.85 | 5.20 | 5.57 | 1.10 |
| 9 | 4.49 | 3.88 | 5.44 | 5.56 | 1.07 |
| 12 | 4.46 | 3.70 | 5.14 | 5.42 | 0.97 |
| 16 | 4.61 | 4.01 | 5.19 | 5.39 | 0.78 |
| 21 | 4.53 | 3.87 | 5.38 | 5.45 | 0.92 |
| 23 | 0.62 | 0.54 | 0.68 | 1.48 | 0.86 |
The script prints all 24 hours. ✅
Read the shape. The first profile has two levels: about 0.6 m³/h from 22:00 to 06:00 and about 4.5 m³/h from 06:00 to 22:00. The second profile has the same two-level shape, lifted. ✅
Read the band. At hour 3 the 10th and 90th percentiles are 0.47 and 0.68 m³/h, a band of 0.21. At hour 12 they are 3.70 and 5.14, a band of 1.44. The night hours give the sharper measurement. ✅
Subtract the profiles. The 24 differences have a mean of 0.917 m³/h. The smallest is 0.78 and the largest is 1.10. ✅
Night against day. The mean difference over the 8 night hours is 0.899 m³/h. Over the 16 day hours it is 0.926 m³/h. The two agree within 0.03 m³/h. ✅
Is the scatter by day real? At hour 2, one reading varies by 0.07 m³/h (standard deviation), and the standard error of the difference of the two means is 0.02 m³/h. At hour 12, one reading varies by 0.59 m³/h and the standard error of the difference is 0.16 m³/h. The day differences, from 0.78 to 1.10, all lie within 0.18 of 0.92, about one standard error. The night differences, from 0.86 to 0.92, are known eight times more closely. All 24 hours are consistent with one constant value of about 0.9 m³/h. ✅
Test the other explanation. The daily volume rose by 28.4 percent (Step 3). If use had grown by 28.4 percent at every hour, the night flow would have risen by only 0.17 m³/h and the day flow by 1.29 m³/h. The data shows 0.90 and 0.93. A proportional rise does not fit. ✅
Conclusion. The same 0.9 m³/h was added at every hour, including the hours when nobody draws water. That is the signature of a constant leak and not of extra use. ✅
Base flow. The minimum of the first profile is 0.58 m³/h, at hour 0. The minimum of the second is 1.48 m³/h, at hour 23. The base flow is 2.5 times what it was. ✅
Peak. The maximum of the first profile is 4.73 m³/h at hour 8, and of the second 5.71 m³/h at hour 13. The peak hour moved only because the day hours are nearly equal, so noise decides which is highest. ✅
Daily volume. The sum of the 24 hourly means is
The rise is 22.0 m³ a day, or 28.4 percent. ✅
Check a second way. A constant 0.917 m³/h for 24 hours is
This equals the rise in daily volume, so the constant addition explains all of it. The data was generated with a leak of 0.9 m³/h from day 35, which is 21.6 m³ a day. The estimate is within 2 percent of the truth. ✅
One mean of everything. The mean of all 730 days is 559.2 kWh a day, with a standard deviation of 159.4 kWh. Few days are near 559: the building has two kinds of day. ✅
Two means. The 522 weekdays have a mean of 609.9 kWh. The 208 weekend days have a mean of 431.9 kWh. ✅
The weekday step.
(The script keeps all digits, so the last figure differs by 0.1 from the rounded subtraction.) A working day costs about 178 kWh more than a rest day. ✅
By day of week. Monday 598.9, Tuesday 622.4, Wednesday 616.3, Thursday 610.0, Friday 601.6, Saturday 434.2, Sunday 429.6 kWh. The five working days are alike and the two rest days are alike, so two groups describe this building well. ✅
First window. Days 0 to 6 are one full week. Their mean is the trend for the middle day, day 3.
The trend on day 3 is 512.7 kWh. ✅
Move the window one day. For day 4, drop day 0 and add day 7. Each window still holds five working days and two rest days, so the weekly pattern cancels. ✅
The end effect. Days 0, 1, 2 and days 727, 728, 729 have no full window. The trend has no value on 6 of the 730 days. ✅
What the trend shows. With the weekly pattern removed, the slow movement is visible. The trend is highest at 816 kWh on day 466 and lowest at 367 kWh on day 627. That swing follows the warm and cool seasons, and it is larger than the weekday step. ✅
A yearly window. To remove the yearly pattern as well, the window must be 365 days. That centred average has no value on 364 of the 730 days: only the middle year remains. Two years of data cannot show a trend free of season except across their middle. ✅
Remove the trend. Calculate
Mean deviation by day of week. After the seven means are shifted to sum to zero, the seasonal component is, in kWh:
| Mon | Tue | Wed | Thu | Fri | Sat | Sun |
|---|---|---|---|---|---|---|
A Saturday is 125.0 kWh below the trend and a Tuesday 64.5 kWh above it. ✅
Remainder for one day. Day 3 is a Thursday.
(The script, with all digits, prints
Size of the remainder. The standard deviation of the 724 remainders is 56.4 kWh. The raw series had 159.4 kWh. Trend and weekly pattern together account for most of the movement, and 56.4 kWh a day is what the calendar cannot explain. ✅
Check a second way. The mean of the five weekday values of
Check with a library. seasonal_decompose(energy, period=7, model="additive") from statsmodels (pip install statsmodels) uses the same four steps. It returns the same seven seasonal values, the same trend of 512.7 kWh on day 3, no trend on 6 days, and a remainder with a standard deviation of 56.4 kWh. A hand method that agrees with a library on known data can be trusted on new data. ✅
The script generates both data sets, prints the borehole profile for the two periods, then the weekly means, the centred moving average and the decomposition of the building’s energy. It saves one figure.
"""Typical-day profile of a borehole and weekly pattern of a building's energy."""import numpy as npimport matplotlib.pyplot as plt
def borehole_hourly(seed=37, days=60): rng = np.random.default_rng(seed) h = np.arange(days * 24); hour = h % 24 demand = np.where((hour >= 6) & (hour < 22), 4.6, 0.6) # m3/h drawn by users demand = demand * (1.0 + rng.normal(0, 0.12, h.size)) leak = np.where(h >= 35 * 24, 0.9, 0.0) # a leak starts on day 35 flow = np.clip(demand + leak, 0, None) # m3/h kwh_per_m3 = 0.42 + 0.0006 * (h / 24.0) # slow wear: rising power = flow * kwh_per_m3 * (1.0 + rng.normal(0, 0.03, h.size)) # kW return h, flow, power
def building_daily(seed=23, days=730): rng = np.random.default_rng(seed) d = np.arange(days) temp = 21.0 + 4.5 * np.sin(2 * np.pi * (d - 20) / 365.0) + rng.normal(0, 1.6, days) weekday = (d % 7) < 5 # day 0 is a Monday cdd = np.clip(temp - 18.0, 0.0, None) # cooling degree days, base 18 °C energy = 310.0 + 42.0 * cdd + np.where(weekday, 180.0, 0.0) + rng.normal(0, 28.0, days) # an energy-saving measure is installed on day 500: 12 percent less from then on energy[500:] *= 0.88 return d, temp, weekday, energy # kWh a day
def centred_average(x, window): """Centred moving average for an odd window. The ends are left as NaN.""" k = window // 2 out = np.full(x.size, np.nan) out[k:x.size - k] = np.convolve(x, np.ones(window) / window, mode="valid") return out
# ---------- Part 1: data set C, the typical day ----------h, flow, power = borehole_hourly()table = flow.reshape(60, 24) # one row a day, one column an hourearly, late = table[:35], table[35:] # days 0 to 34 and days 35 to 59p_early, p_late = early.mean(axis=0), late.mean(axis=0)lo, hi = np.percentile(early, 10, axis=0), np.percentile(early, 90, axis=0)diff = p_late - p_early
print("Borehole: typical day (m3/h)")print(" hour days 0-34 p10 p90 days 35-59 difference")for k in range(24): print(f" {k:4d} {p_early[k]:9.2f} {lo[k]:4.2f} {hi[k]:4.2f} " f"{p_late[k]:10.2f} {diff[k]:10.2f}")night = np.r_[22:24, 0:6]day = np.r_[6:22]print(f" difference: mean {diff.mean():.3f}, smallest {diff.min():.2f}, " f"largest {diff.max():.2f}")print(f" difference: night hours {diff[night].mean():.3f}, " f"day hours {diff[day].mean():.3f}")print(f" base flow: {p_early.min():.2f} at hour {p_early.argmin()}, " f"then {p_late.min():.2f} at hour {p_late.argmin()}")print(f" peak flow: {p_early.max():.2f} at hour {p_early.argmax()}, " f"then {p_late.max():.2f} at hour {p_late.argmax()}")for k in (2, 12): sd = early[:, k].std(ddof=1) se = np.sqrt(sd ** 2 / 35 + late[:, k].std(ddof=1) ** 2 / 25) print(f" hour {k}: one reading varies by {sd:.2f} (standard deviation), " f"standard error of the difference {se:.2f}")v_early, v_late = p_early.sum(), p_late.sum()print(f" daily volume: {v_early:.1f} m3, then {v_late:.1f} m3, " f"rise {v_late - v_early:.1f} m3 ({100 * (v_late / v_early - 1):.1f} %)")grow = v_late / v_early - 1.0print(f" if use had grown {100 * grow:.1f} %: night +{grow * p_early[night].mean():.2f}, " f"day +{grow * p_early[day].mean():.2f} m3/h")
# ---------- Part 2: data set B, the typical week ----------d, temp, weekday, energy = building_daily()dow = d % 7names = ("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")print("Building: weekly pattern (kWh a day)")print(f" mean of all 730 days: {energy.mean():.1f}, " f"standard deviation {energy.std(ddof=1):.1f}")print(f" weekdays {int(weekday.sum())}, weekend days {int((~weekday).sum())}")print(f" weekday mean {energy[weekday].mean():.1f}, weekend mean " f"{energy[~weekday].mean():.1f}, difference " f"{energy[weekday].mean() - energy[~weekday].mean():.1f}")print(" by day of week: " + " ".join( f"{names[k]} {energy[dow == k].mean():.1f}" for k in range(7)))
trend = centred_average(energy, 7)print(f" first 7 days: " + " ".join(f"{v:.1f}" for v in energy[:7]))print(f" trend on day 3: {trend[3]:.1f}; days with no trend value: " f"{int(np.isnan(trend).sum())}")detrended = energy - trendseasonal = np.array([np.nanmean(detrended[dow == k]) for k in range(7)])seasonal -= seasonal.mean() # make the seven values sum to zeroprint(" seasonal component: " + " ".join( f"{names[k]} {seasonal[k]:+.1f}" for k in range(7)))step = seasonal[:5].mean() - seasonal[5:].mean()print(f" weekday minus weekend from the seasonal component: {step:.1f}")remainder = energy - trend - seasonal[dow]print(f" day 3: measured {energy[3]:.1f} = trend {trend[3]:.1f} " f"+ seasonal {seasonal[3]:+.1f} + remainder {remainder[3]:+.1f}")print(f" remainder standard deviation: {np.nanstd(remainder, ddof=1):.1f}")print(f" trend: highest {np.nanmax(trend):.0f} on day {np.nanargmax(trend)}, " f"lowest {np.nanmin(trend):.0f} on day {np.nanargmin(trend)}")for a, b in ((0, 500), (500, 730)): e, w = energy[a:b], weekday[a:b] print(f" days {a} to {b - 1}: weekday minus weekend " f"{e[w].mean() - e[~w].mean():.1f}")print(f" a 365-day centred average would have no value on " f"{int(np.isnan(centred_average(energy, 365)).sum())} of 730 days")
# ---------- Plot ----------fig, ax = plt.subplots(2, 1, figsize=(8, 7))hours = np.arange(24)ax[0].fill_between(hours, lo, hi, step="mid", alpha=0.25, label="days 0 to 34, 10th to 90th percentile")ax[0].step(hours, p_early, where="mid", label="days 0 to 34, mean")ax[0].step(hours, p_late, where="mid", label="days 35 to 59, mean")ax[0].set_xlabel("hour of day")ax[0].set_ylabel("flow (m3/h)")ax[0].set_title("Borehole: typical day")ax[0].legend()ax[1].plot(d, energy, linewidth=0.6, label="daily energy")ax[1].plot(d, trend, linewidth=1.6, label="centred 7-day average")ax[1].set_xlabel("day")ax[1].set_ylabel("energy (kWh a day)")ax[1].set_title("Building: daily energy and its trend")ax[1].legend()fig.tight_layout()fig.savefig("profiles_and_weekly_pattern.png", dpi=120)print("Saved profiles_and_weekly_pattern.png")Expected output
Borehole: typical day (m3/h) hour days 0-34 p10 p90 days 35-59 difference 0 0.58 0.48 0.67 1.49 0.91 1 0.59 0.51 0.68 1.50 0.91 2 0.59 0.51 0.70 1.50 0.90 3 0.59 0.47 0.68 1.50 0.91 4 0.60 0.52 0.67 1.51 0.92 5 0.61 0.51 0.72 1.53 0.91 6 4.47 3.85 5.20 5.57 1.10 7 4.49 3.66 5.23 5.38 0.90 8 4.73 4.22 5.25 5.58 0.85 9 4.49 3.88 5.44 5.56 1.07 10 4.52 3.84 5.26 5.34 0.82 11 4.60 3.83 5.21 5.52 0.92 12 4.46 3.70 5.14 5.42 0.97 13 4.69 3.94 5.30 5.71 1.01 14 4.46 3.74 5.07 5.47 1.01 15 4.47 3.77 5.05 5.28 0.81 16 4.61 4.01 5.19 5.39 0.78 17 4.54 3.83 4.96 5.36 0.81 18 4.53 3.93 5.09 5.55 1.01 19 4.68 4.05 5.29 5.48 0.80 20 4.48 3.98 5.21 5.51 1.03 21 4.53 3.87 5.38 5.45 0.92 22 0.62 0.52 0.70 1.49 0.87 23 0.62 0.54 0.68 1.48 0.86 difference: mean 0.917, smallest 0.78, largest 1.10 difference: night hours 0.899, day hours 0.926 base flow: 0.58 at hour 0, then 1.48 at hour 23 peak flow: 4.73 at hour 8, then 5.71 at hour 13 hour 2: one reading varies by 0.07 (standard deviation), standard error of the difference 0.02 hour 12: one reading varies by 0.59 (standard deviation), standard error of the difference 0.16 daily volume: 77.6 m3, then 99.6 m3, rise 22.0 m3 (28.4 %) if use had grown 28.4 %: night +0.17, day +1.29 m3/hBuilding: weekly pattern (kWh a day) mean of all 730 days: 559.2, standard deviation 159.4 weekdays 522, weekend days 208 weekday mean 609.9, weekend mean 431.9, difference 177.9 by day of week: Mon 598.9 Tue 622.4 Wed 616.3 Thu 610.0 Fri 601.6 Sat 434.2 Sun 429.6 first 7 days: 549.3 579.3 559.7 538.8 568.2 347.3 446.1 trend on day 3: 512.7; days with no trend value: 6 seasonal component: Mon +41.1 Tue +64.5 Wed +56.6 Thu +50.4 Fri +42.2 Sat -125.0 Sun -129.9 weekday minus weekend from the seasonal component: 178.4 day 3: measured 538.8 = trend 512.7 + seasonal +50.4 + remainder -24.4 remainder standard deviation: 56.4 trend: highest 816 on day 466, lowest 367 on day 627 days 0 to 499: weekday minus weekend 184.7 days 500 to 729: weekday minus weekend 162.1 a 365-day centred average would have no value on 364 of 730 daysSaved profiles_and_weekly_pattern.pngIn the upper plot the second profile sits above the first by the same distance at night and by day. In the lower plot the trend line stops 3 days before each end of the record.
1. A site’s flow profile is 0.4 m³/h for the 8 night hours and 3.0 m³/h for the 16 day hours. Find the daily volume, the base flow, and the share of the daily volume that the base flow accounts for if it runs for all 24 hours.
Daily volume:
2. A month later the profile of the same site is 1.0 m³/h at night and 3.6 m³/h by day. Is this a leak or extra use, and how much water is it a day? What would the profile have been if use had grown by 20 percent instead?
The difference is 0.6 m³/h at night and 0.6 m³/h by day: a constant addition, so a leak, of
3. Daily energy for days 0 to 8 is 520, 540, 530, 550, 525, 350, 340, 535 and 545 kWh. Calculate the centred 7-day moving average for days 3, 4 and 5. For a record of 60 days, on how many days does a centred 7-day average have no value, and a centred 31-day average?
Day 3:
4. After the trend is removed, the mean deviations by day of week are
The seven values sum to
5. A building uses a mean of 610 kWh on weekdays and 432 kWh on weekend days, and nothing about it changes. Find the mean daily energy of a month with 23 weekdays and 8 weekend days, and of a month with 20 weekdays and 8 weekend days. What does the difference show?
First month:
A borehole pumps 28 percent more water this month. Either more people use it, or a pipe is broken. Which single number tells the two apart best?
The dotted line is the typical day of the borehole for days 0 to 34 (Application 1). The solid line is a typical day after a change: a constant leak added to every hour, a growth that multiplies every hour, or both; or the measured days 35 to 59. The bars are the difference at each hour. Both causes can raise the daily volume by the same 22 m³; only the shape of the bars tells them apart.
Three questions. Each wrong choice is a mistake people really make, so read the note after you answer.
1. Two months of a pumped supply are compared hour by hour. The night flow rose from 0.60 to 0.72 m³/h and the day flow from 4.5 to 5.4 m³/h. What is the most likely cause?
2. A dashboard draws a 7-day trailing average of daily energy (each day and the six before it). The average turns down on day 50. About when did the building's use really turn?
3. The building of Application 2 uses 609.9 kWh on a weekday and 431.9 kWh on a weekend day, in both months. Month A has 23 weekdays and 8 weekend days; month B has 20 weekdays and 10 weekend days. The mean of all days falls from 564.0 to 550.6 kWh. What do you report?
No comments yet. Questions, results from your own build, a better way to explain it: all welcome.
Kept on this device only. Nothing is sent anywhere.
Tip: select words in the lesson, or tap a figure or an equation, to put a note right there.
The lesson has changed and these words are no longer in it. Your notes are kept, with the words you chose.