Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature: sector offset #236

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 40 additions & 6 deletions windrose/windrose.py
Expand Up @@ -378,6 +378,8 @@ def _init_plot(self, direction, var, **kwargs):
if nsector is None:
nsector = 16

sector_offset = kwargs.get("sectoroffset", 0)

# Sets the colors table based on the colormap or the "colors" argument
colors = kwargs.pop("colors", None)
cmap = kwargs.pop("cmap", None)
Expand All @@ -401,9 +403,10 @@ def _init_plot(self, direction, var, **kwargs):
var,
bins,
nsector,
total,
sector_offset,
normed,
blowto,
total,
)

return bins, nbins, nsector, colors, angles, kwargs
Expand Down Expand Up @@ -575,6 +578,12 @@ def bar(self, direction, var, **kwargs):
number of sectors used to compute the windrose table. If not set,
nsector=16, then each sector will be 360/16=22.5°, and the
resulting computed table will be aligned with the cardinals points.
sectoroffset: float, optional
the offset for the sectors between [-180/nsector, 180/nsector].
By default, the offsect is zero, and the first sector is
[-360/nsector/2, 360/nsector/2] or [-11.25, 11.25] for nsector=16.
If offset is non-zero, the first sector will be
[-360/nsector + offset, 360/nsector + offset] and etc.
bins : 1D array or integer, optional
number of bins, or a sequence of bins variable. If not set, bins=6
between min(`var`) and max(`var`).
Expand Down Expand Up @@ -617,6 +626,9 @@ def bar(self, direction, var, **kwargs):

self._calm_circle()

# sector offset in radius
sector_offset = kwargs.pop("sectoroffset", 0) / 180 * np.pi

for j in range(nsector):
origin = 0
for i in range(nbins):
Expand All @@ -625,7 +637,7 @@ def bar(self, direction, var, **kwargs):
val = self._info["table"][i, j]
zorder = ZBASE + nbins - i
patch = mpl.patches.Rectangle(
(angles[j] - opening / 2, origin),
(angles[j] - opening / 2 - sector_offset, origin),
opening,
val,
facecolor=colors[i],
Expand Down Expand Up @@ -656,6 +668,11 @@ def box(self, direction, var, **kwargs):
number of sectors used to compute the windrose table. If not set,
nsector=16, then each sector will be 360/16=22.5°, and the
resulting computed table will be aligned with the cardinals points.
sectoroffset: float, optional
the offset for the sectors. By default, the offsect is zero, and
the first sector is [-360/nsector, 360/nsector] or [-11.25, 11.25]
for nsector=16. If offset is non-zero, the first sector will be
[-360/nsector + offset, 360/nsector + offset] and etc.
bins : 1D array or integer, optional
number of bins, or a sequence of bins variable. If not set, bins=6
between min(`var`) and max(`var`).
Expand Down Expand Up @@ -691,6 +708,9 @@ def box(self, direction, var, **kwargs):

self._calm_circle()

# sector offset in radius
sector_offset = kwargs.pop("sectoroffset", 0) / 180 * np.pi

for j in range(nsector):
origin = 0
for i in range(nbins):
Expand All @@ -699,7 +719,7 @@ def box(self, direction, var, **kwargs):
val = self._info["table"][i, j]
zorder = ZBASE + nbins - i
patch = mpl.patches.Rectangle(
(angles[j] - opening[i] / 2, origin),
(angles[j] - opening[i] / 2 - sector_offset, origin),
opening[i],
val,
facecolor=colors[i],
Expand Down Expand Up @@ -760,7 +780,16 @@ def pdf(
return (self, params)


def histogram(direction, var, bins, nsector, normed=False, blowto=False, total=0):
def histogram(
direction,
var,
bins,
nsector,
total,
sectoroffset=0,
normed=False,
blowto=False,
):
"""
Returns an array where, for each sector of wind
(centred on the north), we have the number of time the wind comes with a
Expand Down Expand Up @@ -791,11 +820,16 @@ def histogram(direction, var, bins, nsector, normed=False, blowto=False, total=0

angle = 360.0 / nsector

dir_bins = np.arange(-angle / 2, 360.0 + angle, angle, dtype=float)
dir_bins = np.arange(
-angle / 2 + sectoroffset,
360.0 + angle + sectoroffset,
angle,
dtype=float,
)
dir_edges = dir_bins.tolist()
dir_edges.pop(-1)
dir_edges[0] = dir_edges.pop(-1)
dir_bins[0] = 0.0
# dir_bins[0] = 0.0 + sectoroffset

var_bins = bins.tolist()
var_bins.append(np.inf)
Expand Down