-
Notifications
You must be signed in to change notification settings - Fork 235
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 12 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| """ | ||
| PyGMT input/output (I/O) utilities. | ||
| """ | ||
| import xarray as xr | ||
|
|
||
|
|
||
| def load_dataarray(filename_or_obj, **kwargs): | ||
| """ | ||
| Open, load into memory, and close a DataArray from a file or file-like | ||
| object containing a single data variable. | ||
|
|
||
| This is a thin wrapper around :py:meth:`xarray.open_dataarray`. It differs | ||
| from :py:meth:`xarray.open_dataarray` in that it loads the DataArray into | ||
| memory, gets GMT specific metadata about the grid via | ||
| :py:meth:`GMTDataArrayAccessor`, closes the file, and returns the | ||
| DataArray. In contrast, :py:meth:`xarray.open_dataarray` keeps the file | ||
| handle open and lazy loads its contents. All parameters are passed directly | ||
| to :py:meth:`xarray.open_dataarray`. See that documentation for further | ||
maxrjones marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| details. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| filename_or_obj : str or Path or file-like or DataStore | ||
maxrjones marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Strings and Path objects are interpreted as a path to a netCDF file | ||
| or an OpenDAP URL and opened with python-netCDF4, unless the filename | ||
| ends with .gz, in which case the file is gunzipped and opened with | ||
| scipy.io.netcdf (only netCDF3 supported). Byte-strings or file-like | ||
| objects are opened by scipy.io.netcdf (netCDF3) or h5py (netCDF4/HDF). | ||
|
|
||
| Returns | ||
| ------- | ||
| datarray : xarray.DataArray | ||
| The newly created DataArray. | ||
|
|
||
| See Also | ||
| -------- | ||
| xarray.open_dataarray | ||
| """ | ||
| if "cache" in kwargs: | ||
| raise TypeError("cache has no effect in this context") | ||
|
|
||
| with xr.open_dataarray(filename_or_obj, **kwargs) as dataarray: | ||
| result = dataarray.load() | ||
| _ = result.gmt # load GMTDataArray accessor information | ||
|
|
||
| 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
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.