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 gallery example to show usage of tile maps #2585

Merged
merged 16 commits into from
Jul 12, 2023
Merged

Add gallery example to show usage of tile maps #2585

merged 16 commits into from
Jul 12, 2023

Conversation

michaelgrund
Copy link
Member

@michaelgrund michaelgrund commented Jun 26, 2023

Description of proposed changes

So far we don't promote the usage of tilemaps. Here's a gallery example to show its application using two different sources.

Preview: https://pygmt-dev--2585.org.readthedocs.build/en/2585/gallery/maps/tilemaps.html

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

@michaelgrund michaelgrund added the documentation Improvements or additions to documentation label Jun 26, 2023
@michaelgrund michaelgrund added this to the 0.10.0 milestone Jun 26, 2023
@michaelgrund
Copy link
Member Author

/format

@michaelgrund
Copy link
Member Author

/format

@michaelgrund
Copy link
Member Author

/format

@michaelgrund michaelgrund added the needs review This PR has higher priority and needs review. label Jun 26, 2023
Co-authored-by: Yvonne Fröhlich <[email protected]>
Copy link
Member

@weiji14 weiji14 left a comment

Choose a reason for hiding this comment

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

Nice one, thanks @michaelgrund for adding this example! Just one comment for now.

examples/gallery/maps/tilemaps.py Outdated Show resolved Hide resolved
@seisman
Copy link
Member

seisman commented Jun 28, 2023

Nice example! Do you think switching the order of the two examples makes more sense? I.e., the first example uses the tile providers available from contextily and the second is a more advanced example for people who wants to use custom tile servers that contextily doesn't provide (source="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" as an example although contextily supports OpenStreetMap).

@michaelgrund
Copy link
Member Author

Nice example! Do you think switching the order of the two examples makes more sense? I.e., the first example uses the tile providers available from contextily and the second is a more advanced example for people who wants to use custom tile servers that contextily doesn't provide (source="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" as an example although contextily supports OpenStreetMap).

Not sure, since contextily needs to be loaded additionally as a separate library, compared to the "direct" link to the custom tile servers. What do others think?

@yvonnefroehlich
Copy link
Member

Nice example! Do you think switching the order of the two examples makes more sense? I.e., the first example uses the tile providers available from contextily and the second is a more advanced example for people who wants to use custom tile servers that contextily doesn't provide (source="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" as an example although contextily supports OpenStreetMap).

Not sure, since contextily needs to be loaded additionally as a separate library, compared to the "direct" link to the custom tile servers. What do others think?

I have no clear answer here, and I feel I am fine with both orders. Here are some thoughts or ideas, which are maybe helpful regarding a decision:
Considering that contextily needs to be loaded additionally and that the Stamen.Watercolor option is a more special visualization than OpenStreetMap, the current Figure order makes sense to me. However, by default (i.e., the source parameter is not specified), the xyzservices.TileProvider object xyzservices.providers.Stamen.Terrain is used. So, maybe expand the example and start without specifying source. Then introduce source based on using not the default Stamen.Terrain web tiles, but the Stamen.Watercolor option from contextily. Create a second figure to show that also a web tile provider in the form of a URL can be used and introduce the zoom parameter.

Code example: (comments need definitly some improvement)

import contextily
import pygmt

fig = pygmt.Figure()

# Default xyzservices.providers.Stamen.Terrain
fig.tilemap(
    region=[-157.84, -157.8, 21.255, 21.285],
    projection="M12c",
    frame="af+e",
)

fig.shift_origin(xshift="13c")

fig.tilemap(
    region=[-157.84, -157.8, 21.255, 21.285],
    projection="M12c",
    # Instead of Stamen.Terrain web tiles use the Stamen.Watercolor option
    # from contextily
    source=contextily.providers.Stamen.Watercolor,
    frame=["wSne", "af+e"],
)

fig.show()

###############################################################################
# Instead of a web tile provider in the form of a xyzservices.TileProvider
# object use one in the form of a URL

fig = pygmt.Figure()

fig.tilemap(
    region=[-157.84, -157.8, 21.255, 21.285],
    projection="M12c",
    # Set level of details (0-22)
    # Higher levels mean a zoom level closer to the Earth's
    # surface with more tiles covering a smaller
    # geographic area and thus more details and vice versa
    # Please note, not all zoom levels are always available
    zoom=14,
    # Use tiles from OpenStreetMap tile server
    source="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
    frame="afg+e",
)

fig.show()

Output figures:
tilemaps_xyzservices

tilemaps_url

@seisman
Copy link
Member

seisman commented Jul 1, 2023

maybe expand the example and start without specifying source. Then introduce source based on using not the default Stamen.Terrain web tiles, but the Stamen.Watercolor option from contextily. Create a second figure to show that also a web tile provider in the form of a URL can be used and introduce the zoom parameter.

Good idea!

@weiji14
Copy link
Member

weiji14 commented Jul 3, 2023

maybe expand the example and start without specifying source. Then introduce source based on using not the default Stamen.Terrain web tiles, but the Stamen.Watercolor option from contextily. Create a second figure to show that also a web tile provider in the form of a URL can be used and introduce the zoom parameter.

Good idea!

This is starting to sound like a tutorial instead of a gallery example 😅 Let's maybe keep to just 2 maps at a maximum instead of 3 for this gallery example. We can still show one using Stamen, and another figure using OpenStreetmap's tile server.

Note that the latter OpenStreetMap example is actually the same as using contextily.OpenStreetMap.Mapnik, but it's still good to show how people can use a tile server url like https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png. Also, either way, contextily will have to be used with or without import contextily, so the order doesn't matter too much.

@seisman
Copy link
Member

seisman commented Jul 3, 2023

This is starting to sound like a tutorial instead of a gallery example

Why not extend it as a tutorial?

@michaelgrund
Copy link
Member Author

This is starting to sound like a tutorial instead of a gallery example

Why not extend it as a tutorial?

I think we should have both, gallery example and tutorial.

@yvonnefroehlich yvonnefroehlich changed the title Create gallery example to show usage of tilemaps Create gallery example to show usage of tile maps Jul 3, 2023
@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 Jul 8, 2023
Copy link
Member

@seisman seisman left a comment

Choose a reason for hiding this comment

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

OK. Approving this PR.

Copy link
Member

@yvonnefroehlich yvonnefroehlich left a comment

Choose a reason for hiding this comment

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

I am fine with having both gallery example and tutorial, as suggested by @michaelgrund. In this case, I feel @weiji14 is right, and the gallery example should be short. For the tutorial, I suggest considering also the lonlat parameter.

Copy link
Member

@weiji14 weiji14 left a comment

Choose a reason for hiding this comment

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

Yep, let's open up a separate PR for a longer tutorial.

@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Jul 11, 2023
@seisman seisman merged commit 2a724e5 into main Jul 12, 2023
@seisman seisman deleted the gallery-tilemaps branch July 12, 2023 09:41
@yvonnefroehlich
Copy link
Member

Yep, let's open up a separate PR for a longer tutorial.

@michaelgrund do you also plan to add this tutorial, or @weiji14 do you want to work on this?

@weiji14 weiji14 changed the title Create gallery example to show usage of tile maps Add gallery example to show usage of tile maps Aug 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants