-
Notifications
You must be signed in to change notification settings - Fork 233
Add pygmt.load_dataarray function and refactor modules that return None or xarray.dataarray #1439
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
37d27c5
Create process_output_grid function in pygmt/io.py
2214237
Use process_output_grid() to return dataarray or None
ab8954e
Update pygmt/io.py
fd3ae22
Apply suggestions from code review
269b185
Update var name
d56c626
Update function name
6bfd0a3
Update modules to use load_dataarray
c58bbf2
Merge branch 'main' into io-outgrid
66fbfed
Update grdproject
9d4698b
Make load_dataarray public
3da72c1
Update docstring
e7c3544
Refactor earth_relief.py
e4725ef
Apply suggestions from code review
f19562d
Update pygmt/io.py
34630ca
Merge branch 'main' into io-outgrid
98f4f85
Merge branch 'main' into io-outgrid
afd0500
Merge branch 'main' into io-outgrid
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| """ | ||
| PyGMT input/output (I/O) utilities. | ||
| """ | ||
| import xarray as xr | ||
|
|
||
|
|
||
| def process_output_grid(grid_name, tmpfile_name): | ||
maxrjones marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """ | ||
| Processes the output from the GMT API to return an xarray.DataArray if | ||
| ``grid_name`` matches ``tmpfile_name`` and return None if it does not. | ||
maxrjones marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Parameters | ||
| ---------- | ||
| grid_name : str | ||
| The name of the output netCDF file with extension .nc to store the grid | ||
| in. | ||
| tmpfile_name : str | ||
| The name attribute from a GMTTempFile instance. | ||
maxrjones marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Returns | ||
| ------- | ||
| ret: xarray.DataArray or None | ||
| Return type depends on whether the ``outgrid`` parameter is set: | ||
| - :class:`xarray.DataArray` if ``outgrid`` is not set | ||
| - None if ``outgrid`` is set (grid output will be stored in file set by | ||
| ``outgrid``) | ||
maxrjones marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
maxrjones marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """ | ||
| if grid_name == tmpfile_name: # Implies user did not set outgrid, return DataArray | ||
| with xr.open_dataarray(grid_name) as dataarray: | ||
| result = dataarray.load() | ||
| _ = result.gmt # load GMTDataArray accessor information | ||
| else: | ||
| result = None # Implies user set an outgrid, return None | ||
maxrjones marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return result | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.