-
Notifications
You must be signed in to change notification settings - Fork 224
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 wiggle #1145
Merged
Merged
Wrap wiggle #1145
Changes from 19 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
d2f726d
Wrap wiggle
core-man bd459ef
Add a draft example
core-man 1899f40
Apply suggestions from code review
core-man 33deee7
Add wiggle in doc/api/index
core-man 9f1c7d2
Merge branch 'master' into wiggle
core-man 5f9f7a1
Add test_wiggle
core-man 6722661
Fix test name
core-man 54adcff
Add test_wiggle.png into DVC
core-man 2316537
Refine the wiggle gallery example
core-man cd44b14
Remove the transparency parameter
core-man 7deaa0e
Format wiggle gallery example
core-man faf6555
Merge branch 'master' into wiggle
core-man 5e6c4bc
Add more explanation for color
core-man ca35b51
Add more comments for the example
core-man 3fff8e3
Update the pen parameter
core-man 3a1f78e
Apply suggestions from code review
core-man 0880391
Fix the explanation for x/y/z
core-man 101ee29
Merge branch 'wiggle' of github.com:core-man/pygmt into wiggle
core-man b359c55
Merge branch 'master' into wiggle
core-man 4e57362
Apply suggestions from code review
core-man 96a140a
Apply suggestions from code review
core-man 06c5515
Merge branch 'master' into wiggle
core-man dedcd91
Apply suggestions from code review
core-man 3f32058
Move wiggel example to be within Line
core-man e80d04a
Merge branch 'master' into wiggle
core-man File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
""" | ||
Wiggle along tracks | ||
-------------------- | ||
core-man marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The :meth:`pygmt.Figure.wiggle` method can plot z = f(x,y) anomalies along | ||
tracks. ``x``, ``y``, ``z`` can be specified as 1d arrays or within a specified | ||
file. The ``scale`` parameter can be used to set anomaly scale in | ||
core-man marked this conversation as resolved.
Show resolved
Hide resolved
|
||
data-units/distance-unit. The positive and/or negative areas can be filled with | ||
color by setting the ``color`` parameter. | ||
""" | ||
|
||
import numpy as np | ||
import pygmt | ||
|
||
# Create (x, y, z) triplets | ||
x = np.arange(-7, 7, 0.1) | ||
y = np.zeros(x.size) | ||
z = 50 * np.exp(-((x / 3) ** 2)) * np.cos(2 * np.pi * x) | ||
|
||
fig = pygmt.Figure() | ||
fig.basemap(region=[-8, 12, -1, 1], projection="X10c", frame=["Snlr", "xa2f1"]) | ||
fig.wiggle( | ||
x=x, | ||
y=y, | ||
z=z, | ||
# Set anomaly scale to "20c" | ||
scale="20c", | ||
# Fill positive and negative areas red and gray, respectively | ||
color=["red+p", "gray+n"], | ||
# Set the outline width to "1.0p" | ||
pen="1.0p", | ||
# Draw a blue track of width 0.5 points | ||
core-man marked this conversation as resolved.
Show resolved
Hide resolved
|
||
track="0.5p,blue", | ||
# Plot a vertical scale bar at the right middle. The bar length is 100 in | ||
# data (z) units. Set the z unit lable to "nT". | ||
core-man marked this conversation as resolved.
Show resolved
Hide resolved
|
||
position="jRM+w100+lnT", | ||
) | ||
fig.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -423,6 +423,7 @@ def _repr_html_(self): | |
solar, | ||
subplot, | ||
text, | ||
wiggle, | ||
) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
""" | ||
wiggle - Plot z=f(x,y) anomalies along tracks. | ||
""" | ||
from pygmt.clib import Session | ||
from pygmt.helpers import build_arg_string, fmt_docstring, kwargs_to_strings, use_alias | ||
|
||
|
||
@fmt_docstring | ||
@use_alias( | ||
B="frame", | ||
D="position", | ||
G="color", | ||
J="projection", | ||
R="region", | ||
T="track", | ||
U="timestamp", | ||
V="verbose", | ||
W="pen", | ||
X="xshift", | ||
Y="yshift", | ||
Z="scale", | ||
c="panel", | ||
i="columns", | ||
p="perspective", | ||
) | ||
@kwargs_to_strings(R="sequence", c="sequence_comma", i="sequence_comma", p="sequence") | ||
def wiggle(self, x=None, y=None, z=None, data=None, **kwargs): | ||
r""" | ||
Plot z=f(x,y) anomalies along tracks. | ||
|
||
Takes a matrix, (x,y,z) triplets, or a file name as input and plots z as a | ||
function of distance along track. | ||
|
||
Must provide either ``data`` or ``x``/``y``/``z``. | ||
|
||
Full parameter list at :gmt-docs:`wiggle.html` | ||
|
||
{aliases} | ||
|
||
Parameters | ||
---------- | ||
x/y/z : 1d arrays | ||
The arrays of x and y coordinates and z data points. | ||
data : str or 2d array | ||
Either a data file name or a 2d numpy array with the tabular data. | ||
Use parameter ``columns`` to choose which columns are x, y, z, | ||
respectively. | ||
core-man marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{J} | ||
{R} | ||
scale : str or float | ||
Gives anomaly scale in data-units/distance-unit. Append **c**, **i**, | ||
or **p** to indicate the distance unit (cm, inch, or point); if no unit | ||
is given we use the default unit that is controlled by | ||
:gmt-term:`PROJ_LENGTH_UNIT`. | ||
{B} | ||
position : str | ||
[**g**\|\ **j**\|\ **J**\|\ **n**\|\ **x**]\ *refpoint*\ | ||
**+w**\ *length*\ [**+j**\ *justify*]\ [**+al**\ |\ **r**]\ | ||
[**+o**\ *dx*\ [/*dy*]][**+l**\ [*label*]]. | ||
Defines the reference point on the map for the vertical scale bar. | ||
color: str | ||
core-man marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Set fill shade, color or pattern for positive and/or negative wiggles | ||
[Default is no fill]. Optionally, append **+p** to fill positive areas | ||
(this is the default behavior). Append **+n** to fill negative areas. | ||
Append **+n+p** to fill both positive and negative areas with the same | ||
fill. Note: You will need to repeat the color parameter to select | ||
different fills for the positive and negative wiggles. | ||
|
||
track : str | ||
Draw track [Default is no track]. Append pen attributes to use | ||
[Default is **0.25p,black,solid**\ ]. | ||
core-man marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{U} | ||
{V} | ||
pen : str | ||
Specify outline pen attributes [Default is no outline]. | ||
{XY} | ||
{c} | ||
columns : str or 1d array | ||
Choose which columns are x, y, and z, respectively if input is provided | ||
via *data*. E.g. ``columns = [0, 1, 2]`` or ``columns = "0,1,2"`` if | ||
the *x* values are stored in the first column, *y* values in the second | ||
one and *z* values in the third one. Note: zero-based indexing is used. | ||
{p} | ||
""" | ||
kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access | ||
|
||
with Session() as lib: | ||
# Choose how data will be passed in to the module | ||
file_context = lib.virtualfile_from_data( | ||
check_kind="vector", data=data, x=x, y=y, z=z | ||
) | ||
|
||
with file_context as fname: | ||
arg_str = " ".join([fname, build_arg_string(kwargs)]) | ||
lib.call_module("wiggle", arg_str) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
outs: | ||
- md5: 5ac12f7e91127dae1fa70cec77b84c0b | ||
size: 9144 | ||
path: test_wiggle.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# pylint: disable=redefined-outer-name | ||
core-man marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
Tests wiggle. | ||
""" | ||
import numpy as np | ||
import pytest | ||
from pygmt import Figure | ||
|
||
|
||
@pytest.mark.mpl_image_compare | ||
def test_wiggle(): | ||
""" | ||
Plot the z=f(x,y) anomalies along tracks. | ||
""" | ||
x = np.arange(-2, 2, 0.02) | ||
y = np.zeros(x.size) | ||
z = np.cos(2 * np.pi * x) | ||
|
||
fig = Figure() | ||
fig.wiggle( | ||
region=[-4, 4, -1, 1], | ||
projection="X8c", | ||
x=x, | ||
y=y, | ||
z=z, | ||
scale="0.5c", | ||
color=["red+p", "gray+n"], | ||
pen="1.0p", | ||
track="0.5p", | ||
position="jRM+w2+lnT", | ||
) | ||
return fig |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
I don't think
wiggle
is a seismology-specific module. I recommend moving the example to the "Line" category.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.
okay. @seisman done in 3f32058.