-
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 x2sys_init and x2sys_cross #546
Conversation
Wrapping the x2sys_cross function (and x2sys_init), implemented under x2sys.py. Original GMT `x2sys_cross` documentation can be found at https://docs.generic-mapping-tools.org/6.1/supplements/x2sys/x2sys_cross.html. Sample test cases stored under test_x2sys_cross.py, and they uses the load_sample_bathymetry dataset. Aliased fmtfile (D) and force (F) for x2sys_init. Aliased tag (T) and coe (Q) for x2sys_cross.
pygmt/x2sys.py
Outdated
elif kind == "matrix": | ||
file_context = lib.virtualfile_from_matrix(track.values) |
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.
Making a virtualfile from a pandas.DataFrame
and passing that into x2sys_cross
doesn't work yet. It might just be because I'm using ASCII
with x2sys_init
, not sure if BINARY
would work (see https://docs.generic-mapping-tools.org/6.1/supplements/x2sys/x2sys_init.html#format-definition-files). Error message is as follows:
x2sys_cross [WARNING]: No time column, use dummy times
Not a valid unit: c [meter assumed]
Not a valid unit: c [meter assumed]
x2sys_cross [ERROR]: x2sys_read_file : Cannot find track @GMTAPI@-S-I-D-M-T-N-000000
(null): Error from fclose [@GMTAPI@-S-I-D-M-T-N-000000]
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.
As I understand how GMT works, I think x2sys related modules don't support virtual files. Perhaps you could open an issue in the GMT repository.
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.
Not surprised actually, I'll open an issue! Edit: Done at GenericMappingTools/gmt#3717
Support only filename inputs into x2sys_cross for now, because passing in matrix type virtualfiles into GMT C API doesn't work properly yet.
Aliased suffix (E), discontinuity (G), spacing (I), units (I), region (R), gap (W), distcalc (j) for x2sys_init. Also checked that passing a list into region (R), spacing (I), units (N), and gap (W) works properly.
Aliased combitable (A), runtimes(C), interpolation (I), region (R), speed(S), numpoints (W) for x2sys_cross. Also checked that setting the region (R), interpolation (I) and numpoints (W) args work properly.
pygmt/x2sys.py
Outdated
A="combitable", | ||
C="runtimes", | ||
# D="", | ||
I="interpolation", | ||
R="region", | ||
S="speed", | ||
T="tag", | ||
Q="coe", | ||
V="verbose", | ||
W="numpoints", | ||
# Z="", |
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.
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.
My bad suggestions:
- D (True/False, N or S) = override/overridepole
- Z (True/False) = trackvalues/rawreport/rawvalue/xvalue
Edit: Going with override (D) and trackvalues (Z)!
On Linux, z_X.mean() = -139.196212, On macOS/Windows, z_X.mean() = -139.20221.
Maybe better to open separate PRs for other unrelated changes, e.g., |
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 never used these modules, but the code quality looks good to me.
Cool, thanks @seisman! It is quite a tricky library to setup, I only got back to X2SYS a few days ago because me and my friend @arrran were getting into some crossover analysis work on satellite altimetry datasets. I'll try and get the |
for i in range(2): | ||
np.random.seed(seed=i) | ||
with open(os.path.join(os.getcwd(), f"track_{i}.xyz"), mode="w") as fname: | ||
np.savetxt(fname=fname, X=np.random.rand(10, 3)) | ||
|
||
output = x2sys_cross( | ||
tracks=["track_0.xyz", "track_1.xyz"], tag=tag, coe="e", verbose="i" | ||
) |
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.
This test produces two files track_0.xyz
and track_1.xyz
in the tmp-test-dir-with-unique-name
directory.
I'm not fully understand what the test does. It should either output to a temporary directory, or delete these two files at the end of the test.
…oss (GenericMappingTools#951) Move the x2sys modules originally wrapped in GenericMappingTools#546. The single x2sys.py has been separated into x2sys_init.py and x2sys_cross.py inside the src/ folder as per GenericMappingTools#807.
Description of proposed changes
Wrapping the x2sys_cross function (which also requires x2sys_init), implemented under x2sys.py.
X2SYS
is a tool for analyzing intersecting track data (e.g. ships measuring ocean bathymetry, satellite altimeters measuring land elevation)!Live documentation preview for this Pull Request is at https://pygmt-git-x2syscross.gmt.vercel.app/api/generated/pygmt.x2sys_cross.html.
Example code:
This is useful for performing crossover analysis (e.g. finding the elevation error between intersecting tracks). It will be tremendously useful for some of my ICESat-2 satellite laser altimetry work, and having used it in GMT 5 back in 2015 for ICESat-1, I think it's time to bring it to the Python world!
TODO:
x2sys_init
x2sys_cross
pandas.DataFrame
input intox2sys_cross
(dependent on Passing in virtual files into the supplementary x2sys modules gmt#3717, may do it in separate PR)Fixes #545
Reminders
make format
andmake check
to make sure the code follows the style guide.doc/api/index.rst
.