{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Day 10 - 3D movies! VR capabilties! Woo!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Topics\n", "\n", " 1. Reading in Kepler-11 simulation data & looking at its mass & radii in planets with our NASA database\n", " 1. Download the \"generic planet files\"\n", " * by hand\n", " * with wget\n", " * ~~with a user-defined function~~\n", " 1. Making realistic planetary systems\n", " 1. BACK TO SLIDES FOR 3D MOVIES INTRO\n", " 1. 3D movies in Sketchfab with a .timeframe file\n", "\n", "Let's import our usual things:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import pandas as pd\n", "import ipywidgets" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And some user-defined functions to help us parse this data (making sure we have the hermite_library.py file in our directory):" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from hermite_library import read_hermite_solution_from_file" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Reading in Kepler-11 simulation data & looking at its mass & radii in planets with our NASA database" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's import a planet simulation to work with, again assuming the `data` directory containing our simulation files is in the same directory as this notebook:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "planet_file = 'data/Kepler-11-savedSim.txt'\n", "\n", "t_h, E_h, r_h, v_h = read_hermite_solution_from_file(planet_file)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Before making any visualizations of this, we'll want to get a sense of what the planets in this system look like. Let's print out some important things -- mass & radii -- of each of these planets by looking back at our planetary database:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "planets = pd.read_csv('https://raw.githubusercontent.com/jnaiman/csci-p-14110_su2020/master/lesson08/planets_2020.06.22_10.10.17.csv', \n", " comment=\"#\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's grab some info about this particular planetary system:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
rowidpl_hostnamepl_letterpl_namepl_discmethodpl_controvflagpl_pnumpl_orbperpl_orbpererr1pl_orbpererr2...st_bmyst_bmyerrst_bmylimst_m1st_m1errst_m1limst_c1st_c1errst_c1limst_colorn
15461547Kepler-11bKepler-11 bTransit0610.30390.0006-0.0010...NaNNaNNaNNaNNaNNaNNaNNaNNaN5.0
15471548Kepler-11cKepler-11 cTransit0613.02410.0013-0.0008...NaNNaNNaNNaNNaNNaNNaNNaNNaN5.0
15481549Kepler-11dKepler-11 dTransit0622.68450.0009-0.0009...NaNNaNNaNNaNNaNNaNNaNNaNNaN5.0
15491550Kepler-11eKepler-11 eTransit0631.99960.0008-0.0012...NaNNaNNaNNaNNaNNaNNaNNaNNaN5.0
15501551Kepler-11fKepler-11 fTransit0646.68880.0027-0.0032...NaNNaNNaNNaNNaNNaNNaNNaNNaN5.0
15511552Kepler-11gKepler-11 gTransit06118.38070.0010-0.0006...NaNNaNNaNNaNNaNNaNNaNNaNNaN5.0
\n", "

6 rows × 356 columns

\n", "
" ], "text/plain": [ " rowid pl_hostname pl_letter pl_name pl_discmethod pl_controvflag \\\n", "1546 1547 Kepler-11 b Kepler-11 b Transit 0 \n", "1547 1548 Kepler-11 c Kepler-11 c Transit 0 \n", "1548 1549 Kepler-11 d Kepler-11 d Transit 0 \n", "1549 1550 Kepler-11 e Kepler-11 e Transit 0 \n", "1550 1551 Kepler-11 f Kepler-11 f Transit 0 \n", "1551 1552 Kepler-11 g Kepler-11 g Transit 0 \n", "\n", " pl_pnum pl_orbper pl_orbpererr1 pl_orbpererr2 ... st_bmy \\\n", "1546 6 10.3039 0.0006 -0.0010 ... NaN \n", "1547 6 13.0241 0.0013 -0.0008 ... NaN \n", "1548 6 22.6845 0.0009 -0.0009 ... NaN \n", "1549 6 31.9996 0.0008 -0.0012 ... NaN \n", "1550 6 46.6888 0.0027 -0.0032 ... NaN \n", "1551 6 118.3807 0.0010 -0.0006 ... NaN \n", "\n", " st_bmyerr st_bmylim st_m1 st_m1err st_m1lim st_c1 st_c1err \\\n", "1546 NaN NaN NaN NaN NaN NaN NaN \n", "1547 NaN NaN NaN NaN NaN NaN NaN \n", "1548 NaN NaN NaN NaN NaN NaN NaN \n", "1549 NaN NaN NaN NaN NaN NaN NaN \n", "1550 NaN NaN NaN NaN NaN NaN NaN \n", "1551 NaN NaN NaN NaN NaN NaN NaN \n", "\n", " st_c1lim st_colorn \n", "1546 NaN 5.0 \n", "1547 NaN 5.0 \n", "1548 NaN 5.0 \n", "1549 NaN 5.0 \n", "1550 NaN 5.0 \n", "1551 NaN 5.0 \n", "\n", "[6 rows x 356 columns]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#for planet in planets['pl_hostname']:\n", "# if 'Kepler' in planet:\n", "# print(planet)\n", "\n", "planets.loc[planets['pl_hostname'] == 'Kepler-11']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And let's check out the masses and radii of these objects in particular:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
pl_hostnamepl_letterpl_namepl_bmassjpl_radj
1546Kepler-11bKepler-11 b0.0060.161
1547Kepler-11cKepler-11 c0.0090.256
1548Kepler-11dKepler-11 d0.0230.278
1549Kepler-11eKepler-11 e0.0250.374
1550Kepler-11fKepler-11 f0.0060.222
1551Kepler-11gKepler-11 g0.0790.297
\n", "
" ], "text/plain": [ " pl_hostname pl_letter pl_name pl_bmassj pl_radj\n", "1546 Kepler-11 b Kepler-11 b 0.006 0.161\n", "1547 Kepler-11 c Kepler-11 c 0.009 0.256\n", "1548 Kepler-11 d Kepler-11 d 0.023 0.278\n", "1549 Kepler-11 e Kepler-11 e 0.025 0.374\n", "1550 Kepler-11 f Kepler-11 f 0.006 0.222\n", "1551 Kepler-11 g Kepler-11 g 0.079 0.297" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "planets.loc[planets['pl_hostname'] == 'Kepler-11', \n", " ['pl_hostname', 'pl_letter', 'pl_name', 'pl_bmassj', 'pl_radj']]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Ok cool. We'll keep this little table us to be able to look at later when we are making some aesthetic choices about our dataset." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Download the \"generic planet files\"\n", "\n", "Before we get to making a model of our planetary system in 3D we need some graphical objects to update. These are file formats associated with 3D models (.obj and .mtl files).\n", "\n", "There are a few ways to get this data:\n", "\n", "1. We can download it by hand here: genericPlanetFiles.zip\n", " * make sure you copy this file to your local directory (or if it unzips itself you can copy that folder here)\n", "1. We can install a package called \"wget\" and have it do it for us:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: wget in /opt/anaconda3/envs/myNewEnv2/lib/python3.7/site-packages (3.2)\r\n" ] } ], "source": [ "!pip install wget" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "# import wget\n", "# url = 'https://github.com/jnaiman/csci-p-14110_su2020/raw/master/lesson10/genericPlanetFiles.zip'\n", "# filename = wget.download(url)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And then we can unzip this file to have a working directory from which to build models from:" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "import zipfile" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "# path_to_zip_file = './genericPlanetFiles.zip'\n", "generic_dir = './genericPlanetFiles/'\n", "\n", "# with zipfile.ZipFile(path_to_zip_file, 'r') as zip_ref:\n", "# zip_ref.extractall(generic_dir)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We're going to use the `make3dplanets` function that got downloaded with the generic planet files, but we have to tell our system where to look for it by updating our PATH variable:" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "from sys import path\n", "path.append(generic_dir)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "from make3dplanets import make3dplanets" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To do the \"look at the files\" thing inline in windows you can replace \"ls\" with \"dir\"" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1m\u001b[34m__pycache__\u001b[m\u001b[m generic.obj \u001b[1m\u001b[34mtextureMaps\u001b[m\u001b[m\r\n", "generic.mtl make3dplanets.py\r\n" ] } ], "source": [ "!ls genericPlanetFiles" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's first try opening the `generic.obj` + `generic.mtl` files in [the creator3d online viewer](https://www.creators3d.com/online-viewer).\n", "\n", "## Making realistic planetary systems\n", "\n", "We can see its pretty boring -- just a spherical object without any color or texture. This is our \"generic\" planet object that we can size up or down and attach different planet textures to.\n", "\n", "To do this we have to pick what sizes and textures we think our planets should be. Lucky for us, we have that info! Let's look at that table again of info:" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
pl_hostnamepl_letterpl_namepl_bmassjpl_radj
1546Kepler-11bKepler-11 b0.0060.161
1547Kepler-11cKepler-11 c0.0090.256
1548Kepler-11dKepler-11 d0.0230.278
1549Kepler-11eKepler-11 e0.0250.374
1550Kepler-11fKepler-11 f0.0060.222
1551Kepler-11gKepler-11 g0.0790.297
\n", "
" ], "text/plain": [ " pl_hostname pl_letter pl_name pl_bmassj pl_radj\n", "1546 Kepler-11 b Kepler-11 b 0.006 0.161\n", "1547 Kepler-11 c Kepler-11 c 0.009 0.256\n", "1548 Kepler-11 d Kepler-11 d 0.023 0.278\n", "1549 Kepler-11 e Kepler-11 e 0.025 0.374\n", "1550 Kepler-11 f Kepler-11 f 0.006 0.222\n", "1551 Kepler-11 g Kepler-11 g 0.079 0.297" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "planets.loc[planets['pl_hostname'] == 'Kepler-11', \n", " ['pl_hostname', 'pl_letter', 'pl_name', 'pl_bmassj', 'pl_radj']]\n", "# note: we are using jupter masses and radii!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We'll need to input the planet radii so:" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
pl_radj
15460.161
15470.256
15480.278
15490.374
15500.222
15510.297
\n", "
" ], "text/plain": [ " pl_radj\n", "1546 0.161\n", "1547 0.256\n", "1548 0.278\n", "1549 0.374\n", "1550 0.222\n", "1551 0.297" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "planets.loc[planets['pl_hostname'] == 'Kepler-11', ['pl_radj']]" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[0.161],\n", " [0.256],\n", " [0.278],\n", " [0.374],\n", " [0.222],\n", " [0.297]])" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "planets.loc[planets['pl_hostname'] == 'Kepler-11', ['pl_radj']].values" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0.161, 0.256, 0.278, 0.374, 0.222, 0.297])" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "planets.loc[planets['pl_hostname'] == 'Kepler-11', ['pl_radj']].values.flatten() # formatting" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "radii = planets.loc[planets['pl_hostname'] == 'Kepler-11', ['pl_radj']].values.flatten()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Ok, these are just the radii of our *planets*. We also need to include the radii of the *star*." ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
st_rad
15461.06
15471.06
15481.06
15491.06
15501.06
15511.06
\n", "
" ], "text/plain": [ " st_rad\n", "1546 1.06\n", "1547 1.06\n", "1548 1.06\n", "1549 1.06\n", "1550 1.06\n", "1551 1.06" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "planets.loc[planets['pl_hostname'] == 'Kepler-11', ['st_rad']]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Since its of the host star and they are all the same, we can just take one:" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([1.06])" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "planets.loc[planets['pl_hostname'] == 'Kepler-11', ['st_rad']].values[0]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And now we have to append it to the end of our radii list. Since we are dealing with numpy arrays, we can use numpy's version of append:" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "radii = np.append(radii, planets.loc[planets['pl_hostname'] == 'Kepler-11', ['st_rad']].values[0])" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0.161, 0.256, 0.278, 0.374, 0.222, 0.297, 1.06 ])" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "radii" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Ok neat! The last thing we need to do is define a directory where we will save all of our planet systems:" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [], "source": [ "out_planet_dir = './outPlanets/' # so in a sub-directory" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "... and what to call our planetary system:" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [], "source": [ "SystemName = 'kepler11_take1'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Finally, we are going to start with only one timestep, let's start with the zero-th timestep:" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [], "source": [ "Nplot = 0" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Put it all together by and us the make planet files!" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Going to overwrite files in ./outPlanets/kepler11_take1/\n", "Assuming radii are in Jupiter units except for the last particle which should have solar units, distances in AU... if not things are going to look weird!\n", "no colors/textures specified -- generating random colors!\n" ] } ], "source": [ "fname = make3dplanets(SystemName, r_h, radii, out_planet_dir, generic_dir, Nplot=0)" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'kepler11_take1.obj'" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fname" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This will be the name of the base file. Let's take a look!" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1m\u001b[34mkepler11-movie\u001b[m\u001b[m \u001b[1m\u001b[34mkepler11_take1\u001b[m\u001b[m\r\n" ] } ], "source": [ "!ls outPlanets" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "kepler11_take1.mtl kepler11_take1.obj\r\n" ] } ], "source": [ "!ls outPlanets/kepler11_take1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If we upload this to [creator3d.com's online viewer](https://www.creators3d.com/online-viewer) we notice that we don't see anything except the host star! This is because as we talked about a few days ago its hard to both show planet distances and radii correctly at the same time since the spaces are so huge. Let's try making our radii artifically bigger, *but only for the planets*:" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([16.1 , 25.6 , 27.8 , 37.4 , 22.2 , 29.7 , 1.06])" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "radii = planets.loc[planets['pl_hostname'] == 'Kepler-11', ['pl_radj']].values.flatten()*100\n", "radii = np.append(radii, planets.loc[planets['pl_hostname'] == 'Kepler-11', ['st_rad']].values[0])\n", "radii" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "and recreate our 3D system:" ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Going to overwrite files in ./outPlanets/kepler11_take1/\n", "Assuming radii are in Jupiter units except for the last particle which should have solar units, distances in AU... if not things are going to look weird!\n", "no colors/textures specified -- generating random colors!\n" ] } ], "source": [ "fname = make3dplanets(SystemName, r_h, radii, out_planet_dir, generic_dir, Nplot=0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And now if we reupload to [creator3d.com's online viewer](https://www.creators3d.com/online-viewer) we can see the initial starting positions of our objects much more clearly." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Adding in textures\n", "\n", "So far, we've been letting the 3D planet generator choose the colors for us. Now we'll pick some textures based on what we think these planets/star look like.\n", "\n", "Going back to our table:" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
pl_hostnamepl_letterpl_namepl_bmassjpl_radj
1546Kepler-11bKepler-11 b0.0060.161
1547Kepler-11cKepler-11 c0.0090.256
1548Kepler-11dKepler-11 d0.0230.278
1549Kepler-11eKepler-11 e0.0250.374
1550Kepler-11fKepler-11 f0.0060.222
1551Kepler-11gKepler-11 g0.0790.297
\n", "
" ], "text/plain": [ " pl_hostname pl_letter pl_name pl_bmassj pl_radj\n", "1546 Kepler-11 b Kepler-11 b 0.006 0.161\n", "1547 Kepler-11 c Kepler-11 c 0.009 0.256\n", "1548 Kepler-11 d Kepler-11 d 0.023 0.278\n", "1549 Kepler-11 e Kepler-11 e 0.025 0.374\n", "1550 Kepler-11 f Kepler-11 f 0.006 0.222\n", "1551 Kepler-11 g Kepler-11 g 0.079 0.297" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "planets.loc[planets['pl_hostname'] == 'Kepler-11', \n", " ['pl_hostname', 'pl_letter', 'pl_name', 'pl_bmassj', 'pl_radj']]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Looking at wikipedia we can check out the [relative masses of objects in the solar system in Jupiter masses](https://en.wikipedia.org/wiki/Jupiter_mass#Relative_mass) we see that our objects are between Earth-mass and Neptune mass. Also, our host star is ~mass of sun, so we'll use the sun texture. So, let's make a list of textures to associate with each system from the planet system directory:" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "MarsMap_2500x1250.jpg preview_sun.jpg\r\n", "earth_1200.jpg red_sun.jpg\r\n", "green_sun.jpg saturn_1024.jpg\r\n", "jupiter_1200.jpg sun_texture1.jpg\r\n", "mercury_1024.jpg uranus_1024.jpg\r\n", "neptunemap_1000.jpg venus_surface_texture_1024.jpg\r\n", "pluto_1024.jpg\r\n" ] } ], "source": [ "!ls genericPlanetFiles/textureMaps/" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [], "source": [ "planet_textures = ['earth_1200.jpg', # Kepler-11 b\n", " 'uranus_1024.jpg', # c\n", " 'uranus_1024.jpg', # d\n", " 'uranus_1024.jpg', # e\n", " 'earth_1200.jpg', #f\n", " 'saturn_1024.jpg', #g\n", " 'sun_texture1.jpg'] # last one is a sun texture" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Recall & make planets again:" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Going to overwrite files in ./outPlanets/kepler11_take1/\n", "Assuming radii are in Jupiter units except for the last particle which should have solar units, distances in AU... if not things are going to look weird!\n" ] } ], "source": [ "fname = make3dplanets(SystemName, r_h, radii, out_planet_dir, generic_dir, texture_file=planet_textures, Nplot=0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now if we look in our outplanet directory we can see that we have another file with our texture maps:" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "earth_1200.jpg kepler11_take1.obj sun_texture1.jpg\r\n", "kepler11_take1.mtl saturn_1024.jpg uranus_1024.jpg\r\n" ] } ], "source": [ "!ls outPlanets/kepler11_take1/" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we can upload all of these files to the creator3d webpage for a quick look." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now would be a great time to test uploading to Sketchfab and play around with all of the controls!\n", "\n", "**DO THIS**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## BACK TO SLIDES FOR 3D MOVIES INTRO" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3D movies in Sketchfab with a .timeframe file\n", "\n", "Now, lets make an array of time steps we want to use. Let's start with two only and we can increase this as we go to make longer/less choppy movies. But 2 is good to debug!" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [], "source": [ "Nplots = [5, 100] # make a \"movie\" with timesteps 5 & 100" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's call this system differently:" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [], "source": [ "SystemName = 'kepler11-movie'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now let's make the planet files! Now, this is a loop and we have to save the delta-t's between each file for outputing to a ```sketchfab.timeframe``` later." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "How much time (in seconds) do we want between these two snapshots?" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [], "source": [ "dt_movie = 0.5 # 1/2 second" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now let's loop over our selected snapshots and save files!" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [], "source": [ "# save dts\n", "time_list = []\n", "\n", "for iplot, Nplot in enumerate(Nplots): # fancy way to loop and count at the same time\n", " fname = make3dplanets(SystemName, r_h, radii, out_planet_dir, \n", " generic_dir, texture_file=planet_textures, \n", " Nplot=Nplot, fnum=iplot, verbose=False) # setting a few extra params\n", " #print('saving:', fname, iplot)\n", " # save the time\n", " time_list.append( str(dt_movie) + ' ' + fname + '\\n') # note new-line character" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "('kepler11-movie', './outPlanets/')" ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "SystemName, out_planet_dir" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Finally, we have to save all our times and filenames in the .timeframe file:" ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['0.5 kepler11-movie0000.obj\\n', '0.5 kepler11-movie0001.obj\\n']" ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "time_list" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [], "source": [ "timeframe_filename = out_planet_dir+SystemName+'/sketchfab.timeframe'\n", "ftime = open(timeframe_filename,'w')\n", "\n", "for tobj in time_list:\n", " ftime.write(tobj)\n", " \n", "# close file\n", "ftime.close()" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "earth_1200.jpg kepler11-movie0001.obj sun_texture1.jpg\r\n", "kepler11-movie.mtl saturn_1024.jpg uranus_1024.jpg\r\n", "kepler11-movie0000.obj sketchfab.timeframe\r\n" ] } ], "source": [ "!ls outPlanets/kepler11-movie/" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [], "source": [ "# this is just for me to re-zip things at the end of mods\n", "\n", "save_mods = False\n", "\n", "if save_mods:\n", " import os\n", " import zipfile\n", "\n", " def zipdir(path, ziph):\n", " # ziph is zipfile handle\n", " for root, dirs, files in os.walk(path):\n", " for file in files:\n", " ziph.write(os.path.join(root, file))\n", "\n", " zipf = zipfile.ZipFile('../genericPlanetFiles.zip', 'w', zipfile.ZIP_DEFLATED)\n", " zipdir('./genericPlanetFiles', zipf)\n", " zipf.close()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.7.6" } }, "nbformat": 4, "nbformat_minor": 4 }