From eadbb8ae269b38b66528a34cfc35d07d0ce9810f Mon Sep 17 00:00:00 2001 From: lubyant Date: Sat, 22 Apr 2023 22:50:10 -0500 Subject: [PATCH 1/4] Add feature: sector offset --- windrose/windrose.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/windrose/windrose.py b/windrose/windrose.py index d5ec96b..99f08fe 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], From 66625901511f6f9ac85680e5c9731157f3e1e8df Mon Sep 17 00:00:00 2001 From: Boyuan Lu Date: Sat, 17 Jun 2023 17:55:28 -0500 Subject: [PATCH 2/4] Update the histogram adjusting for sector offset --- windrose/windrose.py | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/windrose/windrose.py b/windrose/windrose.py index b6f81ee..5ec074b 100644 --- a/windrose/windrose.py +++ b/windrose/windrose.py @@ -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) @@ -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 @@ -576,9 +579,10 @@ def bar(self, direction, var, **kwargs): 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 + 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 @@ -776,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 @@ -807,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) From fc3042478ba46614837c9116377f82ad30ddcd16 Mon Sep 17 00:00:00 2001 From: lubyant Date: Wed, 3 Jul 2024 21:26:34 -0500 Subject: [PATCH 3/4] Update windrose/windrose.py Co-authored-by: Filipe --- windrose/windrose.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/windrose/windrose.py b/windrose/windrose.py index 5ec074b..aee2510 100644 --- a/windrose/windrose.py +++ b/windrose/windrose.py @@ -580,7 +580,7 @@ def bar(self, direction, var, **kwargs): 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 + By default, the offset 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. From 1f45313f294f4b3c68c2a244be7df50dd8596b02 Mon Sep 17 00:00:00 2001 From: lubyant Date: Wed, 3 Jul 2024 22:16:29 -0500 Subject: [PATCH 4/4] Update windrose.py --- windrose/windrose.py | 1 - 1 file changed, 1 deletion(-) diff --git a/windrose/windrose.py b/windrose/windrose.py index aee2510..7ed05c7 100644 --- a/windrose/windrose.py +++ b/windrose/windrose.py @@ -829,7 +829,6 @@ def histogram( dir_edges = dir_bins.tolist() dir_edges.pop(-1) dir_edges[0] = dir_edges.pop(-1) - # dir_bins[0] = 0.0 + sectoroffset var_bins = bins.tolist() var_bins.append(np.inf)