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

Wrapper for surface #243

Closed
weiji14 opened this issue Nov 17, 2018 · 0 comments · Fixed by #245
Closed

Wrapper for surface #243

weiji14 opened this issue Nov 17, 2018 · 0 comments · Fixed by #245

Comments

@weiji14
Copy link
Member

weiji14 commented Nov 17, 2018

Description of the desired feature

Hi there, I'd like to help implement the surface function which "Grids table data using adjustable tension continuous curvature splines". There's a lot of plotting related functionality in gmt-python now, but there's more to GMT than that! Basically, this feature request aims to bring some data processing functionality into gmt-python.

The surface function is actually just one small part of the 'Gridding of Data Tables' family of functions in GMT (see module quickref), but I'd like to start with surface because 1) It appears to be a common gridding function (there's a tutorial for it) and 2) I'm using it.

Things to keep in mind:

Idea for structure:

Store the surface function in a Gridding class under gridding.py. Similar to how e.g. psconvert is in the Figure class under figure.py. This means we can store future gridding functions like nearneighbor in the same place.

# File at gmt/gridding.py
"""
Define the Gridding class that handles all gridding.
"""

class Gridding:
    def surface(x=None, y=None, z=None, data=None, **kwargs):
        raise NotImplementedError("GMT gridding surface")

This is my initial stab at a test case file. Loosely based on the following bash code used in the tutorial.

    gmt blockmedian -R245/255/20/30 -I5m -V @tut_ship.xyz > ship_5m.xyz
    gmt surface ship_5m.xyz -R245/255/20/30 -I5m -Gship.nc -V
# File at gmt/tests/test_surface.py
"""
Test Gridding.surface
"""

from .. import Gridding
from ..datasets import load_tut_ship

def test_surface():
    ship_data = load_tut_ship()
    outputfile = Gridding.surface(
        x=ship_data.x,
        y=ship_data.y,
        z=ship_data.z,
        G="ship.nc",
        I="5m",
        R="245/255/20/30",
    )
    return outputfile

I've actually got some boilerplate code ready on my fork. Just wanting to get the green light and check if I've missed out on any important details.

Are you willing to help implement and maintain this feature? Yes!

weiji14 added a commit to weiji14/pygmt that referenced this issue Nov 18, 2018
Initial commit for GenericMappingTools#243. Implement GMT surface function under gridding.py. Test cases checking file/matrix/vectors type inputs stored in test_surface.py. Sample dataset for tests uses newly created load_tut_ship function in datasets/tutorial.py.

Note that original GMT surface module https://gmt.soest.hawaii.edu/doc/latest/surface.html requires a -Goutputfile.nc parameter. Here, the implementation of surface does not respect this -G parameter properly. Instead, it stores the output file to a GMTTempFile and returns an xarray.Dataset in Python.
@weiji14 weiji14 mentioned this issue Nov 25, 2018
5 tasks
leouieda pushed a commit that referenced this issue Jan 16, 2019
surface is a module for gridding using splines in tension.
Adds a `surface` function that does the gridding.
Add a `datasets.load_sample_bathymetry` function to get an example
data for testing.
Output is directed to a temporary file which is then loaded with xarray.

Fixes #243
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant