|
| 1 | +""" |
| 2 | +rose - Plot windrose diagrams or polar histograms. |
| 3 | +""" |
| 4 | + |
| 5 | +from pygmt.clib import Session |
| 6 | +from pygmt.helpers import build_arg_string, fmt_docstring, kwargs_to_strings, use_alias |
| 7 | + |
| 8 | + |
| 9 | +@fmt_docstring |
| 10 | +@use_alias( |
| 11 | + A="sector", |
| 12 | + B="frame", |
| 13 | + C="cmap", |
| 14 | + D="shift", |
| 15 | + Em="vectors", |
| 16 | + F="no_scale", |
| 17 | + G="color", |
| 18 | + I="inquire", |
| 19 | + JX="diameter", |
| 20 | + L="labels", |
| 21 | + M="vector_params", |
| 22 | + Q="alpha", |
| 23 | + R="region", |
| 24 | + S="norm", |
| 25 | + T="orientation", |
| 26 | + U="timestamp", |
| 27 | + V="verbose", |
| 28 | + W="pen", |
| 29 | + X="xshift", |
| 30 | + Y="yshift", |
| 31 | + Z="scale", |
| 32 | + i="columns", |
| 33 | + c="panel", |
| 34 | + p="perspective", |
| 35 | + t="transparency", |
| 36 | +) |
| 37 | +@kwargs_to_strings(R="sequence", c="sequence_comma", i="sequence_comma", p="sequence") |
| 38 | +def rose(self, length=None, azimuth=None, data=None, **kwargs): |
| 39 | + """ |
| 40 | + Plot windrose diagrams or polar histograms. |
| 41 | +
|
| 42 | + Takes a matrix, (length,azimuth) pairs, or a file name as input |
| 43 | + and plots windrose diagrams or polar histograms (sector diagram |
| 44 | + or rose diagram). |
| 45 | +
|
| 46 | + Must provide either ``data`` or ``length`` and ``azimuth``. |
| 47 | +
|
| 48 | + Options include full circle and half circle plots. The outline |
| 49 | + of the windrose is drawn with the same color as |
| 50 | + :gmt-term:`MAP_DEFAULT_PEN`. |
| 51 | +
|
| 52 | + Full option list at :gmt-docs:`rose.html` |
| 53 | +
|
| 54 | + {aliases} |
| 55 | +
|
| 56 | + Parameters |
| 57 | + ---------- |
| 58 | + length/azimuth : float or 1d arrays |
| 59 | + Length and azimuth values, or arrays of length and azimuth |
| 60 | + values |
| 61 | +
|
| 62 | + data : str or 2d array |
| 63 | + Either a data file name or a 2d numpy array with the tabular data. |
| 64 | + Use option ``columns`` to choose which columns are length and |
| 65 | + azimuth, respectively. If a file with only azimuths is given, |
| 66 | + use ``columns`` to indicate the single column with azimuths; then |
| 67 | + all lengths are set to unity (see ``scale = 'u'`` to set actual |
| 68 | + lengths to unity as well). |
| 69 | +
|
| 70 | + orientation : bool |
| 71 | + Specifies that the input data are orientation data (i.e., have a |
| 72 | + 180 degree ambiguity) instead of true 0-360 degree directions |
| 73 | + [Default is 0-360 degrees]. We compensate by counting each record |
| 74 | + twice: First as azimuth and second as azimuth +180. Ignored if |
| 75 | + range is given as -90/90 or 0/180. |
| 76 | +
|
| 77 | + region : str or list |
| 78 | + *Required if this is the first plot command*. |
| 79 | + *r0/r1/az0/az1*. |
| 80 | + Specifies the 'region' of interest in (*r*, *azimuth*) space. Here, |
| 81 | + *r0* is 0, *r1* is max length in units. For *az0* and *az1*, |
| 82 | + specify either -90/90 or 0/180 for half circle plot or 0/360 for |
| 83 | + full circle. |
| 84 | +
|
| 85 | + diameter : str |
| 86 | + Sets the diameter of the rose diagram. If not given, |
| 87 | + then we default to a diameter of 7.5 cm. |
| 88 | +
|
| 89 | + sector : str |
| 90 | + Gives the sector width in degrees for sector and rose diagram. |
| 91 | + Default ``'0'`` means windrose diagram. Append **+r** to draw rose |
| 92 | + diagram instead of sector diagram (e.g. ``'10+r'``). |
| 93 | +
|
| 94 | + norm : bool |
| 95 | + Normalize input radii (or bin counts if ``sector_width`` is used) |
| 96 | + by the largest value so all radii (or bin counts) range from 0 |
| 97 | + to 1. |
| 98 | +
|
| 99 | + frame : str |
| 100 | + Set map boundary frame and axes attributes. Remember that *x* |
| 101 | + here is radial distance and *y* is azimuth. The ylabel may be |
| 102 | + used to plot a figure caption. The scale bar length is determined |
| 103 | + by the radial gridline spacing. |
| 104 | +
|
| 105 | + scale : float or str |
| 106 | + Multiply the data radii by scale. E.g., use ``scale = 0.001`` to |
| 107 | + convert your data from m to km. To exclude the radii from |
| 108 | + consideration, set them all to unity with ``scale = 'u'`` |
| 109 | + [Default is no scaling]. |
| 110 | +
|
| 111 | + columns : str or 1d array |
| 112 | + Select input columns and transformations. E.g. choose |
| 113 | + ``columns = [1, 0]`` or ``columns = '1,0'`` if the length values |
| 114 | + are stored in the second column and the direction (azimuth) |
| 115 | + values in the first one. Note: zero-based indexing is used. |
| 116 | +
|
| 117 | + color : str |
| 118 | + Selects shade, color or pattern for filling the sectors [Default |
| 119 | + is no fill]. |
| 120 | +
|
| 121 | + cmap : str |
| 122 | + Give a CPT. The *r*-value for each sector is used to look-up the |
| 123 | + sector color. Cannot be used with a rose diagram. |
| 124 | +
|
| 125 | + pen : str |
| 126 | + Set pen attributes for sector outline or rose plot, e.g. |
| 127 | + ``pen = '0.5p'``. [Default is no outline]. To change pen used to |
| 128 | + draw vector (requires ``vectors``) [Default is same as sector |
| 129 | + outline] use e.g. ``pen = 'v0.5p'``. |
| 130 | +
|
| 131 | + labels : str |
| 132 | + ``'wlabel,elabel,slabel,nlabel'``. Specify labels for the 0, 90, |
| 133 | + 180, and 270 degree marks. For full-circle plot the default is |
| 134 | + WEST,EAST,SOUTH,NORTH and for half-circle the default is |
| 135 | + 90W,90E,-,0. A **-** in any entry disables that label |
| 136 | + (e.g. ``labels = 'W,E,-,N'``). Use ``labels = ''`` to disable |
| 137 | + all four labels. Note that the :gmt-term:`GMT_LANGUAGE` setting |
| 138 | + will affect the words used. |
| 139 | +
|
| 140 | + no_scale : bool |
| 141 | + Do NOT draw the scale length bar (``no_scale = True``). |
| 142 | + Default plots scale in lower right corner provided ``frame`` |
| 143 | + is used. |
| 144 | +
|
| 145 | + shift : bool |
| 146 | + Shift sectors so that they are centered on the bin interval |
| 147 | + (e.g., first sector is centered on 0 degrees). |
| 148 | +
|
| 149 | + vectors : str |
| 150 | + ``vectors = 'mode_file'``. Plot vectors showing the |
| 151 | + principal directions given in the *mode_file* file. |
| 152 | + Alternatively, specify ``vectors`` to compute and plot |
| 153 | + mean direction. See ``vector_params`` to control the vector |
| 154 | + attributes. Finally, to instead save the computed mean |
| 155 | + direction and other statistics, use |
| 156 | + ``vectors = '+wmode_file'``. The eight items saved to |
| 157 | + a single record are: *mean_az*, *mean_r*, *mean_resultant*, |
| 158 | + *max_r*, *scaled_mean_r*, *length_sum*, *n*, *sign@alpha*, |
| 159 | + where the last term is 0 or 1 depending on whether the mean |
| 160 | + resultant is significant at the level of confidence set via |
| 161 | + ``alpha``. |
| 162 | +
|
| 163 | + vector_params : str |
| 164 | + Used with ``vectors`` to modify vector parameters. For |
| 165 | + vector heads, append vector head size [Default is 0, i.e., a |
| 166 | + line]. See :gmt-docs:`rose.html#vector-attributes` for |
| 167 | + specifying additional attributes. If ``vectors`` is not |
| 168 | + given and the current plot mode is to draw a windrose diagram |
| 169 | + then using ``vector_params`` will add vector heads to all |
| 170 | + individual directions using the supplied attributes. |
| 171 | +
|
| 172 | + alpha : float or str |
| 173 | + Sets the confidence level used to determine if the mean |
| 174 | + resultant is significant (i.e., Lord Rayleigh test for |
| 175 | + uniformity) [``alpha = 0.05``]. Note: The critical |
| 176 | + values are approximated [Berens, 2009] and requires at |
| 177 | + least 10 points; the critical resultants are accurate to at |
| 178 | + least 3 significant digits. For smaller data sets you |
| 179 | + should consult exact statistical tables. |
| 180 | +
|
| 181 | + Berens, P., 2009, CircStat: A MATLAB Toolbox for Circular |
| 182 | + Statistics, *J. Stat. Software*, 31(10), 1-21, |
| 183 | + https://doi.org/10.18637/jss.v031.i10. |
| 184 | +
|
| 185 | + {U} |
| 186 | + {V} |
| 187 | + {XY} |
| 188 | + {c} |
| 189 | + {p} |
| 190 | + {t} |
| 191 | + """ |
| 192 | + |
| 193 | + kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access |
| 194 | + |
| 195 | + with Session() as lib: |
| 196 | + # Choose how data will be passed into the module |
| 197 | + file_context = lib.virtualfile_from_data( |
| 198 | + check_kind="vector", data=data, x=length, y=azimuth |
| 199 | + ) |
| 200 | + |
| 201 | + with file_context as fname: |
| 202 | + arg_str = " ".join([fname, build_arg_string(kwargs)]) |
| 203 | + |
| 204 | + lib.call_module("rose", arg_str) |
0 commit comments