-
Notifications
You must be signed in to change notification settings - Fork 224
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
Tutorial: Adding a data set on top of a topographic surface via "drapegrid" of "Figure.grdview" #3316
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 <[email protected]>
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you forget zsize
here?
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.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should skip this part and only focus on draping?
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
Looks good to me.
Description of proposed changes
It would be nice to have a gallery example showing the usage of the
drapegrid
parameter ofpygmt.Figure.grdview
for adding a data set on top of a topographic surface.So far I started working on two different ideas / examples in parallel:
xarray.DataArray
netCDF file
At the momentan I am not 100 % happy with both examples - some aspects:
grdconvert
andgrdedit
are not wrapped yet; other method to do this in PythonTODO
region
parameterPreview
https://pygmt-dev--3316.org.readthedocs.build/en/3316/tutorials/advanced/draping_on_3d_surface.html
Reminders
make format
andmake check
to 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