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

Add pygmt.load_dataarray function and refactor modules that return None or xarray.dataarray #1439

Merged
merged 17 commits into from
Sep 1, 2021

Conversation

maxrjones
Copy link
Member

@maxrjones maxrjones commented Aug 11, 2021

Description of proposed changes

This PR adds a new pygmt/io.py module that holds process_output_grid, which returns an xarray.DataArray or None depending on whether outgrid matches tmpfile.name.

It replaces duplicate code with the new function.

Fixes #1400

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.

Slash Commands

You can write slash commands (/command) in the first line of a comment to perform
specific operations. Supported slash commands are:

  • /format: automatically format and lint the code
  • /test-gmt-dev: run full tests on the latest GMT development version

Copy link
Contributor

@willschlitzer willschlitzer left a comment

Choose a reason for hiding this comment

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

Looks great!

pygmt/io.py Outdated Show resolved Hide resolved
pygmt/io.py Outdated Show resolved Hide resolved
pygmt/src/surface.py Outdated Show resolved Hide resolved
Co-authored-by: Wei Ji <[email protected]>
@weiji14 weiji14 added final review call This PR requires final review and approval from a second reviewer maintenance Boring but important stuff for the core devs labels Aug 12, 2021
pygmt/io.py Outdated Show resolved Hide resolved
@maxrjones maxrjones removed the final review call This PR requires final review and approval from a second reviewer label Aug 12, 2021
@maxrjones maxrjones marked this pull request as draft August 12, 2021 17:57
@maxrjones maxrjones changed the title Standardize code for returning xr.DataArray or None depending on outgrid parameter WIP: Standardize code for returning xr.DataArray or None depending on outgrid parameter Aug 12, 2021
@maxrjones maxrjones self-assigned this Aug 24, 2021
Copy link
Member

@weiji14 weiji14 left a comment

Choose a reason for hiding this comment

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

Hi @meghanrjones, hoping that you can spend some time working on this PR soon (since there's a lot of open PRs that could benefit from a standardized function)! Based on the discussion above at #1439 (comment), here are some suggested changes. You'll also need to:

  1. Update doc/api/index.rst to include the new load_datagrid function. My thought was to place it under 'Data Processing', but we could start a dedicated Input/output section in the API docs if you prefer, similar to https://geopandas.org/docs/reference/io.html. You'll also need to add from pygmt.io import load_datagrid to pygmt/__init__.py.
Input/Output:

.. autosummary::
    :toctree: generated

    load_datagrid
  1. Find and replace process_output_grid to load_datagrid across all the grd* functions. Remember to also include grdproject added recently in Wrap grdproject #1377 and load_earth_relief at
    with xr.open_dataarray(fname, engine="netcdf4") as dataarray:
    grid = dataarray.load()
    _ = grid.gmt # load GMTDataArray accessor information
    .

Let me know if you need any help. I'm happy to push some changes directly to this branch too if you're ok with working on this together.

pygmt/io.py Outdated Show resolved Hide resolved
pygmt/src/grdclip.py Outdated Show resolved Hide resolved
pygmt/src/grdclip.py Outdated Show resolved Hide resolved
pygmt/io.py Outdated Show resolved Hide resolved
pygmt/io.py Outdated Show resolved Hide resolved
pygmt/io.py Outdated Show resolved Hide resolved
pygmt/io.py Outdated Show resolved Hide resolved
@maxrjones
Copy link
Member Author

maxrjones commented Aug 30, 2021

Thanks for the ping @weiji14. I will prioritize this PR tomorrow (8/31) or am fine with you pushing changes if you post a message first.

@maxrjones maxrjones changed the title WIP: Standardize code for returning xr.DataArray or None depending on outgrid parameter Add pygmt.load_dataarray function and refactor modules that return None or xarray.dataarray Aug 31, 2021
@maxrjones maxrjones marked this pull request as ready for review August 31, 2021 20:40
@maxrjones
Copy link
Member Author

@weiji14, thanks for your detailed comment. I named the function load_dataarray rather than load_datagrid to be more specific about the output type. Of course, you can comment if you disagree with this decision.

@maxrjones maxrjones added feature Brand new feature and removed maintenance Boring but important stuff for the core devs labels Aug 31, 2021
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.

Looks a clean solution to me!

@seisman seisman added this to the 0.5.0 milestone Aug 31, 2021
@seisman seisman added the final review call This PR requires final review and approval from a second reviewer label Aug 31, 2021
Copy link
Member

@weiji14 weiji14 left a comment

Choose a reason for hiding this comment

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

@weiji14, thanks for your detailed comment. I named the function load_dataarray rather than load_datagrid to be more specific about the output type. Of course, you can comment if you disagree with this decision.

Ok with renaming this to load_dataarray. It's not a commonly used function I think, so hopefully the xarray folks don't mind 😸 Other than that, only a few more minor suggestions on the docstrings.

pygmt/io.py Outdated Show resolved Hide resolved
pygmt/io.py Outdated Show resolved Hide resolved
pygmt/io.py Outdated Show resolved Hide resolved
Co-authored-by: Wei Ji <[email protected]>
@maxrjones
Copy link
Member Author

I would prefer to wait to merge this until after #1458 so that I can resolve the merge conflict rather than causing one for that PR.

@maxrjones maxrjones merged commit b137613 into main Sep 1, 2021
@maxrjones maxrjones deleted the io-outgrid branch September 1, 2021 22:53
This was referenced Sep 2, 2021
@weiji14 weiji14 removed the final review call This PR requires final review and approval from a second reviewer label Sep 3, 2021
@weiji14 weiji14 mentioned this pull request Sep 9, 2021
5 tasks
weiji14 added a commit that referenced this pull request Sep 18, 2021
Patches missing code coverage of pygmt.load_dataarray
function wrapped in #1439. Checks that a NetCDF grid
can be read with GMTDataArrayAccessor information loaded,
and that load_dataarray fails when the cache argument is used.
sixy6e pushed a commit to sixy6e/pygmt that referenced this pull request Dec 21, 2022
…ne or xarray.dataarray (GenericMappingTools#1439)

Add new function pygmt.load_datarray
Use pygmt.load_dataarrary for modules that return grids
Add documentation

Co-authored-by: Wei Ji <[email protected]>
sixy6e pushed a commit to sixy6e/pygmt that referenced this pull request Dec 21, 2022
…gTools#1518)

Patches missing code coverage of pygmt.load_dataarray
function wrapped in GenericMappingTools#1439. Checks that a NetCDF grid
can be read with GMTDataArrayAccessor information loaded,
and that load_dataarray fails when the cache argument is used.
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.

Reduce repeated code for managing the outgrid parameter
5 participants