Meshing spherical harmonics
Repo
Notebook
Spherical harmonics seem to be in vogue in biophysical modeling recently, so I set out for an intuitive understanding of what they are. They aren't easily plotted in 2d, since they are defined on the unit sphere. Matplotlib and mayavi can plot isosurfaces, but as an exercise I take a more hands-on approach rather than just calling a function.
Scipy can evaluate a spherical harmonic, of a given order and degree, for a given azimuth and altitude. This results in a spherical heat-map, i.e. positive and negative values defined on the surface of the unit sphere. To turn this into an iso-surface the notebook linked above evaluates the function using the angular coordinates of every grid point in a cube, then compares the spherical harmonic value of each point to the point's actual distance from the origin. This defines a signed distance function (SDF), which can then be meshed with marching cubes after converting from spherical coordinates back into grid coordinates, then back into universe coordinates.
Incidentally I figured out that meshplot can write meshes to .html, which can be saved on github and published via github pages such that they can be embedded in a webstite as an html object, like so (try moving it around!):