Skip to content

Commit

Permalink
fix animation in dtopo_triangular/CSZ_example.ipynb
Browse files Browse the repository at this point in the history
  • Loading branch information
rjleveque committed Jul 26, 2020
1 parent d39649b commit 878e315
Showing 1 changed file with 64 additions and 91 deletions.
155 changes: 64 additions & 91 deletions notebooks/geoclaw/dtopo_triangular/CSZ_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,19 @@
"This sample uses one rupture scenario extracted from `data/cascadia.001297`."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Version\n",
"\n",
"Animation revised 2020-07-26 to run with v5.7.0"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline"
Expand All @@ -34,16 +41,17 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"from clawpack.geoclaw import dtopotools\n",
"import matplotlib.pyplot as plt\n",
"from mpl_toolkits.mplot3d import Axes3D\n",
"import numpy as np\n",
"from copy import copy\n",
"import matplotlib.pyplot as pl\n",
"import os"
"from clawpack.visclaw import animation_tools\n",
"import os\n",
"from IPython.display import HTML"
]
},
{
Expand All @@ -56,9 +64,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"fault_geometry_file = './cascadia30.mshout'\n",
Expand All @@ -70,9 +76,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# read in .mshout (CSZ geoemetry)\n",
Expand All @@ -93,9 +97,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"print(cascadia[0,4:7])\n",
Expand All @@ -120,9 +122,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"fault0 = dtopotools.Fault()\n",
Expand Down Expand Up @@ -150,21 +150,16 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"from mpl_toolkits.mplot3d import Axes3D\n",
"import numpy\n",
"fig = plt.figure(figsize=(15,10))\n",
"#ax = fig.add_subplot(121, projection='3d')\n",
"ax = fig.add_axes([.05,.05,.65,.9], projection='3d')\n",
"for s in fault0.subfaults:\n",
" c = s.corners\n",
" c.append(c[0])\n",
" c = numpy.array(c)\n",
" c = np.array(c)\n",
" ax.plot(c[:,0],c[:,1],-c[:,2]/1000.,color='b')\n",
"ax.view_init(10,60)\n",
"ax.set_xlabel('Longitude')\n",
Expand All @@ -177,9 +172,9 @@
"for s in fault0.subfaults:\n",
" c = s.corners\n",
" c.append(c[0])\n",
" c = numpy.array(c)\n",
" c = np.array(c)\n",
" ax.plot(c[:,0],c[:,1], 'b')\n",
"ax.set_aspect(1./numpy.cos(45*numpy.pi/180.))\n",
"ax.set_aspect(1./np.cos(45*np.pi/180.))\n",
"ax.set_xlabel('Longitude')\n",
"ax.set_ylabel('Latitude')\n",
"ax.set_title('Plan view')"
Expand All @@ -202,9 +197,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"rupt_fname = '_cascadia.001297.rupt'\n",
Expand All @@ -222,9 +215,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"fault0 = dtopotools.Fault()\n",
Expand Down Expand Up @@ -268,9 +259,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"x,y = fault0.create_dtopo_xy(dx = 4/60.)\n",
Expand All @@ -283,9 +272,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"x.shape,y.shape, dtopo0.dZ.shape"
Expand All @@ -294,12 +281,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"fig,(ax0,ax1,ax2, ax3) = pl.subplots(ncols=4,nrows=1,figsize=(16,6))\n",
"fig,(ax0,ax1,ax2, ax3) = plt.subplots(ncols=4,nrows=1,figsize=(16,6))\n",
"fault0.plot_subfaults(axes=ax0,slip_color=True,plot_box=False);\n",
"ax0.set_title('Slip on Fault');\n",
"\n",
Expand Down Expand Up @@ -337,21 +322,19 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"pl.figure(figsize=(14,8))\n",
"pl.axes()\n",
"plt.figure(figsize=(14,8))\n",
"plt.axes()\n",
"latitudes = [s.latitude for s in fault0.subfaults]\n",
"rise_times = [s.rise_time for s in fault0.subfaults]\n",
"rupture_times = [s.rupture_time for s in fault0.subfaults]\n",
"for j,lat in enumerate(latitudes):\n",
" pl.plot([lat,lat],[rupture_times[j],rupture_times[j]+rise_times[j]],'b')\n",
"pl.xlabel('latitude')\n",
"pl.ylabel('seconds')\n",
"pl.title('rupture time + rise time of each triangle vs. latitude')"
" plt.plot([lat,lat],[rupture_times[j],rupture_times[j]+rise_times[j]],'b')\n",
"plt.xlabel('latitude')\n",
"plt.ylabel('seconds')\n",
"plt.title('rupture time + rise time of each triangle vs. latitude')"
]
},
{
Expand All @@ -366,22 +349,20 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"pl.figure(figsize=(10,9))\n",
"plt.figure(figsize=(10,9))\n",
"for kk in range(5):\n",
" pl.subplot(5,1,kk+1)\n",
" plt.subplot(5,1,kk+1)\n",
" j = 60\n",
" k = 50 + 25*kk\n",
" pl.title('dynamic deformation at fixed location (' + '{:4.2f}'.format(x[j]) \\\n",
" plt.title('dynamic deformation at fixed location (' + '{:4.2f}'.format(x[j]) \\\n",
" + ',' + '{:4.2f}'.format(y[k]) + ')' )\n",
" pl.plot(dtopo0.times,dtopo0.dZ[:,k,j]);\n",
" pl.ylabel('dZ (meters)');\n",
" pl.xlabel('time (seconds)');\n",
"pl.tight_layout()"
" plt.plot(dtopo0.times,dtopo0.dZ[:,k,j]);\n",
" plt.ylabel('dZ (meters)');\n",
" plt.xlabel('time (seconds)');\n",
"plt.tight_layout()"
]
},
{
Expand All @@ -394,9 +375,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"ruptno = rupt_fname.split('.')[1]\n",
Expand All @@ -407,9 +386,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"print('Created %s, with dynamic rupture of a Mw %.2f event' % (fname, fault0.Mw()))"
Expand All @@ -427,14 +404,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"from clawpack.visclaw.JSAnimation import IPython_display\n",
"import clawpack.visclaw.JSAnimation.JSAnimation_frametools as J\n",
"\n",
"dz_max = abs(dtopo0.dZ).max()\n",
"\n",
"# Incorporate this function in dtopotools to replace animate_dz_colors?\n",
Expand All @@ -447,15 +419,17 @@
" dtopo0.plot_dZ_colors(axes=ax2, t=t, cmax_dZ=dz_max)\n",
" return fig\n",
"\n",
"plotdir = '_plots'\n",
"J.make_plotdir(plotdir, clobber=True)\n",
"fig = pl.figure(figsize=(12,5))\n",
"\n",
"for k,t in enumerate(dtopo0.times[::10]):\n",
" plot_subfaults_dZ(t,fig)\n",
" J.save_frame(k, verbose=False)\n",
"figs = []\n",
"times = dtopo0.times[::5] # only use every 5th time for animation\n",
"if dtopo0.times[-1] not in times:\n",
" times = np.hstack((times, dtopo0.times[-1])) # include final dz\n",
" \n",
"pl.close(fig)"
"print('Animation will include %i times' % len(times))\n",
"for k,t in enumerate(times):\n",
" fig = plt.figure(figsize=(12,5))\n",
" plot_subfaults_dZ(t,fig)\n",
" figs.append(fig)\n",
" plt.close(fig)"
]
},
{
Expand All @@ -464,18 +438,17 @@
"metadata": {},
"outputs": [],
"source": [
"anim = J.make_anim(plotdir)\n",
"anim"
"anim = animation_tools.animate_figs(figs, figsize=(12,6))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": []
"source": [
"HTML(anim.to_jshtml())"
]
}
],
"metadata": {
Expand All @@ -494,7 +467,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.2"
"version": "3.6.10"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 878e315

Please sign in to comment.