Skip to content

Commit

Permalink
Merge pull request #65 from leosaffin/version-1-prep
Browse files Browse the repository at this point in the history
Update notebooks
  • Loading branch information
leosaffin authored Nov 19, 2024
2 parents 063716e + 80358cc commit 9e3dd67
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 51 deletions.
5 changes: 0 additions & 5 deletions docs/api/info.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ info
.. automodule:: huracanpy.info
.. currentmodule:: huracanpy.info

.. autosummary::
:toctree: _autosummary

add_all_info

Geographic
----------

Expand Down
36 changes: 15 additions & 21 deletions docs/examples/utils.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"metadata": {},
"source": [
"# Additional information with the `info` module\n",
"In the `info` module, an `add_all_info` function add to your dataset all the information that HuracanPy may compute. Submodules allow for the computation of individual attributes."
"The `info` allows for the computation of individual attributes."
]
},
{
Expand All @@ -27,19 +27,6 @@
"list(data.keys()) # Available attributes"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "93773851-9c08-453f-ad99-c0cdcb5a3fba",
"metadata": {},
"outputs": [],
"source": [
"# Add info\n",
"data = huracanpy.info.add_all_info(data)\n",
"\n",
"list(data.keys()) # Available attributes"
]
},
{
"cell_type": "markdown",
"id": "64456089-dc90-4551-8b2b-dadcf6745424",
Expand All @@ -55,7 +42,8 @@
"metadata": {},
"outputs": [],
"source": [
"# hemisphere, can also be obtained with huracanpy.info.get_hemisphere\n",
"# hemisphere, can also be obtained with huracanpy.info.hemisphere\n",
"data = data.hrcn.add_hemisphere()\n",
"huracanpy.plot.tracks(\n",
" data.lon, data.lat, intensity_var=data.hemisphere, scatter_kws=dict(s=10)\n",
")"
Expand All @@ -68,7 +56,8 @@
"metadata": {},
"outputs": [],
"source": [
"# basin, can also be obtained with huracanpy.info.get_basin (NB: Several convention available)\n",
"# basin, can also be obtained with huracanpy.info.basin (NB: Several convention available)\n",
"data = data.hrcn.add_basin()\n",
"huracanpy.plot.tracks(\n",
" data.lon, data.lat, intensity_var=data.basin, scatter_kws=dict(s=10)\n",
")"
Expand All @@ -81,7 +70,8 @@
"metadata": {},
"outputs": [],
"source": [
"# is_ocean, can also be obtained with huracanpy.info.get_is_ocean\n",
"# is_ocean, can also be obtained with huracanpy.info.is_ocean\n",
"data = data.hrcn.add_is_ocean()\n",
"huracanpy.plot.tracks(\n",
" data.lon, data.lat, intensity_var=data.is_ocean, scatter_kws=dict(s=10)\n",
")"
Expand All @@ -100,7 +90,8 @@
},
"outputs": [],
"source": [
"# country, can also be obtained with huracanpy.info.get_country\n",
"# country, can also be obtained with huracanpy.info.country\n",
"data = data.hrcn.add_country()\n",
"data_ = data.isel(record=slice(0, 60))\n",
"huracanpy.plot.tracks(\n",
" data_.lon, data_.lat, intensity_var=data_.country, scatter_kws=dict(s=10)\n",
Expand All @@ -114,7 +105,8 @@
"metadata": {},
"outputs": [],
"source": [
"# continent, can also be obtained with huracanpy.info.get_country\n",
"# continent, can also be obtained with huracanpy.info.continent\n",
"data = data.hrcn.add_continent()\n",
"huracanpy.plot.tracks(\n",
" data.lon, data.lat, intensity_var=data.continent, scatter_kws=dict(s=10)\n",
")"
Expand All @@ -135,7 +127,9 @@
"metadata": {},
"outputs": [],
"source": [
"# Season. Can also be obtained with huracanpy.info.get_season\n",
"# Season. Can also be obtained with huracanpy.info.season\n",
"data = data.hrcn.add_season()\n",
"data = data.hrcn.add_hemisphere()\n",
"sns.scatterplot(data=data, x=\"time\", y=\"hemisphere\", hue=\"season\")"
]
},
Expand Down Expand Up @@ -201,7 +195,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
"version": "3.12.4"
}
},
"nbformat": 4,
Expand Down
31 changes: 20 additions & 11 deletions docs/user_guide/demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"source": [
"import huracanpy\n",
"\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns"
]
Expand Down Expand Up @@ -83,7 +84,7 @@
"metadata": {},
"source": [
"### 1b. 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/huracanpy.info.rst))."
"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))."
]
},
{
Expand Down Expand Up @@ -318,7 +319,7 @@
"metadata": {},
"source": [
"### 2b. Adding info to the tracks\n",
"HuracanPy has several function to add useful information to the tracks (for full list, see [huracanpy.info](../api/huracanpy.info.rst)). Here for example we add basin and SSHS category information."
"HuracanPy has several function to add useful information to the tracks (for full list, see [huracanpy.info](../api/info.rst)). Here for example we add basin and SSHS category information."
]
},
{
Expand Down Expand Up @@ -546,7 +547,7 @@
"outputs": [],
"source": [
"## 2. Compute lifetime maximum intensity per track with xarray's groupby\n",
"LMI_wind = tracks.groupby(\"track_id\").max().wind10\n",
"LMI_wind = tracks.wind10.groupby(tracks.track_id).max()\n",
"LMI_wind # xarray.Dataset with track_id as dimension"
]
},
Expand Down Expand Up @@ -614,6 +615,16 @@
"tracks.time_from_apex"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1ad10480-b4b8-4749-a98d-811dbb3d93aa",
"metadata": {},
"outputs": [],
"source": [
"tracks.time_from_apex / np.timedelta64(1, \"h\")"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -623,11 +634,9 @@
"source": [
"# Plot composite SLP lifecycle\n",
"## Convert time_from_apex to hours\n",
"tracks[\"time_from_apex\"] = tracks.time_from_apex * 1e-9 / 3600\n",
"## Use xarray's where to mask points too far away from apex (100 hours away)\n",
"tracks_close_to_apex = tracks.where(\n",
" (tracks.time_from_apex >= -100) & (tracks.time_from_apex <= 100), drop=True\n",
")\n",
"tracks[\"time_from_apex\"] = tracks.time_from_apex / np.timedelta64(1, \"h\")\n",
"## Use xarray's where to mask points too far away from apex (48 hours away)\n",
"tracks_close_to_apex = tracks.where(np.abs(tracks.time_from_apex) <= 48, drop=True)\n",
"## Seaborn lineplot allows for drawing composites with uncertainty range\n",
"sns.lineplot(\n",
" x=tracks_close_to_apex.time_from_apex, # x-axis is time from apex\n",
Expand Down Expand Up @@ -694,9 +703,9 @@
"outputs": [],
"source": [
"# Compute LMI for both sets\n",
"LMI_wind_ib = ib_1996.groupby(\"track_id\").max().wind\n",
"LMI_wind_ib = ib_1996.wind.groupby(ib_1996.track_id).max()\n",
"LMI_wind_ib = LMI_wind_ib / 1.94 # Convert kn to m/s\n",
"LMI_wind_ERA5 = ERA5.groupby(\"track_id\").max().wind10\n",
"LMI_wind_ERA5 = ERA5.wind10.groupby(ERA5.track_id).max()\n",
"# Plot both histograms\n",
"LMI_wind_ib.plot.hist(\n",
" bins=[10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65], color=\"k\", label=\"IBTrACS\"\n",
Expand Down Expand Up @@ -803,7 +812,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.10"
"version": "3.12.4"
}
},
"nbformat": 4,
Expand Down
1 change: 1 addition & 0 deletions docs/user_guide/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ The flowchart below illustrates this structure. The present user guide details h
:maxdepth: 4
:hidden:

self
install
demo
load
Expand Down
26 changes: 13 additions & 13 deletions docs/user_guide/info.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"outputs": [],
"source": [
"# Get the info: Two equvalent ways\n",
"huracanpy.info.get_hemisphere(data.lat) # Function call\n",
"huracanpy.info.hemisphere(data.lat) # Function call\n",
"data.hrcn.get_hemisphere(lat_name=\"lat\") # Accessor method"
]
},
Expand All @@ -61,7 +61,7 @@
"outputs": [],
"source": [
"# Add the info: Two equvalent ways\n",
"data[\"hemisphere\"] = huracanpy.info.get_hemisphere(data.lat)\n",
"data[\"hemisphere\"] = huracanpy.info.hemisphere(data.lat)\n",
"data = data.hrcn.add_hemisphere(lat_name=\"lat\")\n",
"\n",
"data # data now includes hemisphere"
Expand All @@ -84,7 +84,7 @@
"outputs": [],
"source": [
"# Hemisphere\n",
"huracanpy.info.get_hemisphere(data.lat) # Function\n",
"huracanpy.info.hemisphere(data.lat) # Function\n",
"data.hrcn.get_hemisphere(\"lat\") # Accessor method"
]
},
Expand All @@ -96,7 +96,7 @@
"outputs": [],
"source": [
"# Basin\n",
"huracanpy.info.get_basin(data.lon, data.lat) # Function\n",
"huracanpy.info.basin(data.lon, data.lat) # Function\n",
"data.hrcn.get_basin(\"lon\", \"lat\") # Accessor method"
]
},
Expand All @@ -108,8 +108,8 @@
"outputs": [],
"source": [
"# land or ocean\n",
"huracanpy.info.get_land_or_ocean(data.lon, data.lat) # Function\n",
"data.hrcn.get_land_or_ocean(\"lon\", \"lat\") # Accessor method"
"huracanpy.info.is_ocean(data.lon, data.lat) # Function\n",
"data.hrcn.get_is_ocean(\"lon\", \"lat\") # Accessor method"
]
},
{
Expand All @@ -120,7 +120,7 @@
"outputs": [],
"source": [
"# Continent: If track is over land, return the corresponding continent, else ''\n",
"huracanpy.info.get_continent(data.lon, data.lat) # Function\n",
"huracanpy.info.continent(data.lon, data.lat) # Function\n",
"data.hrcn.get_continent(\"lon\", \"lat\") # Accessor method"
]
},
Expand All @@ -132,7 +132,7 @@
"outputs": [],
"source": [
"# Country: If track is over land, return the corresponding country, else ''\n",
"huracanpy.info.get_country(data.lon, data.lat) # Function\n",
"huracanpy.info.country(data.lon, data.lat) # Function\n",
"data.hrcn.get_country(\"lon\", \"lat\") # Accessor method"
]
},
Expand All @@ -153,7 +153,7 @@
"outputs": [],
"source": [
"# Get the values\n",
"huracanpy.info.get_time_components(data.time) # Function\n",
"huracanpy.info.time_components(data.time) # Function\n",
"data.hrcn.get_time_components(\"time\") # Accessor method"
]
},
Expand All @@ -165,8 +165,8 @@
"outputs": [],
"source": [
"# Add them\n",
"data[\"year\"], data[\"month\"], data[\"day\"], data[\"hour\"] = (\n",
" huracanpy.info.get_time_components(data.time)\n",
"data[\"year\"], data[\"month\"], data[\"day\"], data[\"hour\"] = huracanpy.info.time_components(\n",
" data.time\n",
")\n",
"data = data.hrcn.add_time_components(\"time\")\n",
"\n",
Expand All @@ -190,7 +190,7 @@
"metadata": {},
"outputs": [],
"source": [
"huracanpy.info.get_category(data.wind10, bins=[0, 10, 20, 30, 40], labels=[0, 1, 2, 3])"
"huracanpy.info.category(data.wind10, bins=[0, 10, 20, 30, 40], labels=[0, 1, 2, 3])"
]
}
],
Expand All @@ -210,7 +210,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.10"
"version": "3.12.4"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "huracanpy"
version = "1.0-beta2"
version = "1.0.0"
authors = [
{ name="Leo Saffin", email="[email protected]" },
{ name="Stella Bourdin", email="[email protected]" },
Expand Down

0 comments on commit 9e3dd67

Please sign in to comment.