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 load_earth_mask function for GSHHG Global Earth Mask dataset #2310

Merged
merged 17 commits into from
Jan 22, 2023

Conversation

willschlitzer
Copy link
Contributor

Add load_earth_mask to load the remote GSHHG Global Earth Mask dataset.

Addresses: #1786

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 wrapping a new module, open a 'Wrap new GMT module' issue and submit reasonably-sized PRs.
  • If adding new functionality, add an example to docstrings or tutorials.
  • Use underscores (not hyphens) in names of Python files and directories.

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

@willschlitzer willschlitzer added the feature Brand new feature label Jan 6, 2023
@willschlitzer willschlitzer added this to the 0.9.0 milestone Jan 6, 2023
@willschlitzer willschlitzer self-assigned this Jan 6, 2023
pygmt/datasets/earth_mask.py Outdated Show resolved Hide resolved
pygmt/datasets/earth_mask.py Outdated Show resolved Hide resolved
pygmt/datasets/load_remote_dataset.py Outdated Show resolved Hide resolved
pygmt/datasets/earth_mask.py Outdated Show resolved Hide resolved
pygmt/tests/test_datasets_earth_mask.py Outdated Show resolved Hide resolved
pygmt/tests/test_datasets_earth_mask.py Outdated Show resolved Hide resolved
willschlitzer and others added 3 commits January 13, 2023 11:53
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Michael Grund <23025878+michaelgrund@users.noreply.github.com>
@willschlitzer
Copy link
Contributor Author

/format

@willschlitzer willschlitzer added the needs review This PR has higher priority and needs review. label Jan 14, 2023
- 2: Lake
- 3: Island
- 4: Pond
"""
Copy link
Member

@seisman seisman Jan 15, 2023

Choose a reason for hiding this comment

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

This function now returns a dataarray like below:

<xarray.DataArray 'z' (lat: 181, lon: 361)>
array([[1., 1., 1., ..., 1., 1., 1.],
       [1., 1., 1., ..., 1., 1., 1.],
       [1., 1., 1., ..., 1., 1., 1.],
       ...,
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.]], dtype=float32)
Coordinates:
  * lon      (lon) float64 -180.0 -179.0 -178.0 -177.0 ... 178.0 179.0 180.0
  * lat      (lat) float64 -90.0 -89.0 -88.0 -87.0 -86.0 ... 87.0 88.0 89.0 90.0
Attributes:
    long_name:     z
    actual_range:  [0. 2.]

The data dtype is float32, but the original grid @earth_mask_01d_g contains int8 values. Ideally, the function should return a grid with integer values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How would I change the value types across the entire array?

Copy link
Member

Choose a reason for hiding this comment

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

How would I change the value types across the entire array?

I don't know. Need to read the xarray docs.

Copy link
Member

Choose a reason for hiding this comment

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

Likely we need to use xarray.DataArray.astype to convert the data from float32 to int8, i.e., return grid.astype("int8").

@willschlitzer
Copy link
Contributor Author

It looks like the number of if statements in _load_remote_dataset() is causing a style check failure. Should I refactor _load_remote_dataset() to use some smaller functions (i.e. _get_registration and _get_resolution) or use pylint: disable=too-many-branches?

pygmt/tests/test_datasets_earth_mask.py Outdated Show resolved Hide resolved
pygmt/tests/test_datasets_earth_mask.py Outdated Show resolved Hide resolved
pygmt/tests/test_datasets_earth_mask.py Outdated Show resolved Hide resolved
@seisman
Copy link
Member

seisman commented Jan 19, 2023

use pylint: disable=too-many-branches?

This sounds good to me.

@seisman seisman added final review call This PR requires final review and approval from a second reviewer and removed needs review This PR has higher priority and needs review. labels Jan 20, 2023
@seisman seisman merged commit 28c5c3f into main Jan 22, 2023
@seisman seisman deleted the load-remote-dataset/earth_mask branch January 22, 2023 12:02
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Jan 22, 2023
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.

4 participants