codex/nail-clipping-temporal-window.py

nail-clipping-temporal-window.py
"""Original constant-speed, uniform-mass clipping model.

Python 3.14; dependencies are NumPy and Matplotlib in root pyproject.toml.
Run in the output directory to write a white PNG to cwd.
"""
from pathlib import Path
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt

t = np.linspace(0,100,2001)
pulse = ((t>=40)&(t<=45)).astype(float)
overlap = np.maximum(0,np.minimum(t,45)-np.maximum(t-30,40))
average = overlap/30
fig, ax = plt.subplots(figsize=(8,3.5),dpi=120)
fig.patch.set_facecolor('white'); ax.set_facecolor('white')
ax.plot(t,pulse,color='#3e6fa1',label='Five-day retained-concentration input',lw=2)
ax.plot(t,average,color='#b45425',label='30-day clipping average',lw=2)
ax.axvspan(30,60,color='#b45425',alpha=.07,label='Material-time window at collection day 60')
ax.plot([60],[1/6],'o',color='#b45425',ms=5)
ax.annotate('Peak average = 1/6 of input peak',xy=(60,1/6),xytext=(53,.47),
            arrowprops={'arrowstyle':'->','color':'#555555'},fontsize=10)
ax.set(xlim=(0,100),ylim=(-.025,1.08),xlabel='Reference-crossing / collection time (days)',
       ylabel='Concentration / input peak',title='A short material input becomes a broad clipping average')
ax.grid(alpha=.15);ax.legend(fontsize=8,loc='upper right')
fig.tight_layout();fig.savefig(Path.cwd()/'nail-clipping-temporal-window.png',facecolor='white')
plt.close(fig)