-
Notifications
You must be signed in to change notification settings - Fork 220
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
Wrap rose #794
Wrap rose #794
Changes from 118 commits
728eec4
49044ff
009dc41
dc999d2
048cfa0
09fb0e1
f33fd7d
5aa59c6
8d368db
39c64ec
132757a
2c69ce8
4772972
d699e62
4c48b7c
70cd244
9a24db9
e803b8f
fce3503
3f398ff
6aeeabc
f91bdae
1c10e3f
405ee62
93b5320
f5a611f
7db6f13
9f24e7b
9fb5979
86bfdb2
e12c2a0
8fb7896
e61ba24
2befeb4
538a76a
566b51d
04d8ab0
24de7a0
caea72c
cbf969f
bffd365
96a52b5
9855d68
abd4fb5
e54ab13
dfbc352
acd1bfb
b52b2c6
7707e85
fd9f7aa
54b9d5d
ef1fb86
227c067
8b9fe59
d677e91
939c7e8
edbfd7e
b4b9be7
dec9116
e4cd8c2
29ef52e
b12f4c1
27f7b55
14b4e88
a96347d
99cf74a
ed3ea86
155641d
db9bf9a
c24302c
929480f
309e454
adfb515
9296640
7b205d2
ebb7f5b
d438269
07335c7
a48adf6
cd57a33
185a995
6eb3c41
fde3583
d4523e6
0a64131
a60393f
9556c60
27a2c49
151164e
7503be5
62679e6
62193a2
374eef7
3ecc451
683b3ba
e0ac586
50acec1
08a1b94
2a5ae8a
8da61b0
e4f5fe9
4049d45
209917f
b677cfa
524a500
285b2e6
1dd2838
cd6d4e8
f6a5061
dcebf12
fb2d3df
21ff7fb
5120edb
88d0160
f25d34b
473bc3e
c310ffa
b6ff595
93eb24e
950709e
7789ee3
9c62d4b
da6b829
415fde4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
""" | ||
Rose diagram | ||
------------ | ||
|
||
The :meth:`pygmt.Figure.rose` method can plot windrose diagrams or polar histograms. | ||
""" | ||
|
||
import pygmt | ||
|
||
# Load sample compilation of fracture lengths and azimuth as | ||
# hypothetically digitized from geological maps | ||
data = pygmt.datasets.load_fractures_compilation() | ||
|
||
fig = pygmt.Figure() | ||
|
||
fig.rose( | ||
# use columns of the sample dataset as input for the length and azimuth | ||
# parameters | ||
length=data.length, | ||
azimuth=data.azimuth, | ||
# specify the "region" of interest in the (r,azimuth) space [r0, r1, az0, az1], | ||
# here, r0 is 0 and r1 is 1, for azimuth, az0 is 0 and az1 is 360 which means | ||
# we plot a full circle between 0 and 360 degrees | ||
region=[0, 1, 0, 360], | ||
# set the diameter of the rose diagram to 7.5 cm | ||
diameter="7.5c", | ||
# define the sector width in degrees, we append +r here to draw a rose | ||
# diagram instead of a sector diagram | ||
sector="10+r", | ||
# normalize bin counts by the largest value so all bin counts range from | ||
# 0 to 1 | ||
norm=True, | ||
# use red3 as color fill for the sectors | ||
color="red3", | ||
# define the frame with ticks and gridlines every 0.2 | ||
# length unit in radial direction and every 30 degrees | ||
# in azimuthal direction, set background color to | ||
# lightgray | ||
frame=["x0.2g0.2", "y30g30", "+glightgray"], | ||
# use a pen size of 1p to draw the outlines | ||
pen="1p", | ||
) | ||
|
||
fig.show() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -390,6 +390,7 @@ def _repr_html_(self): | |
meca, | ||
plot, | ||
plot3d, | ||
rose, | ||
set_panel, | ||
solar, | ||
subplot, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
""" | ||
rose - Plot windrose diagrams or polar histograms. | ||
""" | ||
|
||
from pygmt.clib import Session | ||
from pygmt.helpers import build_arg_string, fmt_docstring, kwargs_to_strings, use_alias | ||
|
||
|
||
@fmt_docstring | ||
@use_alias( | ||
A="sector", | ||
B="frame", | ||
C="cmap", | ||
D="shift", | ||
Em="vectors", | ||
F="no_scale", | ||
G="color", | ||
I="inquire", | ||
JX="diameter", | ||
L="labels", | ||
M="vector_params", | ||
Q="alpha", | ||
R="region", | ||
S="norm", | ||
T="orientation", | ||
U="timestamp", | ||
V="verbose", | ||
W="pen", | ||
X="xshift", | ||
Y="yshift", | ||
Z="scale", | ||
i="columns", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The long alias for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, fine for me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the sake of not keeping this PR open for too long, let's stick to using |
||
c="panel", | ||
p="perspective", | ||
michaelgrund marked this conversation as resolved.
Show resolved
Hide resolved
|
||
t="transparency", | ||
) | ||
@kwargs_to_strings(R="sequence", c="sequence_comma", i="sequence_comma", p="sequence") | ||
def rose(self, length=None, azimuth=None, data=None, **kwargs): | ||
""" | ||
Plot windrose diagrams or polar histograms. | ||
|
||
Takes a matrix, (length,azimuth) pairs, or a file name as input | ||
and plots windrose diagrams or polar histograms (sector diagram | ||
or rose diagram). | ||
|
||
Must provide either ``data`` or ``length`` and ``azimuth``. | ||
|
||
Options include full circle and half circle plots. The outline | ||
of the windrose is drawn with the same color as | ||
:gmt-term:`MAP_DEFAULT_PEN`. | ||
|
||
Full option list at :gmt-docs:`rose.html` | ||
|
||
{aliases} | ||
|
||
Parameters | ||
---------- | ||
length/azimuth : float or 1d arrays | ||
Length and azimuth values, or arrays of length and azimuth | ||
values | ||
|
||
data : str or 2d array | ||
Either a data file name or a 2d numpy array with the tabular data. | ||
Use option ``columns`` (i) to choose which columns are length and | ||
weiji14 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
azimuth, respectively. If a file with only azimuths is given, | ||
use ``columns`` to indicate the single column with azimuths; then | ||
all lengths are set to unity (see ``scale = 'u'`` to set actual | ||
lengths to unity as well). | ||
|
||
orientation : bool | ||
Specifies that the input data are orientation data (i.e., have a | ||
180 degree ambiguity) instead of true 0-360 degree directions | ||
[Default is 0-360 degrees]. We compensate by counting each record | ||
twice: First as azimuth and second as azimuth +180. Ignored if | ||
range is given as -90/90 or 0/180. | ||
|
||
region : str or list | ||
*Required if this is the first plot command*. ``'r0/r1/az0/az1'``. | ||
weiji14 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Specifies the ‘region’ of interest in (*r*, *azimuth*) space. Here, | ||
weiji14 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*r0* is 0, *r1* is max length in units. For *az0* and *az1*, | ||
specify either -90/90 or 0/180 for half circle plot or 0/360 for | ||
full circle. | ||
|
||
diameter : str | ||
Sets the diameter of the rose diagram. Only this form of the | ||
projection machinery is supported for this module. If not given, | ||
then we default to a diameter of 7.5 cm. | ||
weiji14 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
sector : str | ||
Gives the sector width in degrees for sector and rose diagram. | ||
Default ``'0'`` means windrose diagram. Append **+r** to draw rose | ||
diagram instead of sector diagram (e.g. ``'10+r'``). | ||
|
||
norm : bool | ||
Normalize input radii (or bin counts if ``sector_width`` is used) | ||
by the largest value so all radii (or bin counts) range from 0 | ||
to 1. | ||
|
||
frame : str | ||
Set map boundary frame and axes attributes. Remember that *x* | ||
here is radial distance and *y* is azimuth. The ylabel may be | ||
used to plot a figure caption. The scale bar length is determined | ||
by the radial gridline spacing. | ||
|
||
scale : float or str | ||
Multiply the data radii by scale. E.g., use ``scale = 0.001`` to | ||
convert your data from m to km. To exclude the radii from | ||
consideration, set them all to unity with ``scale = 'u'`` | ||
[Default is no scaling]. | ||
|
||
columns : str or 1d array | ||
Select input columns and transformations. E.g. choose | ||
``columns = [1, 0]`` or ``columns = '1,0'`` if the length values | ||
are stored in the second column and the direction (azimuth) | ||
values in the first one. Note: zero-based indexing is used. | ||
|
||
color : str | ||
Selects shade, color or pattern for filling the sectors [Default | ||
is no fill]. | ||
|
||
cmap : str | ||
Give a CPT. The *r*-value for each sector is used to look-up the | ||
sector color. Cannot be used with a rose diagram. | ||
|
||
pen : str | ||
Set pen attributes for sector outline or rose plot, e.g. | ||
``pen = '0.5p'``. [Default is no outline]. To change pen used to | ||
draw vector (requires ``vectors``) [Default is same as sector | ||
outline] use e.g. ``pen = 'v0.5p'``. | ||
|
||
labels : str | ||
``'wlabel,elabel,slabel,nlabel'``. Specify labels for the 0, 90, | ||
180, and 270 degree marks. For full-circle plot the default is | ||
WEST,EAST,SOUTH,NORTH and for half-circle the default is | ||
90W,90E,-,0. A **-** in any entry disables that label | ||
(e.g. ``labels = 'W,E,-,N'``). Use ``labels = ''`` to disable | ||
all four labels. Note that the :gmt-term:`GMT_LANGUAGE` setting | ||
will affect the words used. | ||
|
||
no_scale : bool | ||
Do NOT draw the scale length bar (``no_scale = True``). | ||
Default plots scale in lower right corner provided ``frame`` | ||
is used. | ||
|
||
shift : bool | ||
Shift sectors so that they are centered on the bin interval | ||
(e.g., first sector is centered on 0 degrees). | ||
|
||
vectors : str | ||
``vectors = 'mode_file'``. Plot vectors showing the | ||
principal directions given in the *mode_file* file. | ||
Alternatively, specify ``vectors`` to compute and plot | ||
mean direction. See ``vector_params`` to control the vector | ||
attributes. Finally, to instead save the computed mean | ||
direction and other statistics, use | ||
``vectors = '+wmode_file'``. The eight items saved to | ||
a single record are: *mean_az*, *mean_r*, *mean_resultant*, | ||
*max_r*, *scaled_mean_r*, *length_sum*, *n*, *sign@alpha*, | ||
where the last term is 0 or 1 depending on whether the mean | ||
resultant is significant at the level of confidence set via | ||
``alpha``. | ||
|
||
vector_params : str | ||
Used with ``vectors`` to modify vector parameters. For | ||
vector heads, append vector head size [Default is 0, i.e., a | ||
line]. See :gmt-docs:`rose.html#vector-attributes` for | ||
specifying additional attributes. If ``vectors`` is not | ||
given and the current plot mode is to draw a windrose diagram | ||
then using ``vector_params`` will add vector heads to all | ||
individual directions using the supplied attributes. | ||
|
||
alpha : float or str | ||
Sets the confidence level used to determine if the mean | ||
resultant is significant (i.e., Lord Rayleigh test for | ||
uniformity) [``alpha = 0.05``]. Note: The critical | ||
values are approximated [Berens, 2009] and requires at | ||
least 10 points; the critical resultants are accurate to at | ||
least 3 significant digits. For smaller data sets you | ||
should consult exact statistical tables. | ||
|
||
Berens, P., 2009, CircStat: A MATLAB Toolbox for Circular | ||
Statistics, *J. Stat. Software*, 31(10), 1-21, | ||
https://doi.org/10.18637/jss.v031.i10. | ||
|
||
{U} | ||
{V} | ||
{XY} | ||
{c} | ||
{p} | ||
michaelgrund marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{t} | ||
""" | ||
|
||
kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access | ||
|
||
with Session() as lib: | ||
# Choose how data will be passed into the module | ||
file_context = lib.virtualfile_from_data( | ||
check_kind="vector", data=data, x=length, y=azimuth | ||
) | ||
|
||
with file_context as fname: | ||
arg_str = " ".join([fname, build_arg_string(kwargs)]) | ||
|
||
lib.call_module("rose", arg_str) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
outs: | ||
- md5: 2e440e6db215a619829acb08a0ab55bf | ||
size: 41397 | ||
path: test_rose_2d_array_multiple.png |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
outs: | ||
- md5: c64abda4022e5e9fcf5592c5c2f6bb44 | ||
size: 37742 | ||
path: test_rose_2d_array_single.png |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
outs: | ||
- md5: 2b0ba264c2240a6d2da02466d8848d7a | ||
size: 73857 | ||
path: test_rose_bools.png |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
outs: | ||
- md5: eba3b08913112996eca8b9d01f5709c3 | ||
size: 40610 | ||
path: test_rose_data_file.png |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
outs: | ||
- md5: 67613d130577c8083e1d505155421205 | ||
size: 159974 | ||
path: test_rose_no_sectors.png |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
outs: | ||
- md5: 1facbc2eb905197cd6aece39c08c8686 | ||
size: 44793 | ||
path: test_rose_plot_data_using_cpt.png |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
outs: | ||
- md5: 11af5a2d9971898c96f48e0a5215d759 | ||
size: 62490 | ||
path: test_rose_plot_with_transparency.png |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to this comment: #876 (comment), the
rose
example should be put into the "Histogram" category.Edit: As the "Historagm" category is not created yet, it's OK to leave the example here now. We can create the category and move the example later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok fine, to keep track will open a new issue regarding that point.