L1 L2 Dry Cull THI 68 Feed N Manure Leach
← Research Projects
Project 06 Agricultural Science Simulation Modeling

UW–Madison Dairy Herd Simulation
and Decision-Support Tools

Working with Prof. Victor Cabrera's lab to document, modernize, and extend three dairy farm decision-support tools — producing tutorial videos for two web tools and diagnosing and rebuilding a broken whole-farm simulation model that has been inaccessible on modern computers since 2016.

Supervisor Prof. Victor Cabrera, UW–Madison
Collaborator Anish Gogineni, UW–Madison
Status Active
Tools Website dairymgt.cals.wisc.edu
AMS Transition Budgeter Video completed · Published

Evaluates the financial return of switching from conventional milking to automatic milking robots. Partial-budget + 15-year cash flow projections.

Heat Abatement Investment Scouter Video completed · Published

Uses location-specific THI climate data to estimate milk losses from heat stress and calculate payback period on cooling infrastructure.

DyNoFlo — Dynamic Dairy Farm Model Repair in progress

Integrated whole-farm Markov-chain simulation with nitrogen tracking, DSSAT crop models, and LP optimization. Broken on modern Excel — rebuild underway.

Plain-English Summary

Running a profitable dairy farm means making hundreds of interconnected decisions every day — how many cows to milk, when to replace aging animals, how much feed to buy, how to handle manure, and how heat waves will affect production. Prof. Victor Cabrera's lab at UW–Madison has built free web-based tools that let farmers and agricultural advisors model these decisions mathematically and see the financial consequences before committing real money.

This project has two tracks. The first is making those tools more accessible: scripting and producing tutorial videos so dairy producers across the country can actually use them. The second is engineering: a powerful whole-farm simulation has been sitting broken on modern computers since 2016, and this project is diagnosing and rebuilding it.

Should a dairy farm switch to robotic milking?

Milking robots cost roughly $200,000 each — one of the biggest capital decisions a dairy farm can make. The AMS Transition Budgeter helps farmers think through whether that investment makes financial sense for their specific operation. Enter your herd size, current milk price, labor costs, and loan terms, and the tool projects your cash flow over 15 years — showing not just whether the robots pay off, but exactly when.

Key Inputs and Outputs

Web tool · Live
Farm Baseline

How many cows, how much milk each produces, the price you receive, how many hours milking takes, and what you pay your labor. Pre-loaded with industry averages you can overwrite.

Investment & Specs

How many robots, what they cost, barn modification costs, loan terms, and ongoing labor per robot. Defaults reflect typical industry figures.

Operational Impacts

Robots typically increase yield ~5% because cows can be milked more frequently. They also require a special feed pellet and annual maintenance — all adjustable with sliders.

Key Outputs

Annual profit after debt service, hours of labor eliminated, the wage rate at which robots break even, a 15-year cash flow curve, and a chart showing which assumptions matter most.

The most useful output: Breakeven Wage

This tells you the minimum hourly wage at which robots become worth it. If you're already paying more than that, the investment pays off. The tool also shows which inputs — milk price, labor rate, robot cost — swing the outcome most, so you know where your assumptions matter.

Sanjay wrote the full walkthrough script, recorded the live tool, generated AI voiceover, and edited the final video. It's published on YouTube and linked on the lab's tools page at dairymgt.cals.wisc.edu.

Does cooling equipment pay for itself?

Dairy cows start losing milk production when it gets hot and humid — and in much of the U.S., that happens for weeks or months every summer. The Heat Abatement Investment Scouter uses 10 years of climate data for any U.S. location to estimate how much milk a farm is losing to heat stress each year, then calculates whether installing cooling equipment (fans and soakers) would pay for itself.

Methodology and Key Outputs

Web tool · Live
THI Calculation

Pulls 10-year average temperature and humidity for your location and calculates how many hours per year fall into mild, moderate, and severe heat stress zones.

Milk Loss Model

Translates heat stress hours into lost milk production using established research, applied to your herd size and average yield.

Investment Analysis

Enter cooling system cost, loan terms, and electricity/water operating expenses. The tool computes payback period and 5-year return on investment.

2030 Projection

Shows projected heat stress hours in 2030 so producers can factor a warming climate into their long-term investment decision.

Sanjay wrote the script, recorded the video, then reshot it after the tool was updated to match a revised methodology. The final version is published on YouTube and linked on the lab's tools page.

A whole-farm dairy simulation — and an engineering problem

DyNoFlo is Prof. Cabrera's most ambitious tool — a whole-farm simulator built in Excel that tracks everything at once: the herd's milk production, what the cows eat, how manure moves through the farm, how crops grow, and whether it all makes money. Its central question: can a dairy farm reduce the nitrogen that leaches from manure into groundwater, without sacrificing profit? And does the answer change depending on whether it's an El Niño year?

