{ "cells": [ { "cell_type": "markdown", "id": "36c7416c-854a-43ca-b373-4de8fd3e16cb", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "# Getting Started\n", "## Opening files\n", "The first step is to load in some tracks. HuracanPy can load track data from various sources as an [xarray.Dataset](https://docs.xarray.dev/en/stable/generated/xarray.Dataset.html) with a minimal number of assumed variables (track_id, lon, lat, time) e.g." ] }, { "cell_type": "code", "execution_count": null, "id": "5b1565ee-4e86-4053-ad73-0a7557b3e6cd", "metadata": {}, "outputs": [], "source": [ "import huracanpy\n", "\n", "tracks = huracanpy.load(huracanpy.example_csv_file)\n", "print(tracks)" ] }, { "cell_type": "markdown", "id": "e2becf5e-9b2b-4c61-a193-901e90e7815b", "metadata": {}, "source": [ "Each \"record\" corresponds to a TC point (time, lon, lat).\n", "\n", "Note that the data is one dimensional but represents multiple tracks.\n", "This is done rather than having track_id as an additional dimension to avoid having to add blank data to each track when they are not the same length.\n", "The `groupby` function, built in to xarray, allows us to easily loop over tracks in this format." ] }, { "cell_type": "code", "execution_count": null, "id": "960e9a7d-0cf2-4797-a297-c048eb739327", "metadata": {}, "outputs": [], "source": [ "# Iterating over all tracks\n", "# Each track will be a subset of the xarray Dataset with a unique track_id\n", "# The track_id is not necessarily an integer, it follows whatever you have loaded\n", "# e.g. could be a string for IBTrACS\n", "for track_id, track in tracks.groupby(\"track_id\"):\n", " # Do something with the track\n", " print(track_id, len(track.time))" ] }, { "cell_type": "markdown", "id": "8d0954cb-ca6b-4a49-872f-b7fd6a351f82", "metadata": {}, "source": [ "With the data loaded, we can apply the functions from HuracanPy. The example below is\n", "using the `hrcn` accessor from HuracanPy. See the [accessor](accessor.ipynb) page for\n", "more details." ] }, { "cell_type": "code", "execution_count": null, "id": "194049ce-d4e9-4019-a88d-df614db38e61", "metadata": {}, "outputs": [], "source": [ "# Quickly view the tracks\n", "tracks.hrcn.plot_tracks(intensity_var_name=\"wind10\")\n", "\n", "# Add a new variable to the tracks and plot this instead\n", "tracks = tracks.hrcn.add_is_land()\n", "tracks.hrcn.plot_tracks(intensity_var_name=\"is_land\")" ] }, { "cell_type": "markdown", "id": "43984309-495e-4596-ba80-3bf0c6653bfb", "metadata": {}, "source": [ "For more in-depth examples see [example workflows](demo.ipynb) or the [examples gallery](../examples/index.rst).\n", "Or check the [API](../api/index.rst) to see everything included with HuracanPy." ] } ], "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.11.12" } }, "nbformat": 4, "nbformat_minor": 5 }