Skip to content

Commit

Permalink
fixed three issuee, arrows on wind matrix can be turned off, title fo…
Browse files Browse the repository at this point in the history
…r windroses can be set, and scrape_openmeteo can now exclude leap year days
  • Loading branch information
Tom-Kingstone committed Jun 25, 2024
1 parent 246401f commit 2aba063
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,7 @@ def scrape_openmeteo(
end_date: datetime | str,
variables: tuple[OpenMeteoVariable] = None,
convert_units: bool = False,
remove_leapyears: bool = False,
) -> pd.DataFrame:
"""Obtain historic hourly data from Open-Meteo.
https://open-meteo.com/en/docs/historical-weather-api
Expand All @@ -1054,6 +1055,8 @@ def scrape_openmeteo(
A list of variables to query. If None, then all variables will be queried.
convert_units (bool, optional):
Convert units output into more common units, and rename headers accordingly.
remove_leapyears (bool, optional):
Whether or not to remove occurences of February 29th from the scraped data.
Note:
This method saves the data to a local cache, and will return the cached data if it is less
Expand Down Expand Up @@ -1142,6 +1145,9 @@ def scrape_openmeteo(
# combine data
df = pd.concat(available_data, axis=1)

if remove_leapyears:
df = df[~((df.index.month == 2) & (df.index.day == 29))]

if not convert_units:
return df

Expand Down
34 changes: 22 additions & 12 deletions LadybugTools_Engine/Python/src/ladybugtools_toolkit/wind.py
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,7 @@ def plot_windmatrix(
self,
ax: plt.Axes = None,
show_values: bool = False,
show_arrows: bool = True,
**kwargs,
) -> plt.Axes:
"""Create a plot showing the annual wind speed and direction bins
Expand All @@ -1597,6 +1598,8 @@ def plot_windmatrix(
The axes to plot on. If None, the current axes will be used.
show_values (bool, optional):
Whether to show values in the cells. Defaults to False.
show_arrows (bool, optional):
Whether to show the directional arrows on each patch.
**kwargs:
Additional keyword arguments to pass to the pcolor function.
Expand Down Expand Up @@ -1640,17 +1643,18 @@ def plot_windmatrix(
_x = -np.sin(np.deg2rad(_wind_directions.values))
_y = -np.cos(np.deg2rad(_wind_directions.values))
direction_matrix = angle_from_north([_x, _y])
ax.quiver(
np.arange(1, 13, 1) - 0.5,
np.arange(0, 24, 1) + 0.5,
_x * _wind_speeds.values / 2,
_y * _wind_speeds.values / 2,
pivot="mid",
fc="white",
ec="black",
lw=0.5,
alpha=0.5,
)
if (show_arrows):
ax.quiver(
np.arange(1, 13, 1) - 0.5,
np.arange(0, 24, 1) + 0.5,
_x * _wind_speeds.values / 2,
_y * _wind_speeds.values / 2,
pivot="mid",
fc="white",
ec="black",
lw=0.5,
alpha=0.5,
)

if show_values:
for _xx, col in enumerate(_wind_directions.values.T):
Expand Down Expand Up @@ -1766,6 +1770,7 @@ def plot_windrose(
other_data: list[float] = None,
other_bins: list[float] = None,
colors: list[str | tuple[float] | Colormap] = None,
title: str = None,
legend: bool = True,
ylim: tuple[float] = None,
label: bool = False,
Expand All @@ -1785,6 +1790,8 @@ def plot_windrose(
colors: (str | tuple[float] | Colormap, optional):
A list of colors to use for the other bins. May also be a colormap. Defaults to the colors used for
Beaufort wind comfort categories.
title (str, optional):
title to display above the plot. Defaults to the source of this wind object.
legend (bool, optional):
Set to False to remove the legend. Defaults to True.
ylim (tuple[float], optional):
Expand Down Expand Up @@ -1837,7 +1844,10 @@ def plot_windrose(
hist_ax.bar(np.array([1]), np.array([1]))
# HACK end

ax.set_title(textwrap.fill(f"{self.source}", 75))
if title is None or title == "":
ax.set_title(textwrap.fill(f"{self.source}", 75))
else:
ax.set_title(title)

theta_width = np.deg2rad(360 / directions)
patches = []
Expand Down

0 comments on commit 2aba063

Please sign in to comment.