From fae5d9fb38f5d5cb90c9b1743afe8d1656037c50 Mon Sep 17 00:00:00 2001 From: Boyuan Lu Date: Sat, 22 Apr 2023 17:44:53 -0500 Subject: [PATCH] Squashed commit of the following: commit f537627c45b13b664fbab9c937b1f56ab38c4257 Author: Boyuan Lu Date: Sat Apr 22 17:37:42 2023 -0500 Add feature: flexible sector (and documentation) commit f6e884d649508945a08923514191b69c614446d1 Author: Boyuan Lu Date: Fri Apr 21 18:30:21 2023 -0500 Add feature: flexible sector --- windrose/windrose.py | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/windrose/windrose.py b/windrose/windrose.py index d5ec96b..ef24aea 100644 --- a/windrose/windrose.py +++ b/windrose/windrose.py @@ -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`). @@ -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): @@ -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], @@ -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`). @@ -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): @@ -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], @@ -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 @@ -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 @@ -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)