You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Integration with contextily to plot xyz basemaps #2115
On the implementation, here are 2 ideas on how to integrate contextily basemaps with pygmt.
Have an additional option under fig.basemap which allows selection of the basemap (e.g. OpenStreetMap, Stamen, Mapbox, etc) (Add Figure.tilemap to plot XYZ tile maps #2394, to be called fig.tilemap)
On the implementation, here are 2 ideas on how to integrate contextily basemaps with pygmt.
Have an additional option under fig.basemap which allows selection of the basemap (e.g. OpenStreetMap, Stamen, Mapbox, etc)
Create a new load_basemap function under pygmt/datasets that would load the image (np.ndarray) and georeference it (to an xarray.DataArray), and then the user plots it using fig.grdimage.
Maybe there's another more Pythonic way? Comment down below!
Can we do both 1 and 2? I.e., having the load_basemap (maybe load_map_tiles?) function in pygmt/datasets and having a new parameter in Figure.basemap to call this function.
On the implementation, here are 2 ideas on how to integrate contextily basemaps with pygmt.
Have an additional option under fig.basemap which allows selection of the basemap (e.g. OpenStreetMap, Stamen, Mapbox, etc)
Create a new load_basemap function under pygmt/datasets that would load the image (np.ndarray) and georeference it (to an xarray.DataArray), and then the user plots it using fig.grdimage.
Maybe there's another more Pythonic way? Comment down below!
Can we do both 1 and 2? I.e., having the load_basemap (maybe load_map_tiles?) function in pygmt/datasets and having a new parameter in Figure.basemap to call this function.
That sounds like a neat idea. Start with (2) load_map_tiles first, and then do (1) new option in fig.basemap() (which will be a lot more complicated.
Actually, we'll also need to let fig.grdimage work with RGB (3 bands) instead of just 1 band. It works if we save the RGB image to a GeoTIFF first and tell fig.grdimage to plot the .tif file, but would be nicer to plot a 3 band xr.DataArray directly, xref #1555. Or we can use a tempfile 😉
Started a Pull Request at #2125 for load_map_tilesload_tile_map (renamed based on #2125 (comment)).
To jump ahead a little bit, this is the code I'm currently using to plot the 3-band xarray.DataArray. The raster can be obtained from running the snippet in #2125 (comment).
Have an additional option under fig.basemap which allows selection of the basemap (e.g. OpenStreetMap, Stamen, Mapbox, etc)
After a bit of thinking, and as mentioned in in #2125 (comment), I'm considering creating a new fig.tilemap method instead of complicating fig.basemap further. This fig.tilemap method would essentially look like:
Any thoughts on this implementation? Note that projections will also need to be handled, something mentioned in #2125 (comment). Also, the .rio.to_raster requires adding rioxarray as another optional dependency.
The tempfile is a bit of a hack to be honest, but is necessary until we can use grdimage to plot 3-band xarray.DataArrays directly, something to be done in #1555.
After a bit of thinking, and as mentioned in in #2125 (comment), I'm considering creating a new fig.tilemap method instead of complicating fig.basemap further.
Yes, I aslo prefer fig.tilemap!
The tempfile is a bit of a hack to be honest, but is necessary until we can use grdimage to plot 3-band xarray.DataArrays directly, something to be done in #1555.
Activity
seisman commentedon Sep 19, 2022
Can we do both 1 and 2? I.e., having the
load_basemap(maybeload_map_tiles?) function inpygmt/datasetsand having a new parameter inFigure.basemapto call this function.weiji14 commentedon Sep 19, 2022
That sounds like a neat idea. Start with (2)
load_map_tilesfirst, and then do (1) new option infig.basemap()(which will be a lot more complicated.Actually, we'll also need to let
fig.grdimagework with RGB (3 bands) instead of just 1 band. It works if we save the RGB image to a GeoTIFF first and tellfig.grdimageto plot the .tif file, but would be nicer to plot a 3 bandxr.DataArraydirectly, xref #1555. Or we can use a tempfile 😉weiji14 commentedon Sep 19, 2022
Started a Pull Request at #2125 for
load_map_tilesload_tile_map(renamed based on #2125 (comment)).To jump ahead a little bit, this is the code I'm currently using to plot the 3-band
xarray.DataArray. Therastercan be obtained from running the snippet in #2125 (comment).produces this Stamen Terrain map over Singapore
weiji14 commentedon Mar 2, 2023
After a bit of thinking, and as mentioned in in #2125 (comment), I'm considering creating a new
fig.tilemapmethod instead of complicatingfig.basemapfurther. Thisfig.tilemapmethod would essentially look like:Any thoughts on this implementation? Note that projections will also need to be handled, something mentioned in #2125 (comment). Also, the
.rio.to_rasterrequires addingrioxarrayas another optional dependency.The tempfile is a bit of a hack to be honest, but is necessary until we can use
grdimageto plot 3-bandxarray.DataArrays directly, something to be done in #1555.seisman commentedon Mar 2, 2023
Yes, I aslo prefer
fig.tilemap!I agree.