Skip to content

Commit

Permalink
Finish Jupyter example
Browse files Browse the repository at this point in the history
  • Loading branch information
mandli committed Jun 27, 2024
1 parent 0a4008e commit ab9a8c9
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 3 deletions.
7 changes: 5 additions & 2 deletions synthetic/boundary/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ $\alpha_{\text{bc}}$
- $0 < \alpha_{\text{bc}} < 1$: Decaying value of the incoming flux
- $\alpha_{\text{bc}}=1$: zero-order extrapolation

The additional scripts `run_tests.py` and `plot_comparison.py` will run a number
of values for $\alpha_{\text{bc}}$ and plot comparisons between the gauges.
The additional scripts `run_tests.py` will run a number of values for
$\alpha_{\text{bc}}$ and plot comparisons between the gauges.

A Jupyter notebook is also provided to give examples of how to plot storms from
various data sources and look at how their extents compare with boundaries.
Empty file removed synthetic/boundary/bctools.py
Empty file.
131 changes: 130 additions & 1 deletion synthetic/boundary/boundary_storm.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,136 @@
"id": "25a8ba1d-c11f-4400-8291-964b104ceb35",
"metadata": {},
"outputs": [],
"source": []
"source": [
"%matplotlib\n",
"import os\n",
"import gzip\n",
"import datetime\n",
"\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"import clawpack.clawutil as clawutil\n",
"import clawpack.geoclaw.topotools as topotools\n",
"from clawpack.geoclaw.surge.storm import Storm"
]
},
{
"cell_type": "markdown",
"id": "97d3543a-c7b2-4720-aae9-fda72484f344",
"metadata": {},
"source": [
"# Plotting of Storm Size and Track"
]
},
{
"cell_type": "markdown",
"id": "99b6505d-dba4-48ad-bf95-8bf1f130eb66",
"metadata": {},
"source": [
"These examples illustrate how to plot the track of the synthetic storm included in this directory and an example with Hurricane Ike. These examples should be useful for deteremining distances that should prevent boundary condition problems with storm surge where the storm may get too close to the boundary."
]
},
{
"cell_type": "markdown",
"id": "102b4669-109f-4da2-9c77-a971158ceee6",
"metadata": {},
"source": [
"## Example 1: Read in synthetic storm data\n",
"Read in the synthetic storm `synthetic.storm` created in the `setrun.py` file and plot it. This example includes coloring of the track to indicate the category (intensity) of the storm. We also want this to not be in lat-long coordinates so that is also specified."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2b0a6fab-0035-42ce-bee4-c2003eb172fe",
"metadata": {},
"outputs": [],
"source": [
"storm = Storm(path=\"synthetic.storm\", file_format=\"geoclaw\")\n",
"fig, ax = plt.subplots()\n",
"storm.plot(ax, coordinate_system=1, track_style={})\n",
"ax.set_aspect('equal')\n",
"ax.set_title(\"Storm Track - Example 1\")\n",
"ax.set_xlabel(\"x (m)\")\n",
"ax.set_ylabel(\"y (m)\")\n",
"ax.set_xlim((-500e3, 500e3))\n",
"ax.set_ylim((-500e3, 500e3))"
]
},
{
"cell_type": "markdown",
"id": "555e1f1b-54a7-4e44-b6e4-ca7ec2cd29e6",
"metadata": {},
"source": [
"## Example 2: Reading output track data\n",
"This example reads in the track from the file `fort.track` that is produced while simulating the storm. This constitutes simply loading a `Storm` object with the data loaded from the file. This does not set the `storm_radius` of the storm so we explicitly draw a radius of 300 km. This example also shows how to restrict the time range via the `storm.plot` function."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4130389a-08ef-4d59-ab75-1c5c1076e1cd",
"metadata": {},
"outputs": [],
"source": [
"# Load track data\n",
"data = np.loadtxt(os.path.join(os.getcwd(), \"_output\", \"fort.track\"))\n",
"storm = Storm()\n",
"storm.t = data[:, 0]\n",
"storm.eye_location = data[:, 1:3]\n",
"\n",
"# Plot swath\n",
"fig, ax = plt.subplots()\n",
"storm.plot(ax, radius=300e3, t_range=[10, 220000])\n",
"ax.set_aspect('equal')\n",
"ax.set_title(\"Storm Track - Example 2\")\n",
"ax.set_xlabel(\"x (m)\")\n",
"ax.set_ylabel(\"y (m)\")\n",
"ax.set_xlim((-500e3, 500e3))\n",
"ax.set_ylim((-500e3, 500e3))"
]
},
{
"cell_type": "markdown",
"id": "7c25219b-4df4-46ac-b467-39d5c44957e9",
"metadata": {},
"source": [
"## Example 3: ATCF storm file\n",
"Fetch the storm file for Hurricane Ike and plot the track, intensity, and radius on a plot with topography taken from the same GeoClaw example. Here we also restrict the spatial domain to the one used in the example as well as the times used. Note that the conversion of the radius in km to lat-long is handled automatically in this case."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3196c05e-f3dd-4750-8c44-56589297a88e",
"metadata": {},
"outputs": [],
"source": [
"scratch_dir = os.path.join(os.environ[\"CLAW\"], 'geoclaw', 'scratch')\n",
"\n",
"# Topography\n",
"clawutil.data.get_remote_file(\"https://depts.washington.edu/clawpack/geoclaw/topo/gulf_caribbean.tt3.tar.bz2\")\n",
"topo = topotools.Topography(path=os.path.join(scratch_dir, 'gulf_caribbean.tt3'))\n",
"\n",
"# Storm\n",
"clawutil.data.get_remote_file(\"http://ftp.nhc.noaa.gov/atcf/archive/2008/bal092008.dat.gz\")\n",
"atcf_path = os.path.join(scratch_dir, \"bal092008.dat\")\n",
"with gzip.open(\".\".join((atcf_path, 'gz')), 'rb') as atcf_file, open(atcf_path, 'w') as atcf_unzipped_file:\n",
" atcf_unzipped_file.write(atcf_file.read().decode('ascii'))\n",
"ike = Storm(path=atcf_path, file_format=\"ATCF\")\n",
"ike.time_offset = datetime.datetime(2008, 9, 13, 7)\n",
"\n",
"# Plot\n",
"fig, ax = plt.subplots()\n",
"ax.set_aspect('equal')\n",
"topo.plot(ax)\n",
"t_range = [ike.time_offset - datetime.timedelta(3), \n",
" ike.time_offset + datetime.timedelta(1)]\n",
"ike.plot(ax, t_range=t_range, track_style={})\n",
"ax.set_xlim((-99, -70))\n",
"ax.set_ylim((8, 32))"
]
}
],
"metadata": {
Expand Down

0 comments on commit ab9a8c9

Please sign in to comment.