diff --git a/docs/user_guide/info.ipynb b/docs/user_guide/info.ipynb index 7e2167a..8a4b52a 100644 --- a/docs/user_guide/info.ipynb +++ b/docs/user_guide/info.ipynb @@ -49,8 +49,8 @@ "outputs": [], "source": [ "# Get the info: Two equvalent ways\n", - "huracanpy.info.get_hemisphere(data.lat) # Function call\n", - "data.hrcn.get_hemisphere(lat_name = \"lat\") # Accessor method" + "huracanpy.info.get_hemisphere(data.lat) # Function call\n", + "data.hrcn.get_hemisphere(lat_name=\"lat\") # Accessor method" ] }, { @@ -62,9 +62,9 @@ "source": [ "# Add the info: Two equvalent ways\n", "data[\"hemisphere\"] = huracanpy.info.get_hemisphere(data.lat)\n", - "data = data.hrcn.add_hemisphere(lat_name = \"lat\")\n", + "data = data.hrcn.add_hemisphere(lat_name=\"lat\")\n", "\n", - "data # data now includes hemisphere" + "data # data now includes hemisphere" ] }, { @@ -84,8 +84,8 @@ "outputs": [], "source": [ "# Hemisphere\n", - "huracanpy.info.get_hemisphere(data.lat) # Function\n", - "data.hrcn.get_hemisphere(\"lat\") # Accessor method" + "huracanpy.info.get_hemisphere(data.lat) # Function\n", + "data.hrcn.get_hemisphere(\"lat\") # Accessor method" ] }, { @@ -96,8 +96,8 @@ "outputs": [], "source": [ "# Basin\n", - "huracanpy.info.get_basin(data.lon, data.lat) # Function\n", - "data.hrcn.get_basin(\"lon\", \"lat\") # Accessor method" + "huracanpy.info.get_basin(data.lon, data.lat) # Function\n", + "data.hrcn.get_basin(\"lon\", \"lat\") # Accessor method" ] }, { @@ -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.get_land_or_ocean(data.lon, data.lat) # Function\n", + "data.hrcn.get_land_or_ocean(\"lon\", \"lat\") # Accessor method" ] }, { @@ -120,8 +120,8 @@ "outputs": [], "source": [ "# Continent: If track is over land, return the corresponding continent, else ''\n", - "huracanpy.info.get_continent(data.lon, data.lat) # Function\n", - "data.hrcn.get_continent(\"lon\", \"lat\") # Accessor method" + "huracanpy.info.get_continent(data.lon, data.lat) # Function\n", + "data.hrcn.get_continent(\"lon\", \"lat\") # Accessor method" ] }, { @@ -132,8 +132,8 @@ "outputs": [], "source": [ "# Country: If track is over land, return the corresponding country, else ''\n", - "huracanpy.info.get_country(data.lon, data.lat) # Function\n", - "data.hrcn.get_country(\"lon\", \"lat\") # Accessor method" + "huracanpy.info.get_country(data.lon, data.lat) # Function\n", + "data.hrcn.get_country(\"lon\", \"lat\") # Accessor method" ] }, { @@ -153,8 +153,8 @@ "outputs": [], "source": [ "# Get the values\n", - "huracanpy.info.get_time_components(data.time) # Function\n", - "data.hrcn.get_time_components(\"time\") # Accessor method" + "huracanpy.info.get_time_components(data.time) # Function\n", + "data.hrcn.get_time_components(\"time\") # Accessor method" ] }, { @@ -165,10 +165,12 @@ "outputs": [], "source": [ "# Add them\n", - "data[\"year\"], data[\"month\"], data[\"day\"], data[\"hour\"] = huracanpy.info.get_time_components(data.time)\n", + "data[\"year\"], data[\"month\"], data[\"day\"], data[\"hour\"] = (\n", + " huracanpy.info.get_time_components(data.time)\n", + ")\n", "data = data.hrcn.add_time_components(\"time\")\n", "\n", - "data # Now contains year, month, day, hour" + "data # Now contains year, month, day, hour" ] }, { @@ -188,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.get_category(data.wind10, bins=[0, 10, 20, 30, 40], labels=[0, 1, 2, 3])" ] } ], diff --git a/docs/user_guide/save.ipynb b/docs/user_guide/save.ipynb index b58f9cc..94f6307 100644 --- a/docs/user_guide/save.ipynb +++ b/docs/user_guide/save.ipynb @@ -27,8 +27,8 @@ "source": [ "import huracanpy\n", "\n", - "tracks = huracanpy.load(huracanpy.example_csv_file) # Load sample file\n", - "huracanpy.save(tracks, \"saved_data.csv\") # Save as csv\n", + "tracks = huracanpy.load(huracanpy.example_csv_file) # Load sample file\n", + "huracanpy.save(tracks, \"saved_data.csv\") # Save as csv\n", "huracanpy.save(tracks, \"saved_data.nc\") # Save as NetCDF" ] }, diff --git a/huracanpy/info/_category.py b/huracanpy/info/_category.py index ea74051..8d8d1eb 100644 --- a/huracanpy/info/_category.py +++ b/huracanpy/info/_category.py @@ -4,6 +4,7 @@ import warnings +import numpy as np import pint import pandas as pd @@ -47,4 +48,9 @@ def category(variable, bins, labels=None, variable_units=None): variable_units = str(bins.units) variable = variable * units(variable_units) - return pd.cut(variable, bins, labels=labels) + if not isinstance(bins, pint.Quantity) or bins.unitless: + bins = bins * units(variable_units) + + bins = bins.to(variable.units) + + return np.array(pd.cut(variable, bins, labels=labels)) diff --git a/huracanpy/tc/_category.py b/huracanpy/tc/_category.py index 76e2b20..ff7913d 100644 --- a/huracanpy/tc/_category.py +++ b/huracanpy/tc/_category.py @@ -8,6 +8,7 @@ from metpy.xarray import preprocess_and_wrap from ..info import category +from .._metpy import dequantify_results from ._conventions import _thresholds @@ -40,6 +41,7 @@ def saffir_simpson_category(wind, convention="Saffir-Simpson", wind_units="m s-1 ) +@dequantify_results @preprocess_and_wrap(wrap_like="slp") def pressure_category(slp, convention="Klotzbach", slp_units="hPa"): """