{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Produce the figures for the numerical results"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This IPython notebook produces the error x distance-size ratio figures for the section \"Evaluation of the accuracy\" of the article.\n",
"\n",
"The data was calculated by the `tesseroid_vs_spherical_shell.ipynb` notebook and saved to CSV files in the `data` directory of the main repository."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Load the required libraries and set the plot defaults"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We'll use the pandas library to load and manipulate the data. Plots will be made with matplotlib."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline\n",
"from __future__ import division\n",
"from IPython.display import set_matplotlib_formats\n",
"set_matplotlib_formats('svg')\n",
"import pandas as pd\n",
"import numpy as np\n",
"from matplotlib import pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"plt.rcParams['axes.labelsize'] = 9.0 # fontsize of the x any y labels\n",
"plt.rcParams['xtick.labelsize'] = 9.0 # fontsize of the tick labels\n",
"plt.rcParams['ytick.labelsize'] = 9.0 # fontsize of the tick labels\n",
"plt.rcParams['legend.fontsize'] = 9.0\n",
"plt.rcParams['font.family'] = 'serif'\n",
"plt.rcParams['font.serif'] = 'Computer Modern Roman'\n",
"plt.rcParams['text.usetex'] = True # use latex for all text handling\n",
"plt.rcParams['text.color'] = '3a3a3a'\n",
"plt.rcParams['figure.facecolor'] = 'white'\n",
"plt.rcParams['axes.linewidth'] = 1\n",
"plt.rcParams['axes.edgecolor'] = '3a3a3a'\n",
"plt.rcParams['axes.facecolor'] = 'white'\n",
"plt.rcParams['lines.linewidth'] = 1\n",
"plt.rcParams['lines.markersize'] = 4\n",
"plt.rcParams['xtick.major.size'] = 2\n",
"plt.rcParams['ytick.major.size'] = 2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Load the spherical shell data"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And load the computed shell effect per height so that we can calculate the relative difference."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"shell = pd.read_csv('../data/shell-per-height.csv', index_col=0)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"
\n",
" \n",
" \n",
" | \n",
" gx | \n",
" gxx | \n",
" gxy | \n",
" gxz | \n",
" gy | \n",
" gyy | \n",
" gyz | \n",
" gz | \n",
" gzz | \n",
" pot | \n",
" height | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 0 | \n",
" -0.350758 | \n",
" 0 | \n",
" 0 | \n",
" 0 | \n",
" -0.350758 | \n",
" 0 | \n",
" 223.788630 | \n",
" 0.701517 | \n",
" 14278.021191 | \n",
" 2000 | \n",
"
\n",
" \n",
" 1 | \n",
" 0 | \n",
" -0.349442 | \n",
" 0 | \n",
" 0 | \n",
" 0 | \n",
" -0.349442 | \n",
" 0 | \n",
" 223.228471 | \n",
" 0.698884 | \n",
" 14260.140521 | \n",
" 10000 | \n",
"
\n",
" \n",
" 2 | \n",
" 0 | \n",
" -0.342959 | \n",
" 0 | \n",
" 0 | \n",
" 0 | \n",
" -0.342959 | \n",
" 0 | \n",
" 220.458972 | \n",
" 0.685919 | \n",
" 14171.404761 | \n",
" 50000 | \n",
"
\n",
" \n",
" 3 | \n",
" 0 | \n",
" -0.327439 | \n",
" 0 | \n",
" 0 | \n",
" 0 | \n",
" -0.327439 | \n",
" 0 | \n",
" 213.756587 | \n",
" 0.654878 | \n",
" 13954.322847 | \n",
" 150000 | \n",
"
\n",
" \n",
" 4 | \n",
" 0 | \n",
" -0.311429 | \n",
" 0 | \n",
" 0 | \n",
" 0 | \n",
" -0.311429 | \n",
" 0 | \n",
" 206.730999 | \n",
" 0.622858 | \n",
" 13723.086957 | \n",
" 260000 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" gx gxx gxy gxz gy gyy gyz gz gzz \\\n",
"0 0 -0.350758 0 0 0 -0.350758 0 223.788630 0.701517 \n",
"1 0 -0.349442 0 0 0 -0.349442 0 223.228471 0.698884 \n",
"2 0 -0.342959 0 0 0 -0.342959 0 220.458972 0.685919 \n",
"3 0 -0.327439 0 0 0 -0.327439 0 213.756587 0.654878 \n",
"4 0 -0.311429 0 0 0 -0.311429 0 206.730999 0.622858 \n",
"\n",
" pot height \n",
"0 14278.021191 2000 \n",
"1 14260.140521 10000 \n",
"2 14171.404761 50000 \n",
"3 13954.322847 150000 \n",
"4 13723.086957 260000 "
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"shell"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Plot the error vs distance-size ratio for the 4 experiments"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Load the computed differences between the shell and tesseroid effects for each experiment.\n",
"We'll use the `groupby` method of the *pandas* `DataFrame` to compute the maximum absolute difference per distance-size ratio and keep that."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def load_max_diff(fname):\n",
" data = pd.read_csv(fname)\n",
" return data.groupby(['size', 'ratio']).max()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"pole = load_max_diff('../data/difference-size-1-height-2000-pole.csv')\n",
"equator = load_max_diff('../data/difference-size-1-height-2000-equator.csv')\n",
"goce = load_max_diff('../data/difference-size-1-height-260000-pole.csv')\n",
"big = load_max_diff('../data/difference-size-30-height-2000-pole.csv')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This is what the data looks like after taking the maximum difference per ratio."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"
\n",
" \n",
" \n",
" | \n",
" | \n",
" point | \n",
" gx | \n",
" gxx | \n",
" gxy | \n",
" gxz | \n",
" gy | \n",
" gyy | \n",
" gyz | \n",
" gz | \n",
" gzz | \n",
" pot | \n",
"
\n",
" \n",
" size | \n",
" ratio | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" 1 | \n",
" 0.0 | \n",
" 99 | \n",
" 769.086112 | \n",
" 854.704698 | \n",
" 26.822236 | \n",
" 5372.013197 | \n",
" 0.876313 | \n",
" 311.835644 | \n",
" 27.800405 | \n",
" 686.281514 | \n",
" 782.758707 | \n",
" 33.533012 | \n",
"
\n",
" \n",
" 0.5 | \n",
" 199 | \n",
" 11.215857 | \n",
" 85.182630 | \n",
" 21.765414 | \n",
" 45.271905 | \n",
" 1.271564 | \n",
" 64.388814 | \n",
" 13.539341 | \n",
" 99.543785 | \n",
" 128.777627 | \n",
" 6.633058 | \n",
"
\n",
" \n",
" 1.0 | \n",
" 299 | \n",
" 0.463330 | \n",
" 19.514930 | \n",
" 2.203664 | \n",
" 13.430373 | \n",
" 0.236333 | \n",
" 12.838965 | \n",
" 8.384167 | \n",
" 1.027770 | \n",
" 32.012723 | \n",
" 0.074944 | \n",
"
\n",
" \n",
" 1.5 | \n",
" 399 | \n",
" 0.070450 | \n",
" 1.144707 | \n",
" 0.209287 | \n",
" 0.557937 | \n",
" 0.031353 | \n",
" 1.392990 | \n",
" 0.662468 | \n",
" 0.203132 | \n",
" 2.289414 | \n",
" 0.023323 | \n",
"
\n",
" \n",
" 2.0 | \n",
" 499 | \n",
" 0.022737 | \n",
" 0.149761 | \n",
" 0.024231 | \n",
" 0.120548 | \n",
" 0.005499 | \n",
" 0.208828 | \n",
" 0.123601 | \n",
" 0.020666 | \n",
" 0.283195 | \n",
" 0.007042 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" point gx gxx gxy gxz gy \\\n",
"size ratio \n",
"1 0.0 99 769.086112 854.704698 26.822236 5372.013197 0.876313 \n",
" 0.5 199 11.215857 85.182630 21.765414 45.271905 1.271564 \n",
" 1.0 299 0.463330 19.514930 2.203664 13.430373 0.236333 \n",
" 1.5 399 0.070450 1.144707 0.209287 0.557937 0.031353 \n",
" 2.0 499 0.022737 0.149761 0.024231 0.120548 0.005499 \n",
"\n",
" gyy gyz gz gzz pot \n",
"size ratio \n",
"1 0.0 311.835644 27.800405 686.281514 782.758707 33.533012 \n",
" 0.5 64.388814 13.539341 99.543785 128.777627 6.633058 \n",
" 1.0 12.838965 8.384167 1.027770 32.012723 0.074944 \n",
" 1.5 1.392990 0.662468 0.203132 2.289414 0.023323 \n",
" 2.0 0.208828 0.123601 0.020666 0.283195 0.007042 "
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pole.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Make a plot of the maximum relative difference as a function of the distance-size ratio used in the computations."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"ratio = pole.index.levels[1] # Get the unique values of the distance-size ratio used"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plotargs = dict(color='#3a3a3a', markeredgewidth=0.5, markeredgecolor='#3a3a3a')\n",
"styles = \"-s -^ -v -o\".split()\n",
"fig, subplots = plt.subplots(3, 1, figsize=(3.33, 5), sharex='col')\n",
"axes = subplots.ravel()\n",
"fields = ['pot', 'gz', 'gzz']\n",
"titles = [r'V', r'gz', r'gzz']\n",
"subfigure = ['(a)', '(b)', '(c)']\n",
"for ax, f, title, sub in zip(axes, fields, titles, subfigure):\n",
" ax.text(-0.21, 0.9, sub, fontsize=12, fontdict={'weight': 'bold'},\n",
" transform=ax.transAxes)\n",
" ax.text(0.5, 0.9, title, fontsize=11, \n",
" horizontalalignment='center', verticalalignment='center',\n",
" bbox={'facecolor': 'w', \n",
" 'edgecolor': '#9b9b9b',\n",
" 'linewidth': 0.5, 'pad': 8}, \n",
" transform=ax.transAxes)\n",
" shell_low = np.abs(shell[shell.height == 2000][f].values)\n",
" shell_high = np.abs(shell[shell.height == 260000][f].values)\n",
" ax.plot(ratio, 100*pole[f]/shell_low, styles[0], label='pole', \n",
" **plotargs)\n",
" ax.plot(ratio, 100*equator[f]/shell_low, styles[1], label='equator', \n",
" **plotargs)\n",
" ax.plot(ratio, 100*goce[f]/shell_high, styles[2], label='260 km', \n",
" **plotargs)\n",
" ax.plot(ratio, 100*big[f]/shell_low, styles[3], label=r'$30^\\circ$ size', \n",
" **plotargs)\n",
" ax.hlines(0.1, ratio.min(), ratio.max(), colors=['#3a3a3a'], linewidth=1.5) \n",
" ax.set_xlim(ratio.min(), ratio.max())\n",
" ax.set_yscale('log')\n",
" ax.set_xticks(range(11))\n",
" ax.set_yticks(ax.get_yticks()[2:-2])\n",
" ax.set_ylabel('Difference (\\\\%)')\n",
" ax.grid(True, linewidth=0.5, color='#aeaeae')\n",
" ax.set_axisbelow(True)\n",
" ax.minorticks_off()\n",
"ax = axes[-1]\n",
"ax.set_xlabel('Distance-size ratio')\n",
"ax.legend(borderpad=0.5, numpoints=1, bbox_to_anchor=(1, 1), \n",
" fancybox=True, shadow=False, fontsize=9, )\n",
"plt.tight_layout(pad=0.3, h_pad=0, w_pad=0)\n",
"plt.subplots_adjust(hspace=0, wspace=0)\n",
"plt.savefig('../figs/distance-size-curves.eps') # Save the figure to an EPS"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Plot the error curves for gzz for various heights"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Load the data for the gzz difference per height. I'll use the pre-loaded spherical shell data to calculate the relative difference."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"gzz = pd.read_csv('../data/difference-gzz-per-height-size-1-pole.csv', \n",
" index_col=0).groupby(['height', 'ratio']).max()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This is what the first few lines of the data look like."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"
\n",
" \n",
" \n",
" | \n",
" | \n",
" gzz | \n",
"
\n",
" \n",
" height | \n",
" ratio | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" 2000 | \n",
" 0.0 | \n",
" 782.758707 | \n",
"
\n",
" \n",
" 0.5 | \n",
" 128.777627 | \n",
"
\n",
" \n",
" 1.0 | \n",
" 32.012723 | \n",
"
\n",
" \n",
" 1.5 | \n",
" 2.289414 | \n",
"
\n",
" \n",
" 2.0 | \n",
" 0.283195 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" gzz\n",
"height ratio \n",
"2000 0.0 782.758707\n",
" 0.5 128.777627\n",
" 1.0 32.012723\n",
" 1.5 2.289414\n",
" 2.0 0.283195"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gzz.head()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"heights = gzz.index.levels[0].values # Get the unique values of the computation height"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([ 2000., 10000., 50000., 150000., 260000.])"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"heights"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we'll make the difference x ratio plot with a curve for each height."
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"color = '#3a3a3a'\n",
"styles = \"-s -^ -v -o -*\".split()\n",
"fig = plt.figure(figsize=(3.33, 3))\n",
"ax = plt.subplot(111)\n",
"for h, sty in zip(heights, styles):\n",
" shell_value = np.abs(shell[shell.height == h]['gzz'].values)\n",
" diff = 100*gzz.loc[int(h)]/shell_value\n",
" markersize = 4\n",
" if sty[-1] == '*':\n",
" markersize = 7\n",
" ax.plot(ratio, diff, sty, label='{:.0f} km'.format(h/1000), color=color, \n",
" markeredgewidth=0.5, markeredgecolor=color, markersize=markersize)\n",
"ax.hlines(0.1, ratio.min(), ratio.max(), colors=['#3a3a3a'], linewidth=1.5) \n",
"ax.set_xlim(ratio.min(), ratio.max())\n",
"ax.set_yscale('log')\n",
"ax.set_xticks(range(11))\n",
"ax.set_yticks(ax.get_yticks())\n",
"ax.minorticks_off()\n",
"ax.grid(True, linewidth=0.5, color='#aeaeae')\n",
"ax.set_axisbelow(True)\n",
"ax.set_ylabel('Difference (\\\\%)')\n",
"ax.set_xlabel('Distance-size ratio')\n",
"ax.legend(borderpad=0.5, numpoints=1, bbox_to_anchor=(1, 1), \n",
" fancybox=True, shadow=False, fontsize=9, )\n",
"plt.tight_layout(pad=0.25, h_pad=0, w_pad=0)\n",
"plt.subplots_adjust(hspace=0, wspace=0)\n",
"plt.savefig('../figs/gzz-with-height.eps') # Save the figure to an EPS"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.10"
}
},
"nbformat": 4,
"nbformat_minor": 0
}