{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# 3D Animation\n\nExample of creating a 3D animation of the Cox et al. (2013) torsional\noscillations.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\nimport scipy.interpolate\nimport matplotlib.pyplot as plt\nimport sys\nsys.path.append('../') #So taco_vis.py is visible to import\n\nfrom taco_vis import FLOW"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Read in Cox et al. (2013) dataset\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "data_file = \"../cox_etal_2013.txt\"  # Data file\ndata = np.genfromtxt(data_file, delimiter=\",\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Regrid the data down (too high resolution to be practically plotted as is)\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "r, t = np.linspace(0, 1, data.shape[0]), np.linspace(0, 1, data.shape[1])\ntime, radius = np.linspace(0, 1, 2000), np.linspace(0, 1, 16)\n\nfunc = scipy.interpolate.RectBivariateSpline(r, t, data)\nu = func(radius, time)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Initialise FLOW class\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "f = FLOW(u)\n\n# Up the speed of texture advection\nf.speed = 5\n\nf.time = np.linspace(0, 20, time.size)\nf.title = \"%.2f years\"\nf.colorbar_title = \"Velocity\\n(dimensionless)\""
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Animate\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "f.plot_cylinders_3D(animate=True)"
      ]
    }
  ],
  "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.9"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}