-
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 velo #525
Wrap velo #525
Conversation
💖 Thanks for opening this pull request! 💖 Please make sure you read our contributing guidelines and abide by our code of conduct. A few things to keep in mind:
|
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.
Hi @lhoupert, thanks for opening up this Pull Request, and sorry for all the linter noise! I've made a couple of docstring related suggestions, see if they can help silence the lint errors.
To answer your question: "what should be the pygmt code to run the gmt example given", this is the code (that should go under test_velo.py
)!:
"""
Tests velo.
"""
import pandas as pd
from pygmt import Figure
@pytest.mark.mpl_image_compare
def test_velo_pandas_dataframe():
"""
Plot velocity vectors, crosses, and wedges from a pandas.DataFrame
"""
fig = Figure()
df = pd.DataFrame(
data={
"Long.": [0, -8, 0, -5, 5, 0],
"Lat.": [-8, 5, 0, -5, 0, -5],
"Evel": [0, 3, 4, 6, -6, 6],
"Nvel": [0, 3, 6, 4, 4, -4],
"Esig": [4, 0, 4, 6, 6, 6],
"Nsig": [6, 0, 6, 4, 4, 4],
"CorEN": [0.5, 0.5, 0.5, 0.5, -0.5, -0.5],
# "SITE": ["4x6", "3x3", "NaN", "6x4", "-6x4", "6x-4"],
}
)
fig.velo(
data=df.to_numpy(),
region=[-10, 10, -10, 10],
W="0.25p,red",
G="green",
L=True,
S="e0.2/0.39/18",
frame="1g1",
projection="x0.4/0.4",
A="0.3p",
V=True,
)
# fig.show()
return fig
Yes, it actually works 😄, now what we need to do is to make it nicer, e.g. by:
- Tidy up the docstring to use long-form aliases like
pen
instead ofW
. You can preview the documentation for this PR live at https://pygmt-git-fork-lhoupert-add-velo.gmt.now.sh/api/generated/pygmt.Figure.velo.html - Write some more unit tests to make sure we can handle numpy arrays, pandas DataFrames and filenames
- Handle string types (note how I commented out "SITE"), need to wait for Wrap GMT_Put_Strings to pass str columns into GMT C API directly #520.
Just let us know how much you're comfortable with handling and we'll try to help you with the other stuff (or you can handle everything!). If you could tick the "Allow edits from maintainers" box somewhere on the right, we can directly make commits to your branch and help you out directly too.
Thank you @weiji14 for your great suggestions. I checked and the bock "allow edits from maintainers" appears ticked.
I am happy to give it a go and let you know when I need help. I will not be able to work on this for the next month or so, but I will be back at some point in August with some updates! |
Hi @lhoupert, no worries with leaving it for a while. I'm a bit busy myself these days, but I'll try to get this in for the v0.2.0 or v0.2.1 release.
Naming aliases is indeed a hard problem, usually we look at https://www.generic-mapping-tools.org/GMT.jl/latest/ but they don't seem to have
I found https://automationpanda.com/ to be a great resource when I started writing tests (maybe 2 years ago). It's quite long but comprehensive, definitely worth a read (or skim) if you're interested into getting good at writing tests. Happy for you to take a stab at it in this PR, real world examples are the best way to learn! |
Hi @weiji14 , just to let you know I don't forget abouot it. Hopefully, I should have time to work on it at some point in November! |
/test-gmt-dev View at https://github.com/GenericMappingTools/pygmt/actions/runs/798234237 |
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.
Except the minor typo, this PR looks good to me.
Co-authored-by: Michael Grund <[email protected]>
I will merge this in tomorrow after #1232 is finalized (so that the required checks are all green). Sorry to keep the world waiting, we're a bit too perfectionist here 🤓 Note to self, cross-references: SciTools/cartopy#1487, matplotlib/matplotlib#16750 and https://stackoverflow.com/questions/60679029/cartopy-cant-plot-vector-field-with-uncertainties-and-related-questions. |
As per GenericMappingTools#1190 (comment). Plus re-wrap some paragraphs to 79 characters.
@@ -0,0 +1,42 @@ | |||
""" |
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.
Co-Authored-By: Dongdong Tian <[email protected]>
🎉🎉🎉 Congrats on merging your first pull request and welcome to the team! 🎉🎉🎉 Please open a new pull request to add yourself to the |
Thanks @lhoupert, really appreciate your work on this 🥳 You can now use
Also ping @tobiscode who might be interested to try PyGMT's Sorry again that this dragged on for so long (too many sidetracked issues), we're starting to streamline and cut down on the time to implement new features in PyGMT (<1 month), so please don't hesitate to open new feature request issues or pull requests. Feel free to provide any feedback here on GitHub or on our forum. Cheers! |
Thanks very much @weiji14 @seisman @meghanrjones @michaelgrund and others for the achievement! And sorry to not have been available to help more at the end. I think it's going to be a great addition to pygmt particularly for the physical oceanography community :-) |
Add `velo` function for plotting velocity vectors, crosses, anisotropy bars, and wedges. Original GMT velo function can be found at https://docs.generic-mapping-tools.org/6.1/supplements/geodesy/velo.html * clarify the type of data input * raise error if alias S is not defined * Refactor velo to use virtualfile_from_data and add three more unit tests * Alias panel (c) for velo, and lightly edit some docstrings * Alias scale (H), intensity (I) and zvalue (Z) from GMT 6.2.0 Update docstring to include new options in `velo` from the upcoming GMT 6.2.0 that were added in GenericMappingTools/gmt#4970, GenericMappingTools/gmt#4901, and GenericMappingTools/gmt#4907. Removed the default vector="+p1p+e" argument, and formatted docstring to have nested lists to be nicer looking. * Fix typos and add intersphinx mappings * Update the frame, region, projection and color of velo example * Rename alias intensity for -I to shading * Rename alias facecolor for -G to color * Move docstring for projection (J) and region (R) up a bit * Rename alias to spec (S) and update baseline images for GMT 6.2.0rc1 * Mark fig.velo tests with xfail * Rename alias uncertainty_color to uncertaintycolor for parameter E * Move velo_arrow_ellipse.py under "Seismology and Geodesy" category Co-authored-by: Wei Ji <[email protected]> Co-authored-by: Dongdong Tian <[email protected]> Co-authored-by: Michael Grund <[email protected]> Co-authored-by: Meghan Jones <[email protected]>
Adding the velo function! Original GMT velo function can be found at https://docs.generic-mapping-tools.org/latest/supplements/geodesy/velo.html.
Live documentation preview: https://pygmt-git-fork-lhoupert-add-velo-gmt.vercel.app/api/generated/pygmt.Figure.velo.html
Gallery example preview: https://pygmt-git-fork-lhoupert-add-velo-gmt.vercel.app/gallery/seismology/velo_arrow_ellipse.html
I followed advice from @weiji14 [see the feature request I opened here]. I implemented the function by mostly copy-modify-pasted from plot and edited the doc string. The options for
velo
are quite different fromplot
so most of the parameters were changed.Problems encountered
I need help to understand how pygmt is handling the dataframe
data
. The gmtvelo
function requires the argumenttable
(One or more ASCII (or binary, see -bi[ncols][type]) data table file(s) holding a number of data columns. If no tables are given then we read from standard input.). My opinion is that in pygmt,Figure.velo
should reads data values from files, numpy array or panda dataframe.Can someone help to figure out what should be the pygmt code to run the gmt example given at the end of my request?
I converted the table from standard input into a panda dataframe:
Original GMT example for
velo
(more details here)The following should make big red arrows with green ellipses outlined in red. Note that the 39% confidence scaling will give an ellipse which fits inside a rectangle of dimension Esig by Nsig.
Fixes #510