{ "cells": [ { "cell_type": "markdown", "id": "2b7bbca4-2c58-493c-9f08-4e5a8bc53d08", "metadata": {}, "source": [ "# Getting Started\n", "HuracanPy provides a standard way for working with cyclone track data from different sources.\n", "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 or index tracks in this format." ] }, { "cell_type": "code", "execution_count": null, "id": "960e9a7d-0cf2-4797-a297-c048eb739327", "metadata": {}, "outputs": [], "source": [ "import huracanpy\n", "\n", "tracks = huracanpy.load(huracanpy.example_csv_file)\n", "\n", "track_groups = tracks.groupby(\"track_id\")\n", "\n", "# Selecting track by 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", "track_id1 = track_groups[1]\n", "\n", "# Iterating over all tracks\n", "# Each track will be a subset of the xarray Dataset with a unique track_id\n", "for n, track in track_groups:\n", " # Do something with the track\n", " print(track)" ] } ], "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.10" } }, "nbformat": 4, "nbformat_minor": 5 }