Skip to content
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

Merged
merged 124 commits into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from 118 commits
Commits
Show all changes
124 commits
Select commit Hold shift + click to select a range
728eec4
Wrap rose
michaelgrund Jan 17, 2021
49044ff
Create test_rose.py
michaelgrund Jan 17, 2021
009dc41
Update index.rst
michaelgrund Jan 17, 2021
dc999d2
[format-command] fixes
actions-bot Jan 17, 2021
048cfa0
Update base_plotting.py
michaelgrund Jan 17, 2021
09fb0e1
Update base_plotting.py
michaelgrund Jan 17, 2021
f33fd7d
updated docstrings
michaelgrund Jan 17, 2021
5aa59c6
add baseline plots for testing rose
michaelgrund Jan 18, 2021
8d368db
Update base_plotting.py
michaelgrund Jan 18, 2021
39c64ec
[format-command] fixes
actions-bot Jan 18, 2021
132757a
Merge branch 'master' into patch-2
michaelgrund Jan 19, 2021
2c69ce8
corrected typos
Jan 19, 2021
4772972
updated tests
Jan 19, 2021
d699e62
updated test_rose.py
michaelgrund Jan 20, 2021
4c48b7c
removed pytest from test_rose.py
michaelgrund Jan 20, 2021
70cd244
Update pygmt/base_plotting.py
michaelgrund Jan 22, 2021
9a24db9
updated docstrings
michaelgrund Jan 22, 2021
e803b8f
updated docstrings
michaelgrund Jan 22, 2021
fce3503
updated docstrings
michaelgrund Jan 22, 2021
3f398ff
updated docstrings
michaelgrund Jan 22, 2021
6aeeabc
Merge branch 'master' into patch-2
michaelgrund Jan 23, 2021
f91bdae
update
michaelgrund Jan 23, 2021
1c10e3f
Merge branch 'patch-2' of https://github.com/michaelgrund/pygmt into …
michaelgrund Jan 23, 2021
405ee62
updated format
michaelgrund Jan 23, 2021
93b5320
updated
michaelgrund Jan 23, 2021
f5a611f
adjusted aliases according to the rose wrapper for Julia
michaelgrund Jan 24, 2021
7db6f13
corrected typo
michaelgrund Jan 24, 2021
9f24e7b
adjustments to handle input if 'inquire' = True
michaelgrund Jan 26, 2021
9fb5979
added some modifications and a gallery example
michaelgrund Jan 27, 2021
86bfdb2
Merge branch 'master' into patch-2
michaelgrund Jan 27, 2021
e12c2a0
updates
michaelgrund Jan 27, 2021
8fb7896
updates
michaelgrund Jan 27, 2021
e61ba24
added missing import
michaelgrund Jan 27, 2021
2befeb4
added test for bools
michaelgrund Jan 28, 2021
538a76a
Merge branch 'master' into patch-2
michaelgrund Jan 29, 2021
566b51d
Merge branch 'master' into patch-2
michaelgrund Jan 29, 2021
04d8ab0
move rose function from base_plotting.py to rose.py
michaelgrund Jan 29, 2021
24de7a0
Merge branch 'patch-2' of https://github.com/michaelgrund/pygmt into …
michaelgrund Jan 29, 2021
caea72c
Merge branch 'master' into patch-2
michaelgrund Jan 29, 2021
cbf969f
Merge branch 'master' into patch-2
michaelgrund Jan 30, 2021
bffd365
Update pygmt/src/rose.py
michaelgrund Jan 31, 2021
96a52b5
Merge branch 'master' into patch-2
michaelgrund Jan 31, 2021
9855d68
adjustments based on review
michaelgrund Jan 31, 2021
abd4fb5
test updates
michaelgrund Jan 31, 2021
e54ab13
added 'diameter' argument to gallery example
michaelgrund Jan 31, 2021
dfbc352
Update pygmt/base_plotting.py
michaelgrund Feb 1, 2021
acd1bfb
Update pygmt/base_plotting.py
michaelgrund Feb 1, 2021
b52b2c6
updates
michaelgrund Feb 1, 2021
7707e85
Update pygmt/src/rose.py
michaelgrund Feb 7, 2021
fd9f7aa
merge master into patch-2
michaelgrund Feb 7, 2021
54b9d5d
updated figure.py
michaelgrund Feb 7, 2021
ef1fb86
updated branch
michaelgrund Feb 10, 2021
227c067
Merge branch 'master' into patch-2
michaelgrund Feb 11, 2021
8b9fe59
update to avoid pylint warnings
michaelgrund Feb 11, 2021
d677e91
Merge branch 'master' into patch-2
michaelgrund Feb 11, 2021
939c7e8
Merge branch 'master' into patch-2
michaelgrund Feb 12, 2021
edbfd7e
Merge branch 'master' into patch-2
michaelgrund Feb 12, 2021
b4b9be7
Merge branch 'master' into patch-2
michaelgrund Feb 13, 2021
dec9116
Merge branch 'master' into patch-2
michaelgrund Feb 19, 2021
e4cd8c2
Merge branch 'master' into patch-2
michaelgrund Feb 20, 2021
29ef52e
Merge branch 'master' into patch-2
michaelgrund Feb 28, 2021
b12f4c1
Merge branch 'master' into patch-2
michaelgrund Mar 2, 2021
27f7b55
Merge branch 'master' into patch-2
michaelgrund Mar 4, 2021
14b4e88
Merge branch 'master' into patch-2
michaelgrund Mar 18, 2021
a96347d
moved rose gallery example to new embellishments folder
michaelgrund Mar 18, 2021
99cf74a
adjusted how data will be passed into module
michaelgrund Mar 19, 2021
ed3ea86
formatting
michaelgrund Mar 19, 2021
155641d
Merge branch 'master' into patch-2
michaelgrund Mar 21, 2021
db9bf9a
updated rose.py and added comments to gallery example
michaelgrund Mar 21, 2021
c24302c
Merge branch 'master' into patch-2
michaelgrund Mar 21, 2021
929480f
Merge branch 'master' into patch-2
michaelgrund Mar 21, 2021
309e454
Merge branch 'master' into patch-2
michaelgrund Mar 22, 2021
adfb515
Update pygmt/src/rose.py
michaelgrund Mar 22, 2021
9296640
Update pygmt/src/rose.py
michaelgrund Mar 22, 2021
7b205d2
Update pygmt/src/rose.py
michaelgrund Mar 22, 2021
ebb7f5b
Update pygmt/src/rose.py
michaelgrund Mar 22, 2021
d438269
[format-command] fixes
actions-bot Mar 22, 2021
07335c7
Merge branch 'master' into patch-2
michaelgrund Mar 23, 2021
a48adf6
Merge branch 'master' into patch-2
michaelgrund Mar 24, 2021
cd57a33
Merge branch 'master' into patch-2
michaelgrund Mar 25, 2021
185a995
added test plots into DVC
michaelgrund Mar 25, 2021
6eb3c41
adjusted tests for rose
michaelgrund Mar 25, 2021
fde3583
Merge branch 'master' into patch-2
michaelgrund Mar 25, 2021
d4523e6
formatting
michaelgrund Mar 25, 2021
0a64131
updated gallery example
michaelgrund Mar 25, 2021
a60393f
Merge branch 'master' into patch-2
michaelgrund Mar 26, 2021
9556c60
Merge branch 'master' into patch-2
michaelgrund Mar 26, 2021
27a2c49
Merge branch 'master' into patch-2
michaelgrund Mar 26, 2021
151164e
Merge branch 'master' into patch-2
michaelgrund Mar 29, 2021
7503be5
Merge branch 'master' into patch-2
michaelgrund Mar 30, 2021
62679e6
Merge branch 'master' into patch-2
michaelgrund Mar 30, 2021
62193a2
Merge branch 'master' into patch-2
michaelgrund Mar 31, 2021
374eef7
updates based on code review
michaelgrund Mar 31, 2021
3ecc451
Update examples/gallery/embellishments/rose.py
michaelgrund Mar 31, 2021
683b3ba
updates based on code review
michaelgrund Mar 31, 2021
e0ac586
Update pygmt/src/rose.py
michaelgrund Mar 31, 2021
50acec1
Merge branch 'master' into patch-2
michaelgrund Mar 31, 2021
08a1b94
updates based on code review from seisman
michaelgrund Mar 31, 2021
2a5ae8a
Update pygmt/src/rose.py
michaelgrund Mar 31, 2021
8da61b0
Update pygmt/src/rose.py
michaelgrund Mar 31, 2021
e4f5fe9
Update pygmt/src/rose.py
michaelgrund Mar 31, 2021
4049d45
Update pygmt/src/rose.py
michaelgrund Mar 31, 2021
209917f
Update pygmt/src/rose.py
michaelgrund Mar 31, 2021
b677cfa
Update pygmt/src/rose.py
michaelgrund Mar 31, 2021
524a500
Update pygmt/src/rose.py
michaelgrund Mar 31, 2021
285b2e6
Update pygmt/src/rose.py
michaelgrund Mar 31, 2021
1dd2838
Update pygmt/src/rose.py
michaelgrund Mar 31, 2021
cd6d4e8
Update pygmt/src/rose.py
michaelgrund Mar 31, 2021
f6a5061
Update pygmt/src/rose.py
michaelgrund Mar 31, 2021
dcebf12
Update pygmt/src/rose.py
michaelgrund Mar 31, 2021
fb2d3df
Update pygmt/src/rose.py
michaelgrund Mar 31, 2021
21ff7fb
Update pygmt/src/rose.py
michaelgrund Mar 31, 2021
5120edb
Update pygmt/src/rose.py
michaelgrund Mar 31, 2021
88d0160
Update pygmt/src/rose.py
michaelgrund Mar 31, 2021
f25d34b
formatting
michaelgrund Mar 31, 2021
473bc3e
Update pygmt/src/rose.py
michaelgrund Mar 31, 2021
c310ffa
removed -I option and if query, adjusted gallery example
michaelgrund Mar 31, 2021
b6ff595
Update pygmt/src/rose.py
michaelgrund Mar 31, 2021
93eb24e
Apply suggestions from code review
weiji14 Apr 1, 2021
950709e
Update pygmt/src/rose.py
weiji14 Apr 1, 2021
7789ee3
Remove whitespace before return fig
weiji14 Apr 1, 2021
9c62d4b
Merge branch 'master' into patch-2
Apr 1, 2021
da6b829
Use pytest fixtures for sample data to test rose
weiji14 Apr 1, 2021
415fde4
Merge branch 'master' into patch-2
michaelgrund Apr 1, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Plotting data and laying out the map:
Figure.meca
Figure.plot
Figure.plot3d
Figure.rose
Figure.set_panel
Figure.shift_origin
Figure.solar
Expand Down
44 changes: 44 additions & 0 deletions examples/gallery/embellishments/rose.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""
Copy link
Member

