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

Remote datasets: Add "uncertainty" parameter to "load_earth_free_air_anomaly" to load the "free-air anomaly uncertainty" dataset #3727

Merged
merged 33 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a6ca401
Add remote dataset free air anomaly errors
yvonnefroehlich Dec 26, 2024
fcd3a3d
Adjust 'atol' in tests
yvonnefroehlich Dec 26, 2024
0a96819
Try if-else statement
yvonnefroehlich Dec 26, 2024
a2c2116
Revert "Try if-else statement"
yvonnefroehlich Dec 26, 2024
b45d24c
Fix order of dictionary
yvonnefroehlich Dec 26, 2024
ca94508
Improve docs
yvonnefroehlich Dec 26, 2024
8dfa23c
Adjust minimum values for tests | Fix order of datasets
yvonnefroehlich Dec 26, 2024
3ba3b8a
Adjust minimum and maximum values for tests
yvonnefroehlich Dec 26, 2024
b220050
Adjust minimum and maximum values for tests
yvonnefroehlich Dec 26, 2024
b167338
Adjust maximum values and round values for tests
yvonnefroehlich Dec 26, 2024
f9cbab6
Use table to show both images
yvonnefroehlich Dec 27, 2024
c880fcf
Change 'data_source' to 'uncertainty'
yvonnefroehlich Dec 27, 2024
0e85bf6
Use Literal for type hints
yvonnefroehlich Dec 27, 2024
6154ede
Merge branch 'main' into add-remote-earth-faaerror
yvonnefroehlich Dec 27, 2024
552f761
Fix type hints
yvonnefroehlich Dec 27, 2024
8245f6d
Use if-else instead of dictionary
yvonnefroehlich Dec 27, 2024
1532541
Remove 'GMTInvalidInput'
yvonnefroehlich Dec 27, 2024
9898ec5
Fix typo
yvonnefroehlich Dec 27, 2024
d6cfac4
Update docstring for 'uncertainty'
yvonnefroehlich Dec 27, 2024
e4ee230
Update docs
yvonnefroehlich Dec 27, 2024
945a301
Remove blank line
yvonnefroehlich Dec 27, 2024
2e24b2d
Shorten formulation
yvonnefroehlich Dec 27, 2024
6e366e3
Fix line length
yvonnefroehlich Dec 27, 2024
523e108
Remove data type
yvonnefroehlich Dec 27, 2024
f44bf48
Remove bank line
yvonnefroehlich Dec 27, 2024
e8b1b81
Update docs
yvonnefroehlich Dec 27, 2024
189cb3a
Change "error" to "uncertainty"
yvonnefroehlich Dec 27, 2024
5d8c606
Fix line length | Fix typos | Improve formulations
yvonnefroehlich Dec 27, 2024
4665c61
Improve formulations
yvonnefroehlich Dec 27, 2024
50d928e
Use complete line length
yvonnefroehlich Dec 27, 2024
a1bb505
Improve formulation
yvonnefroehlich Dec 28, 2024
4b93a73
Improve formulation
yvonnefroehlich Dec 28, 2024
0c84b68
Improve formulation
yvonnefroehlich Dec 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 50 additions & 39 deletions pygmt/datasets/earth_free_air_anomaly.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,43 @@ def load_earth_free_air_anomaly(
] = "01d",
region: Sequence[float] | str | None = None,
registration: Literal["gridline", "pixel", None] = None,
uncertainty: bool = False,
yvonnefroehlich marked this conversation as resolved.
Show resolved Hide resolved
) -> xr.DataArray:
r"""
Load the IGPP Earth free-air anomaly dataset in various resolutions.
Load the IGPP Earth free-air anomaly and uncertainty datasets in various
resolutions.

.. figure:: https://www.generic-mapping-tools.org/remote-datasets/_images/GMT_earth_faa.jpg
:width: 80 %
:align: center
.. list-table::
:widths: 50 50
:header-rows: 1

IGPP Earth free-air anomaly dataset.
* - IGPP Earth Free-Air Anomaly
- IGPP Earth Free-Air Anomaly Errors
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- IGPP Earth Free-Air Anomaly Errors
- IGPP Earth Free-Air Anomaly Uncertainty

Copy link
Member Author

@yvonnefroehlich yvonnefroehlich Dec 27, 2024

Choose a reason for hiding this comment

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

Hm. I used the name for the upstream docs at https://www.generic-mapping-tools.org/remote-datasets/earth-faaerror.html. But I was wondering, if "uncertainty" is better, as it is used in the docstrings. Maybe we should also update the upstream docs; I can include this in PR GenericMappingTools/remote-datasets#128 if approved.

Copy link
Member

Choose a reason for hiding this comment

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

The GMT remote-dataset docs is inconsistenly using "error" and "uncertainty", while the officiail README file (https://topex.ucsd.edu/pub/global_grav_1min/README_V32.txt) uses "uncertainty":

grav_error_32.1.nc - uncertainty in gravity anomaly and sea surface slope, milligal or microradian, netcdf, lon-lat coordinates

Copy link
Member Author

Choose a reason for hiding this comment

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

Made commit GenericMappingTools/remote-datasets@5aa5e58 for changing this in the GMT remote-dataset docs.

But we stick to "error" in the GMT dataset name faaerror ?

Copy link
Member

Choose a reason for hiding this comment

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

I think faaerror is fine.

* - .. figure:: https://www.generic-mapping-tools.org/remote-datasets/_images/GMT_earth_faa.jpg
- .. figure:: https://www.generic-mapping-tools.org/remote-datasets/_images/GMT_earth_faaerror.jpg

The grids are downloaded to a user data directory
(usually ``~/.gmt/server/earth/earth_faa/``) 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.
The grids are downloaded to a user data directory (usually
``~/.gmt/server/earth/earth_faa/`` or ``~/.gmt/server/earth/earth_faaerror/``) the
first time you invoke this function. Afterwards, it will load the grid from 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_faa**\_\ *res*\[_\ *reg*] to any grid processing function or
plotting method. *res* is the grid resolution (see below), and *reg* is
the grid registration type (**p** for pixel registration or **g** for
gridline registration).

The default color palette table (CPT) for this dataset is *@earth_faa.cpt*.
It's implicitly used when passing in the file name of the dataset to any
grid plotting method if no CPT is explicitly specified. When the dataset
is loaded and plotted as an :class:`xarray.DataArray` object, the default
CPT is ignored, and GMT's default CPT (*turbo*) is used. To use the
dataset-specific CPT, you need to explicitly set ``cmap="@earth_faa.cpt"``.

Refer to :gmt-datasets:`earth-faa.html` for more details about available
datasets, including version information and references.
**@earth_faa_type**\_\ *res*\[_\ *reg*] to any grid processing function or
plotting method. *earth_faa_type* is the GMT name for the dataset. The available
options are **earth_faa** and **earth_faaerror**. *res* is the grid resolution
(see below), and *reg* is the grid registration type (**p** for pixel registration
or **g** for gridline registration).

The default color palette tables (CPTs) for these datasets are *@earth_faa.cpt* and
*@earth_faaerror.cpt*. The dataset-specific CPT is implicitly used when passing in
the file name of the dataset to any grid plotting method if no CPT is explicitly
specified. When the dataset is loaded and plotted as an :class:`xarray.DataArray`
object, the default CPT is ignored, and GMT's default CPT (*turbo*) is used. To use
the dataset-specific CPT, you need to explicitly set ``cmap="@earth_faa.cpt"`` or
``cmap="@earth_faaerror.cpt"``.

Refer to :gmt-datasets:`earth-faa.html` and :gmt-datasets:`earth-faaerror.html` for
more details about available datasets, including version information and references.

Parameters
----------
Expand All @@ -63,44 +70,48 @@ def load_earth_free_air_anomaly(
registration
Grid registration type. Either ``"pixel"`` for pixel registration or
``"gridline"`` for gridline registration. Default is ``None``, means
``"gridline"`` for all resolutions except ``"01m"`` which is
``"pixel"`` only.
``"gridline"`` for all resolutions except ``"01m"`` which is ``"pixel"`` only.
uncertainty
Set to ``True`` to download the uncertainties related to the free-air anomaly
values [Default is ``False`` and gives the altimetry-based marine free-air
anomaly values.
yvonnefroehlich marked this conversation as resolved.
Show resolved Hide resolved

Returns
-------
grid
The Earth free-air anomaly grid. Coordinates are latitude and
longitude in degrees. Units are in mGal.
The Earth free-air anomaly grid. Coordinates are latitude and longitude in
yvonnefroehlich marked this conversation as resolved.
Show resolved Hide resolved
degrees. Units are in mGal.

Note
----
The registration and coordinate system type of the returned
:class:`xarray.DataArray` grid can be accessed via the GMT accessors
(i.e., ``grid.gmt.registration`` and ``grid.gmt.gtype`` respectively).
However, these properties may be lost after specific grid operations (such
as slicing) and will need to be manually set before passing the grid to any
PyGMT data processing or plotting functions. Refer to
:class:`pygmt.GMTDataArrayAccessor` for detailed explanations and
workarounds.
:class:`xarray.DataArray` grid can be accessed via the GMT accessors (i.e.,
``grid.gmt.registration`` and ``grid.gmt.gtype`` respectively). However, these
properties may be lost after specific grid operations (such as slicing) and will
need to be manually set before passing the grid to any PyGMT data processing or
plotting functions. Refer to :class:`pygmt.GMTDataArrayAccessor` for detailed
explanations and workarounds.

Examples
--------

>>> from pygmt.datasets import load_earth_free_air_anomaly
>>> # load the default grid (gridline-registered 1 arc-degree grid)
>>> grid = load_earth_free_air_anomaly()
>>> # load the uncertainties related to the default grid
>>> grid = load_earth_free_air_anomaly(uncertainty=True)
>>> # load the 30 arc-minutes grid with "gridline" registration
>>> grid = load_earth_free_air_anomaly(resolution="30m", registration="gridline")
>>> # load high-resolution (5 arc-minutes) grid for a specific region
>>> grid = load_earth_free_air_anomaly(
... resolution="05m",
... region=[120, 160, 30, 60],
... registration="gridline",
... resolution="05m", region=[120, 160, 30, 60], registration="gridline"
... )
"""
prefix = "earth_faaerror" if uncertainty is True else "earth_faa"

