Source code for energy_methods.wildlife_curtailment

"""Offline screening of wind-energy loss versus a *proxy* for wildlife exposure.

The proxy is bird/bat activity-index hours while the rotor would operate.
It is not collision probability or avoided mortality. Within each time step,
partial shutdown represents a fraction of the interval spent stopped.
"""

from __future__ import annotations

import math
from collections.abc import Sequence
from dataclasses import dataclass


[docs] @dataclass(frozen=True, slots=True) class WildlifeCurtailmentScreen: """Energy in MWh; exposure in arbitrary activity-index hours.""" baseline_energy_mwh: float delivered_energy_mwh: float curtailed_energy_mwh: float exposure_before_index_hours: float exposure_after_index_hours: float proxy_reduction_fraction: float
def _validated_profiles( power_mw: Sequence[float], activity_index: Sequence[float], timestep_hours: float ) -> tuple[tuple[float, ...], tuple[float, ...]]: if not power_mw or len(power_mw) != len(activity_index): raise ValueError("Nonempty power and activity profiles must have matching lengths") if not math.isfinite(timestep_hours) or timestep_hours <= 0: raise ValueError("timestep_hours must be finite and positive") if any(not math.isfinite(x) or x < 0 for x in (*power_mw, *activity_index)): raise ValueError("All power and activity values must be finite and nonnegative") return tuple(power_mw), tuple(activity_index)
[docs] def screen_wildlife_curtailment( power_mw: Sequence[float], activity_index: Sequence[float], shutdown_fraction: Sequence[float], *, timestep_hours: float = 1.0, ) -> WildlifeCurtailmentScreen: """Account for wind output and activity-weighted rotor-operating time. This *linear* risk proxy is an illustrative screening assumption, not a validated link between radar activity and wildlife collisions. If the baseline wind power is zero, the model assumes the rotor is not operating. """ power, activity = _validated_profiles(power_mw, activity_index, timestep_hours) if len(shutdown_fraction) != len(power): raise ValueError("Shutdown schedule must match input profile length") if any(not math.isfinite(x) or not 0 <= x <= 1 for x in shutdown_fraction): raise ValueError("Shutdown fractions must be finite and between zero and one") energy_before = sum(p * timestep_hours for p in power) energy_lost = sum(p * f * timestep_hours for p, f in zip(power, shutdown_fraction, strict=True)) # Only potentially rotating intervals receive exposure weight. before = sum(a * timestep_hours for p, a in zip(power, activity, strict=True) if p > 0) after = sum( a * (1 - f) * timestep_hours for p, a, f in zip(power, activity, shutdown_fraction, strict=True) if p > 0 ) return WildlifeCurtailmentScreen( baseline_energy_mwh=energy_before, delivered_energy_mwh=energy_before - energy_lost, curtailed_energy_mwh=energy_lost, exposure_before_index_hours=before, exposure_after_index_hours=after, proxy_reduction_fraction=(1 - after / before) if before else 0.0, )
[docs] def min_energy_loss_schedule( power_mw: Sequence[float], activity_index: Sequence[float], target_proxy_reduction: float, *, timestep_hours: float = 1.0, ) -> tuple[float, ...]: """Minimize energy lost for a target activity-exposure proxy reduction. Solves a *continuous*, linear fractional-knapsack problem: rank positive power/activity intervals by incremental MWh per index-hour and curtail cheapest first. Fractional interval shutdown is allowed; this does not optimize binary turbine stops or real ecological safety constraints. """ power, activity = _validated_profiles(power_mw, activity_index, timestep_hours) if not math.isfinite(target_proxy_reduction) or not 0 <= target_proxy_reduction <= 1: raise ValueError("target_proxy_reduction must be finite and in [0, 1]") exposure = sum(a * timestep_hours for p, a in zip(power, activity, strict=True) if p > 0) remaining = target_proxy_reduction * exposure schedule = [0.0] * len(power) candidates = sorted( (i for i, (p, a) in enumerate(zip(power, activity, strict=True)) if p > 0 and a > 0), key=lambda i: (power[i] / activity[i], i), ) for i in candidates: if remaining <= 0: break weight = activity[i] * timestep_hours fraction = min(1.0, remaining / weight) schedule[i] = fraction remaining = max(0.0, remaining - fraction * weight) return tuple(schedule)