A command line tool to calculate a gearing range for a bicycle, based on inputs such as chainring and cassette size, or cassette range. Also accepts wheel and tire sizes, and can calculate speed-at-rpm instead of gear inches.
Gear Inches is a concept that dates back to some of the earliest bicycles - the ones now known as "penny farthings" and "high wheelers" which were, at the time, known as "bicycles." With the cranks directly connected to the front wheel, there was no way to increase the distance travelled with each pedal stroke, save to simply increase the size of the front wheel. A bicycle with a 55" front wheel would travel farther with each revolution than one with a 45" front wheel, and was therefore capable of greater speed.
On modern bikes with a chain drive, we must calculate the virtual gear inches with the formula of (front gear teeth / rear gear teeth) * diameter of drive wheel.
This command line tool does this calculation for a typical range of bicycle gears, and outputs an easily readable chart, using tabulate as called by the print_table function. The default is to do so with typical values, but the user has a lot of options as well. Here's the default output:
$ python gearinches.py
+---------------+--------+-------+-------+-------+------+-------+-------+-------+-------+
| Gear Inches | 11 | 12 | 14 | 16 | 18 | 21 | 24 | 28 | 32 |
+===============+========+=======+=======+=======+======+=======+=======+=======+=======+
| 28 | 68.73 | 63 | 54 | 47.25 | 42 | 36 | 31.5 | 27 | 23.62 |
+---------------+--------+-------+-------+-------+------+-------+-------+-------+-------+
| 38 | 93.27 | 85.5 | 73.29 | 64.12 | 57 | 48.86 | 42.75 | 36.64 | 32.06 |
+---------------+--------+-------+-------+-------+------+-------+-------+-------+-------+
| 48 | 117.82 | 108 | 92.57 | 81 | 72 | 61.71 | 54 | 46.29 | 40.5 |
+---------------+--------+-------+-------+-------+------+-------+-------+-------+-------+
Here we have a chart using the fice cogs that we specified. You can see them in the top row. Along the left are three chainrings, or front gear tooth counts. (This particular chart example is using the default of 28, 38, and 48, but it's possible to change that.) The rest of the grid shows the virtual gear inches for each combination, assuming a default 27" wheel, which is about the equivalent of a modern wheel with a 700x32c tire, as you might find on a hybrid or commuter bike.
Since differing bicycles tend to use specific rear gears (cogs), this tool allows the user to specify them with the --cassette argument, for example
$ python gearinches.py --cassette 11,12,15,18,21
+---------------+--------+-------+------+------+-------+
| Gear Inches | 11 | 12 | 15 | 18 | 21 |
+===============+========+=======+======+======+=======+
| 28 | 68.73 | 63 | 50.4 | 42 | 36 |
+---------------+--------+-------+------+------+-------+
| 38 | 93.27 | 85.5 | 68.4 | 57 | 48.86 |
+---------------+--------+-------+------+------+-------+
| 48 | 117.82 | 108 | 86.4 | 72 | 61.71 |
+---------------+--------+-------+------+------+-------+
So for example, you can see in the chart above that if you are using your 48 tooth chainring with your 15 tooth cog, you're using the equivalent of a 68.4" wheel. You would have needed long legs in the late 19th Century to ride a bicycle with such a large front wheel!
Sometimes you may not want to type in all of the specific cogs to your cassette, so you can just specify a range and a number of cogs. The tool will generate a plausible set of gears based on the principle used in most bicycle cassettes that the steps from one cog to the next should be as even as possible. So if there's a jump from 11 to 12 teeth at the beginning of the cassette, and that is a 9% increase (approximately), then if we later have a 27 tooth cog in our sequence, the next would be a 30, giving us a relatively close 11% jump.
All of this is calculated in the get_sequence function.
$ python gearinches.py -a11-32 -s10
+---------------+--------+-------+-------+-------+------+------+-------+-------+-------+-------+
| Gear Inches | 11 | 12 | 14 | 16 | 18 | 20 | 22 | 25 | 28 | 32 |
+===============+========+=======+=======+=======+======+======+=======+=======+=======+=======+
| 28 | 68.73 | 63 | 54 | 47.25 | 42 | 37.8 | 34.36 | 30.24 | 27 | 23.62 |
+---------------+--------+-------+-------+-------+------+------+-------+-------+-------+-------+
| 38 | 93.27 | 85.5 | 73.29 | 64.12 | 57 | 51.3 | 46.64 | 41.04 | 36.64 | 32.06 |
+---------------+--------+-------+-------+-------+------+------+-------+-------+-------+-------+
| 48 | 117.82 | 108 | 92.57 | 81 | 72 | 64.8 | 58.91 | 51.84 | 46.29 | 40.5 |
+---------------+--------+-------+-------+-------+------+------+-------+-------+-------+-------+
The program will output a chart assuming three chainrings, but you can input your own chainring as well with --chainrings or just -r.
Some other options include the ability to calculate a speed-at-rpm in mph and kph, as well as the ability to produce "tall" output with --tall or just -t, so you can print it, cut it out, and attach it to your top tube. This would be the badge of a true bicycle nerd!
All of these options and a few more are spelled out with the -h command line argument, so you may want to start there.
Possible future improvements to this program include more output options, the ability to save some defaults, and instructions on how to set it up to run without needing the python command before it, or needing to specify the full path to the script.