Cubic Splines and the Lost Art of Roast Planning

2023-10-07

Lately I've noticed a trend in coffee roasting discussions where it's increasingly common that someone is trying to approach the roast in a way that's a bit outside their comfort zone, show what they consider a failed attempt at some idea, and then ask what they're doing wrong. The first step in diagnosing an issue like that is comparing that failed attempt with a concrete plan. A visual comparison of the plan together with the roasting data often makes it obvious what went wrong and having that plan before roasting makes it much easier to avoid the mistake in the first place. So why has the idea of having a plan become such an alien concept? In this case, I think it's fair to blame the tools roasters are working with.

When I first started roasting coffee, it was clear that profile roasting wasn't just a fad and there was real value in having precise process data and controls that allow people to reliably replicate past results not just for a single style of roasting, but with variations on plans aimed at getting desired results in the cup that may vary from one coffee to the next. It's a change from the passive vision of roasters as mere machine operators with a responsibility to not mess up the hard work of the people who produced our raw materials toward a view of roasting as a valuable craft in which people can actively choose the right balance across a range of potentially delicious outcomes, from which on any batch we can pick only one.

Automated profiling systems did already exist by then, but the few options available were generally tied to machines from a single manufacturer and failed to live up its potential. The technology was also expensive, which made it more common at huge mass market companies. It would be rare to see this on a small shop roaster. This meant that the vast majority of people doing profile roasting were recording data by hand and working from plans on paper.

Roasting plans and batch data are basically the same thing and it can be just writing some numbers on paper. If this is how you work, it's easy to have the idea of writing down what you'd like your numbers to be and there are no technological hurdles in the way of just doing that.

That said, there are huge advantages to connecting a computer to a coffee roaster and automating at least the data collection. After I wrote Typica, the number of options for profiling software exploded, the cost of hardware dropped, and most of these newer options could be connected to a wide range of machines from most manufacturers. There's no reason people using these systems can't print a table of data to paper and keep a paper system available. Failing to do that means any of a large number of technological problems can unnecessarily shut down your production, but these sorts of events should be rare and it's easy to get away with ignoring those possibilities. The technology is good enough and cheap enough that it's hard to imagine most roasters switching back to paper for enough of their work that hand crafting a roasting plan returns to being a normal and expected skill.

Profiling software is generally great at helping people replicate their past success, but when it comes to editing that data or creating synthetic data to use as a plan, many of the options are not great.

There are two core problems. First, logging software just collects too much data for this use case. Depending on hardware sampling rates and the overall duration of the roast, you could easily have thousands of data points for each batch. That's nothing for a computer, but for humans looking to make their own decisions, it would be better to keep the number of points we need to a minimum. Fewer than 10 is a good target to shoot for.

Second, when simpler mathematical models are chosen rather than working from real data, developers have generally chosen to apply entirely the wrong kinds of math, resulting in systems that lack expressive power, have excessively high learning curves, or produce plans that are physically impossible to replicate with real world coffee.

The easiest math to use for roast planning is the linear spline. That's just a fancy way of saying that we pick out a few points we want the profile to pass through and then connect the dots, resulting in a few line segments where each shares an end point with adjacent segments. This isn't a bad choice. It's easy to work out by hand, you get a desired average rate of change directly from the slope of each segment. It's similarly easy to see the durations of key ranges. The main problem is these can't be replicated as the rate of change has a discontinuity every time the roast progresses between segments with different rates. That means a decision is needed on how to deviate from the plan.

Bézier splines are another choice. They solve the discontinuity problem and are easy for programmers to put into a profiling system since they're implemented in many of the graphics libraries a profiling system might use, but these advantages come with the sacrifice of everything that's good about linear splines. The points used to control the shape of the curve are notoriously unintuitive and while it's possible to get a system like this to generate whatever plan you want, it's likely to be a frustrating experience with far too much fussing with dots on a screen.

Moving even farther from reasoning around events, some use other mathematical constructs such as logarithm based formulae. These tend to lack the ability to express many common approaches to coffee roasting. The lighter you roast, the more usable something like this is, but the limitations that tend to be found in these systems are overly restrictive.

With options like these, is it any wonder that so many people choose not to bother with roast planning at all?

Relaxed cubic splines by contrast solve the problems with linear splines while also retaining the advantages. The way to control the shape of the curve is just by adding or removing points. The curve will pass through each point specified so if you have a few desired milestones, that's enough to make a plan.

In physical terms, imagine plotting these points on graph paper, bending a flexible ruler such that it passes through those points, then tracing the resulting curve. This gets you the least bendy path through those points and continuity both in the rate of change and the rate at which that rate is changing.

That matches with the behavior of coffee in the roaster. When you change your airflow and gas settings, some influence can be noticed soon after, but the change isn't a sharp turn. It takes time for that change to be fully realized. As coffee is roasted and the heat transfer characteristics of the coffee change, there are similar changes in the path the curve takes which you may or may not want to adjust with control changes. These are also smooth, gentle changes that happen over an extended period of time. This match between the properties of how coffee behaves in a roaster and the properties of the relaxed cubic splines constructed in CRUCS means that a small number of points can be used to create roasting plans that are easy to follow, quick to edit, while still retaining the full power to capture plans for any roasting style.

My hope is that by giving roasters a simple planning tool that quickly produces easy to follow plans, more people will take a moment to have a plan before roasting the coffee and this will make it easier to achieve the profile they want or, if the roast didn't go to plan, make it more obvious where things started going wrong. CRUCS also serves as a demonstration that cubic splines are the right default curve type to use in profile planning or roast automation systems and I'd love to see other systems adopt this more usable approach.

Make a Contribution

CRUCS is made possible by the generous financial support of people like you. If you found this article useful and interesting or have found that using CRUCS helps you roast coffee better, please consider making a financial contribution.