using gnu units for hormone calculations

I really like the units command and I use it very often. It works offline and it has so many units, around 4000 in the default definitions file.

Among those many many units are the length of a football field, planetary orbit durations, world currencies, and the mass of a US standard egg including separately the mass of the egg whites and yolk.

units has an interactive mode:

$ units
Currency exchange rates from FloatRates (USD base) on 2020-11-15 
3677 units, 109 prefixes, 114 nonlinear units

You have: 0.5 footballfields per blink
You want: m/s
	* 52.916667
	/ 0.018897638

as well as a way to pass in units as arguments:

$ units 'tempC(30)' tempF
	86
$ units 5ft+10in cm
	* 177.8
	/ 0.005624297
$ units 164cm 'ft;in'
	5 ft + 4.5669291 in

You can check all the different pre-built units by reading through the default units file. On my system it's /usr/share/units/definitions.units and running units -V will print the default location on your system.

However! There are no built-in units for comparing different hormone levels you might get back from a blood test. You might have nmol/L (nanomoles per liter) of testosterone or pg/mL (picograms per milliliter) of estradiol, with lots of different combinations of grams, picograms, nanomoles, picomoles, liters, deciliters, milliliters, and more!

But this is the sort of situation that a tool like units excels at.

unit file

units has a -f or --file option where you can pass in your own unit definitions. That's where we can add some units to make conversions for different human sex hormones.

If we make a file called hormones.units with the molar masses copied from wikipedia for different hormones:

estrone               270.366 g/mol
oestrone              estrone
e_1                   estrone

estradiol             272.38 g/mol
oestradiol            estradiol
e_2                   estradiol

estriol               288.387 g/mol 
oestriol              estriol
e_3                   estriol

estetrol              304.386 g/mol
oestetrol             estetrol
e_4                   estetrol

testosterone          288.431 g/mol
progesterone          314.469 g/mol 
dihydrotestosterone   290.447 g/mol
dht                   dihydrotestosterone

Then we can run units with -f hormones.units as well as -f '' for the built-in units to perform calculations useful for interpreting blood test results for hormones:

$ units -f ''  -f hormones.units
You have: 200 pg/mL
You want: pmol estradiol / L
    * 734.2683
    / 0.0013619
You have: 70 nmol testosterone / dL
You want: ng/mL
    * 201.9017
    / 0.0049529053

And we can cross-check the conversions against another hormone calculator to verify that our conversions are indeed correct.