Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/upstream/version-1-prep' i…
Browse files Browse the repository at this point in the history
…nto merge-master
  • Loading branch information
leosaffin committed Nov 15, 2024
2 parents 68e9e04 + 6149cef commit 22ac221
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
40 changes: 21 additions & 19 deletions docs/user_guide/info.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand All @@ -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"
]
},
{
Expand All @@ -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"
]
},
{
Expand All @@ -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"
]
},
{
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.get_land_or_ocean(data.lon, data.lat) # Function\n",
"data.hrcn.get_land_or_ocean(\"lon\", \"lat\") # Accessor method"
]
},
{
Expand All @@ -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"
]
},
{
Expand All @@ -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"
]
},
{
Expand All @@ -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"
]
},
{
Expand All @@ -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"
]
},
{
Expand All @@ -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])"
]
}
],
Expand Down
4 changes: 2 additions & 2 deletions docs/user_guide/save.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
Expand Down
8 changes: 7 additions & 1 deletion huracanpy/info/_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import warnings

import numpy as np
import pint
import pandas as pd

Expand Down Expand Up @@ -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))
2 changes: 2 additions & 0 deletions huracanpy/tc/_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from metpy.xarray import preprocess_and_wrap

from ..info import category
from .._metpy import dequantify_results
from ._conventions import _thresholds


Expand Down Expand Up @@ -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"):
"""
Expand Down

0 comments on commit 22ac221

Please sign in to comment.