{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Running `vplanet`" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2023-08-23T23:27:50.122924Z", "iopub.status.busy": "2023-08-23T23:27:50.122412Z", "iopub.status.idle": "2023-08-23T23:27:50.500538Z", "shell.execute_reply": "2023-08-23T23:27:50.499918Z" }, "tags": [ "hide_input" ] }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Overview" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2023-08-23T23:27:50.503644Z", "iopub.status.busy": "2023-08-23T23:27:50.503230Z", "iopub.status.idle": "2023-08-23T23:27:50.511792Z", "shell.execute_reply": "2023-08-23T23:27:50.511232Z" }, "tags": [ "hide_input" ] }, "outputs": [], "source": [ "# Tar up the example folder\n", "import glob\n", "import tarfile\n", "import os\n", "\n", "with tarfile.open(\"examples/CircumbinaryOrbit.tar.gz\", \"w:gz\") as tar:\n", " for file in glob.glob(\"examples/CircumbinaryOrbit/*.in\"):\n", " tar.add(file, arcname=os.path.basename(file))" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Let's run :py:class:`vplanet` on the :download:`CircumbinaryOrbit ` example." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2023-08-23T23:27:50.514606Z", "iopub.status.busy": "2023-08-23T23:27:50.514293Z", "iopub.status.idle": "2023-08-23T23:27:50.699437Z", "shell.execute_reply": "2023-08-23T23:27:50.698777Z" } }, "outputs": [], "source": [ "import vplanet" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2023-08-23T23:27:50.702669Z", "iopub.status.busy": "2023-08-23T23:27:50.702324Z", "iopub.status.idle": "2023-08-23T23:27:51.348021Z", "shell.execute_reply": "2023-08-23T23:27:51.347328Z" } }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "output = vplanet.run(\"examples/CircumbinaryOrbit/vpl.in\")\n", "output" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "The variable :py:obj:`output` is an instance of :py:class:`vplanet.Output`. We can peek at its contents by accessing the :py:class:`members ` attribute:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2023-08-23T23:27:51.351057Z", "iopub.status.busy": "2023-08-23T23:27:51.350630Z", "iopub.status.idle": "2023-08-23T23:27:51.355904Z", "shell.execute_reply": "2023-08-23T23:27:51.355333Z" } }, "outputs": [ { "data": { "text/plain": [ "['sysname', 'bodies', 'log', 'path', 'primary', 'secondary', 'cbp', 'earth']" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "output.members" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "The properties :py:obj:`sysname`, :py:obj:`bodies`, and :py:obj:`path` are just strings, but :py:obj:`log` is a :py:class:`vplanet.Log` instance and the remaining four are :py:class:`vplanet.Body` instances." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## The log file" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Let's peek at :py:obj:`log`:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2023-08-23T23:27:51.358443Z", "iopub.status.busy": "2023-08-23T23:27:51.358146Z", "iopub.status.idle": "2023-08-23T23:27:51.361861Z", "shell.execute_reply": "2023-08-23T23:27:51.361309Z" } }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "log = output.log\n", "log" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Again, let's look at the :py:class:`members ` attribute:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2023-08-23T23:27:51.364710Z", "iopub.status.busy": "2023-08-23T23:27:51.364407Z", "iopub.status.idle": "2023-08-23T23:27:51.368113Z", "shell.execute_reply": "2023-08-23T23:27:51.367556Z" } }, "outputs": [ { "data": { "text/plain": [ "['sysname', 'path', 'header', 'initial', 'final']" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "log.members" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "The :py:obj:`header`, :py:obj:`initial`, and :py:obj:`final` properties are instances of :py:class:`vplanet.LogStage`, containing information about specific stages of the simulation. Let's check out everything in the header of the log file:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "execution": { "iopub.execute_input": "2023-08-23T23:27:51.370904Z", "iopub.status.busy": "2023-08-23T23:27:51.370611Z", "iopub.status.idle": "2023-08-23T23:27:51.374409Z", "shell.execute_reply": "2023-08-23T23:27:51.373946Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Executable: /usr/share/miniconda/envs/vplot/bin/vplanet\n", "Version: Unknown\n", "SystemName: kepler16\n", "PrimaryInputFile: vpl.in\n", "BodyFile1: primary.in\n", "BodyFile2: secondary.in\n", "BodyFile3: cbp.in\n", "BodyFile4: earth.in\n", "AllowFilesToBeOverwitten: True\n", "MassUnits: Grams\n", "LengthUnits: Meters\n", "TimeUnits: Seconds\n", "AngleUnits: Radians\n", "VerbosityLevel: 5\n", "CrossoverDecadeForScientificNotation: 4\n", "NumberOfDigitsAfterDecimal: 6\n", "IntegrationMethod: Runge-Kutta4\n", "Direction: Forward\n", "TimeStep: 31557600.0\n", "StopTime: 3155760000.0\n", "OutputInterval: 315576.0\n", "UseVariableTimestep: True\n", "dEta: 0.01\n", "MinimumValueOfEccAndObl: 1e-10\n" ] } ], "source": [ "for member in log.header.members:\n", " print(\"{}: {}\".format(member, getattr(log.header, member)))" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Note that all of these can, of course, be accessed as regular properties:" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "execution": { "iopub.execute_input": "2023-08-23T23:27:51.376835Z", "iopub.status.busy": "2023-08-23T23:27:51.376643Z", "iopub.status.idle": "2023-08-23T23:27:51.380265Z", "shell.execute_reply": "2023-08-23T23:27:51.379729Z" } }, "outputs": [ { "data": { "text/plain": [ "'/usr/share/miniconda/envs/vplot/bin/vplanet'" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "log.header.Executable" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Next, let's inspect the :py:obj:`initial` stage of the log file:" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "execution": { "iopub.execute_input": "2023-08-23T23:27:51.383182Z", "iopub.status.busy": "2023-08-23T23:27:51.382742Z", "iopub.status.idle": "2023-08-23T23:27:51.386539Z", "shell.execute_reply": "2023-08-23T23:27:51.385969Z" } }, "outputs": [ { "data": { "text/plain": [ "['system', 'primary', 'secondary', 'cbp', 'earth']" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "log.initial.members" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "There is one attribute per body, plus one for the system. Here's what's in :py:obj:`earth`:" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "execution": { "iopub.execute_input": "2023-08-23T23:27:51.389452Z", "iopub.status.busy": "2023-08-23T23:27:51.389012Z", "iopub.status.idle": "2023-08-23T23:27:51.394377Z", "shell.execute_reply": "2023-08-23T23:27:51.393824Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ActiveModules: BINARY\n", "ModuleBitSum: 1025\n", "Color: 0\n", "Mass: 5.972186e+24 kg\n", "Radius: 6378100.0 m\n", "RadGyra: 0.5\n", "RotAngMom: 4.416946e+33 kg m2 / sec\n", "BodyType: 0.0\n", "Density: 5495.038549 kg / m3\n", "HZLimitDryRunaway: -1.0 m\n", "HZLimRecVenus: -1.0\n", "HZLimRunaway: -1.0\n", "HZLimMoistGreenhouse: -1.0\n", "HZLimMaxGreenhouse: -1.0\n", "HZLimEarlyMars: -1.0\n", "Instellation: -1.0 kg / sec3\n", "Eccentricity: 0.009302\n", "OrbEnergy: 0.0 kg m2 / sec2\n", "MeanMotion: 1.877507e-07 1 / sec\n", "OrbPeriod: 33905420.0 sec\n", "SemiMajorAxis: 150905800000.0 m\n", "CriticalSemiMajorAxis: -1.0 m\n", "COPP: 0.0\n", "OrbAngMom: 0.0 kg m2 / sec\n", "ArgP: 3.970693 rad\n", "Inc: 0.005425 rad\n", "LongA: 3.112206 rad\n", "LongP: 0.799715 rad\n", "TotOrbEnergy: 0.0 kg m2 / sec2\n", "OrbPotEnergy: 0.0 kg m2 / sec2\n", "FreeEcc: 0.03\n", "FreeInc: 0.005381 rad\n", "LL13N0: 1.88385e-07 sec\n", "LL13K0: 1.870849e-07 sec\n", "LL13V0: 1.896763e-07 sec\n", "CBPR: 149950500000.0 m\n", "CBPZ: 0.03614 m\n", "CBPPhi: 6.253799 rad\n", "CBPRDot: -191.811805 m / sec\n", "CBPZDot: -152.682529 m / sec\n", "CBPPhiDot: 1.87673e-07 1 / sec\n", "R0: 149597900000.0 m\n", "CBPInsol: -1.0 F/F_Earth\n", "BinPriR: 8366404000.0 m\n", "BinPriPhi: 0.658853 rad\n", "BinSecR: 28406370000.0 m\n", "BinSecPhi: 3.800446 rad\n", "OutputOrder: Time[year] CBPR[au] ArgP[deg] LongA[deg] Eccentricity[] Inc[deg] LongP[deg]\n", "GridOutputOrder: None\n" ] } ], "source": [ "for member in log.initial.earth.members:\n", " print(\"{}: {}\".format(member, getattr(log.initial.earth, member)))" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "The other attributes similarly list all of the initial properties of each body (or the system)." ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Before we move on, note the type of each of these properties:" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "execution": { "iopub.execute_input": "2023-08-23T23:27:51.397029Z", "iopub.status.busy": "2023-08-23T23:27:51.396612Z", "iopub.status.idle": "2023-08-23T23:27:51.401763Z", "shell.execute_reply": "2023-08-23T23:27:51.401234Z" } }, "outputs": [ { "data": { "text/plain": [ "vplanet.quantity.VPLANETQuantity" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(log.initial.earth.Inc)" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "This isn't a regular number, but an instance of :py:class:`vplanet.Quantity`, which is a subclasss of :py:class:`astropy.units.Quantity`. These objects have numerical values (either scalars or arrays) *and* units; plus, they automatically handle unit conversions when operated on." ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "execution": { "iopub.execute_input": "2023-08-23T23:27:51.404567Z", "iopub.status.busy": "2023-08-23T23:27:51.404127Z", "iopub.status.idle": "2023-08-23T23:27:51.408668Z", "shell.execute_reply": "2023-08-23T23:27:51.408126Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.005425 rad\n", "0.31082960385847164 deg\n" ] } ], "source": [ "inc = log.initial.earth.Inc\n", "print(inc)\n", "print(inc.to(\"deg\"))" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "execution": { "iopub.execute_input": "2023-08-23T23:27:51.411275Z", "iopub.status.busy": "2023-08-23T23:27:51.410838Z", "iopub.status.idle": "2023-08-23T23:27:51.415411Z", "shell.execute_reply": "2023-08-23T23:27:51.414834Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "5.972186e+24 kg\n", "1.000003036118378 earthMass\n" ] } ], "source": [ "mass = log.initial.earth.Mass\n", "print(mass)\n", "print(mass.to(\"Mearth\"))" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Check out the `astropy documentation `_ for more information on supported units." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## The bodies" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Going back to the :py:obj:`output` object, let's inspect its :py:obj:`earth` member:" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "execution": { "iopub.execute_input": "2023-08-23T23:27:51.418047Z", "iopub.status.busy": "2023-08-23T23:27:51.417685Z", "iopub.status.idle": "2023-08-23T23:27:51.422656Z", "shell.execute_reply": "2023-08-23T23:27:51.422124Z" } }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "output.earth" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "This object contains the information of the arrays computed during the simulation, which are specified in the :py:obj:`saOutputOrder` line of the input files." ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "execution": { "iopub.execute_input": "2023-08-23T23:27:51.425147Z", "iopub.status.busy": "2023-08-23T23:27:51.424857Z", "iopub.status.idle": "2023-08-23T23:27:51.428664Z", "shell.execute_reply": "2023-08-23T23:27:51.428214Z" } }, "outputs": [ { "data": { "text/plain": [ "['name',\n", " 'infile',\n", " 'fwfile',\n", " 'bwfile',\n", " 'climfile',\n", " 'Time',\n", " 'CBPR',\n", " 'ArgP',\n", " 'LongA',\n", " 'Eccentricity',\n", " 'Inc',\n", " 'LongP']" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "output.earth.members" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Let's check out one of them:" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "execution": { "iopub.execute_input": "2023-08-23T23:27:51.430696Z", "iopub.status.busy": "2023-08-23T23:27:51.430503Z", "iopub.status.idle": "2023-08-23T23:27:51.436573Z", "shell.execute_reply": "2023-08-23T23:27:51.436026Z" } }, "outputs": [ { "data": { "text/latex": [ "$[0.310855,~0.311045,~0.311036,~\\dots,~0.310957,~0.310998,~0.311019] \\; \\mathrm{{}^{\\circ}}$" ], "text/plain": [ "" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "output.earth.Inc" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "As before, these are :py:class:`vplanet.Quantity` instances, which behave like :py:class:`numpy` arrays except they have units attached." ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "execution": { "iopub.execute_input": "2023-08-23T23:27:51.439216Z", "iopub.status.busy": "2023-08-23T23:27:51.438698Z", "iopub.status.idle": "2023-08-23T23:27:51.442869Z", "shell.execute_reply": "2023-08-23T23:27:51.442319Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[0.00542544 0.00542876 0.0054286 ... 0.00542722 0.00542794 0.00542831] rad\n" ] } ], "source": [ "print(output.earth.Inc.to(\"rad\"))" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "That's it for this tutorial! Check out the `plotting tutorial `_ for information on how to easily visualize all of these quantities." ] } ], "metadata": { "celltoolbar": "Tags", "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.8.17" } }, "nbformat": 4, "nbformat_minor": 2 }