@seisman seisman Apr 1, 2021

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.

Copy link
Member Author

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.

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()
1 change: 1 addition & 0 deletions pygmt/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ def _repr_html_(self):
meca,
plot,
plot3d,
rose,
set_panel,
solar,
subplot,
Expand Down
2 changes: 2 additions & 0 deletions pygmt/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Source code for PyGMT modules.
"""
# pylint: disable=import-outside-toplevel

from pygmt.src.basemap import basemap
from pygmt.src.blockm import blockmean, blockmedian
from pygmt.src.coast import coast
Expand All @@ -25,6 +26,7 @@
from pygmt.src.meca import meca
from pygmt.src.plot import plot
from pygmt.src.plot3d import plot3d
from pygmt.src.rose import rose
from pygmt.src.solar import solar
from pygmt.src.subplot import set_panel, subplot
from pygmt.src.surface import surface
Expand Down
204 changes: 204 additions & 0 deletions pygmt/src/rose.py
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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The long alias for i might change from 'columns' to 'incols' or something (see #764 and links in there). Will need to discuss further.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, fine for me.

Copy link
Member

Choose a reason for hiding this comment

The 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 i="columns" now. But will need to remember to change it after there's a decision is made on #764 and before PyGMT v0.4.0 comes out.

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)
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_rose_2d_array_multiple.png.dvc
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
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_rose_2d_array_single.png.dvc
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
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_rose_bools.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 2b0ba264c2240a6d2da02466d8848d7a
size: 73857
path: test_rose_bools.png
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_rose_data_file.png.dvc
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
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_rose_no_sectors.png.dvc
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
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_rose_plot_data_using_cpt.png.dvc
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
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_rose_plot_with_transparency.png.dvc
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
Loading