{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 3D Earth and Celestial Bodies {#planets_example}\n\nPlot the solar system in PyVista.\n\nThis example is inspired by\n[planet3D-MATLAB](https://github.com/tamaskis/planet3D-MATLAB).\n\n::: note\n::: title\nNote\n:::\n\nThe purpose of this example is to demonstrate plotting celestial bodies\nand may lack astronomical precision. There may be inaccuracies in the\nrepresentation, so please take care when reusing or repurposing this\nexample.\n\nPlease take a look at libraries like [astropy](https://www.astropy.org/)\nif you wish to use Python for astronomical calculations.\n:::\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import pyvista\nfrom pyvista import examples" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Plot the Solar System with Stars in the Background\n\nThis section relies on calculations in [Visualizing Celestial Bodies in\n3D](https://tamaskis.github.io/files/Visualizing_Celestial_Bodies_in_3D.pdf).\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Light of the Sun.\nlight = pyvista.Light()\nlight.set_direction_angle(30, -20)\n\n# Load planets\nmercury = examples.planets.load_mercury(radius=2439.0)\nmercury_texture = examples.planets.download_mercury_surface(texture=True)\nvenus = examples.planets.load_venus(radius=6052.0)\nvenus_texture = examples.planets.download_venus_surface(texture=True)\nearth = examples.planets.load_earth(radius=6378.1)\nearth_texture = examples.load_globe_texture()\nmars = examples.planets.load_mars(radius=3397.2)\nmars_texture = examples.planets.download_mars_surface(texture=True)\njupiter = examples.planets.load_jupiter(radius=71492.0)\njupiter_texture = examples.planets.download_jupiter_surface(texture=True)\nsaturn = examples.planets.load_saturn(radius=60268.0)\nsaturn_texture = examples.planets.download_saturn_surface(texture=True)\n# Saturn's rings range from 7000.0 km to 80000.0 km from the surface of the planet\ninner = 60268.0 + 7000.0\nouter = 60268.0 + 80000.0\nsaturn_rings = examples.planets.load_saturn_rings(inner=inner, outer=outer, c_res=50)\nsaturn_rings_texture = examples.planets.download_saturn_rings(texture=True)\nuranus = examples.planets.load_uranus(radius=25559.0)\nuranus_texture = examples.planets.download_uranus_surface(texture=True)\nneptune = examples.planets.load_neptune(radius=24764.0)\nneptune_texture = examples.planets.download_neptune_surface(texture=True)\npluto = examples.planets.load_pluto(radius=1151.0)\npluto_texture = examples.planets.download_pluto_surface(texture=True)\n\n# Move planets to a nice position for the plotter. These numbers are not\n# grounded in reality and are for demonstration purposes only.\nmercury.translate((0.0, 0.0, 0.0), inplace=True)\nvenus.translate((-15000.0, 0.0, 0.0), inplace=True)\nearth.translate((-30000.0, 0.0, 0.0), inplace=True)\nmars.translate((-45000.0, 0.0, 0.0), inplace=True)\njupiter.translate((-150000.0, 0.0, 0.0), inplace=True)\nsaturn.translate((-400000.0, 0.0, 0.0), inplace=True)\nsaturn_rings.translate((-400000.0, 0.0, 0.0), inplace=True)\nuranus.translate((-600000.0, 0.0, 0.0), inplace=True)\nneptune.translate((-700000.0, 0.0, 0.0), inplace=True)\n\n# Add planets to Plotter.\npl = pyvista.Plotter(lighting=\"none\")\ncubemap = examples.download_cubemap_space_16k()\n_ = pl.add_actor(cubemap.to_skybox())\npl.set_environment_texture(cubemap, True)\npl.add_light(light)\npl.add_mesh(mercury, texture=mercury_texture, smooth_shading=True)\npl.add_mesh(venus, texture=venus_texture, smooth_shading=True)\npl.add_mesh(earth, texture=earth_texture, smooth_shading=True)\npl.add_mesh(mars, texture=mars_texture, smooth_shading=True)\npl.add_mesh(jupiter, texture=jupiter_texture, smooth_shading=True)\npl.add_mesh(saturn, texture=saturn_texture, smooth_shading=True)\npl.add_mesh(saturn_rings, texture=saturn_rings_texture, smooth_shading=True)\npl.add_mesh(uranus, texture=uranus_texture, smooth_shading=True)\npl.add_mesh(neptune, texture=neptune_texture, smooth_shading=True)\npl.add_mesh(pluto, texture=pluto_texture, smooth_shading=True)\npl.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Plot the Planets and their Textures\n\nEach planet here is in a different subplot. The planet\\'s textures are\nfrom [Solar Textures](https://www.solarsystemscope.com/textures/).\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "pl = pyvista.Plotter(shape=(3, 2))\npl.subplot(0, 0)\npl.add_text(\"Mercury\")\npl.add_mesh(examples.planets.download_mercury_surface(), rgb=True)\npl.subplot(0, 1)\npl.add_mesh(mercury, texture=mercury_texture)\npl.subplot(1, 0)\npl.add_text(\"Venus\")\npl.add_mesh(examples.planets.download_venus_surface(atmosphere=True), rgb=True)\npl.subplot(1, 1)\npl.add_mesh(venus, texture=venus_texture)\npl.subplot(2, 0)\npl.add_text(\"Mars\")\npl.add_mesh(examples.planets.download_mars_surface(), rgb=True)\npl.subplot(2, 1)\npl.add_mesh(mars, texture=mars_texture)\npl.show(cpos=\"xy\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Plot the Atmosphere and Surface of Venus\n\nHere we plot Venus with and without its atmosphere.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "venus = examples.planets.load_venus()\natmosphere_texture = examples.planets.download_venus_surface(atmosphere=True, texture=True)\nsurface_texture = examples.planets.download_venus_surface(atmosphere=False, texture=True)\n\npl = pyvista.Plotter(shape=(1, 2))\npl.subplot(0, 0)\npl.add_text(\"Venus Atmosphere\")\npl.add_mesh(venus, texture=atmosphere_texture, smooth_shading=True)\npl.subplot(0, 1)\npl.add_text(\"Venus Surface\")\npl.add_mesh(venus, texture=surface_texture, smooth_shading=True)\npl.link_views()\npl.show(cpos=\"xy\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.12.2" } }, "nbformat": 4, "nbformat_minor": 0 }