{ "cells": [ { "cell_type": "markdown", "id": "e8ec02c1-fd58-46b6-9211-e3ac1b36a2fd", "metadata": {}, "source": [ "# Studying a specific cyclone\n", "In this example, we want to study hurricane Wilma (the deepest Atlantic hurricane on record)." ] }, { "cell_type": "code", "execution_count": null, "id": "98f00647-d338-4bea-b551-511758fa39c2", "metadata": {}, "outputs": [], "source": [ "import huracanpy\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "markdown", "id": "b458a5ab-e8dc-4a94-9a9d-51078981e617", "metadata": {}, "source": [ "## Load IBTrACS and subset the specific hurricane\n", "Two subsets of IBTrACS are embedded within HuracanPy: WMO and JTWC.\n", "Default behavior is loading the embedded WMO subset.\n", "You can also retrieve the full and latest IBTrACS files by specifying a different subset.\n", "For more information, see the [huracanpy.load guide](../load.ipynb).\n", "\n", "The tracks are loaded as an xarray.Dataset, with one dimension \"record\" corresponding to each point.\n", "Variables indicate position in space and time, as well as additional attributes such as maximum wind speed and minimum sea-level pressure (SLP)." ] }, { "cell_type": "code", "execution_count": null, "id": "999c3ab4-a444-4b4a-bbe6-c36c9b19fade", "metadata": {}, "outputs": [], "source": [ "# Here we load the WMO subset. This raises a warning that reminds you of the main\n", "# caveats.\n", "ib = huracanpy.load(source=\"ibtracs\")\n", "ib" ] }, { "cell_type": "markdown", "id": "80573172-49c6-435f-aad0-3063acce521c", "metadata": {}, "source": [ "Wilma corresponds to index 2005289N18282, so we subset this storm. There are two ways of doing this:\n", "\n", "1. Use `xarray`'s where" ] }, { "cell_type": "code", "execution_count": null, "id": "a0bd8d77-7139-47bc-9473-1f6725ff922e", "metadata": {}, "outputs": [], "source": [ "wilma = ib.where(ib.track_id == \"2005289N18282\", drop=True)" ] }, { "cell_type": "markdown", "id": "e7051a6d-1599-4162-a97b-0f9be0c14d6d", "metadata": {}, "source": [ "2. Use huracanpy's sel_id method (more efficient and shorter, but does the same thing)\n", "\n", "Note: the `.hrcn` is called an accessor, and allows you to call HuracanPy functions as methods on the xarray objects." ] }, { "cell_type": "code", "execution_count": null, "id": "9caf83ea-1a97-4cb4-bf4a-8aceac9eb5b9", "metadata": {}, "outputs": [], "source": [ "wilma = ib.hrcn.sel_id(\"2005289N18282\")\n", "# The Wilma object contains only the data for Wilma:\n", "wilma" ] }, { "cell_type": "markdown", "id": "ee08d4f1-e18f-4820-810d-0005b92f9105", "metadata": {}, "source": [ "## Add category info\n", "You can add the Saffir-Simpson and/or the pressure category of Wilma to the tracks (for full list of available info, see [huracanpy.info](../../api/info.rst)).\n", "\n", "### Add Saffir-Simpson Category\n", "This is stored in the `saffir_simpson_category` variable" ] }, { "cell_type": "code", "execution_count": null, "id": "99f5e05f-77f1-48af-85e4-e4dbeea3ea7c", "metadata": {}, "outputs": [], "source": [ "wilma = wilma.hrcn.add_saffir_simpson_category(wind_name=\"wind\", wind_units=\"knots\")\n", "wilma.saffir_simpson_category" ] }, { "cell_type": "markdown", "id": "2da6db0d-4f24-4836-9a05-7b3e268c28f4", "metadata": {}, "source": [ "### Add pressure category" ] }, { "cell_type": "code", "execution_count": null, "id": "59c13d3d-bdaf-4f32-a2b8-e9fb9912c7a8", "metadata": {}, "outputs": [], "source": [ "wilma = wilma.hrcn.add_pressure_category(slp_name=\"slp\")\n", "wilma.pressure_category" ] }, { "cell_type": "markdown", "id": "aa68ca18-eb4a-4ce5-8c7e-b2263292926d", "metadata": {}, "source": [ "Note: Most of the accessor methods have a `get_` and an `add_` version.\n", "`get_` returns the values of what you ask for as a DataArray, while `add_` adds it directly to the dataset with a default name.\n", "In the previous case, we could have called get_pressure_category and then save it as a variable, and potentially add it to the dataset separately" ] }, { "cell_type": "code", "execution_count": null, "id": "f8e42735-daac-4a59-9d3e-92db5a6b46e5", "metadata": {}, "outputs": [], "source": [ "wilma.hrcn.get_pressure_category(slp_name=\"slp\")" ] }, { "cell_type": "markdown", "id": "58a151fe-4f12-48f9-8f7b-92e8e3eda692", "metadata": {}, "source": [ "## Plot the track and its evolution\n", "### Plot the track on a map, colored by Saffir-Simpson category" ] }, { "cell_type": "code", "execution_count": null, "id": "f3a5cca2-4899-487e-abea-1244ea1aa4b2", "metadata": {}, "outputs": [], "source": [ "wilma.hrcn.plot_tracks(\n", " intensity_var_name=\"saffir_simpson_category\", scatter_kws={\"palette\": \"turbo\"}\n", ")" ] }, { "cell_type": "markdown", "id": "ad157c6f-3bc0-4c6f-a41e-a27916b2348f", "metadata": {}, "source": [ "### Plot intensity time series using matplotlib" ] }, { "cell_type": "code", "execution_count": null, "id": "318f54d6-f974-4ca1-8876-1b46978a0043", "metadata": {}, "outputs": [], "source": [ "fig, axs = plt.subplots(2, sharex=True)\n", "axs[0].plot(wilma.time, wilma.wind)\n", "axs[1].plot(wilma.time, wilma.slp)\n", "axs[0].set_ylabel(\"Wind / kn\")\n", "axs[1].set_ylabel(\"SLP / hPa\")" ] }, { "cell_type": "markdown", "id": "997d6782-d0ea-4274-98d9-bd1930a259c4", "metadata": {}, "source": [ "## Calculate properties " ] }, { "cell_type": "markdown", "id": "fcdec2df-6d47-4b3c-9c94-ee6d7237694c", "metadata": {}, "source": [ "### Duration\n", "Note duration is in hours" ] }, { "cell_type": "code", "execution_count": null, "id": "fe2d0d35-2782-4080-b0e9-acc67a3c5d70", "metadata": {}, "outputs": [], "source": [ "wilma.hrcn.get_track_duration()" ] }, { "cell_type": "markdown", "id": "98b4cd18-d260-491b-96ed-061991d1c141", "metadata": {}, "source": [ "### ACE\n", "Accumulated cyclone energy (ACE) is a commonly used measure of cyclone activity that combines the energy and duration of cyclones.\n", "\n", "#### Compute ACE for each point" ] }, { "cell_type": "code", "execution_count": null, "id": "60aafd0b-1f7f-46e2-bdec-933c44d60863", "metadata": {}, "outputs": [], "source": [ "wilma = wilma.hrcn.add_ace(wind_units=\"knots\")\n", "wilma.ace" ] }, { "cell_type": "markdown", "id": "6465b829-01ce-4b76-b5c2-ddb20ab2be96", "metadata": {}, "source": [ "#### Plot cumulated ACE" ] }, { "cell_type": "code", "execution_count": null, "id": "b06d515b-c77c-4296-81d3-28e86ec38816", "metadata": {}, "outputs": [], "source": [ "plt.plot(wilma.time, wilma.ace.cumsum())" ] }, { "cell_type": "markdown", "id": "0362378e-149e-4e02-975a-7e123399ff51", "metadata": {}, "source": [ "### Translation speed\n", "#### Compute translation speed" ] }, { "cell_type": "code", "execution_count": null, "id": "f14bb6ea-a99a-4b57-b395-eae4f75ceb82", "metadata": {}, "outputs": [], "source": [ "wilma = wilma.hrcn.add_translation_speed()" ] }, { "cell_type": "markdown", "id": "b8eb3b9a-6035-40b3-a3b0-b4d9db808dca", "metadata": {}, "source": [ "#### Plot translation speed against latitude" ] }, { "cell_type": "code", "execution_count": null, "id": "c75c6603-548c-441b-ac7b-242c993e33f8", "metadata": {}, "outputs": [], "source": [ "plt.plot(wilma.lat, wilma.translation_speed)\n", "plt.xlabel(\"Latitude / °\")\n", "plt.ylabel(\"Translation speed / m/s\")" ] }, { "cell_type": "markdown", "id": "4eee8b7e-7b71-4528-b411-4b91db62ead5", "metadata": {}, "source": [ "### Intensification rate\n", "#### Add intensification rate in wind and pressure\n", "NB: The rates will be in unit/s, where unit is the unit of the variable." ] }, { "cell_type": "code", "execution_count": null, "id": "0ea0f5ef-d7f4-4a69-b37e-b7a437713c79", "metadata": {}, "outputs": [], "source": [ "wilma = wilma.hrcn.add_rate(var_name=\"wind\")\n", "wilma = wilma.hrcn.add_rate(var_name=\"slp\")" ] }, { "cell_type": "markdown", "id": "4455d2c7-0b8a-49b3-a2c5-eb492d61e664", "metadata": {}, "source": [ "#### Plot intensity time series" ] }, { "cell_type": "code", "execution_count": null, "id": "2baf0771-a278-4b93-ad1c-81ec83eabcbd", "metadata": {}, "outputs": [], "source": [ "fig, axs = plt.subplots(2, sharex=True)\n", "# Convert to kn/h and hPa/h\n", "axs[0].plot(wilma.time, wilma.rate_wind * 3600)\n", "axs[1].plot(wilma.time, wilma.rate_slp * 3600)\n", "axs[0].set_ylabel(\"kn/h\")\n", "axs[1].set_ylabel(\"hPa/h\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.12.4" } }, "nbformat": 4, "nbformat_minor": 5 }