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 x2sys_init and x2sys_cross #546

Merged
merged 15 commits into from
Jul 27, 2020
Merged

Wrap x2sys_init and x2sys_cross #546

merged 15 commits into from
Jul 27, 2020

Conversation

weiji14
Copy link
Member

@weiji14 weiji14 commented Jul 23, 2020

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:

import pygmt

fname: str = pygmt.which("@tut_ship.xyz", download="a")
pygmt.x2sys_init(tag="GMT", fmtfile="xyz", force=True)
df: pd.DataFrame = x2sys_cross(tracks=[fname], tag=tag, coe="i")

assert df.shape == (14294, 12)

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:

  • Alias short-form arguments in x2sys_init
    • fmtfile (D)
    • suffix (E)
    • force (F)
    • discontinuity (G)
    • spacing (I)
    • units (N) (Nd or Nt)
    • region (R)
    • gap (W) (Wd or Wt)
    • distcalc (j)
  • Alias short-form arguments in x2sys_cross
    • combitable (A)
    • runtimes (C)
    • override (D)
    • interpolation (I)
    • coe (Q)
    • region (R)
    • speed (S)
    • tag (T)
    • verbose (V)
    • numpoints (W)
    • trackvalues (Z)
  • Allow for pandas.DataFrame input into x2sys_cross (dependent on Passing in virtual files into the supplementary x2sys modules gmt#3717, may do it in separate PR)
  • Handle multiple crossover files (b5aa8a8)
  • Load datetime columns with correct dtype into pandas.DataFrame (f61e289)

Fixes #545

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If adding new functionality, add an example to docstrings or tutorials.

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.
@weiji14 weiji14 added the feature Brand new feature label Jul 23, 2020
pygmt/tests/test_x2sys_cross.py Outdated Show resolved Hide resolved
pygmt/x2sys.py Outdated
Comment on lines 122 to 123
elif kind == "matrix":
file_context = lib.virtualfile_from_matrix(track.values)
Copy link
Member Author

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]

Copy link
Member

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.

Copy link
Member Author

@weiji14 weiji14 Jul 23, 2020

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

@vercel vercel bot temporarily deployed to Preview July 23, 2020 11:23 Inactive
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.
weiji14 added 2 commits July 26, 2020 12:55
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
Comment on lines 130 to 140
A="combitable",
C="runtimes",
# D="",
I="interpolation",
R="region",
S="speed",
T="tag",
Q="coe",
V="verbose",
W="numpoints",
# Z="",
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, almost done aliasing all the arguments for x2sys_cross. Any good names for D or Z?

Copy link
Member Author

@weiji14 weiji14 Jul 26, 2020

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.
@vercel vercel bot temporarily deployed to Preview July 27, 2020 01:35 Inactive
@seisman
Copy link
Member

seisman commented Jul 27, 2020

Maybe better to open separate PRs for other unrelated changes, e.g., pygmt/helpers/decorators.py and .pylintrc?

@weiji14
Copy link
Member Author

weiji14 commented Jul 27, 2020

Maybe better to open separate PRs for other unrelated changes, e.g., pygmt/helpers/decorators.py and .pylintrc?

Ok, opened #550 for verbose (V) and #551 for distcalc (j). I've renamed df to table/dataframe so the .pylintrc change isn't needed anymore.

@seisman seisman added this to the 0.2.x milestone Jul 27, 2020
Copy link
Member

@seisman seisman left a 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.

@weiji14
Copy link
Member Author

weiji14 commented Jul 27, 2020

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 pandas.DataFrame input and tutorial for this once I have a play with it a little bit more (probably next month).

@weiji14 weiji14 merged commit a851624 into master Jul 27, 2020
@weiji14 weiji14 deleted the x2sys_cross branch July 27, 2020 22:58
Comment on lines +110 to +117
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"
)
Copy link
Member

@seisman seisman Jul 28, 2020

Choose a reason for hiding this comment

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

@weiji14

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.

weiji14 added a commit that referenced this pull request Feb 22, 2021
Move the x2sys modules originally wrapped in #546.
The single x2sys.py has been separated into x2sys_init.py
and x2sys_cross.py inside the src/ folder as per #807.
weiji14 added a commit that referenced this pull request Feb 22, 2021
Move the x2sys modules originally wrapped in #546.
The single x2sys.py has been separated into x2sys_init.py
and x2sys_cross.py inside the src/ folder as per #807.
weiji14 added a commit that referenced this pull request Feb 22, 2021
…oss (#951)

Move the x2sys modules originally wrapped in #546.
The single x2sys.py has been separated into x2sys_init.py
and x2sys_cross.py inside the src/ folder as per #807.
sixy6e pushed a commit to sixy6e/pygmt that referenced this pull request Dec 21, 2022
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Brand new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrapper for x2sys_cross
2 participants