Skip to content

Commit

Permalink
Merge branch 'shape-families-tables' of https://github.com/glotzerlab…
Browse files Browse the repository at this point in the history
…/coxeter into shape-families-tables
  • Loading branch information
josephburkhart committed Feb 7, 2025
2 parents e80f345 + d0da2e4 commit 459667c
Showing 1 changed file with 52 additions and 30 deletions.
82 changes: 52 additions & 30 deletions make_tables.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import csv\n",
"import coxeter\n",
"from pathlib import Path"
"from pathlib import Path\n",
"\n",
"import numpy as np\n",
"\n",
"import coxeter"
]
},
{
Expand All @@ -32,17 +34,21 @@
" Path(\"doc/source/_data/science.1220869.catalan.csv\"),\n",
" Path(\"doc/source/_data/science.1220869.johnson.csv\"),\n",
" Path(\"doc/source/_data/science.1220869.other.csv\"),\n",
" Path(\"doc/source/_data/science.1220869.platonic.csv\")\n",
" Path(\"doc/source/_data/science.1220869.platonic.csv\"),\n",
"]\n",
"for file_path in paths:\n",
" with open(file_path, \"r\", newline=\"\") as infile:\n",
" with open(file_path, newline=\"\") as infile:\n",
" reader = csv.reader(infile, delimiter=\",\")\n",
"\n",
" for i, (id, paper_name) in enumerate(reader):\n",
" if i != 0:\n",
" coxeter_name = coxeter.families.DOI_SHAPE_REPOSITORIES[\"10.1126/science.1220869\"][0].data[id][\"name\"]\n",
" coxeter_name = coxeter.families.DOI_SHAPE_REPOSITORIES[\n",
" \"10.1126/science.1220869\"\n",
" ][0].data[id][\"name\"]\n",
" if paper_name != coxeter_name:\n",
" print(f\"Name mismatch found for {id}: {paper_name = }, {coxeter_name = }\")"
" print(\n",
" f\"Name mismatch found for {id}: {paper_name = }, {coxeter_name = }\"\n",
" )"
]
},
{
Expand All @@ -67,6 +73,7 @@
"source": [
"from xml.etree import ElementTree\n",
"\n",
"\n",
"def to_x3d(shape, filename):\n",
" \"\"\"Save shape to an Extensible 3D (X3D) file.\n",
"\n",
Expand All @@ -90,7 +97,7 @@
" },\n",
" )\n",
" x3d_scene = ElementTree.SubElement(root, \"Scene\")\n",
" \n",
"\n",
" # Faces\n",
" x3d_shape_faces = ElementTree.SubElement(\n",
" x3d_scene, \"shape\", attrib={\"DEF\": f\"{shape.__class__.__name__} Faces\"}\n",
Expand Down Expand Up @@ -153,18 +160,19 @@
"\n",
" # Position the camera\n",
" try:\n",
" camera_pos_z = 3*shape.circumsphere_radius\n",
" camera_pos_z = 3 * shape.circumsphere_radius\n",
" except RuntimeError:\n",
" widths = np.max(shape.vertices, axis=0) - np.min(shape.vertices, axis=0)\n",
" camera_pos_z = (3/2)*(np.max(widths))\n",
" camera_pos_z = (3 / 2) * (np.max(widths))\n",
"\n",
" x3d_viewpoint = ElementTree.SubElement(\n",
" x3d_scene,\n",
" \"Viewpoint\",\n",
" attrib={\n",
" \"position\": f\"0,0,{camera_pos_z}\", # Note the hardcoded position\n",
" \"centerOfRotation\": \",\".join(map(str, np.around(shape.centroid, 3)))\n",
" })\n",
" \"position\": f\"0,0,{camera_pos_z}\", # Note the hardcoded position\n",
" \"centerOfRotation\": \",\".join(map(str, np.around(shape.centroid, 3))),\n",
" },\n",
" )\n",
"\n",
" # Write to file\n",
" ElementTree.ElementTree(root).write(filename, encoding=\"UTF-8\")"
Expand All @@ -181,20 +189,26 @@
" Path(\"doc/source/_data/science.1220869.catalan.csv\"),\n",
" Path(\"doc/source/_data/science.1220869.johnson.csv\"),\n",
" Path(\"doc/source/_data/science.1220869.other.csv\"),\n",
" Path(\"doc/source/_data/science.1220869.platonic.csv\")\n",
" Path(\"doc/source/_data/science.1220869.platonic.csv\"),\n",
"]\n",
"\n",
"for file_path in paths:\n",
" with open(file_path, \"r\", newline=\"\") as infile:\n",
" with open(file_path, newline=\"\") as infile:\n",
" reader = csv.reader(infile, delimiter=\",\")\n",
"\n",
" with open(file_path.parent / (file_path.stem + \"_processed.csv\"), \"w\", newline=\"\") as outfile:\n",
" with open(\n",
" file_path.parent / (file_path.stem + \"_processed.csv\"), \"w\", newline=\"\"\n",
" ) as outfile:\n",
" writer = csv.writer(outfile)\n",
"\n",
" for i, (id, name) in enumerate(reader):\n",
" if i!=0:\n",
" shape = coxeter.families.DOI_SHAPE_REPOSITORIES[\"10.1126/science.1220869\"][0].get_shape(id)\n",
" newfilepath = Path(\"/home/joseph/GlotzerGroup/coxeter/doc/source/_static\") / (name.lower().replace(\" \", \"_\") + \".x3d\")\n",
" if i != 0:\n",
" shape = coxeter.families.DOI_SHAPE_REPOSITORIES[\n",
" \"10.1126/science.1220869\"\n",
" ][0].get_shape(id)\n",
" newfilepath = Path(\n",
" \"/home/joseph/GlotzerGroup/coxeter/doc/source/_static\"\n",
" ) / (name.lower().replace(\" \", \"_\") + \".x3d\")\n",
" to_x3d(shape, newfilepath)"
]
},
Expand All @@ -209,25 +223,31 @@
" Path(\"doc/source/_data/science.1220869.catalan.csv\"),\n",
" Path(\"doc/source/_data/science.1220869.johnson.csv\"),\n",
" Path(\"doc/source/_data/science.1220869.other.csv\"),\n",
" Path(\"doc/source/_data/science.1220869.platonic.csv\")\n",
" Path(\"doc/source/_data/science.1220869.platonic.csv\"),\n",
"]\n",
"\n",
"for file_path in paths:\n",
" with open(file_path, \"r\", newline=\"\") as infile:\n",
" with open(file_path, newline=\"\") as infile:\n",
" reader = csv.reader(infile, delimiter=\",\")\n",
"\n",
" with open(file_path.parent / (file_path.stem + \"_processed.csv\"), \"w\", newline=\"\") as outfile:\n",
" with open(\n",
" file_path.parent / (file_path.stem + \"_processed.csv\"), \"w\", newline=\"\"\n",
" ) as outfile:\n",
" writer = csv.writer(outfile)\n",
"\n",
" for i, (id, name) in enumerate(reader):\n",
" if i==0:\n",
" if i == 0:\n",
" writer.writerow([\"ID\", \"Name\", \"Vertices\", \"Faces\", \"Model\"])\n",
" else:\n",
" shape = coxeter.families.DOI_SHAPE_REPOSITORIES[\"10.1126/science.1220869\"][0].get_shape(id)\n",
" shape = coxeter.families.DOI_SHAPE_REPOSITORIES[\n",
" \"10.1126/science.1220869\"\n",
" ][0].get_shape(id)\n",
" vertices = shape.num_vertices\n",
" faces = shape.num_faces\n",
" model_info = f\":model:`_static/{name.lower().replace(\" \", \"_\")}.x3d`\"\n",
" writer.writerow([id, name, vertices, faces, model_info])\n"
" model_info = (\n",
" f\":model:`_static/{name.lower().replace(\" \", \"_\")}.x3d`\"\n",
" )\n",
" writer.writerow([id, name, vertices, faces, model_info])"
]
},
{
Expand Down Expand Up @@ -256,6 +276,7 @@
],
"source": [
"import coxeter\n",
"\n",
"# Create Square Prism and Triangular Antiprism X3D models\n",
"shape = coxeter.families.PrismAntiprismFamily.get_shape(\"Square Prism\")\n",
"coxeter.io.to_x3d(shape, \"square_prism.x3d\")\n",
Expand Down Expand Up @@ -287,19 +308,20 @@
"source": [
"import coxeter\n",
"\n",
"\n",
"# Create Pyramid and Dipyramid X3D models\n",
"names = [\n",
" \"Triangular Pyramid\", \n",
" \"Triangular Pyramid\",\n",
" \"Square Pyramid\",\n",
" \"Pentagonal Pyramid\",\n",
" \"Triangular Dipyramid\",\n",
" \"Square Dipyramid\",\n",
" \"Pentagonal Dipyramid\"\n",
" \"Pentagonal Dipyramid\",\n",
"]\n",
"for n in names:\n",
" shape = coxeter.families.PyramidDipyramidFamily.get_shape(n)\n",
" print(f\"{n},{len(shape.vertices)},{len(shape.faces)},:x3d-model:`_static/x3d/{n.lower().replace(\" \", \"_\") + \".x3d\"}`\")\n",
" print(\n",
" f\"{n},{len(shape.vertices)},{len(shape.faces)},:x3d-model:`_static/x3d/{n.lower().replace(\" \", \"_\") + \".x3d\"}`\"\n",
" )\n",
" # coxeter.io.to_x3d(shape, n.lower().replace(\" \", \"_\") + \".x3d\")\n",
" # coxeter.io.to_html(shape, n.lower().replace(\" \", \"_\") + \".html\")"
]
Expand Down

0 comments on commit 459667c

Please sign in to comment.