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 function to load Black Marble dataset #3469

Merged
merged 5 commits into from
Sep 30, 2024
Merged

Add function to load Black Marble dataset #3469

merged 5 commits into from
Sep 30, 2024

Conversation

weiji14
Copy link
Member

@weiji14 weiji14 commented Sep 30, 2024

Description of proposed changes

Function to load the @earth_night_ NASA Black Marble mosaic RGB images stored as GeoTIFF files.

Preview at https://pygmt-dev--3469.org.readthedocs.build/en/3469/api/generated/pygmt.datasets.load_black_marble.html

Example usage:

import pygmt

image = pygmt.datasets.load_black_marble(resolution="06m")

fig = pygmt.Figure()
fig.grdimage(grid=image)
fig.show()

produces

earth_night

Implementation is adapted from #2235.

Fixes #1442, supersedes #1457

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 command is:

  • /format: automatically format and lint the code

Function to load the `@earth_night_` NASA Black Marble mosaic RGB images stored as GeoTIFF files.
@weiji14 weiji14 added the feature Brand new feature label Sep 30, 2024
@weiji14 weiji14 added this to the 0.14.0 milestone Sep 30, 2024
@weiji14 weiji14 self-assigned this Sep 30, 2024
@weiji14 weiji14 marked this pull request as ready for review September 30, 2024 03:01
Comment on lines +94 to +96
# If rioxarray is installed, set the coordinate reference system
if hasattr(image, "rio"):
image = image.rio.write_crs(input_crs="OGC:CRS84")
Copy link
Member Author

Choose a reason for hiding this comment

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

This line is not covered by a unit test. Should I add one, or we can ignore it?

Copy link
Member

Choose a reason for hiding this comment

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

It should be covered when rioxarray is installed, right?

Copy link
Member

Choose a reason for hiding this comment

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

Or do we have to import rioxarray to register the rio accessor

Copy link
Member Author

Choose a reason for hiding this comment

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

The equivalent line in load_blue_marble is covered here in test_grdimage_image.py which has an import rioxarray at the top of the file:

xr_image = load_blue_marble(resolution="01d")

We don't test load_black_marble anywhere else except in test_datasets_earth_night.py, and since rioxarray is not imported in that file, this line isn't covered because there is no rio accessor.

Copy link
Member Author

@weiji14 weiji14 Sep 30, 2024

Choose a reason for hiding this comment

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

Maybe we can cover this line in the test_grdcut_image.py file at https://github.com/GenericMappingTools/pygmt/pull/3115/files#r1780370539?

Copy link
Member

Choose a reason for hiding this comment

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

since rioxarray is not imported in that file, this line isn't covered because there is no rio accessor.

This is not ideal. So even if rioxarray is installed, the rio accessor may still not exist because users don't import the rioxarray package.

I think we should add the following lines to this file (and any other files that try to access the rio accessor):

with contextlib.suppress(ImportError):
# rioxarray is needed to register the rio accessor
import rioxarray # noqa: F401

Copy link
Member

Choose a reason for hiding this comment

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

xref: #3323

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, done at commit 66183ed. I've also applied this to pygmt/datasets/earth_day.py, hopefully you don't mind.

@weiji14 weiji14 added the final review call This PR requires final review and approval from a second reviewer label Sep 30, 2024
@seisman
Copy link
Member

seisman commented Sep 30, 2024

Alos need to add earth_night_01d to caching.py

@weiji14 weiji14 enabled auto-merge (squash) September 30, 2024 04:46
@weiji14 weiji14 removed the final review call This PR requires final review and approval from a second reviewer label Sep 30, 2024
@weiji14 weiji14 merged commit 923111a into main Sep 30, 2024
21 of 22 checks passed
@weiji14 weiji14 deleted the load_black_marble branch September 30, 2024 04:50
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.

Function to load NASA Blue and Black marble mosaic images
2 participants