Skip to content

Commit

Permalink
ENH: Adding ability to provide a img_tile found in cartopy.io.img_tiles.
Browse files Browse the repository at this point in the history
  • Loading branch information
zssherman committed Oct 10, 2023
1 parent 5c273b4 commit 630c54c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 10 deletions.
24 changes: 16 additions & 8 deletions act/plotting/geodisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
try:
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.io.img_tiles import Stamen
from cartopy.io import img_tiles

CARTOPY_AVAILABLE = True
except ImportError:
Expand Down Expand Up @@ -56,7 +56,8 @@ def geoplot(
title=None,
projection=None,
plot_buffer=0.08,
stamen='terrain-background',
img_tile=None,
img_tile_args=[None],
tile=8,
cartopy_feature=None,
cmap='rainbow',
Expand Down Expand Up @@ -91,11 +92,18 @@ def geoplot(
https://scitools.org.uk/cartopy/docs/latest/reference/projections.html?highlight=projections
plot_buffer : float
Buffer to add around data on plot in lat and lon dimension.
stamen : str
Dataset to use for background image. Set to None to not use
background image.
img_tile : str
Image to use for the plot background. Set to None to not use
background image. For all image background types, see:
https://scitools.org.uk/cartopy/docs/v0.16/cartopy/io/img_tiles.html
Default is None.
img_tile_args : list
Arguments for the chosen img_tile. These arguments can be found for
the corresponding img_tile here:
https://scitools.org.uk/cartopy/docs/v0.16/cartopy/io/img_tiles.html
Default is None.
tile : int
Tile zoom to use with background image. Higer number indicates
Tile zoom to use with background image. Higher number indicates
more resolution. A value of 8 is typical for a normal sonde plot.
cartopy_feature : list of str or str
Cartopy feature to add to plot.
Expand Down Expand Up @@ -199,8 +207,8 @@ def geoplot(
else:
plt.title(title)

if stamen:
tiler = Stamen(stamen)
if img_tile is not None:
tiler = getattr(img_tiles, img_tile)(*img_tile_args)
ax.add_image(tiler, tile)

colorbar_map = None
Expand Down
Binary file added act/tests/baseline/test_geoplot_tile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 32 additions & 1 deletion act/tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,38 @@ def test_geoplot():
'RIVERS',
],
text={'Ponca City': [-97.0725, 36.7125]},
stamen=None,
img_tile=None,
)
try:
return geodisplay.fig
finally:
matplotlib.pyplot.close(geodisplay.fig)
except Exception:
pass
sonde_ds.close()


@pytest.mark.skipif(not CARTOPY_AVAILABLE, reason='Cartopy is not installed.')
@pytest.mark.mpl_image_compare(tolerance=30)
def test_geoplot_tile():
sonde_ds = arm.read_netcdf(sample_files.EXAMPLE_SONDE1)
geodisplay = GeographicPlotDisplay({'sgpsondewnpnC1.b1': sonde_ds}, figsize=(15, 8))
try:
geodisplay.geoplot(
'tdry',
marker='.',
cartopy_feature=[
'STATES',
'LAND',
'OCEAN',
'COASTLINE',
'BORDERS',
'LAKES',
'RIVERS',
],
text={'Ponca City': [-97.0725, 36.7125]},
img_tile='GoogleTiles',
img_tile_args=['RGB', 'terrain'],
)
try:
return geodisplay.fig
Expand Down
2 changes: 1 addition & 1 deletion examples/plotting/plot_aaf_track.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
display = act.plotting.GeographicPlotDisplay(ds, figsize=(12, 10))

# Plot the ARM AAF flight track with respect to Pressure Altitude
display.geoplot('press_alt', lat_field='lat', lon_field='lon', stamen=None)
display.geoplot('press_alt', lat_field='lat', lon_field='lon')

# Display the plot
plt.show()

0 comments on commit 630c54c

Please sign in to comment.