yvonnefroehlich marked this conversation as resolved.
Show resolved Hide resolved
grid = _load_remote_dataset(
name="earth_faa",
prefix="earth_faa",
name=prefix,
prefix=prefix,
resolution=resolution,
region=region,
registration=registration,
Expand Down
18 changes: 18 additions & 0 deletions pygmt/datasets/load_remote_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,24 @@ class GMTRemoteDataset(NamedTuple):
"01m": Resolution("01m", registrations=["pixel"], tiled=True),
},
),
"earth_faaerror": GMTRemoteDataset(
description="IGPP Earth free-air anomaly errors",
units="mGal",
extra_attributes={"horizontal_datum": "WGS84"},
resolutions={
"01d": Resolution("01d"),
"30m": Resolution("30m"),
"20m": Resolution("20m"),
"15m": Resolution("15m"),
"10m": Resolution("10m"),
"06m": Resolution("06m"),
"05m": Resolution("05m", tiled=True),
"04m": Resolution("04m", tiled=True),
"03m": Resolution("03m", tiled=True),
"02m": Resolution("02m", tiled=True),
"01m": Resolution("01m", registrations=["pixel"], tiled=True),
},
),
"earth_gebco": GMTRemoteDataset(
description="GEBCO Earth relief",
units="meters",
Expand Down
2 changes: 2 additions & 0 deletions pygmt/helpers/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def cache_data():
"@earth_day_01d",
"@earth_dist_01d",
"@earth_faa_01d_g",
"@earth_faaerror_01d_g",
"@earth_gebco_01d_g",
"@earth_gebcosi_01d_g",
"@earth_gebcosi_15m_p",
Expand Down Expand Up @@ -51,6 +52,7 @@ def cache_data():
"@N30E090.earth_age_01m_g.nc",
"@N00W030.earth_dist_01m_g.nc",
"@N00W030.earth_faa_01m_p.nc",
"@N00W030.earth_faaerror_01m_p.nc",
"@N00W030.earth_geoid_01m_g.nc",
"@S30W060.earth_mag_02m_p.nc",
"@S30W120.earth_mag4km_02m_p.nc",
Expand Down
51 changes: 51 additions & 0 deletions pygmt/tests/test_datasets_earth_free_air_anomaly.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,54 @@ def test_earth_faa_01m_default_registration():
npt.assert_allclose(data.coords["lon"].data.max(), -9.00833333)
npt.assert_allclose(data.min(), -49.225, atol=0.025)
npt.assert_allclose(data.max(), 115.0, atol=0.025)


def test_earth_faaerror_01d():
"""
Test some properties of the free air anomaly error 01d data.
"""
data = load_earth_free_air_anomaly(resolution="01d", uncertainty=True)
assert data.name == "z"
assert data.attrs["long_name"] == "faaerror (mGal)"
assert data.attrs["description"] == "IGPP Earth free-air anomaly errors"
assert data.attrs["units"] == "mGal"
assert data.attrs["horizontal_datum"] == "WGS84"
assert data.shape == (181, 361)
assert data.gmt.registration == 0
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(), 0.0, atol=0.04)
npt.assert_allclose(data.max(), 49.16, atol=0.04)


def test_earth_faaerror_01d_with_region():
"""
Test loading low-resolution earth free air anomaly error with 'region'.
"""
data = load_earth_free_air_anomaly(
resolution="01d", region=[-10, 10, -5, 5], uncertainty=True
)
assert data.shape == (11, 21)
assert data.gmt.registration == 0
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(), 0.72, atol=0.04)
npt.assert_allclose(data.max(), 21.04, atol=0.04)


def test_earth_faaerror_01m_default_registration():
"""
Test that the grid returned by default for the 1 arc-minute resolution has a "pixel"
registration.
"""
data = load_earth_free_air_anomaly(
resolution="01m", region=[-10, -9, 3, 5], uncertainty=True
)
assert data.shape == (120, 60)
assert data.gmt.registration == 1
npt.assert_allclose(data.coords["lat"].data.min(), 3.008333333)
npt.assert_allclose(data.coords["lat"].data.max(), 4.991666666)
npt.assert_allclose(data.coords["lon"].data.min(), -9.99166666)
npt.assert_allclose(data.coords["lon"].data.max(), -9.00833333)
npt.assert_allclose(data.min(), 0.40, atol=0.04)
npt.assert_allclose(data.max(), 13.36, atol=0.04)
Loading