Conversation
|
/format |
|
/format |
Actually, it's possible to read the PNG into an xarray.DataArray object and pass it directly to import rasterio
import xarray as xr
with rasterio.open("https://upload.wikimedia.org/wikipedia/commons/thumb/b/b7/Flag_of_Europe.svg/1000px-Flag_of_Europe.svg.png") as dataset:
data = dataset.read()
drapegrid = xr.DataArray(data, dims=("band", "y", "x"))and then change |
I prefer two have two examples, one for draping a grid and another for draping an image. They're slightly different that the first one need a CPT file and the 2nd one doesn't. |
Thanks, @seisman! That's nice, and actually not too difficult. I should definitely work on my xarray knowledge!
I thought about having examples for both draping a grid and draping an image, but then I faced the problem with loading the PNG file. But it can be solved by using rasterio and xarray. I am wondering if it makes sense to make this a tutorial, as the script is a bit longer when keeping both examples, but also totally fine with keeping this a "normal" gallery example? |
|
A tutorial is OK to me. |
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
| # the stars (value 255 -> upper half) | ||
| pygmt.makecpt(cmap="0/51/153,255/204/0", series=[0, 256, 128]) | ||
|
|
||
| fig.grdview( |
There was a problem hiding this comment.
For points, plot3d is needed. For coastlines, it's likely we need to dump the coastlines and the use grdtrack to determine the z-value for each data points and then pass them to plot3d.
| # %% | ||
| # Additionally we can plot some features like coastlines, symbols, and text on top of | ||
| # the map. Setting ``perspective=True`` leads to the same azimuth and elevation values | ||
| # as we passed to the ``perspective`` parameter of :meth:`pygmt.Figure.grdview`. | ||
|
|
||
| # Plot water masses, political broders, and shorelines | ||
| fig.coast( | ||
| water="white@50", | ||
| borders="1/1p,lightgray", | ||
| shorelines="1/0.5p,gray30", | ||
| perspective=True, | ||
| ) | ||
|
|
||
| # Set up a pandas.DataFrame with coordinates and names of three cities | ||
| cities = pd.DataFrame( | ||
| { | ||
| "longitude": [7.10, 4.35, 5.69], # degrees East | ||
| "latitude": [50.73, 50.85, 50.85], # degress North | ||
| "elevation": [60, 13, 49], # meters | ||
| "name": ["Bonn", "Bruxelles", "Maastricht"], | ||
| } | ||
| ) | ||
| # Plot markers | ||
| fig.plot3d( | ||
| x=cities.longitude, | ||
| y=cities.latitude, | ||
| z=cities.elevation, | ||
| style="s0.3c", # Use squares with a size of 0.3 centimeters | ||
| pen="1.5p,white", | ||
| fill="black", | ||
| perspective=True, | ||
| ) | ||
| # Add labels | ||
| fig.text( | ||
| x=cities.longitude, | ||
| y=cities.latitude, | ||
| text=cities.name, | ||
| justify="TL", # Use Top Left corner as anchor point | ||
| offset="0.3c/-0.3c", # x / y directions, in centimeters | ||
| font="12p", | ||
| fill="white@30", # Fill box in white with a transparency of 30 % | ||
| perspective=True, | ||
| ) |
There was a problem hiding this comment.
Maybe we should skip this part and only focus on draping?
There was a problem hiding this comment.
I apologize for the delay with this tutorial 🙁!
I also thought about this. Maybe we can remove this part for now (see commit 5f423b3), to get this tutorial into the release of v0.13.0.
However, I am not 100 % happy with this, as I feel that users actually like to plot more details on top of the 3-D surface. Maybe we can add this later or create a separate tutorial on how to do this.
There was a problem hiding this comment.
as I feel that users actually like to plot more details on top of the 3-D surface. Maybe we can add this later or create a separate tutorial on how to do this.
Sounds good to me.




Description of proposed changes
It would be nice to have a gallery example showing the usage of the
drapegridparameter ofpygmt.Figure.grdviewfor adding a data set on top of a topographic surface.So far I started working on two different ideas / examples in parallel:
xarray.DataArraynetCDF fileAt the momentan I am not 100 % happy with both examples - some aspects:
grdconvertandgrdeditare not wrapped yet; other method to do this in PythonTODO
regionparameterPreview
https://pygmt-dev--3316.org.readthedocs.build/en/3316/tutorials/advanced/draping_on_3d_surface.html
Reminders
make formatandmake checkto make sure the code follows the style guide.doc/api/index.rst.Slash Commands
You can write slash commands (
/command) in the first line of a comment to performspecific operations. Supported slash command is:
/format: automatically format and lint the code