{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# The `auto_plot` function" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2023-08-23T23:27:40.947454Z", "iopub.status.busy": "2023-08-23T23:27:40.947089Z", "iopub.status.idle": "2023-08-23T23:27:41.324777Z", "shell.execute_reply": "2023-08-23T23:27:41.324140Z" }, "tags": [ "hide_input" ] }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/tmp/ipykernel_5324/1180289843.py:5: DeprecationWarning: `set_matplotlib_formats` is deprecated since IPython 7.23, directly use `matplotlib_inline.backend_inline.set_matplotlib_formats()`\n", " set_matplotlib_formats('retina')\n" ] } ], "source": [ "%matplotlib inline\n", "\n", "from IPython.display import set_matplotlib_formats\n", "\n", "set_matplotlib_formats('retina')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Overview" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "The easiest way to plot stuff with :py:obj:`vplot` is using the :py:class:`vplot.auto_plot` function. Given a path to a directory containing a :py:obj:`vplanet` run, :py:class:`vplot.auto_plot` will parse the output and generate plots of all of the simulated quantities as a function of time for all of the bodies." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2023-08-23T23:27:41.328026Z", "iopub.status.busy": "2023-08-23T23:27:41.327498Z", "iopub.status.idle": "2023-08-23T23:27:41.334471Z", "shell.execute_reply": "2023-08-23T23:27:41.333939Z" }, "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:`vplot.auto_plot` on the :download:`CircumbinaryOrbit ` example." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2023-08-23T23:27:41.336925Z", "iopub.status.busy": "2023-08-23T23:27:41.336628Z", "iopub.status.idle": "2023-08-23T23:27:41.520984Z", "shell.execute_reply": "2023-08-23T23:27:41.520368Z" } }, "outputs": [], "source": [ "import vplot" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "When we call :py:class:`vplot.auto_plot`, we pass the directory to the :py:obj:`vplanet` run:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2023-08-23T23:27:41.524129Z", "iopub.status.busy": "2023-08-23T23:27:41.523709Z", "iopub.status.idle": "2023-08-23T23:27:43.756030Z", "shell.execute_reply": "2023-08-23T23:27:43.755331Z" }, "replace_input": "vpl.auto_plot(\"examples/CircumbinaryOrbit\")" }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "WARNING: AstropyDeprecationWarning: support for accessing str attributes such as 'title' from PhysicalType instances is deprecated since 4.3 and will be removed in a subsequent release. [astropy.units.physical]\n" ] }, { "data": { "text/html": [ "\n", " \n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "vpl.auto_plot(\"examples/CircumbinaryOrbit\")" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ ".. note::\n", " You must actually run :py:obj:`vplanet` before calling :py:obj:`vplot`!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "By default, parameters are grouped by *parameter name*. This means that if there are multiple bodies with the same parameter, they will all show up in the same plot, with labels indicating the body they correspond to. We can disable grouping by running" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2023-08-23T23:27:43.772734Z", "iopub.status.busy": "2023-08-23T23:27:43.771326Z", "iopub.status.idle": "2023-08-23T23:27:46.083466Z", "shell.execute_reply": "2023-08-23T23:27:46.082893Z" }, "replace_input": "vpl.auto_plot(\"examples/CircumbinaryOrbit\", group=\"none\")" }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "WARNING: AstropyDeprecationWarning: support for accessing str attributes such as 'title' from PhysicalType instances is deprecated since 4.3 and will be removed in a subsequent release. [astropy.units.physical]\n" ] }, { "data": { "text/html": [ "\n", " \n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "vpl.auto_plot(\"examples/CircumbinaryOrbit\", group=\"none\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Alternatively, we can group by *physical type*. This means that everything that is an angle will be grouped into one plot, everything that has units of distance will be grouped into a different plot, and so forth. It isn't always useful, particularly if you have *lots* of parameters of the same physical type (as is the case here)." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2023-08-23T23:27:46.108220Z", "iopub.status.busy": "2023-08-23T23:27:46.107714Z", "iopub.status.idle": "2023-08-23T23:27:47.072450Z", "shell.execute_reply": "2023-08-23T23:27:47.071897Z" }, "replace_input": "vpl.auto_plot(\"examples/CircumbinaryOrbit\", group=\"type\")" }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "WARNING: AstropyDeprecationWarning: support for accessing str attributes such as 'title' from PhysicalType instances is deprecated since 4.3 and will be removed in a subsequent release. [astropy.units.physical]\n" ] }, { "data": { "text/html": [ "\n", " \n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "vpl.auto_plot(\"examples/CircumbinaryOrbit\", group=\"type\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Useful options" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can plot only specific parameters:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2023-08-23T23:27:47.080358Z", "iopub.status.busy": "2023-08-23T23:27:47.079916Z", "iopub.status.idle": "2023-08-23T23:27:47.639260Z", "shell.execute_reply": "2023-08-23T23:27:47.638611Z" }, "replace_input": "vpl.auto_plot(\"examples/CircumbinaryOrbit\", params=[\"eccentricity\", \"CBPR\"])" }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "WARNING: AstropyDeprecationWarning: support for accessing str attributes such as 'title' from PhysicalType instances is deprecated since 4.3 and will be removed in a subsequent release. [astropy.units.physical]\n" ] }, { "data": { "text/html": [ "\n", " \n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "vpl.auto_plot(\"examples/CircumbinaryOrbit\", params=[\"eccentricity\", \"CBPR\"])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And we can plot only specific bodies:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "execution": { "iopub.execute_input": "2023-08-23T23:27:47.645930Z", "iopub.status.busy": "2023-08-23T23:27:47.645387Z", "iopub.status.idle": "2023-08-23T23:27:48.144445Z", "shell.execute_reply": "2023-08-23T23:27:48.143894Z" }, "replace_input": "vpl.auto_plot(\"examples/CircumbinaryOrbit\", params=[\"eccentricity\", \"CBPR\"], bodies=\"earth\")" }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "WARNING: AstropyDeprecationWarning: support for accessing str attributes such as 'title' from PhysicalType instances is deprecated since 4.3 and will be removed in a subsequent release. [astropy.units.physical]\n" ] }, { "data": { "text/html": [ "\n", " \n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "vpl.auto_plot(\"examples/CircumbinaryOrbit\", params=[\"eccentricity\", \"CBPR\"], bodies=\"earth\")" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ ".. note::\n", " Body and parameter names are case-insensitive, but otherwise \n", " they must match the values in the ``.in`` files exactly.\n", " Note that the parameter names are those specified in the\n", " ``saOutputOrder`` line of the ``.in`` files." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can also plot things logarithmically:" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "execution": { "iopub.execute_input": "2023-08-23T23:27:48.148444Z", "iopub.status.busy": "2023-08-23T23:27:48.148014Z", "iopub.status.idle": "2023-08-23T23:27:48.895535Z", "shell.execute_reply": "2023-08-23T23:27:48.894860Z" }, "replace_input": "vpl.auto_plot(\"examples/CircumbinaryOrbit\", params=[\"eccentricity\", \"CBPR\"], bodies=\"earth\", xlog=True, ylog=False)" }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "WARNING: AstropyDeprecationWarning: support for accessing str attributes such as 'title' from PhysicalType instances is deprecated since 4.3 and will be removed in a subsequent release. [astropy.units.physical]\n" ] }, { "data": { "text/html": [ "\n", " \n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "vpl.auto_plot(\"examples/CircumbinaryOrbit\", params=[\"eccentricity\", \"CBPR\"], bodies=\"earth\", xlog=True, ylog=False)" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Finally, note that :py:class:`vplot.auto_plot` also accepts any keyword arguments accepted by :py:class:`vplot.VPLOTFigure` and :py:class:`matplotlib.figure.Figure`, such as ``figsize`` and ``dpi``." ] } ], "metadata": { "celltoolbar": "Edit 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.8.17" } }, "nbformat": 4, "nbformat_minor": 2 }