-
Notifications
You must be signed in to change notification settings - Fork 224
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 load_earth_vertical_gravity_gradient function for Earth vertical gravity gradient dataset #2240
Merged
seisman
merged 16 commits into
main
from
load-remote-dataset/earth-vertical-gravity-gradient
Dec 23, 2022
Merged
Changes from 4 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f82dcc0
initial commit for earth_vertical_gravity_gradient.py
willschlitzer 18e2dce
add load_earth_vgg to index.rst
willschlitzer be05887
add test_datasets_earth_vertical_gravity_gradient.py and associated c…
willschlitzer 0399fe9
Update pygmt/datasets/load_remote_dataset.py
willschlitzer 9c2c568
remove .grd suffice from earth_vgg_01d_g
willschlitzer 9753e9b
Merge branch 'main' into load-remote-dataset/earth-vertical-gravity-g…
willschlitzer 92c5545
Merge branch 'main' into load-remote-dataset/earth-vertical-gravity-g…
willschlitzer bb41ffc
change load_earth_vgg to load_earth_vertical_gravity_gradient
willschlitzer 30d2f6a
run make format
willschlitzer 8f25c71
Apply suggestions from code review
willschlitzer d4f704e
Merge branch 'main' into load-remote-dataset/earth-vertical-gravity-g…
willschlitzer 6202e59
update test names
willschlitzer 742b95a
Merge remote-tracking branch 'origin/load-remote-dataset/earth-vertic…
willschlitzer fc475a2
Update pygmt/datasets/earth_vertical_gravity_gradient.py
willschlitzer db5a6a2
Merge branch 'main' into load-remote-dataset/earth-vertical-gravity-g…
willschlitzer 15a9a63
Merge branch 'main' into load-remote-dataset/earth-vertical-gravity-g…
seisman 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 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 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 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,69 @@ | ||
""" | ||
Function to download the IGPP Global Earth Vertical Gravity Gradient from the | ||
GMT data server, and load as :class:`xarray.DataArray`. | ||
|
||
The grids are available in various resolutions. | ||
""" | ||
from pygmt.datasets.load_remote_dataset import _load_remote_dataset | ||
from pygmt.helpers import kwargs_to_strings | ||
|
||
|
||
@kwargs_to_strings(region="sequence") | ||
def load_earth_vgg(resolution="01d", region=None, registration=None): | ||
r""" | ||
Load the IGPP Global Earth Vertical Gravity Gradient in various | ||
resolutions. | ||
|
||
The grids are downloaded to a user data directory | ||
(usually ``~/.gmt/server/earth/earth_vgg/``) the first time you invoke | ||
this function. Afterwards, it will load the grid from the data directory. | ||
So you'll need an internet connection the first time around. | ||
|
||
These grids can also be accessed by passing in the file name | ||
**@earth_vgg**\_\ *res*\[_\ *reg*] to any grid plotting/processing | ||
function. *res* is the grid resolution (see below), and *reg* is grid | ||
registration type (**p** for pixel registration or **g** for gridline | ||
registration). | ||
|
||
Refer to :gmt-datasets:`earth-vgg.html` for more details. | ||
|
||
Parameters | ||
---------- | ||
resolution : str | ||
The grid resolution. The suffix ``d`` and ``m`` stand for | ||
arc-degree and arc-minute. It can be ``"01d"``, ``"30m"``, | ||
willschlitzer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``"20m"``, ``"15m"``, ``"10m"``, ``"06m"``, ``"05m"``, ``"04m"``, | ||
``"03m"``, ``"02m"``, or ``"01m"``. | ||
|
||
region : str or list | ||
The subregion of the grid to load, in the forms of a list | ||
willschlitzer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[*xmin*, *xmax*, *ymin*, *ymax*] or a string *xmin/xmax/ymin/ymax*. | ||
Required for grids with resolutions higher than 5 | ||
arc-minute (i.e., ``"05m"``). | ||
willschlitzer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
registration : str | ||
Grid registration type. Either ``"pixel"`` for pixel registration or | ||
``"gridline"`` for gridline registration. Default is ``None``, where | ||
a pixel-registered grid is returned unless only the | ||
gridline-registered grid is available. | ||
|
||
Returns | ||
------- | ||
grid : :class:`xarray.DataArray` | ||
The Earth vertical gravity gradient grid. Coordinates are latitude and | ||
longitude in degrees. Units are in Eotvos. | ||
|
||
Note | ||
---- | ||
The :class:`xarray.DataArray` grid doesn't support slice operation, for | ||
Earth vertical gravity gradient grids with resolutions of 5 arc-minutes or | ||
higher, which are stored as smaller tiles. | ||
""" | ||
grid = _load_remote_dataset( | ||
dataset_name="earth_vgg", | ||
dataset_prefix="earth_vgg_", | ||
resolution=resolution, | ||
region=region, | ||
registration=registration, | ||
) | ||
return grid |
This file contains 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 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
92 changes: 92 additions & 0 deletions
92
pygmt/tests/test_datasets_earth_vertical_gravity_gradient.py
This file contains 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,92 @@ | ||
""" | ||
Test basic functionality for loading Earth vertical gravity gradient datasets. | ||
""" | ||
import numpy as np | ||
import numpy.testing as npt | ||
import pytest | ||
from pygmt.datasets import load_earth_vgg | ||
from pygmt.exceptions import GMTInvalidInput | ||
|
||
|
||
def test_earth_vgg_fails(): | ||
seisman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
Make sure load_earth_vgg fails for invalid resolutions. | ||
""" | ||
resolutions = "1m 1d bla 60d 001m 03".split() | ||
resolutions.append(60) | ||
for resolution in resolutions: | ||
with pytest.raises(GMTInvalidInput): | ||
load_earth_vgg(resolution=resolution) | ||
|
||
|
||
def test_earth_vgg_incorrect_registration(): | ||
""" | ||
Test loading load_earth_vgg with incorrect registration type. | ||
""" | ||
with pytest.raises(GMTInvalidInput): | ||
load_earth_vgg(registration="improper_type") | ||
|
||
|
||
def test_earth_vgg_01d(): | ||
""" | ||
Test some properties of the earth vgg 01d data. | ||
""" | ||
data = load_earth_vgg(resolution="01d", registration="gridline") | ||
assert data.name == "earth_vgg" | ||
assert data.attrs["units"] == "Eotvos" | ||
assert data.attrs["long_name"] == "IGPP Global Earth Vertical Gravity Gradient" | ||
assert data.attrs["horizontal_datum"] == "WGS84" | ||
assert data.shape == (181, 361) | ||
npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) | ||
npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) | ||
npt.assert_allclose(data.min(), -136.34375) | ||
npt.assert_allclose(data.max(), 104.59375) | ||
assert data[1, 1].isnull() | ||
|
||
|
||
def test_earth_vgg_01d_with_region(): | ||
""" | ||
Test loading low-resolution earth vgg with 'region'. | ||
""" | ||
data = load_earth_vgg( | ||
resolution="01d", region=[-10, 10, -5, 5], registration="gridline" | ||
) | ||
assert data.shape == (11, 21) | ||
npt.assert_allclose(data.lat, np.arange(-5, 6, 1)) | ||
npt.assert_allclose(data.lon, np.arange(-10, 11, 1)) | ||
npt.assert_allclose(data.min(), -16.34375) | ||
npt.assert_allclose(data.max(), 19.78125) | ||
|
||
|
||
def test_earth_vgg_05m_with_region(): | ||
""" | ||
Test loading a subregion of high-resolution earth vgg. | ||
""" | ||
data = load_earth_vgg( | ||
resolution="05m", region=[-50, -40, 20, 26], registration="gridline" | ||
) | ||
assert data.coords["lat"].data.min() == 20.0 | ||
assert data.coords["lat"].data.max() == 26.0 | ||
assert data.coords["lon"].data.min() == -50.0 | ||
assert data.coords["lon"].data.max() == -40.0 | ||
npt.assert_allclose(data.min(), -107.625) | ||
npt.assert_allclose(data.max(), 159.75) | ||
assert data.sizes["lat"] == 73 | ||
assert data.sizes["lon"] == 121 | ||
|
||
|
||
def test_earth_vgg_05m_without_region(): | ||
""" | ||
Test loading high-resolution earth vgg without passing 'region'. | ||
""" | ||
with pytest.raises(GMTInvalidInput): | ||
load_earth_vgg("05m") | ||
|
||
|
||
def test_earth_vgg_incorrect_resolution_registration(): | ||
""" | ||
Test that an error is raised when trying to load a grid registration with | ||
an unavailable resolution. | ||
""" | ||
with pytest.raises(GMTInvalidInput): | ||
load_earth_vgg(resolution="01m", region=[0, 1, 3, 5], registration="pixel") |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
earth_vgg
a good name? Perhaps we should useearth_vertical_gravity_gradient
instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I debated that, but my decision to use
earth_vgg
was thatearth_vertical_gravity_gradient
is super long to type out. My thought is thatearth_vgg
is unique enough as to not be confusing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but we have autocompletion so a long name is still easy to type.
earth_vgg
is unique, but it doesn't tell users what the dataset is.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to
load_earth_vertical_gravity_gradient