-
Notifications
You must be signed in to change notification settings - Fork 225
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 velo #525
Merged
Merged
Wrap velo #525
Changes from 60 commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
e3c296f
add new velo function
lhoupert c6e3476
create new velo function
lhoupert c2b951c
format alias
lhoupert 1cf7967
clarify the type of data input
lhoupert fc7bec8
remove reference to vector x, y (not of use anymore)
lhoupert 7b905d7
clear code from reference to variable sizes and direction
lhoupert 1fcf089
start with test
lhoupert ac05994
fix raw string
lhoupert 38514ef
update add-velo with upstream master branch and fix issues
lhoupert fd6e421
clarify aliases and edit test
lhoupert 4858aff
Apply suggestions from code review
lhoupert 099a3d6
update docstring
lhoupert 8c6c0e1
fix errors from make lint
lhoupert 480abd0
remove baseline img
lhoupert 98d5ded
create example and edit test so it fit the example
lhoupert dea4b1c
Apply suggestions from code review
lhoupert 132995a
Merge branch 'master' of https://github.com/GenericMappingTools/pygmt…
lhoupert c908e78
Apply suggestions from code review
lhoupert 6e3076a
temporarily disable pylint check as base_plotting.py exceed 2000 lines
lhoupert 6dff809
Merge branch 'add-velo' of https://github.com/lhoupert/pygmt into add…
lhoupert e5de366
edit gallery example to add text
lhoupert 76c9b28
Apply suggestions from code review
lhoupert 7dccfa9
update baseline test image
lhoupert 1fe7005
Update examples/gallery/plot/velo_arrow_ellipse.py
lhoupert e2e956c
Apply suggestions from code review
lhoupert 8364134
detect data type
lhoupert 7a9de97
remove scaling as alias
lhoupert 909827a
Revert "remove scaling as alias"
lhoupert 1e5fe88
raise error if alias S is not defined
lhoupert cfcae90
edit function arguments
lhoupert 92f94f1
edit dataframe check
lhoupert 0e66deb
Merge branch 'master' into add-velo
weiji14 437e415
Fix velo import errors and do some light code linting
weiji14 dd24153
Refactor velo to use virtualfile_from_data and add three more unit tests
weiji14 cc0ef72
Alias panel (c) for velo, and lightly edit some docstrings
weiji14 34ad182
Merge branch 'master' into add-velo
weiji14 90e9e0d
Alias scale (H), intensity (I) and zvalue (Z) from GMT 6.2.0
weiji14 d3850b7
Merge branch 'master' into add-velo
weiji14 d67bfcd
Fix typos and add intersphinx mappings
weiji14 c90ec47
Remove dash-colon option to interchange column order
weiji14 80743aa
[skip ci] Fix a few more typos and indentation issues
weiji14 2661e2c
Update the frame, region, projection and color of velo example
weiji14 ef3465e
Merge branch 'master' into add-velo
weiji14 86cf8a0
Update dvc hash for test_velo_pandas_dataframe
weiji14 be959fc
Use serial/Oxford comma in velo summary description
weiji14 0653349
Merge branch 'master' into add-velo
weiji14 c9f859d
Merge branch 'master' into add-velo
weiji14 92feb97
Apply suggestions from code review
weiji14 71d3797
Apply suggestions from code review
weiji14 9ef3983
Rename alias intensity for -I to shading
weiji14 88d1c8f
Rename alias facecolor for -G to color
weiji14 984b4cb
Merge branch 'master' into add-velo
weiji14 b8a2410
Move docstring for projection (J) and region (R) up a bit
weiji14 c9c7b66
Merge branch 'master' into add-velo
weiji14 23e908c
Rename alias to spec (S) and update baseline images for GMT 6.2.0rc1
weiji14 d33f7a5
Merge branch 'master' into add-velo
weiji14 6b99454
Fix typo on examples/gallery/symbols/velo_arrow_ellipse.py
weiji14 f949f16
Mark fig.velo tests with xfail
weiji14 1064c82
Rename alias uncertainty_color to uncertaintycolor for parameter E
weiji14 8a7cb44
Merge branch 'master' into add-velo
weiji14 da9ee3b
Move velo_arrow_ellipse.py under "Seismology and Geodesy" category
weiji14 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,42 @@ | ||
""" | ||
Velocity arrows and confidence ellipses | ||
--------------------------------------- | ||
|
||
The :meth:`pygmt.Figure.velo` method can be used to plot mean velocity arrows | ||
and confidence ellipses. | ||
The example below plots red velocity arrows with light-blue confidence ellipses | ||
outlined in red with the east_velocity x north_velocity used for the station names. | ||
Note that the velocity arrows are scaled by 0.2 and the 39% confidence limit | ||
will give an ellipse | ||
which fits inside a rectangle of dimension east_sigma by north_sigma. | ||
""" | ||
|
||
import pandas as pd | ||
import pygmt | ||
|
||
fig = pygmt.Figure() | ||
df = pd.DataFrame( | ||
data={ | ||
"x": [0, -8, 0, -5, 5, 0], | ||
"y": [-8, 5, 0, -5, 0, -5], | ||
"east_velocity": [0, 3, 4, 6, -6, 6], | ||
"north_velocity": [0, 3, 6, 4, 4, -4], | ||
"east_sigma": [4, 0, 4, 6, 6, 6], | ||
"north_sigma": [6, 0, 6, 4, 4, 4], | ||
"correlation_EN": [0.5, 0.5, 0.5, 0.5, -0.5, -0.5], | ||
"SITE": ["0x0", "3x3", "4x6", "6x4", "-6x4", "6x-4"], | ||
} | ||
) | ||
fig.velo( | ||
data=df, | ||
region=[-10, 8, -10, 6], | ||
pen="0.6p,red", | ||
uncertaintycolor="lightblue1", | ||
line=True, | ||
spec="e0.2/0.39/18", | ||
frame=["WSne", "2g2f"], | ||
projection="x0.8c", | ||
vector="0.3c+p1p+e+gred", | ||
) | ||
|
||
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 |
---|---|---|
|
@@ -426,6 +426,7 @@ def _repr_html_(self): | |
solar, | ||
subplot, | ||
text, | ||
velo, | ||
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,247 @@ | ||
""" | ||
velo - Plot velocity vectors, crosses, anisotropy bars, and wedges. | ||
""" | ||
import numpy as np | ||
import pandas as pd | ||
from pygmt.clib import Session | ||
from pygmt.exceptions import GMTInvalidInput | ||
from pygmt.helpers import build_arg_string, fmt_docstring, kwargs_to_strings, use_alias | ||
|
||
|
||
@fmt_docstring | ||
@use_alias( | ||
A="vector", | ||
B="frame", | ||
C="cmap", | ||
D="rescale", | ||
E="uncertaintycolor", | ||
G="color", | ||
H="scale", | ||
I="shading", | ||
J="projection", | ||
L="line", | ||
N="no_clip", | ||
R="region", | ||
S="spec", | ||
U="timestamp", | ||
V="verbose", | ||
W="pen", | ||
X="xshift", | ||
Y="yshift", | ||
Z="zvalue", | ||
maxrjones marked this conversation as resolved.
Show resolved
Hide resolved
|
||
c="panel", | ||
p="perspective", | ||
t="transparency", | ||
) | ||
@kwargs_to_strings(R="sequence", c="sequence_comma", i="sequence_comma", p="sequence") | ||
def velo(self, data=None, **kwargs): | ||
r""" | ||
Plot velocity vectors, crosses, anisotropy bars, and wedges. | ||
|
||
Reads data values from files, :class:`numpy.ndarray` or | ||
:class:`pandas.DataFrame` and plots the selected geodesy symbol on a map. | ||
You may choose from velocity vectors and their uncertainties, rotational | ||
wedges and their uncertainties, anisotropy bars, or strain crosses. Symbol | ||
fills or their outlines may be colored based on constant parameters or via | ||
color lookup tables. | ||
|
||
Must provide ``data`` and ``spec``. | ||
|
||
Full option list at :gmt-docs:`supplements/geodesy/velo.html` | ||
|
||
{aliases} | ||
|
||
Parameters | ||
---------- | ||
data : str or numpy.ndarray or pandas.DataFrame | ||
Either a file name, a 2D :class:`numpy.ndarray` or a | ||
:class:`pandas.DataFrame` with the tabular data. Note that text columns | ||
are only supported with file or pandas DataFrame inputs. | ||
|
||
spec: str | ||
Selects the meaning of the columns in the data file and the figure to | ||
be plotted. In all cases, the scales are in data units per length unit | ||
and sizes are in length units (default length unit is controlled by | ||
:gmt-term:`PROJ_LENGTH_UNIT` unless **c**, **i**, or **p** is | ||
appended). | ||
|
||
- **e**\ [*velscale*/]\ *confidence*\ [**+f**\ *font*] | ||
|
||
Velocity ellipses in (N,E) convention. The *velscale* sets the | ||
scaling of the velocity arrows. If *velscale* is not given then we | ||
read it from the data file as an extra column. The *confidence* sets | ||
the 2-dimensional confidence limit for the ellipse, e.g. 0.95 for 95% | ||
confidence ellipse. Use **+f** to set the font and size of the text | ||
[Default is 9p,Helvetica,black]; give **+f**\ 0 to deactivate | ||
labeling. The arrow will be drawn with the pen attributes specified | ||
by the ``pen`` option and the arrow-head can be colored via | ||
``color``. The ellipse will be filled with the color or shade | ||
specified by the ``uncertaintycolor`` option [Default is | ||
transparent], and its outline will be drawn if ``line`` is selected | ||
using the pen selected (by ``pen`` if not given by ``line``). | ||
Parameters are expected to be in the following columns: | ||
|
||
- **1**,\ **2**: longitude, latitude of station | ||
- **3**,\ **4**: eastward, northward velocity | ||
- **5**,\ **6**: uncertainty of eastward, northward velocities | ||
(1-sigma) | ||
- **7**: correlation between eastward and northward components | ||
- **Trailing text**: name of station (optional) | ||
|
||
- **n**\ [*barscale*] | ||
|
||
Anisotropy bars. *barscale* sets the scaling of the bars. If | ||
*barscale* is not given then we read it from the data file as an | ||
extra column. Parameters are expected to be in the following columns: | ||
|
||
- **1**,\ **2**: longitude, latitude of station | ||
- **3**,\ **4**: eastward, northward components of anisotropy | ||
vector | ||
|
||
- **r**\ [*velscale*/]\ *confidence*\ [**+f**\ *font*] | ||
|
||
Velocity ellipses in rotated convention. The *velscale* sets the | ||
scaling of the velocity arrows. If *velscale* is not given then we | ||
read it from the data file as an extra column. The *confidence* sets | ||
the 2-dimensional confidence limit for the ellipse, e.g. 0.95 for 95% | ||
confidence ellipse. Use **+f** to set the font and size of the text | ||
[Default is 9p,Helvetica,black]; give **+f**\ 0 to deactivate | ||
labeling. The arrow will be drawn with the pen attributes specified | ||
by the ``pen`` option and the arrow-head can be colored via | ||
``color``. The ellipse will be filled with the color or shade | ||
specified by the ``uncertaintycolor`` option [Default is | ||
transparent], and its outline will be drawn if ``line`` is selected | ||
using the pen selected (by ``pen`` if not given by ``line``). | ||
Parameters are expected to be in the following columns: | ||
|
||
- **1**,\ **2**: longitude, latitude of station | ||
- **3**,\ **4**: eastward, northward velocity | ||
- **5**,\ **6**: semi-major, semi-minor axes | ||
- **7**: counter-clockwise angle, in degrees, from horizontal axis | ||
to major axis of ellipse. | ||
- **Trailing text**: name of station (optional) | ||
|
||
- **w**\ [*wedgescale*/]\ *wedgemag* | ||
|
||
Rotational wedges. The *wedgescale* sets the size of the wedges. If | ||
*wedgescale* is not given then we read it from the data file as an | ||
extra column. Rotation values are multiplied by *wedgemag* before | ||
plotting. For example, setting *wedgemag* to 1.e7 works well for | ||
rotations of the order of 100 nanoradians/yr. Use ``color`` to set | ||
the fill color or shade for the wedge, and ``uncertaintycolor`` to | ||
set the color or shade for the uncertainty. Parameters are expected | ||
to be in the following columns: | ||
|
||
- **1**,\ **2**: longitude, latitude of station | ||
- **3**: rotation in radians | ||
- **4**: rotation uncertainty in radians | ||
|
||
- **x**\ [*cross_scale*] | ||
|
||
Strain crosses. The *cross_scale* sets the size of the cross. If | ||
*cross_scale* is not given then we read it from the data file as an | ||
extra column. Parameters are expected to be in the following columns: | ||
|
||
- **1**,\ **2**: longitude, latitude of station | ||
- **3**: eps1, the most extensional eigenvalue of strain tensor, | ||
with extension taken positive. | ||
- **4**: eps2, the most compressional eigenvalue of strain tensor, | ||
with extension taken positive. | ||
- **5**: azimuth of eps2 in degrees CW from North. | ||
|
||
{J} | ||
{R} | ||
vector : bool or str | ||
Modify vector parameters. For vector heads, append vector head *size* | ||
[Default is 9p]. See | ||
:gmt-docs:`supplements/geodesy/velo.html#vector-attributes` for | ||
specifying additional attributes. | ||
{B} | ||
{CPT} | ||
rescale : str | ||
can be used to rescale the uncertainties of velocities (``spec='e'`` | ||
and ``spec='r'``) and rotations (``spec='w'``). Can be combined with | ||
the ``confidence`` variable. | ||
uncertaintycolor : str | ||
Sets the color or shade used for filling uncertainty wedges | ||
(``spec='w'``) or velocity error ellipses (``spec='e'`` or | ||
``spec='r'``). If ``uncertaintycolor`` is not specified, the | ||
uncertainty regions will be transparent. **Note**: Using ``cmap`` and | ||
``zvalue='+e'`` will update the uncertainty fill color based on the | ||
selected measure in ``zvalue`` [magnitude error]. More details at | ||
:gmt-docs:`cookbook/features.html#gfill-attrib`. | ||
color : str | ||
Select color or pattern for filling of symbols [Default is no fill]. | ||
**Note**: Using ``cmap`` (and optionally ``zvalue``) will update the | ||
symbol fill color based on the selected measure in ``zvalue`` | ||
[magnitude]. More details at | ||
:gmt-docs:`cookbook/features.html#gfill-attrib`. | ||
scale : float or bool | ||
[*scale*]. | ||
Scale symbol sizes and pen widths on a per-record basis using the | ||
*scale* read from the data set, given as the first column after the | ||
(optional) *z* and *size* columns [Default is no scaling]. The symbol | ||
size is either provided by ``spec`` or via the input *size* column. | ||
Alternatively, append a constant *scale* that should be used instead of | ||
reading a scale column. | ||
shading : float or bool | ||
*intens*. | ||
Use the supplied *intens* value (nominally in the -1 to +1 range) to | ||
modulate the symbol fill color by simulating illumination [Default is | ||
none]. If *intens* is not provided we will instead read the intensity | ||
from an extra data column after the required input columns determined | ||
by ``spec``. | ||
line: str | ||
[*pen*\ [**+c**\ [**f**\|\ **l**]]]. | ||
Draw lines. Ellipses and rotational wedges will have their outlines | ||
drawn using the current pen (see ``pen``). Alternatively, append a | ||
separate pen to use for the error outlines. If the modifier **+cl** is | ||
appended then the color of the pen is updated from the CPT (see | ||
``cmap``). If instead modifier **+cf** is appended then the color from | ||
the cpt file is applied to error fill only [Default]. Use just **+c** | ||
to set both pen and fill color. | ||
no_clip: bool or str | ||
Do NOT skip symbols that fall outside the frame boundary specified | ||
by ``region``. [Default plots symbols inside frame only]. | ||
{U} | ||
{V} | ||
pen : str | ||
[*pen*][**+c**\ [**f**\|\ **l**]]. | ||
Set pen attributes for velocity arrows, ellipse circumference and fault | ||
plane edges. [Defaults: width = default, color = black, style = solid]. | ||
If the modifier **+cl** is appended then the color of the pen is | ||
updated from the CPT (see ``cmap``). If instead modifier **+cf** is | ||
appended then the color from the cpt file is applied to symbol fill | ||
only [Default]. Use just **+c** to set both pen and fill color. | ||
{XY} | ||
zvalue : str | ||
maxrjones marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[**m**\|\ **e**\|\ **n**\|\ **u**\ ][**+e**]. | ||
Select the quantity that will be used with the CPT given via ``cmap`` | ||
to set the fill color. Choose from **m**\ agnitude (vector magnitude | ||
or rotation magnitude), **e**\ ast-west velocity, **n**\ orth-south | ||
velocity, or **u**\ ser-supplied data column (supplied after the | ||
required columns). To instead use the corresponding error estimates | ||
(i.e., vector or rotation uncertainty) to lookup the color and paint | ||
the error ellipse or wedge instead, append **+e**. | ||
{c} | ||
{p} | ||
{t} | ||
""" | ||
kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access | ||
|
||
if "S" not in kwargs or ("S" in kwargs and not isinstance(kwargs["S"], str)): | ||
raise GMTInvalidInput("Spec is a required argument and has to be a string.") | ||
|
||
if isinstance(data, np.ndarray) and not pd.api.types.is_numeric_dtype(data): | ||
raise GMTInvalidInput( | ||
"Text columns are not supported with numpy.ndarray type inputs. " | ||
"They are only supported with file or pandas.DataFrame inputs." | ||
) | ||
|
||
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) | ||
|
||
with file_context as fname: | ||
arg_str = " ".join([fname, build_arg_string(kwargs)]) | ||
lib.call_module("velo", arg_str) |
4 changes: 4 additions & 0 deletions
4
pygmt/tests/baseline/test_velo_numpy_array_numeric_only.png.dvc
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: 64e45d586112fc131090cfac2c104b63 | ||
size: 45483 | ||
path: test_velo_numpy_array_numeric_only.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,4 @@ | ||
outs: | ||
- md5: 60dff1a72e6d984f095fb4973cecaec7 | ||
size: 42430 | ||
path: test_velo_pandas_dataframe.png |
Oops, something went wrong.
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.
Just one last-minute comment:
This gallery example should be put in the "Seismology and Geodesy" 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.
You're lucky, I was just about to merge this in. Looking closely, I'm actually more tempted to put this under "Lines and vectors" as there doesn't seem to be anything seismology or geodetic about
velo
(though I'm not experienced in either of those fields).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.
The "velo" module is in the "geodesy" supplement (https://docs.generic-mapping-tools.org/dev/supplements/geodesy/velo.html), and the input columns like "eastward, northward velocity, and uncertainty of eastward, northward velocities" are also specific to geodesy applications.
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.
Fair enough, had a closer read at the Geodesy wikipedia page page and it seems to fit. I'll move the gallery example.