Unit conversion
Case study · unitguard
A converter that names what is missing instead of guessing it.
A quantity and two units, with four worked examples to load. Every change is answered with a conversion or with a refusal.
Problem
A spreadsheet will add a mass to an energy without a word, and the version of that failure specific to emissions work is the gas species: a tonne of methane and a tonne of carbon dioxide share nothing but mass, moving between them is a choice of assessment report and time horizon, and turning CO2e back into one gas asks for a mixture the figure was built to forget.
Method
Dimensional analysis with the gas species carried inside the unit, magnitudes read as exact rationals over big integers rather than floating point, and a conversion allowed only where the dimensions match and, for gases, a route between the two species is defined.
What it does
A quantity, two units and four worked examples as chips, answered either with Converted, the result and the sentence written out in full, or with Refused and the input that was missing; a result that does not terminate in decimal prints with a leading tilde, as five hundred tonnes of carbon to tCO2 does at 5500/3.
What it refuses to do
Methane to CO2e, the refusal the instrument exists for: there is only a global warming potential, and over one hundred years AR4 puts methane at 25, AR5 at 28 and AR6 at 27.0 for biogenic and 29.8 for fossil methane, so the instrument names all of them and picks none.
CO2e back into a single gas, because tonnes of CO2 equivalent are a unit of account and without the mix that produced the figure there is no mass to return; the direction that does work is CO2 to CO2e, where the potential is 1 by definition.
A bare mass into a gas unit, because asking for t to tCO2 asks the instrument to supply the species, and the refusal tells you to state it on the input side.
A gas unit into a bare mass, which is arithmetically trivial and refused anyway, because dropping the species stops the figure from being an emissions figure at all.
Across dimensions: energy to mass is refused with both dimensions named and with the missing thing named too, an energy density or an emission factor, and the instrument carries no default emission factor for any country in any year.
Anything that is not a magnitude, answered with Not a number, and two species with no defined route between them, answered with Not defined.
In closing
A converter that guesses is worse than no converter, because it returns a number, and numbers get believed.