Skip to content

Commit 4c5d773

Browse files
bgeurtenclaude
andcommitted
feat(stats_temporal): add barn-temperature columns to thi_daily_profile
Extend compute_thi_daily_profile to also compute mean / SD / Q25 / Q75 of barn temperature per (year, month, hour), alongside the existing THI statistics, plus the herd median barn-temperature breakpoint as a reference line. Output CSV gains temp_mean / temp_std / temp_q25 / temp_q75 / herd_median_temp_bp columns. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 545f2d3 commit 4c5d773

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

src/digimuh/stats_temporal.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ def compute_thi_daily_profile(
241241
thi_conv = bs_results[bs_results["thi_converged"] == True]
242242
herd_median_bp = thi_conv["thi_breakpoint"].median() if not thi_conv.empty else np.nan
243243

244+
# Herd median barn-temperature breakpoint (separate predictor).
245+
temp_conv = bs_results[bs_results["temp_converged"] == True]
246+
herd_median_temp_bp = (temp_conv["temp_breakpoint"].median()
247+
if not temp_conv.empty else np.nan)
248+
244249
records = []
245250
for (year, month), grp in rumen.groupby(["year", "month"]):
246251
if int(month) not in month_names:
@@ -251,12 +256,17 @@ def compute_thi_daily_profile(
251256
"month": int(month),
252257
"month_label": f"{month_names[int(month)]} {int(year)}",
253258
"hour": int(hour),
254-
"thi_mean": hdata["barn_thi"].mean(),
255-
"thi_std": hdata["barn_thi"].std(),
256-
"thi_q25": hdata["barn_thi"].quantile(0.25),
257-
"thi_q75": hdata["barn_thi"].quantile(0.75),
259+
"thi_mean": hdata["barn_thi"].mean(),
260+
"thi_std": hdata["barn_thi"].std(),
261+
"thi_q25": hdata["barn_thi"].quantile(0.25),
262+
"thi_q75": hdata["barn_thi"].quantile(0.75),
263+
"temp_mean": hdata["barn_temp"].mean(),
264+
"temp_std": hdata["barn_temp"].std(),
265+
"temp_q25": hdata["barn_temp"].quantile(0.25),
266+
"temp_q75": hdata["barn_temp"].quantile(0.75),
258267
"n_readings": len(hdata),
259268
"herd_median_bp": herd_median_bp,
269+
"herd_median_temp_bp": herd_median_temp_bp,
260270
})
261271

262272
return pd.DataFrame(records)

0 commit comments

Comments
 (0)