Run (part of) healpy in the browser with pyodide

python
healpy
Published

July 17, 2024

Thanks to the help of @VeerioSDSC and Rick Wagner, I have been able to run part of healpy in the browser. For now only tested reading FITS maps and plotting with projview.

Compiling the C++ and Cython extensions was difficult so for experimental purposes we opted for stripping healpy of all extensions making it a pure Python package, see https://github.com/healpy/pyhealpy

Then it is possible to build a wheel of healpy compiled to Javascript with pyodide and emscripten, see: https://github.com/healpy/pyhealpy/blob/pyhealpy/README.md

Once the wheel is available it is possible to load it in a web page and use it, see the page source at:

index.html for plotting a fits map in the browser

See the generated website, open the Developer console to see the logs.

Details on how to use Github Actions to build and deploy.

Screenshot

JupyterLite

We can also run JupyterLite in the browser and import this package, see a preliminary test at:

https://github.com/healpy/pyhealpy/tree/pyhealpy/jupyterlite

it is deployed at https://healpy.github.io/pyhealpy/jup/lab/index.html

This allows to run JupyterLite, load healpy, read maps loaded into JupyterLite with healpy, it is also possible to use jupyterlab-open-url-parameter to retrieve a map at runtime. However there are several limitations:

  • loading maps via fromUrl is very slow and works only for tiny maps, even a 30 MB map is too large and makes JupyterLite hang for minutes
  • pyhealpy only supports maps in ring ordering, maps in nest ordering require ring2nest functionality which is not imported from the C++ package.