Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit f537627
Author: Boyuan Lu <blu38@wisc.edu>
Date:   Sat Apr 22 17:37:42 2023 -0500

    Add feature: flexible sector (and documentation)

commit f6e884d
Author: Boyuan Lu <blu38@wisc.edu>
Date:   Fri Apr 21 18:30:21 2023 -0500

    Add feature: flexible sector
  • Loading branch information
lubyant committed Apr 22, 2023
1 parent af5b8ca commit fae5d9f
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions windrose/windrose.py
Expand Up @@ -569,6 +569,11 @@ def bar(self, direction, var, **kwargs):
number of sectors used to compute the windrose table. If not set,
nsectors=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 @@ -611,6 +616,9 @@ def bar(self, direction, var, **kwargs):

offs = self._calm_circle()

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

for j in range(nsector):
offset = offs
for i in range(nbins):
Expand All @@ -619,7 +627,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, offset),
(angles[j] - opening / 2 - sector_offset, offset),
opening,
val,
facecolor=colors[i],
Expand Down Expand Up @@ -650,6 +658,11 @@ def box(self, direction, var, **kwargs):
number of sectors used to compute the windrose table. If not set,
nsectors=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 @@ -685,6 +698,9 @@ def box(self, direction, var, **kwargs):

offs = self._calm_circle()

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

for j in range(nsector):
offset = offs
for i in range(nbins):
Expand All @@ -693,7 +709,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, offset),
(angles[j] - opening[i] / 2 - sector_offset, offset),
opening[i],
val,
facecolor=colors[i],
Expand Down Expand Up @@ -754,7 +770,8 @@ def pdf(
return (self, params)


def histogram(direction, var, bins, nsector, normed=False, blowto=False):
def histogram(direction, var, bins, nsector, normed=False,
blowto=False, sectoroffset=0):
"""
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 All @@ -770,7 +787,9 @@ def histogram(direction, var, bins, nsector, normed=False, blowto=False):
list of var category against we're going to compute the table
nsector : integer
number of sectors
sectoroffset : float, default 0
sector offset. For example, the first sector is [-360/nsector+
sectoroffset, 360/nsector+sectoroffset], etc.
Other Parameters
----------------
normed : boolean, default False
Expand All @@ -785,7 +804,9 @@ def histogram(direction, var, bins, nsector, normed=False, blowto=False):

angle = 360.0 / nsector

dir_bins = np.arange(-angle / 2, 360.0 + angle, angle, dtype=float)
dir_bins = np.arange(-angle / 2, 360.0 + angle, angle, dtype=float)\
+ sectoroffset

dir_edges = dir_bins.tolist()
dir_edges.pop(-1)
dir_edges[0] = dir_edges.pop(-1)
Expand Down

0 comments on commit fae5d9f

Please sign in to comment.