Six Integrated Model Components

Markov + DSSAT + LP
Markov-Chain Herd Model

Tracks every cow group by stage of lactation and pregnancy — computing monthly milk output, feed consumption, and manure nitrogen produced.

DSSAT Crop System

Models how different crops (grasses, corn, sorghum) grow on each field under different soil types and rainfall conditions — providing the feed and land-use side of the farm equation.

Nitrogen Tracking

Follows nitrogen from the barn through every step — storage pond, sludge, land application — tracking how much leaches into groundwater versus stays in the soil.

ENSO Climate Module

Assigns each simulated year an El Niño, La Niña, or neutral weather pattern. Wetter El Niño winters drive far more nitrogen leaching — January alone can account for 30–40% of the annual total.

Economic Analysis

Calculates monthly and annual profit from milk revenue, animal sales, and all major expense categories. In a published case study, the optimized management plan cut nitrogen leaching 25% while raising profit 3%.

LP Optimizer

Finds the management strategy that maximizes profit while keeping nitrogen below a set limit — or vice versa. Run separately for each climate pattern so recommendations adapt to the forecast.

The compatibility problem

All of DyNoFlo's data, formulas, charts, and outputs are perfectly intact. The problem is the interactive layer — the buttons that run the simulation, switch between scenarios, and trigger the optimizer. These are powered by Visual Basic macros (VBA) that were written for Excel in 2004, and they simply don't work on any version of Excel released since 2003.

Two compounding failures
1
A discontinued Microsoft component blocks everything. The code depends on a Microsoft add-on called OWC10 that was discontinued after Office 2003. Modern Excel also requires a security keyword (PtrSafe) that the original code doesn't have. Together these cause a compile failure that prevents any macro from running — and, critically, prevents saving any changes. It's a catch-22: the broken state prevents the fix.
2
Missing companion files. DyNoFlo was originally distributed as a package of linked Excel files containing pre-computed crop data. Without those companion files in exactly the right folder path, the simulation runs for about 3 years then stops with an error.

Three repair pathways

01 Reinstall the missing component on an older machine. The original OWC10 component is still available as a free download. Installing it on a 32-bit version of Excel may allow the broken references to be cleaned up — though this approach requires finding a machine still running old Office software.
02 Fix using an old Office installation. On a machine still running Office 2003 or 2007, the broken component references can be unchecked, old interface elements removed, and a clean replacement macro file imported. The result can then be saved and tested on modern Excel.
03 Full rebuild from scratch. Copy all the data and formulas into a brand-new Excel file, rewrite the macro code from scratch in modern VBA, and embed the crop companion data directly so no external files are needed. The most work — but the most portable, future-proof result.

Importantly, the simulation logic itself requires no changes — only the interactive shell around it is broken. Once access to the underlying code is unlocked (which requires a project password from Prof. Cabrera), the actual fix is straightforward.

Tutorial videos for the lab's tool suite

Prof. Cabrera's tools are powerful, but only useful if people know how to use them. Each video walks through the tool from start to finish — what to enter, what the outputs mean, and how to read the results. Sanjay wrote the script, recorded the screen, generated voiceover, and edited the final video for each one.

AMS Transition Budgeter
Script written · Video recorded and edited · Published to YouTube · Linked on lab tools page
Published
Heat Abatement Investment Scouter
Script written · Video recorded · Reshot after tool update with revised script · Published to YouTube
Published
DyNoFlo Dynamic Dairy Farm Model
Script written · Video pending tool repair — interactive simulation must function before screen-recording
Pending repair

What the model reveals about dairy nitrogen management

  • El Niño winters drive the most nitrogen leaching — wetter, cooler conditions increase water percolation and reduce plant nitrogen uptake. La Niña years show the opposite.
  • January alone accounts for 30–40% of total annual nitrogen leaching in the case study farm, making winter management the highest-leverage intervention window.
  • Sandy, shallow soils leach dramatically more nitrogen than more retentive soils under identical management — soil type selection and site matching are critical.
  • The most effective levers for reducing leaching without sacrificing profit: lowering dietary crude protein, planting bermudagrass in pastures and sprayfields, and strip-planting corn into bermudagrass sod.
  • Climate-adaptive management matters: optimizer recommendations differ by ENSO phase. When El Niño is forecast, additional strategies include voluntary culling, exporting manure off-farm, or renting additional pasture.
  • In the published 400-cow case study, optimization reduced nitrogen leaching by 25% while increasing profit by 3%. Feasible adjustments (a practical subset) still achieved 23% leaching reduction with 2.5% profit gain.
← Project 05: Ground-Level NO₂ Predictions