-
Notifications
You must be signed in to change notification settings - Fork 0
Fix figure generation on GMT 6.5+ #13
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
Changes from all commits
5b22f89
da31374
90b7d26
a9369dd
be05ba7
90a44bb
0610015
3bef088
37306d4
dce1754
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,20 +1,19 @@ | ||||||
| """Plotting tools to generate basemaps, grids and contours with PyGMT.""" | ||||||
|
|
||||||
| import itertools | ||||||
| import copy | ||||||
| import itertools | ||||||
| import tempfile | ||||||
| from pathlib import Path | ||||||
| from typing import Any, NamedTuple, Optional, Self, Callable | ||||||
| from typing import Any, Callable, NamedTuple, Optional, Self | ||||||
|
|
||||||
| import geopandas | ||||||
| import numpy as np | ||||||
| import pandas as pd | ||||||
| import pooch | ||||||
| import pygmt | ||||||
| import xarray as xr | ||||||
| from scipy import interpolate | ||||||
| from shapely import geometry | ||||||
| from qcore import point_in_polygon | ||||||
| from scipy import interpolate | ||||||
|
|
||||||
| GMT_DATA = pooch.create( | ||||||
| pooch.os_cache("pygmt_helper"), | ||||||
|
|
@@ -290,41 +289,30 @@ def gen_region_fig( | |||||
| # Merge with default | ||||||
| plot_kwargs = copy.deepcopy(DEFAULT_PLT_KWARGS) | (plot_kwargs or {}) | ||||||
|
|
||||||
| if title: | ||||||
| plot_kwargs["frame_args"] = plot_kwargs.get("frame_args", []) + [ | ||||||
| f"+t{title}".replace(" ", r"\040") | ||||||
| ] | ||||||
|
|
||||||
| if subtitle: | ||||||
| plot_kwargs["frame_args"] = plot_kwargs.get("frame_args", []) + [ | ||||||
| f"+s{subtitle}".replace(" ", r"\040") | ||||||
| ] | ||||||
| if config_options: | ||||||
| pygmt.config(**config_options) | ||||||
|
|
||||||
| if fig is None: | ||||||
| fig = pygmt.Figure() | ||||||
|
|
||||||
| if config_options: | ||||||
| pygmt.config(**config_options) | ||||||
|
|
||||||
| water_color = plot_kwargs["water_color"] | ||||||
| plot_kwargs["frame_args"] = plot_kwargs.get("frame_args", []) + [f"+g{water_color}"] | ||||||
| fig.basemap( | ||||||
| region=region if region else "NZ", | ||||||
| projection=projection, | ||||||
| frame=plot_kwargs["frame_args"], | ||||||
| ) | ||||||
|
|
||||||
| # Plot coastline and background water | ||||||
| bg_region = region if region else fig.region | ||||||
| water_bg = geopandas.GeoSeries( | ||||||
| geometry.LineString( | ||||||
| [ | ||||||
| (bg_region[0], bg_region[2]), | ||||||
| (bg_region[1], bg_region[2]), | ||||||
| (bg_region[1], bg_region[3]), | ||||||
| [bg_region[0], bg_region[3]], | ||||||
| ] | ||||||
| ) | ||||||
| ) | ||||||
| fig.plot(water_bg, fill=plot_kwargs["water_color"], straight_line=True) | ||||||
| title_args = [] | ||||||
| if title: | ||||||
| title_args.append(f"+t{title}") | ||||||
| if subtitle: | ||||||
| title_args.append(f"+s{subtitle}") | ||||||
lispandfound marked this conversation as resolved.
Show resolved
Hide resolved
lispandfound marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
| if title: | ||||||
|
||||||
| if title: | |
| if title_args: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I knew the AI would flag this. Nope it is intentional. See the GMT docs
+ttitle to place the string given in title centered above the plot frame [default is no title].
+ssubtitle (requires +ttitle) to place the string given in subtitle beneath the title [default is no subtitle].
Note that +s requires +t, ergo subtitle= requires title=. Thus checking if title_args is non-empty leaves open the subtle bug that a user might call subtitle= and not title=. Hence, we check if title is not None. In that case, title_args is also not None. Likewise, if title is None then we should ignore the values in title_args even if subtitle is set.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,6 @@ pyarrow | |
| pygmt | ||
| xarray | ||
| scipy | ||
| shapely | ||
| qcore @ git+https://github.com/ucgmsim/qcore.git | ||
| pytest | ||
| pytest-cov | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.