"""Regenerate the two source-based SVGs; optional authoring dependency: Matplotlib."""
import json,datetime
from pathlib import Path
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import matplotlib.dates as md
import numpy as np
r=Path(__file__).resolve().parent;j=json.loads((r/'inputs.json').read_text());rows=j['ndom']['rows'];x=[datetime.datetime.fromisoformat(a['date']) for a in rows]
plt.rcParams['svg.hashsalt']='e2-fervo-2026-10-06'
plt.rcParams.update({'svg.fonttype':'none','font.family':'DejaVu Sans','font.size':14,'text.color':'#F3F2EC','axes.labelcolor':'#9A9A96','xtick.color':'#9A9A96','ytick.color':'#9A9A96','axes.edgecolor':'#4a4a46','axes.facecolor':'none','figure.facecolor':'none'})
def save(name,y,label,ylim):
 fig,ax=plt.subplots(figsize=(6.4,3.6));ax.plot(x,y,color='#F3F2EC',lw=1,marker='o',markersize=3);ax.set_ylabel(label);ax.set_ylim(*ylim);ax.xaxis.set_major_locator(md.MonthLocator(interval=6));ax.xaxis.set_major_formatter(md.DateFormatter('%b %Y'));ax.grid(axis='y',color='#F3F2EC',alpha=.14,lw=.5);ax.spines[['right','top']].set_visible(False);fig.tight_layout();fig.savefig(r/name,format='svg',transparent=True,metadata={'Date':'2026-10-06','Creator':'E²; frozen source inputs in inputs.json'});plt.close(fig)
 (r/name).write_text('\n'.join(line.rstrip() for line in (r/name).read_text().splitlines())+'\n')
save('temperature.svg',[a['tempF'] if a['productionGal']>0 else np.nan for a in rows],'Reported monthly temperature (°F)',(100,365))
save('water.svg',[100*(a['injectionGal']-a['productionGal'])/a['injectionGal'] if a['injectionGal'] else np.nan for a in rows],'Injection–production imbalance (%)',(-40,80))
print('Generated two SVG figures from preserved monthly entries')
