Skip to content

Documentation: Berlin Calendar and Weather Features

This module provides deterministic calendar, public-holiday, school-holiday, bridge-day, and weather features for Berlin.

Purpose

Use build_calendar_weather_dataframe() to generate a daily dataset containing:

  • Berlin calendar features
  • Public and school holiday indicators
  • Bridge-day indicators
  • Seasonal and weather covariates
df = build_calendar_weather_dataframe(
    start=date(2026, 12, 1),
    days=31,
    seed=42,
)

The same input parameters produce the same weather result, making forecasts reproducible.


Berlin School Holidays

_BERLIN_SCHOOL_HOLIDAYS_BY_YEAR contains official or KMK-aligned Berlin school holiday periods for 2022–2028.

Each period is represented as:

(period_name, start_date, end_date)

Supported period names:

  • christmas
  • winter
  • easter
  • summer
  • autumn

_first_monday_on_or_after()

Returns the first Monday on or after an anchor date.

_first_monday_on_or_after(date(2026, 1, 30))

This is primarily used when generating fallback holiday dates.

get_berlin_school_holiday_periods(year)

Returns the school holiday periods for a year.

  • For 2022–2028, it uses the explicit schedule table.
  • For other years, it calculates a deterministic fallback schedule using Easter and calendar-date rules.

The function is cached, so repeated requests for the same year reuse the result.

get_school_holiday_type(target_date)

Returns the holiday period containing a date:

get_school_holiday_type(date(2026, 7, 15))
# "summer"

Returns None when the date is not in a school holiday period.

is_berlin_school_holiday(target_date)

Returns True when a date is inside a Berlin school holiday period.


Public Holidays

get_berlin_public_holidays(year)

Returns public holidays for Berlin using:

holidays.country_holidays("DE", subdiv="BE")

It includes the requested year and neighboring years to ensure reliable boundary handling around year transitions.

The result is cached by year.

is_berlin_public_holiday(target_date)

Checks whether a date is an official Berlin public holiday.


Bridge Days

A Brückentag is a regular Monday–Friday workday located between:

  • Two non-working days, or
  • A non-working day and a weekend

For example:

  • Friday after a Thursday public holiday
  • Monday before a Tuesday public holiday

_is_non_working_day()

Returns True if a date is:

  • Saturday or Sunday, or
  • A Berlin public holiday

is_berlin_bridge_day(target_date)

Returns True if the date:

  • Is a weekday
  • Is not a public holiday
  • Has a non-working day immediately before and after it

Calendar Features

CalendarFeatures

Pydantic model containing all daily Berlin calendar features:

Field Description
date Calendar date
weekday Python weekday, from 0 (Monday) to 6 (Sunday)
is_weekend Whether the date is Saturday or Sunday
is_public_holiday Whether the date is a public holiday
public_holiday_name Holiday name, if applicable
is_school_holiday Whether the date is in a school holiday period
school_holiday_type Holiday period name, if applicable
is_bridge_day Whether the date is a German bridge day
day_of_year 1–365 or 1–366
doy_sin Seasonal sine encoding
doy_cos Seasonal cosine encoding

The sine and cosine fields encode the date cyclically, allowing models to understand that December and January are close together.

extract_calendar_features(target_date)

Creates a CalendarFeatures instance for one date.

Example:

features = extract_calendar_features(date(2026, 12, 25))

features.is_public_holiday
features.is_weekend
features.public_holiday_name
features.doy_sin

Daylight

berlin_daylight_hours(target_date)

Approximates astronomical daylight hours for Berlin at 52.52°N.

The approximation:

  • Peaks at roughly 16.8 hours
  • Reaches a minimum of roughly 7.5 hours
  • Returns 14 hours when no date is provided

Generated weather uses this value to limit the available sunshine hours.


Weather Data Model

_derive_apparent_temp_c()

Calculates an apparent or feels-like temperature from:

  • Ambient temperature
  • Precipitation
  • Cloud coverage
  • Sunshine

The calculation applies:

  • A positive bonus for sustained sunshine
  • A heat bonus during very warm periods
  • Rain and cloud cooling
  • Additional winter wind-chill effects

WeatherDay

Pydantic model representing one coherent daily weather record.

Field Constraints
temperature_c −25°C to 45°C
apparent_temperature_c −30°C to 50°C
precipitation_mm 0 or greater
cloud_fraction 0.0 to 1.0
sunshine_hours 0 to 18 hours
date Optional date

Derived fields

The model can automatically derive omitted fields:

  • cloud_fraction is inferred from precipitation
  • sunshine_hours is derived from daylight, clouds, and rain
  • apparent_temperature_c is calculated from the other weather conditions

Explicit values are preserved and rounded where appropriate.


Weather Generation

generate_berlin_weather_series(start, days, seed)

Generates a smooth daily Berlin weather series using two autocorrelated processes:

  • Temperature anomalies
  • Moisture or wetness anomalies

The generator includes:

  • Seasonal temperature variation
  • Persistent weather regimes
  • Winter stratus clouds
  • Summer heatwaves
  • Rain spells
  • Summer thunderstorms
  • Coherent cloud, rain, and sunshine values

Temperature model

Temperature is based on a seasonal mean:

  • Around 3.5°C in mid-January
  • Around 25.5°C in late July
  • Usually fluctuates within 38°C and −10°C

Rain model

Rain is generally more likely in moist regimes:

if z_wet > 0.25:
    generate_precipitation()
elif hot_and_cloudy_with_chance:
    generate_thunderstorm()

Determinism

The same values for:

start
days
seed

always produce the same weather sequence.

Example:

weather = generate_berlin_weather_series(
    start=date(2026, 7, 1),
    days=7,
    seed=42,
)

for day in weather:
    print(day.date, day.temperature_c, day.precipitation_mm)

Weather Scenarios

_WEATHER_SCENARIO_PRESETS

Available named scenarios:

Preset Typical use
heatwave Extreme warm, dry, sunny conditions
summer_saturday_34c Hot Saturday-style scenario
mild_summer Mild summer conditions
rainy_spell Cool, wet, heavily overcast conditions
cold_winter Cold winter conditions

make_weather_scenario(...)

Creates a deterministic WeatherDay override.

A scenario can use a preset:

weather = make_weather_scenario(
    date(2026, 7, 18),
    preset="heatwave",
)

It can also override individual values:

weather = make_weather_scenario(
    date(2026, 7, 18),
    temperature_c=32.0,
    precipitation_mm=2.5,
)

When custom temperature or sky values are supplied without a preset, omitted derived fields are recalculated.

resolve_weather_override(...)

Normalizes several override formats into a WeatherDay.

Supported inputs:

  • None: generate a deterministic baseline
  • WeatherDay: use directly or update its date
  • Preset name: "heatwave"
  • Dictionary:
{
    "preset": "rainy_spell",
    "temperature_c": 18.0,
}

Unsupported types raise TypeError.


Combined DataFrame

build_calendar_weather_dataframe(start, days, seed)

Generates one row per date and combines calendar and weather features.

Output columns include:

date
weekday
is_weekend
is_public_holiday
public_holiday_name
is_school_holiday
school_holiday_type
is_bridge_day
day_of_year
doy_sin
doy_cos
temperature_c
apparent_temperature_c
precipitation_mm
cloud_fraction
sunshine_hours

Example:

df = build_calendar_weather_dataframe(
    start=date(2026, 1, 1),
    days=365,
    seed=42,
)

df.head()
df.groupby("is_public_holiday")["temperature_c"].mean()
df[df["is_bridge_day"]]

An empty DataFrame is effectively returned for days <= 0 because weather generation produces no rows.