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 zoom_adjust parameter to pygmt.datasets.load_tile_map and Figure.tilemap #2934

Merged
merged 15 commits into from
Jan 8, 2024

Conversation

weiji14
Copy link
Member

@weiji14 weiji14 commented Dec 30, 2023

Description of proposed changes

The zoom_adjust parameter is used to adjust the automatic zoom level by integer increments.

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

Note: This requires contextily>=1.5.0, see geopandas/contextily#228.

Example usage:

import contextily
import pygmt

region = [-157.84, -157.8, 21.255, 21.285]  # West, East, South, North
fig = pygmt.Figure()
with fig.subplot(ncols=2, figsize=("15c", "6c"), sharey=True):
    # Regular zoom level
    fig.tilemap(
        zoom="auto",
        region=region,
        source=contextily.providers.CartoDB.Positron,
        panel=0,
        frame="+tAuto Zoom",
    )
    # Zoom level -1 (more zoomed out)
    fig.tilemap(
        zoom="auto",
        region=region,
        source=contextily.providers.CartoDB.Positron,
        zoom_adjust=-1,
        panel=1,
        frame="+tAuto Zoom -1",
    )
fig.savefig("zoom_adjust.png")
fig.show(width=1000)

produces

zoom_adjust

Fixes #

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

The zoom_adjust parameter is used to adjust the automatic zoom level by integer increments. This was added in contextily=1.5.0, see geopandas/contextily#228.
@weiji14 weiji14 added enhancement Improving an existing feature upstream Bug or missing feature of upstream core GMT labels Dec 30, 2023
@weiji14 weiji14 added this to the 0.11.0 milestone Dec 30, 2023
@weiji14 weiji14 self-assigned this Dec 30, 2023
@@ -128,6 +141,7 @@ def load_tile_map(region, zoom="auto", source=None, lonlat=True, wait=0, max_ret
ll=lonlat,
wait=wait,
max_retries=max_retries,
zoom_adjust=zoom_adjust,
Copy link
Member Author

Choose a reason for hiding this comment

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

Might need to make this backwards compatible with contextily<1.5.0.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, need to check the contextily version and also better to mention that the zoom_adjust parameter requires contextily>=1.5.0.

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, documented at e48c08d, and added another commit at b428d12 to raise an error if zoom_adjust is used but contextily<1.5.0 is installed.

lonlat=True,
wait=0,
max_retries=2,
zoom_adjust=None,
Copy link
Member

Choose a reason for hiding this comment

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

Add type hints to this newly added parameter?

Suggested change
zoom_adjust=None,
zoom_adjust: int | None,

Copy link
Member Author

Choose a reason for hiding this comment

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

Done at f0c95d8 for just the zoom_adjust parameter. Since all the lines are changing, should I just add type hints for all the other parameters too?

Copy link
Member

Choose a reason for hiding this comment

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

Perfer to focus on the zoom_adjust parameter only in this PR.

pygmt/datasets/tile_map.py Outdated Show resolved Hide resolved
automatically. Values outside of -1 to 1 are not recommended as they
can lead to slow execution. [Default is ``None``].

.. versionadded:: 0.11.0
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should not add this until PyGMT reaches v1.0.0?

.. versionadded:: 0.11.0

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, changed to using the note directive instead at 0b01664. I've also used the note and important directive/admonition in other parts of the docstring at 32c04f8:

image

If it looks a bit messy, I can also revert the changes back to the plain text version.

pygmt/datasets/tile_map.py Outdated Show resolved Hide resolved
pygmt/datasets/tile_map.py Outdated Show resolved Hide resolved
@@ -117,6 +135,15 @@ def load_tile_map(region, zoom="auto", source=None, lonlat=True, wait=0, max_ret
"to install the package."
)

contextily_kwargs = {}
Copy link
Member

Choose a reason for hiding this comment

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

Do you want to also include zoom, source, ll, wait and max_retries in contextily_kwargs?

Copy link
Member Author

Choose a reason for hiding this comment

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

Mm, not really necessary. I only made the contextily_kwargs dict to make things backwards compatible with contextily<1.5.0.

@weiji14 weiji14 marked this pull request as ready for review January 6, 2024 08:41
@weiji14 weiji14 added the final review call This PR requires final review and approval from a second reviewer label Jan 6, 2024
@weiji14
Copy link
Member Author

weiji14 commented Jan 6, 2024

Gonna leave this open for another day or so in case someone wants to comment on anything.

pygmt/src/tilemap.py Outdated Show resolved Hide resolved
@weiji14 weiji14 merged commit c9c3a4a into main Jan 8, 2024
16 of 17 checks passed
@weiji14 weiji14 deleted the tilemap_zoom_adjust branch January 8, 2024 00:35
@weiji14 weiji14 removed the final review call This PR requires final review and approval from a second reviewer label Jan 8, 2024
@yvonnefroehlich yvonnefroehlich changed the title Add zoom_adjust param to pygmt.datasets.load_tile_map and Figure.tilemap Add zoom_adjust parameter to pygmt.datasets.load_tile_map and Figure.tilemap Jan 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improving an existing feature upstream Bug or missing feature of upstream core GMT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants