notebooks/stats_tables/cell_counts.ipynb (192 lines of code) (raw):
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Cell counts at different resolutions\n",
"\n",
"H3 covers the sphere with both hexagon and pentagon cells.\n",
"Most of the time you'll only encounter hexagon cells because there are only\n",
"12 pentagons at each resolution, and they're all positioned to be in\n",
"the ocean.\n",
"\n",
"Here are the counts of pentagons, hexagons, and all cells at each resolution."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[('0', '122', '110', '12'),\n",
" ('1', '842', '830', '12'),\n",
" ('2', '5,882', '5,870', '12'),\n",
" ('3', '41,162', '41,150', '12'),\n",
" ('4', '288,122', '288,110', '12'),\n",
" ('5', '2,016,842', '2,016,830', '12'),\n",
" ('6', '14,117,882', '14,117,870', '12'),\n",
" ('7', '98,825,162', '98,825,150', '12'),\n",
" ('8', '691,776,122', '691,776,110', '12'),\n",
" ('9', '4,842,432,842', '4,842,432,830', '12'),\n",
" ('10', '33,897,029,882', '33,897,029,870', '12'),\n",
" ('11', '237,279,209,162', '237,279,209,150', '12'),\n",
" ('12', '1,660,954,464,122', '1,660,954,464,110', '12'),\n",
" ('13', '11,626,681,248,842', '11,626,681,248,830', '12'),\n",
" ('14', '81,386,768,741,882', '81,386,768,741,870', '12'),\n",
" ('15', '569,707,381,193,162', '569,707,381,193,150', '12')]"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import h3\n",
"from tabulate import tabulate\n",
"\n",
"def num_pentagons(res):\n",
" return 12\n",
"\n",
"def num_hexagons(res):\n",
" 'Number of *hexagons* (excluding pentagons) at a resolution'\n",
" return h3.num_hexagons(res) - 12\n",
"\n",
"def num_cells(res):\n",
" 'Number of *hexagons* (excluding pentagons) at a resolution'\n",
" return h3.num_hexagons(res) # function name to be fixed in 4.0 release\n",
"\n",
"def fmt(num):\n",
" s = '{:,.0f}'\n",
" return s.format(num) \n",
"\n",
"\n",
"counts = [\n",
" (res, num_cells(res), num_hexagons(res), num_pentagons(res))\n",
" for res in range(16)\n",
"]\n",
"\n",
"counts = [\n",
" tuple(map(fmt, row))\n",
" for row in counts\n",
"]\n",
"counts"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"| Res | Total number of cells | Number of hexagons | Number of pentagons |\n",
"|------:|------------------------:|---------------------:|----------------------:|\n",
"| 0 | 122 | 110 | 12 |\n",
"| 1 | 842 | 830 | 12 |\n",
"| 2 | 5,882 | 5,870 | 12 |\n",
"| 3 | 41,162 | 41,150 | 12 |\n",
"| 4 | 288,122 | 288,110 | 12 |\n",
"| 5 | 2,016,842 | 2,016,830 | 12 |\n",
"| 6 | 14,117,882 | 14,117,870 | 12 |\n",
"| 7 | 98,825,162 | 98,825,150 | 12 |\n",
"| 8 | 691,776,122 | 691,776,110 | 12 |\n",
"| 9 | 4,842,432,842 | 4,842,432,830 | 12 |\n",
"| 10 | 33,897,029,882 | 33,897,029,870 | 12 |\n",
"| 11 | 237,279,209,162 | 237,279,209,150 | 12 |\n",
"| 12 | 1,660,954,464,122 | 1,660,954,464,110 | 12 |\n",
"| 13 | 11,626,681,248,842 | 11,626,681,248,830 | 12 |\n",
"| 14 | 81,386,768,741,882 | 81,386,768,741,870 | 12 |\n",
"| 15 | 569,707,381,193,162 | 569,707,381,193,150 | 12 |\n"
]
}
],
"source": [
"headers = [\n",
" 'Res',\n",
" 'Total number of cells',\n",
" 'Number of hexagons',\n",
" 'Number of pentagons',\n",
"]\n",
"out = tabulate(counts, headers=headers, tablefmt='pipe', stralign='right')\n",
"\n",
"print(out)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"| Res | Total number of cells | Number of hexagons | Number of pentagons |\n",
"|------:|------------------------:|---------------------:|----------------------:|\n",
"| 0 | 122 | 110 | 12 |\n",
"| 1 | 842 | 830 | 12 |\n",
"| 2 | 5,882 | 5,870 | 12 |\n",
"| 3 | 41,162 | 41,150 | 12 |\n",
"| 4 | 288,122 | 288,110 | 12 |\n",
"| 5 | 2,016,842 | 2,016,830 | 12 |\n",
"| 6 | 14,117,882 | 14,117,870 | 12 |\n",
"| 7 | 98,825,162 | 98,825,150 | 12 |\n",
"| 8 | 691,776,122 | 691,776,110 | 12 |\n",
"| 9 | 4,842,432,842 | 4,842,432,830 | 12 |\n",
"| 10 | 33,897,029,882 | 33,897,029,870 | 12 |\n",
"| 11 | 237,279,209,162 | 237,279,209,150 | 12 |\n",
"| 12 | 1,660,954,464,122 | 1,660,954,464,110 | 12 |\n",
"| 13 | 11,626,681,248,842 | 11,626,681,248,830 | 12 |\n",
"| 14 | 81,386,768,741,882 | 81,386,768,741,870 | 12 |\n",
"| 15 | 569,707,381,193,162 | 569,707,381,193,150 | 12 |"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from IPython.display import Markdown\n",
"Markdown(out)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.12"
}
},
"nbformat": 4,
"nbformat_minor": 4
}