From 5417f386431507717ad170f21c7c991d2254a5cc Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 7 Jul 2024 22:11:59 +0200 Subject: [PATCH 01/48] Add two ideas for gallery example showing the 'drapegrid' parameter --- .../gallery/images/image_on_topography.py | 156 ++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100755 examples/gallery/images/image_on_topography.py diff --git a/examples/gallery/images/image_on_topography.py b/examples/gallery/images/image_on_topography.py new file mode 100755 index 00000000000..7c6c85abad7 --- /dev/null +++ b/examples/gallery/images/image_on_topography.py @@ -0,0 +1,156 @@ +""" +Draping a data set on top of a topographic surface +================================================== + +It can be visually appealing to "drape" a data set (grid or image) over a +topographic surface. This can be accomplished using the ``drapegrid`` parameter +of :meth:`pygmt.Figure.grdview`. + +In the first example, the seafloor crustal age is plotted with color-coding +on top of the topographic map of an area of the Mid-Atlantic Ridge. + +In the second example, the flag of Europe is plotted on top of a topographic +map of northwest Europe. This example is modified from GMT example 32 available +at https://docs.generic-mapping-tools.org/latest/gallery/ex32.html#example-32. +For the sake of simplicity the image grid is already stored as netCDF file +*@euflag.nc* in the GMT directory. + +.. note:: + + The PNG file of the flag of Europe can be downloaded from the internet + (http://upload.wikimedia.org/wikipedia/commons/thumb/b/b7/Flag_of_Europe.svg/1000px-Flag_of_Europe.svg.png) + and converted via *grdconvert* using GDAL support. The dimension + (1000 x 667 pixels) of the image is taken into account for a ratio of 3 x 2. + To add the correct grid region, *grdedit* is used. As *grdconvert* and + *grdedit* are not available in PyGMT yet, please see the GMT example + mentioned above for details. +""" + +import pygmt + +# %% +# Grid of seafloor crustal age on top of topographic map of Mid-Atlantic Ridge +# ----------------------------------------------------------------------------- + +# Define study area +region_2d = [-50, 0, 36, 70] # [lon_min, lon_max, lat_min, lat_max] +region_3d = [*region_2d, -5961, 3366.5] # Append [z_min, z_max] to this list +perspective = [157.5, 30] # Define azimuth, elevation for the 3-D plot + +# ----------------------------------------------------------------------------- +# Create new Figure instance +fig = pygmt.Figure() + +# Download elevation and crustal age grids for the study region with a +# resolution of 3 arc-minutes and load them into xarray.DataArrays +grd_relief = pygmt.datasets.load_earth_relief(resolution="03m", region=region_2d) +grd_age = pygmt.datasets.load_earth_age(resolution="03m", region=region_2d) + +# Set up colormap for curstal age +pygmt.config(COLOR_NAN="lightgray") +pygmt.makecpt(cmap="batlow", series=[0, 200, 1], reverse=True, overrule_bg=True) + +fig.grdview( + projection="M12c", # Mercator projection with a width of 12 centimeters + region=region_3d, + grid=grd_relief, # Use elevation grid for z values + drapegrid=grd_age, # Use crustal age grid for color-coding + cmap=True, + surftype="i", # Create an image plot + # Use an illumination from the azimuthal directions 0° (north) and 270° + # (west) with a normalization via a cumulative Laplace distribution for + # the shading + shading="+a0/270+ne0.6", + perspective=perspective, + zsize="1.5c", + plane="+gdarkgray", + frame=True, +) + +# ----------------------------------------------------------------------------- +# Add colorbar for curstal age +fig.colorbar(frame=["x+lseafloor crustal age", "y+lMyr"], position="+n") + +# Show figure +fig.show() + + +# %% +# Image of the flag of Europe on top of topographic map of northwest Europe +# ------------------------------------------------------------------------- + +# Define study area +region_2d = [3, 9, 50, 54] # [lon_min, lon_max, lat_min, lat_max] +region_3d = [*region_2d, -10, 900] # Append [z_min, z_max] to this list +perspective = [157.5, 30] # Define azimuth, elevation for the 3-D plot + +# Coordinates and names of cities +lons_cities = [7.10, 4.35, 5.69] # degrees East +lats_cities = [50.73, 50.85, 50.85] # degrees North +text_cities = ["Bonn", "Bruxelles", "Maastricht"] + +# ----------------------------------------------------------------------------- +# Create new Figure instance +fig = pygmt.Figure() + +# Download elevation grid for the study region with a resolution of 30 +# arc-seconds and pixel registration and load it into a xarray.DataArray +grd_relief = pygmt.datasets.load_earth_relief(resolution="30s", region=region_2d) + +# Set up a colormap with two colors for the EU flag: blue (0/51/153) for the +# background (value 0 in the nedCDF file -> lower half of 0-255 range) and +# yellow (255/204/0) for the stars (value 255 -> upper half) +pygmt.makecpt(cmap="0/51/153,255/204/0", series=[0, 256, 128]) # [min, max[, step + +fig.grdview( + projection="M12c", # Mercator projection with a width of 12 centimeters + region=region_3d, + grid=grd_relief, # Use elevation grid for z values + drapegrid="@euflag.nc", # Drap image grid for the EU flag on top + cmap=True, # Use colormap defined for the EU flag + surftype="i", # Create an image plot + # Use an illumination from the azimuthal directions 0° (north) and 270° + # (west) with a normalization via a cumulative Laplace distribution for + # the shading + shading="+a0/270+ne0.6", + perspective=perspective, + zsize="1c", + plane="+glightgray", + frame=True, +) + +# ----------------------------------------------------------------------------- +# Plot water, broders, and shorelines on top +fig.coast( + water="white@50", + borders="1/1p,lightgray", + shorelines="1/0.5p,gray30", + perspective=perspective, +) + +# ----------------------------------------------------------------------------- +# Mark cities +# Plot markers +fig.plot( + x=lons_cities, + y=lats_cities, + style="s0.3c", # Use squares with a size of 0.3 centimeters + pen="1.5p,white", + fill="black", + perspective=perspective, +) +# Add labels +fig.text( + x=lons_cities, + y=lats_cities, + text=text_cities, + 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=perspective, +) + +# ----------------------------------------------------------------------------- +# Show figure +fig.show() From f849ceda3cbc58a8037bc3063ecf59cd9cb8dfc4 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 7 Jul 2024 22:43:01 +0200 Subject: [PATCH 02/48] Move and rename file --- .../image_on_topography.py => 3d_plots/dataset_on_surface.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/gallery/{images/image_on_topography.py => 3d_plots/dataset_on_surface.py} (100%) diff --git a/examples/gallery/images/image_on_topography.py b/examples/gallery/3d_plots/dataset_on_surface.py similarity index 100% rename from examples/gallery/images/image_on_topography.py rename to examples/gallery/3d_plots/dataset_on_surface.py From 0669fa56d5c0b788b349855c83cce02ccce2b445 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 7 Jul 2024 22:46:43 +0200 Subject: [PATCH 03/48] Add code block separator --- examples/gallery/3d_plots/dataset_on_surface.py | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/gallery/3d_plots/dataset_on_surface.py b/examples/gallery/3d_plots/dataset_on_surface.py index 7c6c85abad7..37cf0cdbb0b 100755 --- a/examples/gallery/3d_plots/dataset_on_surface.py +++ b/examples/gallery/3d_plots/dataset_on_surface.py @@ -26,6 +26,7 @@ mentioned above for details. """ +# %% import pygmt # %% From 08549a7f7813451f4bda26dd90209d572d9737b2 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 7 Jul 2024 22:49:26 +0200 Subject: [PATCH 04/48] Add shebang --- examples/gallery/3d_plots/dataset_on_surface.py | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/gallery/3d_plots/dataset_on_surface.py b/examples/gallery/3d_plots/dataset_on_surface.py index 37cf0cdbb0b..fd0029a4f69 100755 --- a/examples/gallery/3d_plots/dataset_on_surface.py +++ b/examples/gallery/3d_plots/dataset_on_surface.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- """ Draping a data set on top of a topographic surface ================================================== From a3b31c6978f95790bea3d83ce7b94be42664c696 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 7 Jul 2024 22:54:55 +0200 Subject: [PATCH 05/48] Remove shebang --- examples/gallery/3d_plots/dataset_on_surface.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/gallery/3d_plots/dataset_on_surface.py b/examples/gallery/3d_plots/dataset_on_surface.py index fd0029a4f69..37cf0cdbb0b 100755 --- a/examples/gallery/3d_plots/dataset_on_surface.py +++ b/examples/gallery/3d_plots/dataset_on_surface.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ Draping a data set on top of a topographic surface ================================================== From 2ea0b9a16571b9a3fc916c99f76b96bc6e25447d Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 7 Jul 2024 23:06:01 +0200 Subject: [PATCH 06/48] Select thumbnail image --- examples/gallery/3d_plots/dataset_on_surface.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/gallery/3d_plots/dataset_on_surface.py b/examples/gallery/3d_plots/dataset_on_surface.py index 37cf0cdbb0b..cd1a7f8422a 100755 --- a/examples/gallery/3d_plots/dataset_on_surface.py +++ b/examples/gallery/3d_plots/dataset_on_surface.py @@ -1,4 +1,4 @@ -""" +r""" Draping a data set on top of a topographic surface ================================================== @@ -155,3 +155,5 @@ # ----------------------------------------------------------------------------- # Show figure fig.show() + +# sphinx_gallery_thumbnail_number = 1 From 744287cc5856c4328ece4753988d86d461d969aa Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 7 Jul 2024 23:08:08 +0200 Subject: [PATCH 07/48] Remove 'r' --- examples/gallery/3d_plots/dataset_on_surface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/3d_plots/dataset_on_surface.py b/examples/gallery/3d_plots/dataset_on_surface.py index cd1a7f8422a..51dd162d7d0 100755 --- a/examples/gallery/3d_plots/dataset_on_surface.py +++ b/examples/gallery/3d_plots/dataset_on_surface.py @@ -1,4 +1,4 @@ -r""" +""" Draping a data set on top of a topographic surface ================================================== From 7799c8d3fda429cde4aaafe46fcc7c7bb6a0a039 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 7 Jul 2024 23:11:53 +0200 Subject: [PATCH 08/48] TEST: Modifiy exisiting example --- examples/gallery/3d_plots/scatter3d.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/3d_plots/scatter3d.py b/examples/gallery/3d_plots/scatter3d.py index 0f6a6d1609c..321952dc415 100644 --- a/examples/gallery/3d_plots/scatter3d.py +++ b/examples/gallery/3d_plots/scatter3d.py @@ -11,7 +11,7 @@ using :func:`pygmt.info`. To plot the z-axis frame, set ``frame`` as a minimum to something like ``frame=["WsNeZ", "zaf"]``. Use ``perspective`` to control the azimuth and elevation angle of the view, and ``zscale`` to adjust -the vertical exaggeration factor. +the vertical exaggeration factor . """ # %% From bee912583a7904d82653b12331da278d44bdea2c Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 7 Jul 2024 23:13:29 +0200 Subject: [PATCH 09/48] TEST: Redo change --- examples/gallery/3d_plots/scatter3d.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/3d_plots/scatter3d.py b/examples/gallery/3d_plots/scatter3d.py index 321952dc415..0f6a6d1609c 100644 --- a/examples/gallery/3d_plots/scatter3d.py +++ b/examples/gallery/3d_plots/scatter3d.py @@ -11,7 +11,7 @@ using :func:`pygmt.info`. To plot the z-axis frame, set ``frame`` as a minimum to something like ``frame=["WsNeZ", "zaf"]``. Use ``perspective`` to control the azimuth and elevation angle of the view, and ``zscale`` to adjust -the vertical exaggeration factor . +the vertical exaggeration factor. """ # %% From ea05d25a9f42c0891fb253b4c4a6627ba81b4c23 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 7 Jul 2024 23:27:00 +0200 Subject: [PATCH 10/48] Remove execution permission --- examples/gallery/3d_plots/dataset_on_surface.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 examples/gallery/3d_plots/dataset_on_surface.py diff --git a/examples/gallery/3d_plots/dataset_on_surface.py b/examples/gallery/3d_plots/dataset_on_surface.py old mode 100755 new mode 100644 From 02691278db413a29084be0cdda224854a265bcf6 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 28 Jul 2024 22:08:38 +0200 Subject: [PATCH 11/48] Use rasterio and xarray to load PNG image --- .../gallery/3d_plots/dataset_on_surface.py | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) mode change 100644 => 100755 examples/gallery/3d_plots/dataset_on_surface.py diff --git a/examples/gallery/3d_plots/dataset_on_surface.py b/examples/gallery/3d_plots/dataset_on_surface.py old mode 100644 new mode 100755 index 51dd162d7d0..36dfab573cb --- a/examples/gallery/3d_plots/dataset_on_surface.py +++ b/examples/gallery/3d_plots/dataset_on_surface.py @@ -15,19 +15,12 @@ For the sake of simplicity the image grid is already stored as netCDF file *@euflag.nc* in the GMT directory. -.. note:: - - The PNG file of the flag of Europe can be downloaded from the internet - (http://upload.wikimedia.org/wikipedia/commons/thumb/b/b7/Flag_of_Europe.svg/1000px-Flag_of_Europe.svg.png) - and converted via *grdconvert* using GDAL support. The dimension - (1000 x 667 pixels) of the image is taken into account for a ratio of 3 x 2. - To add the correct grid region, *grdedit* is used. As *grdconvert* and - *grdedit* are not available in PyGMT yet, please see the GMT example - mentioned above for details. """ # %% import pygmt +import rasterio +import xarray as xr # %% # Grid of seafloor crustal age on top of topographic map of Mid-Atlantic Ridge @@ -98,6 +91,15 @@ # arc-seconds and pixel registration and load it into a xarray.DataArray grd_relief = pygmt.datasets.load_earth_relief(resolution="30s", region=region_2d) +# Download a image of the flage of Europe using rasterio and load it into a +# xarray.DataArray +url_to_image = "https://upload.wikimedia.org/wikipedia/commons/thumb/b/b7/Flag_of_Europe.svg/1000px-Flag_of_Europe.svg.png" +# url_to_image = "https://upload.wikimedia.org/wikipedia/commons/thumb/b/ba/Flag_of_Germany.svg/1024px-Flag_of_Germany.svg.png" +with rasterio.open(url_to_image) as dataset: + data = dataset.read() + drapegrid = xr.DataArray(data, dims=("band", "y", "x")) + +#%% # Set up a colormap with two colors for the EU flag: blue (0/51/153) for the # background (value 0 in the nedCDF file -> lower half of 0-255 range) and # yellow (255/204/0) for the stars (value 255 -> upper half) @@ -107,7 +109,7 @@ projection="M12c", # Mercator projection with a width of 12 centimeters region=region_3d, grid=grd_relief, # Use elevation grid for z values - drapegrid="@euflag.nc", # Drap image grid for the EU flag on top + drapegrid=drapegrid, # Drap image grid for the EU flag on top cmap=True, # Use colormap defined for the EU flag surftype="i", # Create an image plot # Use an illumination from the azimuthal directions 0° (north) and 270° From 1d18eea83bbb601b96bb33bb297c96f7960f0f81 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 28 Jul 2024 22:30:25 +0200 Subject: [PATCH 12/48] Remove execute permission --- examples/gallery/3d_plots/dataset_on_surface.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) mode change 100755 => 100644 examples/gallery/3d_plots/dataset_on_surface.py diff --git a/examples/gallery/3d_plots/dataset_on_surface.py b/examples/gallery/3d_plots/dataset_on_surface.py old mode 100755 new mode 100644 index 36dfab573cb..8f3138b2f23 --- a/examples/gallery/3d_plots/dataset_on_surface.py +++ b/examples/gallery/3d_plots/dataset_on_surface.py @@ -94,12 +94,10 @@ # Download a image of the flage of Europe using rasterio and load it into a # xarray.DataArray url_to_image = "https://upload.wikimedia.org/wikipedia/commons/thumb/b/b7/Flag_of_Europe.svg/1000px-Flag_of_Europe.svg.png" -# url_to_image = "https://upload.wikimedia.org/wikipedia/commons/thumb/b/ba/Flag_of_Germany.svg/1024px-Flag_of_Germany.svg.png" with rasterio.open(url_to_image) as dataset: data = dataset.read() drapegrid = xr.DataArray(data, dims=("band", "y", "x")) -#%% # Set up a colormap with two colors for the EU flag: blue (0/51/153) for the # background (value 0 in the nedCDF file -> lower half of 0-255 range) and # yellow (255/204/0) for the stars (value 255 -> upper half) @@ -158,4 +156,4 @@ # Show figure fig.show() -# sphinx_gallery_thumbnail_number = 1 +# sphinx_gallery_thumbnail_number = 2 From 520e2407807e4f9319dcf629e0de1d09014a8e22 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Mon, 29 Jul 2024 15:51:23 +0200 Subject: [PATCH 13/48] Move to tutoria advanced folder --- .../3d_plots => tutorials/advanced}/dataset_on_surface.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/{gallery/3d_plots => tutorials/advanced}/dataset_on_surface.py (100%) mode change 100644 => 100755 diff --git a/examples/gallery/3d_plots/dataset_on_surface.py b/examples/tutorials/advanced/dataset_on_surface.py old mode 100644 new mode 100755 similarity index 100% rename from examples/gallery/3d_plots/dataset_on_surface.py rename to examples/tutorials/advanced/dataset_on_surface.py From 3ce58e1a12cb763beb414a0046910a03ba79418d Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Mon, 29 Jul 2024 15:58:03 +0200 Subject: [PATCH 14/48] Restructure for tutorial --- .../tutorials/advanced/dataset_on_surface.py | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/examples/tutorials/advanced/dataset_on_surface.py b/examples/tutorials/advanced/dataset_on_surface.py index 8f3138b2f23..95f4b30d8b6 100755 --- a/examples/tutorials/advanced/dataset_on_surface.py +++ b/examples/tutorials/advanced/dataset_on_surface.py @@ -2,19 +2,13 @@ Draping a data set on top of a topographic surface ================================================== -It can be visually appealing to "drape" a data set (grid or image) over a -topographic surface. This can be accomplished using the ``drapegrid`` parameter -of :meth:`pygmt.Figure.grdview`. - -In the first example, the seafloor crustal age is plotted with color-coding -on top of the topographic map of an area of the Mid-Atlantic Ridge. - -In the second example, the flag of Europe is plotted on top of a topographic -map of northwest Europe. This example is modified from GMT example 32 available -at https://docs.generic-mapping-tools.org/latest/gallery/ex32.html#example-32. -For the sake of simplicity the image grid is already stored as netCDF file -*@euflag.nc* in the GMT directory. +It can be visually appealing to "drape" a data set over a topographic surface. +This can be accomplished using the ``drapegrid`` parameter of +:meth:`pygmt.Figure.grdview`. +This tutorial consists of two examples: +- (I) Draping a grid +- (II) Draping an image """ # %% @@ -23,8 +17,11 @@ import xarray as xr # %% -# Grid of seafloor crustal age on top of topographic map of Mid-Atlantic Ridge -# ----------------------------------------------------------------------------- +# (I) Drapping a grid +# ------------------- +# +# In the first example, the seafloor crustal age is plotted with color-coding +# on top of the topographic map of an area of the Mid-Atlantic Ridge. # Define study area region_2d = [-50, 0, 36, 70] # [lon_min, lon_max, lat_min, lat_max] @@ -70,8 +67,12 @@ # %% -# Image of the flag of Europe on top of topographic map of northwest Europe -# ------------------------------------------------------------------------- +# (II) Draping an image +# --------------------- +# +# In the second example, the flag of Europe is plotted on top of a topographic +# map of northwest Europe. This example is modified from GMT example 32 available +# at https://docs.generic-mapping-tools.org/latest/gallery/ex32.html#example-32. # Define study area region_2d = [3, 9, 50, 54] # [lon_min, lon_max, lat_min, lat_max] From a3b5a9ebc50a5260058700da2cc6f45090500266 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Mon, 29 Jul 2024 15:59:14 +0200 Subject: [PATCH 15/48] Remove execution permission --- examples/tutorials/advanced/dataset_on_surface.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 examples/tutorials/advanced/dataset_on_surface.py diff --git a/examples/tutorials/advanced/dataset_on_surface.py b/examples/tutorials/advanced/dataset_on_surface.py old mode 100755 new mode 100644 From 77d9698e7e19e3a43a4da1eec4dae20a30b4c615 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Mon, 29 Jul 2024 17:31:07 +0200 Subject: [PATCH 16/48] Fix bullet point list --- .../tutorials/advanced/dataset_on_surface.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/examples/tutorials/advanced/dataset_on_surface.py b/examples/tutorials/advanced/dataset_on_surface.py index 95f4b30d8b6..4a1d44d2066 100644 --- a/examples/tutorials/advanced/dataset_on_surface.py +++ b/examples/tutorials/advanced/dataset_on_surface.py @@ -7,18 +7,23 @@ :meth:`pygmt.Figure.grdview`. This tutorial consists of two examples: -- (I) Draping a grid -- (II) Draping an image + +1. Draping a grid + +2. Draping an image """ # %% + +# Load the required packages import pygmt import rasterio import xarray as xr + # %% -# (I) Drapping a grid -# ------------------- +# 1. Drapping a grid +# ------------------ # # In the first example, the seafloor crustal age is plotted with color-coding # on top of the topographic map of an area of the Mid-Atlantic Ridge. @@ -67,8 +72,8 @@ # %% -# (II) Draping an image -# --------------------- +# 2. Draping an image +# ------------------- # # In the second example, the flag of Europe is plotted on top of a topographic # map of northwest Europe. This example is modified from GMT example 32 available From fc2587369b7c08f75ba5ec0816888eeb199842fb Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Mon, 29 Jul 2024 17:34:07 +0200 Subject: [PATCH 17/48] Remove blank line --- examples/tutorials/advanced/dataset_on_surface.py | 1 - 1 file changed, 1 deletion(-) mode change 100644 => 100755 examples/tutorials/advanced/dataset_on_surface.py diff --git a/examples/tutorials/advanced/dataset_on_surface.py b/examples/tutorials/advanced/dataset_on_surface.py old mode 100644 new mode 100755 index 4a1d44d2066..e3f7f873918 --- a/examples/tutorials/advanced/dataset_on_surface.py +++ b/examples/tutorials/advanced/dataset_on_surface.py @@ -20,7 +20,6 @@ import rasterio import xarray as xr - # %% # 1. Drapping a grid # ------------------ From 9cf465aaab8b38ae2f8fc4ddf5386040cc7fc63d Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Mon, 29 Jul 2024 17:35:38 +0200 Subject: [PATCH 18/48] Remove execution permission --- examples/tutorials/advanced/dataset_on_surface.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 examples/tutorials/advanced/dataset_on_surface.py diff --git a/examples/tutorials/advanced/dataset_on_surface.py b/examples/tutorials/advanced/dataset_on_surface.py old mode 100755 new mode 100644 From 9c14e587ff33e043903a068f8b9d2d5eeb468038 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= <94163266+yvonnefroehlich@users.noreply.github.com> Date: Sun, 4 Aug 2024 14:51:31 +0200 Subject: [PATCH 19/48] Remove seperation lines Co-authored-by: Dongdong Tian --- examples/tutorials/advanced/dataset_on_surface.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/tutorials/advanced/dataset_on_surface.py b/examples/tutorials/advanced/dataset_on_surface.py index e3f7f873918..a81d101a7e9 100644 --- a/examples/tutorials/advanced/dataset_on_surface.py +++ b/examples/tutorials/advanced/dataset_on_surface.py @@ -32,7 +32,6 @@ region_3d = [*region_2d, -5961, 3366.5] # Append [z_min, z_max] to this list perspective = [157.5, 30] # Define azimuth, elevation for the 3-D plot -# ----------------------------------------------------------------------------- # Create new Figure instance fig = pygmt.Figure() @@ -62,7 +61,6 @@ frame=True, ) -# ----------------------------------------------------------------------------- # Add colorbar for curstal age fig.colorbar(frame=["x+lseafloor crustal age", "y+lMyr"], position="+n") From 3e4b55a30c403cea8e0b7c82491ce9eb700811dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= <94163266+yvonnefroehlich@users.noreply.github.com> Date: Sun, 4 Aug 2024 14:52:54 +0200 Subject: [PATCH 20/48] Set link to gmt documentation Co-authored-by: Dongdong Tian --- examples/tutorials/advanced/dataset_on_surface.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/tutorials/advanced/dataset_on_surface.py b/examples/tutorials/advanced/dataset_on_surface.py index a81d101a7e9..cb8b2c534f2 100644 --- a/examples/tutorials/advanced/dataset_on_surface.py +++ b/examples/tutorials/advanced/dataset_on_surface.py @@ -73,8 +73,8 @@ # ------------------- # # In the second example, the flag of Europe is plotted on top of a topographic -# map of northwest Europe. This example is modified from GMT example 32 available -# at https://docs.generic-mapping-tools.org/latest/gallery/ex32.html#example-32. +# map of northwest Europe. This example is modified from +# :gmt-docs:`GMT example 32 `_. # Define study area region_2d = [3, 9, 50, 54] # [lon_min, lon_max, lat_min, lat_max] From e960cf2d96443908c95d863e656bd4c9604ac571 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= <94163266+yvonnefroehlich@users.noreply.github.com> Date: Sun, 4 Aug 2024 14:53:49 +0200 Subject: [PATCH 21/48] Remove variables as only once used in grid examples Co-authored-by: Dongdong Tian --- examples/tutorials/advanced/dataset_on_surface.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/tutorials/advanced/dataset_on_surface.py b/examples/tutorials/advanced/dataset_on_surface.py index cb8b2c534f2..bd3ebe48188 100644 --- a/examples/tutorials/advanced/dataset_on_surface.py +++ b/examples/tutorials/advanced/dataset_on_surface.py @@ -29,8 +29,6 @@ # Define study area region_2d = [-50, 0, 36, 70] # [lon_min, lon_max, lat_min, lat_max] -region_3d = [*region_2d, -5961, 3366.5] # Append [z_min, z_max] to this list -perspective = [157.5, 30] # Define azimuth, elevation for the 3-D plot # Create new Figure instance fig = pygmt.Figure() From 017f320c302c7eacdc556f84e22a3ca055092e5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= <94163266+yvonnefroehlich@users.noreply.github.com> Date: Sun, 4 Aug 2024 14:55:16 +0200 Subject: [PATCH 22/48] Pass argument directly to 'perspective' parameter for grid example Co-authored-by: Dongdong Tian --- examples/tutorials/advanced/dataset_on_surface.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/tutorials/advanced/dataset_on_surface.py b/examples/tutorials/advanced/dataset_on_surface.py index bd3ebe48188..b124c41bca6 100644 --- a/examples/tutorials/advanced/dataset_on_surface.py +++ b/examples/tutorials/advanced/dataset_on_surface.py @@ -53,7 +53,8 @@ # (west) with a normalization via a cumulative Laplace distribution for # the shading shading="+a0/270+ne0.6", - perspective=perspective, + perspective=[157.5, 30], # Azimuth and elevation for the 3-D plot + zsize="1.5c", plane="+gdarkgray", frame=True, From f0c114bfa54a7f2221704d92f67296b83f4e73e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= <94163266+yvonnefroehlich@users.noreply.github.com> Date: Sun, 4 Aug 2024 14:56:17 +0200 Subject: [PATCH 23/48] Determine z values from relief grid min max value Co-authored-by: Dongdong Tian --- examples/tutorials/advanced/dataset_on_surface.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/tutorials/advanced/dataset_on_surface.py b/examples/tutorials/advanced/dataset_on_surface.py index b124c41bca6..f7333abe768 100644 --- a/examples/tutorials/advanced/dataset_on_surface.py +++ b/examples/tutorials/advanced/dataset_on_surface.py @@ -42,6 +42,8 @@ pygmt.config(COLOR_NAN="lightgray") pygmt.makecpt(cmap="batlow", series=[0, 200, 1], reverse=True, overrule_bg=True) +# Determine the 3D region parameter from relief grid min/max values +region_3d = [*region_2d, grd_relief.min().values, grd_relief.max().values] fig.grdview( projection="M12c", # Mercator projection with a width of 12 centimeters region=region_3d, From 588c07b11e7bfd91e45b10b91e8d3ba61d7aef50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= <94163266+yvonnefroehlich@users.noreply.github.com> Date: Sun, 4 Aug 2024 15:27:25 +0200 Subject: [PATCH 24/48] Use more clearer comment for 'series' parameter Co-authored-by: Dongdong Tian --- examples/tutorials/advanced/dataset_on_surface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tutorials/advanced/dataset_on_surface.py b/examples/tutorials/advanced/dataset_on_surface.py index f7333abe768..baeefbd9065 100644 --- a/examples/tutorials/advanced/dataset_on_surface.py +++ b/examples/tutorials/advanced/dataset_on_surface.py @@ -105,7 +105,7 @@ # Set up a colormap with two colors for the EU flag: blue (0/51/153) for the # background (value 0 in the nedCDF file -> lower half of 0-255 range) and # yellow (255/204/0) for the stars (value 255 -> upper half) -pygmt.makecpt(cmap="0/51/153,255/204/0", series=[0, 256, 128]) # [min, max[, step +pygmt.makecpt(cmap="0/51/153,255/204/0", series=[0, 256, 128]) # [min, max, step] fig.grdview( projection="M12c", # Mercator projection with a width of 12 centimeters From 07dd23c57101fb18425c90a79e81212c1a360ab7 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 4 Aug 2024 15:30:05 +0200 Subject: [PATCH 25/48] Reduce resolution --- examples/tutorials/advanced/dataset_on_surface.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) mode change 100644 => 100755 examples/tutorials/advanced/dataset_on_surface.py diff --git a/examples/tutorials/advanced/dataset_on_surface.py b/examples/tutorials/advanced/dataset_on_surface.py old mode 100644 new mode 100755 index baeefbd9065..2e2ff9a324a --- a/examples/tutorials/advanced/dataset_on_surface.py +++ b/examples/tutorials/advanced/dataset_on_surface.py @@ -35,8 +35,8 @@ # Download elevation and crustal age grids for the study region with a # resolution of 3 arc-minutes and load them into xarray.DataArrays -grd_relief = pygmt.datasets.load_earth_relief(resolution="03m", region=region_2d) -grd_age = pygmt.datasets.load_earth_age(resolution="03m", region=region_2d) +grd_relief = pygmt.datasets.load_earth_relief(resolution="10m", region=region_2d) +grd_age = pygmt.datasets.load_earth_age(resolution="10m", region=region_2d) # Set up colormap for curstal age pygmt.config(COLOR_NAN="lightgray") @@ -74,7 +74,7 @@ # ------------------- # # In the second example, the flag of Europe is plotted on top of a topographic -# map of northwest Europe. This example is modified from +# map of northwest Europe. This example is modified from # :gmt-docs:`GMT example 32 `_. # Define study area From 9976c5b3297293420b4cc26cf63ccd80c856bab2 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 4 Aug 2024 15:37:56 +0200 Subject: [PATCH 26/48] Use pandas DataFrame for cities --- .../tutorials/advanced/dataset_on_surface.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/examples/tutorials/advanced/dataset_on_surface.py b/examples/tutorials/advanced/dataset_on_surface.py index 2e2ff9a324a..bf1f7e33390 100755 --- a/examples/tutorials/advanced/dataset_on_surface.py +++ b/examples/tutorials/advanced/dataset_on_surface.py @@ -17,6 +17,7 @@ # Load the required packages import pygmt +import pandas as pd import rasterio import xarray as xr @@ -83,9 +84,11 @@ perspective = [157.5, 30] # Define azimuth, elevation for the 3-D plot # Coordinates and names of cities -lons_cities = [7.10, 4.35, 5.69] # degrees East -lats_cities = [50.73, 50.85, 50.85] # degrees North -text_cities = ["Bonn", "Bruxelles", "Maastricht"] +cities = pd.DataFrame({ + "longitude": [7.10, 4.35, 5.69], + "latitude": [50.73, 50.85, 50.85], + "name": ["Bonn", "Bruxelles", "Maastricht"] +}) # ----------------------------------------------------------------------------- # Create new Figure instance @@ -137,8 +140,8 @@ # Mark cities # Plot markers fig.plot( - x=lons_cities, - y=lats_cities, + x=cities.longitude, + y=cities.latitutde, style="s0.3c", # Use squares with a size of 0.3 centimeters pen="1.5p,white", fill="black", @@ -146,9 +149,9 @@ ) # Add labels fig.text( - x=lons_cities, - y=lats_cities, - text=text_cities, + 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", From 9e6839033ba3bb55c4495e631bf5dcba01021fd9 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 4 Aug 2024 15:48:49 +0200 Subject: [PATCH 27/48] Fix code style for DataFrame --- examples/tutorials/advanced/dataset_on_surface.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/examples/tutorials/advanced/dataset_on_surface.py b/examples/tutorials/advanced/dataset_on_surface.py index bf1f7e33390..adaf5b1793a 100755 --- a/examples/tutorials/advanced/dataset_on_surface.py +++ b/examples/tutorials/advanced/dataset_on_surface.py @@ -16,8 +16,8 @@ # %% # Load the required packages -import pygmt import pandas as pd +import pygmt import rasterio import xarray as xr @@ -57,7 +57,6 @@ # the shading shading="+a0/270+ne0.6", perspective=[157.5, 30], # Azimuth and elevation for the 3-D plot - zsize="1.5c", plane="+gdarkgray", frame=True, @@ -84,11 +83,13 @@ perspective = [157.5, 30] # Define azimuth, elevation for the 3-D plot # Coordinates and names of cities -cities = pd.DataFrame({ - "longitude": [7.10, 4.35, 5.69], - "latitude": [50.73, 50.85, 50.85], - "name": ["Bonn", "Bruxelles", "Maastricht"] -}) +cities = pd.DataFrame( + { + "longitude": [7.10, 4.35, 5.69], + "latitude": [50.73, 50.85, 50.85], + "name": ["Bonn", "Bruxelles", "Maastricht"], + } +) # ----------------------------------------------------------------------------- # Create new Figure instance From c59af7a871479d2442c14c8be9f8d099beb2420c Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 4 Aug 2024 15:54:14 +0200 Subject: [PATCH 28/48] Fix code style 'values' to 'to_numpy' --- examples/tutorials/advanced/dataset_on_surface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tutorials/advanced/dataset_on_surface.py b/examples/tutorials/advanced/dataset_on_surface.py index adaf5b1793a..f132f140c1e 100755 --- a/examples/tutorials/advanced/dataset_on_surface.py +++ b/examples/tutorials/advanced/dataset_on_surface.py @@ -44,7 +44,7 @@ pygmt.makecpt(cmap="batlow", series=[0, 200, 1], reverse=True, overrule_bg=True) # Determine the 3D region parameter from relief grid min/max values -region_3d = [*region_2d, grd_relief.min().values, grd_relief.max().values] +region_3d = [*region_2d, grd_relief.min().to_numpy(), grd_relief.max().to_numpy()] fig.grdview( projection="M12c", # Mercator projection with a width of 12 centimeters region=region_3d, From 56eea5662171aa1bb1b0663f0a614808e8edad0b Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 4 Aug 2024 15:55:23 +0200 Subject: [PATCH 29/48] Fix typo in code --- examples/tutorials/advanced/dataset_on_surface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tutorials/advanced/dataset_on_surface.py b/examples/tutorials/advanced/dataset_on_surface.py index f132f140c1e..5c3c876e220 100755 --- a/examples/tutorials/advanced/dataset_on_surface.py +++ b/examples/tutorials/advanced/dataset_on_surface.py @@ -142,7 +142,7 @@ # Plot markers fig.plot( x=cities.longitude, - y=cities.latitutde, + y=cities.latitude, style="s0.3c", # Use squares with a size of 0.3 centimeters pen="1.5p,white", fill="black", From e88daedc228d50b40c894af7f34ae2ce1f0c16a3 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 4 Aug 2024 15:58:44 +0200 Subject: [PATCH 30/48] Remove execution permission --- examples/tutorials/advanced/dataset_on_surface.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 examples/tutorials/advanced/dataset_on_surface.py diff --git a/examples/tutorials/advanced/dataset_on_surface.py b/examples/tutorials/advanced/dataset_on_surface.py old mode 100755 new mode 100644 From 7441a9400a78aedeafd563a559217c9bfec3bc2d Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 4 Aug 2024 18:50:32 +0200 Subject: [PATCH 31/48] Fix typos --- examples/tutorials/advanced/dataset_on_surface.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/tutorials/advanced/dataset_on_surface.py b/examples/tutorials/advanced/dataset_on_surface.py index 5c3c876e220..93d30abf301 100644 --- a/examples/tutorials/advanced/dataset_on_surface.py +++ b/examples/tutorials/advanced/dataset_on_surface.py @@ -1,8 +1,8 @@ """ -Draping a data set on top of a topographic surface +Draping a dataset on top of a topographic surface ================================================== -It can be visually appealing to "drape" a data set over a topographic surface. +It can be visually appealing to "drape" a dataset over a topographic surface. This can be accomplished using the ``drapegrid`` parameter of :meth:`pygmt.Figure.grdview`. @@ -43,7 +43,7 @@ pygmt.config(COLOR_NAN="lightgray") pygmt.makecpt(cmap="batlow", series=[0, 200, 1], reverse=True, overrule_bg=True) -# Determine the 3D region parameter from relief grid min/max values +# Determine the 3-D region parameter from the relief grid min/max values region_3d = [*region_2d, grd_relief.min().to_numpy(), grd_relief.max().to_numpy()] fig.grdview( projection="M12c", # Mercator projection with a width of 12 centimeters From 965a29e97466585864280776e00ef0c9721f5599 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Mon, 5 Aug 2024 16:19:40 +0200 Subject: [PATCH 32/48] Improve comments | Subsection for tutorial --- .../tutorials/advanced/dataset_on_surface.py | 54 ++++++++++--------- 1 file changed, 30 insertions(+), 24 deletions(-) mode change 100644 => 100755 examples/tutorials/advanced/dataset_on_surface.py diff --git a/examples/tutorials/advanced/dataset_on_surface.py b/examples/tutorials/advanced/dataset_on_surface.py old mode 100644 new mode 100755 index 93d30abf301..c07b7c7f082 --- a/examples/tutorials/advanced/dataset_on_surface.py +++ b/examples/tutorials/advanced/dataset_on_surface.py @@ -29,22 +29,25 @@ # on top of the topographic map of an area of the Mid-Atlantic Ridge. # Define study area -region_2d = [-50, 0, 36, 70] # [lon_min, lon_max, lat_min, lat_max] - -# Create new Figure instance -fig = pygmt.Figure() +region_2d = [-50, 0, 36, 70] # Download elevation and crustal age grids for the study region with a -# resolution of 3 arc-minutes and load them into xarray.DataArrays +# resolution of 10 arc-minutes and load them into xarray.DataArrays grd_relief = pygmt.datasets.load_earth_relief(resolution="10m", region=region_2d) grd_age = pygmt.datasets.load_earth_age(resolution="10m", region=region_2d) +# Determine the 3-D region from the minimum and maxiumum values of the relief grid +region_3d = [*region_2d, grd_relief.min().to_numpy(), grd_relief.max().to_numpy()] + +# %% +# TODO + +fig = pygmt.Figure() + # Set up colormap for curstal age pygmt.config(COLOR_NAN="lightgray") pygmt.makecpt(cmap="batlow", series=[0, 200, 1], reverse=True, overrule_bg=True) -# Determine the 3-D region parameter from the relief grid min/max values -region_3d = [*region_2d, grd_relief.min().to_numpy(), grd_relief.max().to_numpy()] fig.grdview( projection="M12c", # Mercator projection with a width of 12 centimeters region=region_3d, @@ -78,11 +81,9 @@ # :gmt-docs:`GMT example 32 `_. # Define study area -region_2d = [3, 9, 50, 54] # [lon_min, lon_max, lat_min, lat_max] -region_3d = [*region_2d, -10, 900] # Append [z_min, z_max] to this list -perspective = [157.5, 30] # Define azimuth, elevation for the 3-D plot +region_2d = [3, 9, 50, 54] -# Coordinates and names of cities +# Set up a pandas DataFrame with coordinates and names of three cities cities = pd.DataFrame( { "longitude": [7.10, 4.35, 5.69], @@ -91,25 +92,29 @@ } ) -# ----------------------------------------------------------------------------- -# Create new Figure instance -fig = pygmt.Figure() - # Download elevation grid for the study region with a resolution of 30 # arc-seconds and pixel registration and load it into a xarray.DataArray grd_relief = pygmt.datasets.load_earth_relief(resolution="30s", region=region_2d) -# Download a image of the flage of Europe using rasterio and load it into a +# Determine the 3-D region from the minimum and maxiumum values of the relief grid +region_3d = [*region_2d, grd_relief.min().to_numpy(), grd_relief.max().to_numpy()] + +# Download an image of the flage of Europe using rasterio and load it into a # xarray.DataArray url_to_image = "https://upload.wikimedia.org/wikipedia/commons/thumb/b/b7/Flag_of_Europe.svg/1000px-Flag_of_Europe.svg.png" with rasterio.open(url_to_image) as dataset: data = dataset.read() drapegrid = xr.DataArray(data, dims=("band", "y", "x")) +# %% +# TODO + +fig = pygmt.Figure() + # Set up a colormap with two colors for the EU flag: blue (0/51/153) for the # background (value 0 in the nedCDF file -> lower half of 0-255 range) and # yellow (255/204/0) for the stars (value 255 -> upper half) -pygmt.makecpt(cmap="0/51/153,255/204/0", series=[0, 256, 128]) # [min, max, step] +pygmt.makecpt(cmap="0/51/153,255/204/0", series=[0, 256, 128]) fig.grdview( projection="M12c", # Mercator projection with a width of 12 centimeters @@ -122,22 +127,24 @@ # (west) with a normalization via a cumulative Laplace distribution for # the shading shading="+a0/270+ne0.6", - perspective=perspective, + perspective=[157.5, 30], # Define azimuth, elevation for the 3-D plot zsize="1c", plane="+glightgray", frame=True, ) -# ----------------------------------------------------------------------------- +# %% +# We can plot some features, including coastlines, symbols, and text on top +# of the map. + # Plot water, broders, and shorelines on top fig.coast( water="white@50", borders="1/1p,lightgray", shorelines="1/0.5p,gray30", - perspective=perspective, + perspective=True, ) -# ----------------------------------------------------------------------------- # Mark cities # Plot markers fig.plot( @@ -146,7 +153,7 @@ style="s0.3c", # Use squares with a size of 0.3 centimeters pen="1.5p,white", fill="black", - perspective=perspective, + perspective=True, ) # Add labels fig.text( @@ -157,10 +164,9 @@ 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=perspective, + perspective=True, ) -# ----------------------------------------------------------------------------- # Show figure fig.show() From aafda1ae18f1f678e2d94ff67ad5e03a1650bade Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Mon, 5 Aug 2024 16:23:02 +0200 Subject: [PATCH 33/48] Fix typos --- examples/tutorials/advanced/dataset_on_surface.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/tutorials/advanced/dataset_on_surface.py b/examples/tutorials/advanced/dataset_on_surface.py index c07b7c7f082..d96f507e4d0 100755 --- a/examples/tutorials/advanced/dataset_on_surface.py +++ b/examples/tutorials/advanced/dataset_on_surface.py @@ -36,7 +36,7 @@ grd_relief = pygmt.datasets.load_earth_relief(resolution="10m", region=region_2d) grd_age = pygmt.datasets.load_earth_age(resolution="10m", region=region_2d) -# Determine the 3-D region from the minimum and maxiumum values of the relief grid +# Determine the 3-D region from the minimum and maximum values of the relief grid region_3d = [*region_2d, grd_relief.min().to_numpy(), grd_relief.max().to_numpy()] # %% @@ -96,10 +96,10 @@ # arc-seconds and pixel registration and load it into a xarray.DataArray grd_relief = pygmt.datasets.load_earth_relief(resolution="30s", region=region_2d) -# Determine the 3-D region from the minimum and maxiumum values of the relief grid +# Determine the 3-D region from the minimum and maximum values of the relief grid region_3d = [*region_2d, grd_relief.min().to_numpy(), grd_relief.max().to_numpy()] -# Download an image of the flage of Europe using rasterio and load it into a +# Download an image of the flag of Europe using rasterio and load it into a # xarray.DataArray url_to_image = "https://upload.wikimedia.org/wikipedia/commons/thumb/b/b7/Flag_of_Europe.svg/1000px-Flag_of_Europe.svg.png" with rasterio.open(url_to_image) as dataset: From 8e48b87af1d8b9d1bec7e85f77660773e7adbcdb Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Mon, 5 Aug 2024 16:24:45 +0200 Subject: [PATCH 34/48] Fix link to GMT documentation --- examples/tutorials/advanced/dataset_on_surface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tutorials/advanced/dataset_on_surface.py b/examples/tutorials/advanced/dataset_on_surface.py index d96f507e4d0..0d23bd76d5e 100755 --- a/examples/tutorials/advanced/dataset_on_surface.py +++ b/examples/tutorials/advanced/dataset_on_surface.py @@ -78,7 +78,7 @@ # # In the second example, the flag of Europe is plotted on top of a topographic # map of northwest Europe. This example is modified from -# :gmt-docs:`GMT example 32 `_. +# :gmt-docs:`GMT example 32 `. # Define study area region_2d = [3, 9, 50, 54] From 3e5959ed4c87bcb915e17a6356a4fb69c6908a84 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Mon, 5 Aug 2024 16:26:18 +0200 Subject: [PATCH 35/48] Remove execution permission --- examples/tutorials/advanced/dataset_on_surface.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 examples/tutorials/advanced/dataset_on_surface.py diff --git a/examples/tutorials/advanced/dataset_on_surface.py b/examples/tutorials/advanced/dataset_on_surface.py old mode 100755 new mode 100644 From 194b7bccdd72e53853135155b063a36feca90ef7 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Mon, 5 Aug 2024 19:40:47 +0200 Subject: [PATCH 36/48] Add explanations --- .../tutorials/advanced/dataset_on_surface.py | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) mode change 100644 => 100755 examples/tutorials/advanced/dataset_on_surface.py diff --git a/examples/tutorials/advanced/dataset_on_surface.py b/examples/tutorials/advanced/dataset_on_surface.py old mode 100644 new mode 100755 index 0d23bd76d5e..34c4e639a37 --- a/examples/tutorials/advanced/dataset_on_surface.py +++ b/examples/tutorials/advanced/dataset_on_surface.py @@ -28,8 +28,8 @@ # In the first example, the seafloor crustal age is plotted with color-coding # on top of the topographic map of an area of the Mid-Atlantic Ridge. -# Define study area -region_2d = [-50, 0, 36, 70] +# Define study area in degrees East or North +region_2d = [-50, 0, 36, 70] # [lon_min, lon_max, lat_min, lat_max] # Download elevation and crustal age grids for the study region with a # resolution of 10 arc-minutes and load them into xarray.DataArrays @@ -40,11 +40,17 @@ region_3d = [*region_2d, grd_relief.min().to_numpy(), grd_relief.max().to_numpy()] # %% -# TODO +# The topographic surface is created based on the grid passed to the ``grid`` +# parameter of :meth:`pygmt.Figure.grdview`; here we use a grid of the Earth relief. +# To add a color-coding based on *another* grid we have to pass a second grid to +# the ``drapegrid`` parameter; here we use a grid of the crustal age. In this case +# the colormap specified via the ``cmap`` parameter applies to the grid passed to +# ``drapegrid``, not to ``grid``. The azimuth and elevation a the 3-D plot are set +# via the ``perspective`` parameter. fig = pygmt.Figure() -# Set up colormap for curstal age +# Set up colormap for the crustal age pygmt.config(COLOR_NAN="lightgray") pygmt.makecpt(cmap="batlow", series=[0, 200, 1], reverse=True, overrule_bg=True) @@ -53,7 +59,7 @@ region=region_3d, grid=grd_relief, # Use elevation grid for z values drapegrid=grd_age, # Use crustal age grid for color-coding - cmap=True, + cmap=True, # Use colormap created for the crustal age surftype="i", # Create an image plot # Use an illumination from the azimuthal directions 0° (north) and 270° # (west) with a normalization via a cumulative Laplace distribution for @@ -65,10 +71,9 @@ frame=True, ) -# Add colorbar for curstal age +# Add colorbar for the crustal age fig.colorbar(frame=["x+lseafloor crustal age", "y+lMyr"], position="+n") -# Show figure fig.show() @@ -76,12 +81,12 @@ # 2. Draping an image # ------------------- # -# In the second example, the flag of Europe is plotted on top of a topographic -# map of northwest Europe. This example is modified from +# In the second example, the flag of the European Union (EU) is plotted on top of +# a topographic map of northwest Europe. This example is modified from # :gmt-docs:`GMT example 32 `. -# Define study area -region_2d = [3, 9, 50, 54] +# Define study area in degrees East or North +region_2d = [3, 9, 50, 54] # [lon_min, lon_max, lat_min, lat_max] # Set up a pandas DataFrame with coordinates and names of three cities cities = pd.DataFrame( @@ -93,13 +98,13 @@ ) # Download elevation grid for the study region with a resolution of 30 -# arc-seconds and pixel registration and load it into a xarray.DataArray +# arc-seconds and pixel registration and load it into an xarray.DataArray grd_relief = pygmt.datasets.load_earth_relief(resolution="30s", region=region_2d) # Determine the 3-D region from the minimum and maximum values of the relief grid region_3d = [*region_2d, grd_relief.min().to_numpy(), grd_relief.max().to_numpy()] -# Download an image of the flag of Europe using rasterio and load it into a +# Download an image of the flag of the EU using rasterio and load it into a # xarray.DataArray url_to_image = "https://upload.wikimedia.org/wikipedia/commons/thumb/b/b7/Flag_of_Europe.svg/1000px-Flag_of_Europe.svg.png" with rasterio.open(url_to_image) as dataset: @@ -107,7 +112,9 @@ drapegrid = xr.DataArray(data, dims=("band", "y", "x")) # %% -# TODO +# Again we create a 3-D plot with :meth:`pygmt.Figure.grdview` and passe an Earth +# relief grid to the ``grid`` parameter to create the topographic surface. But now +# we pass the PNG image loaded into an xarray.DataArray to the ``drapgrid`` parameter. fig = pygmt.Figure() @@ -128,16 +135,17 @@ # the shading shading="+a0/270+ne0.6", perspective=[157.5, 30], # Define azimuth, elevation for the 3-D plot - zsize="1c", - plane="+glightgray", frame=True, ) +fig.show() + # %% -# We can plot some features, including coastlines, symbols, and text on top -# of the map. +# 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, broders, and shorelines on top +# Plot water masses, political broders, and shorelines fig.coast( water="white@50", borders="1/1p,lightgray", @@ -167,7 +175,6 @@ perspective=True, ) -# Show figure fig.show() # sphinx_gallery_thumbnail_number = 2 From 0e839304be1091698657ab8360ec12cefb44b406 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Mon, 5 Aug 2024 19:41:33 +0200 Subject: [PATCH 37/48] Remove execution permission --- examples/tutorials/advanced/dataset_on_surface.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 examples/tutorials/advanced/dataset_on_surface.py diff --git a/examples/tutorials/advanced/dataset_on_surface.py b/examples/tutorials/advanced/dataset_on_surface.py old mode 100755 new mode 100644 From cdf0e607d26d9eb1d3b03f95508687154606f71b Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Mon, 5 Aug 2024 19:44:13 +0200 Subject: [PATCH 38/48] Adjsut thumbnail image --- examples/tutorials/advanced/dataset_on_surface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tutorials/advanced/dataset_on_surface.py b/examples/tutorials/advanced/dataset_on_surface.py index 34c4e639a37..af0ee5e678f 100644 --- a/examples/tutorials/advanced/dataset_on_surface.py +++ b/examples/tutorials/advanced/dataset_on_surface.py @@ -177,4 +177,4 @@ fig.show() -# sphinx_gallery_thumbnail_number = 2 +# sphinx_gallery_thumbnail_number = 3 From 90676e9851da37984bf959dab01460578eee6099 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Mon, 5 Aug 2024 21:29:25 +0200 Subject: [PATCH 39/48] Add highlighting --- examples/tutorials/advanced/dataset_on_surface.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/tutorials/advanced/dataset_on_surface.py b/examples/tutorials/advanced/dataset_on_surface.py index af0ee5e678f..98794ddd98a 100644 --- a/examples/tutorials/advanced/dataset_on_surface.py +++ b/examples/tutorials/advanced/dataset_on_surface.py @@ -104,7 +104,7 @@ # Determine the 3-D region from the minimum and maximum values of the relief grid region_3d = [*region_2d, grd_relief.min().to_numpy(), grd_relief.max().to_numpy()] -# Download an image of the flag of the EU using rasterio and load it into a +# Download an PNG image of the flag of the EU using rasterio and load it into a # xarray.DataArray url_to_image = "https://upload.wikimedia.org/wikipedia/commons/thumb/b/b7/Flag_of_Europe.svg/1000px-Flag_of_Europe.svg.png" with rasterio.open(url_to_image) as dataset: @@ -114,7 +114,8 @@ # %% # Again we create a 3-D plot with :meth:`pygmt.Figure.grdview` and passe an Earth # relief grid to the ``grid`` parameter to create the topographic surface. But now -# we pass the PNG image loaded into an xarray.DataArray to the ``drapgrid`` parameter. +# we pass the PNG image which was loaded into an :class:`xarray.DataArray` to the +# ``drapgrid`` parameter. fig = pygmt.Figure() From b3da9994d5f4b6111b1e47c4a6cce31b782a84a0 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Mon, 5 Aug 2024 22:40:28 +0200 Subject: [PATCH 40/48] Improve file name of tutorial --- .../advanced/{dataset_on_surface.py => draping_on_3d_surface.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/tutorials/advanced/{dataset_on_surface.py => draping_on_3d_surface.py} (100%) diff --git a/examples/tutorials/advanced/dataset_on_surface.py b/examples/tutorials/advanced/draping_on_3d_surface.py similarity index 100% rename from examples/tutorials/advanced/dataset_on_surface.py rename to examples/tutorials/advanced/draping_on_3d_surface.py From 1038e8680d2adb4037a45404246e9f98de28e4e8 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Mon, 5 Aug 2024 22:53:58 +0200 Subject: [PATCH 41/48] Use complete line length of 88 characters --- .../advanced/draping_on_3d_surface.py | 60 +++++++++---------- 1 file changed, 29 insertions(+), 31 deletions(-) mode change 100644 => 100755 examples/tutorials/advanced/draping_on_3d_surface.py diff --git a/examples/tutorials/advanced/draping_on_3d_surface.py b/examples/tutorials/advanced/draping_on_3d_surface.py old mode 100644 new mode 100755 index 98794ddd98a..94a11d4d72f --- a/examples/tutorials/advanced/draping_on_3d_surface.py +++ b/examples/tutorials/advanced/draping_on_3d_surface.py @@ -2,9 +2,8 @@ Draping a dataset on top of a topographic surface ================================================== -It can be visually appealing to "drape" a dataset over a topographic surface. -This can be accomplished using the ``drapegrid`` parameter of -:meth:`pygmt.Figure.grdview`. +It can be visually appealing to "drape" a dataset over a topographic surface. This can +be accomplished using the ``drapegrid`` parameter of :meth:`pygmt.Figure.grdview`. This tutorial consists of two examples: @@ -25,14 +24,14 @@ # 1. Drapping a grid # ------------------ # -# In the first example, the seafloor crustal age is plotted with color-coding -# on top of the topographic map of an area of the Mid-Atlantic Ridge. +# In the first example, the seafloor crustal age is plotted with color-coding on top of +# the topographic map of an area of the Mid-Atlantic Ridge. # Define study area in degrees East or North region_2d = [-50, 0, 36, 70] # [lon_min, lon_max, lat_min, lat_max] -# Download elevation and crustal age grids for the study region with a -# resolution of 10 arc-minutes and load them into xarray.DataArrays +# Download elevation and crustal age grids for the study region with a resolution of 10 +# arc-minutes and load them into xarray.DataArrays grd_relief = pygmt.datasets.load_earth_relief(resolution="10m", region=region_2d) grd_age = pygmt.datasets.load_earth_age(resolution="10m", region=region_2d) @@ -40,13 +39,13 @@ region_3d = [*region_2d, grd_relief.min().to_numpy(), grd_relief.max().to_numpy()] # %% -# The topographic surface is created based on the grid passed to the ``grid`` -# parameter of :meth:`pygmt.Figure.grdview`; here we use a grid of the Earth relief. -# To add a color-coding based on *another* grid we have to pass a second grid to -# the ``drapegrid`` parameter; here we use a grid of the crustal age. In this case -# the colormap specified via the ``cmap`` parameter applies to the grid passed to -# ``drapegrid``, not to ``grid``. The azimuth and elevation a the 3-D plot are set -# via the ``perspective`` parameter. +# The topographic surface is created based on the grid passed to the ``grid`` parameter +# of :meth:`pygmt.Figure.grdview`; here we use a grid of the Earth relief. To add a +# color-coding based on *another* grid we have to pass a second grid to the +# ``drapegrid`` parameter; here we use a grid of the crustal age. In this case the +# colormap specified via the ``cmap`` parameter applies to the grid passed to +# ``drapegrid``, not to ``grid``. The azimuth and elevation a the 3-D plot are set via +# the ``perspective`` parameter. fig = pygmt.Figure() @@ -81,8 +80,8 @@ # 2. Draping an image # ------------------- # -# In the second example, the flag of the European Union (EU) is plotted on top of -# a topographic map of northwest Europe. This example is modified from +# In the second example, the flag of the European Union (EU) is plotted on top of a +# topographic map of northwest Europe. This example is modified from # :gmt-docs:`GMT example 32 `. # Define study area in degrees East or North @@ -97,8 +96,8 @@ } ) -# Download elevation grid for the study region with a resolution of 30 -# arc-seconds and pixel registration and load it into an xarray.DataArray +# Download elevation grid for the study region with a resolution of 30 arc-seconds and +# pixel registration and load it into an xarray.DataArray grd_relief = pygmt.datasets.load_earth_relief(resolution="30s", region=region_2d) # Determine the 3-D region from the minimum and maximum values of the relief grid @@ -112,16 +111,16 @@ drapegrid = xr.DataArray(data, dims=("band", "y", "x")) # %% -# Again we create a 3-D plot with :meth:`pygmt.Figure.grdview` and passe an Earth -# relief grid to the ``grid`` parameter to create the topographic surface. But now -# we pass the PNG image which was loaded into an :class:`xarray.DataArray` to the -# ``drapgrid`` parameter. +# Again we create a 3-D plot with :meth:`pygmt.Figure.grdview` and passe an Earth relief +# grid to the ``grid`` parameter to create the topographic surface. But now we pass the +# PNG image which was loaded into an :class:`xarray.DataArray` to the ``drapgrid`` +# parameter. fig = pygmt.Figure() -# Set up a colormap with two colors for the EU flag: blue (0/51/153) for the -# background (value 0 in the nedCDF file -> lower half of 0-255 range) and -# yellow (255/204/0) for the stars (value 255 -> upper half) +# Set up a colormap with two colors for the EU flag: blue (0/51/153) for the background +# (value 0 in the nedCDF file -> lower half of 0-255 range) and yellow (255/204/0) for +# the stars (value 255 -> upper half) pygmt.makecpt(cmap="0/51/153,255/204/0", series=[0, 256, 128]) fig.grdview( @@ -131,9 +130,8 @@ drapegrid=drapegrid, # Drap image grid for the EU flag on top cmap=True, # Use colormap defined for the EU flag surftype="i", # Create an image plot - # Use an illumination from the azimuthal directions 0° (north) and 270° - # (west) with a normalization via a cumulative Laplace distribution for - # the shading + # Use an illumination from the azimuthal directions 0° (north) and 270° (west) with + # a normalization via a cumulative Laplace distribution for the shading shading="+a0/270+ne0.6", perspective=[157.5, 30], # Define azimuth, elevation for the 3-D plot frame=True, @@ -142,9 +140,9 @@ fig.show() # %% -# 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`. +# 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( From ce940a1c623de32bf9faacaa8b12c3503188228f Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Mon, 5 Aug 2024 23:14:56 +0200 Subject: [PATCH 42/48] Move pandas.DataFrame for cities to plotting part --- .../advanced/draping_on_3d_surface.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) mode change 100755 => 100644 examples/tutorials/advanced/draping_on_3d_surface.py diff --git a/examples/tutorials/advanced/draping_on_3d_surface.py b/examples/tutorials/advanced/draping_on_3d_surface.py old mode 100755 new mode 100644 index 94a11d4d72f..7a6d73de669 --- a/examples/tutorials/advanced/draping_on_3d_surface.py +++ b/examples/tutorials/advanced/draping_on_3d_surface.py @@ -87,15 +87,6 @@ # Define study area in degrees East or North region_2d = [3, 9, 50, 54] # [lon_min, lon_max, lat_min, lat_max] -# Set up a pandas DataFrame with coordinates and names of three cities -cities = pd.DataFrame( - { - "longitude": [7.10, 4.35, 5.69], - "latitude": [50.73, 50.85, 50.85], - "name": ["Bonn", "Bruxelles", "Maastricht"], - } -) - # Download elevation grid for the study region with a resolution of 30 arc-seconds and # pixel registration and load it into an xarray.DataArray grd_relief = pygmt.datasets.load_earth_relief(resolution="30s", region=region_2d) @@ -152,7 +143,14 @@ perspective=True, ) -# Mark cities +# Set up a pandas.DataFrame with coordinates and names of three cities +cities = pd.DataFrame( + { + "longitude": [7.10, 4.35, 5.69], + "latitude": [50.73, 50.85, 50.85], + "name": ["Bonn", "Bruxelles", "Maastricht"], + } +) # Plot markers fig.plot( x=cities.longitude, From 0bbc1bc3b18588c809352f30f34e3f1d54e12543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= <94163266+yvonnefroehlich@users.noreply.github.com> Date: Tue, 6 Aug 2024 17:43:22 +0200 Subject: [PATCH 43/48] Remove double white spaces Co-authored-by: Dongdong Tian --- examples/tutorials/advanced/draping_on_3d_surface.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/tutorials/advanced/draping_on_3d_surface.py b/examples/tutorials/advanced/draping_on_3d_surface.py index 7a6d73de669..052a30d7e92 100644 --- a/examples/tutorials/advanced/draping_on_3d_surface.py +++ b/examples/tutorials/advanced/draping_on_3d_surface.py @@ -103,8 +103,8 @@ # %% # Again we create a 3-D plot with :meth:`pygmt.Figure.grdview` and passe an Earth relief -# grid to the ``grid`` parameter to create the topographic surface. But now we pass the -# PNG image which was loaded into an :class:`xarray.DataArray` to the ``drapgrid`` +# grid to the ``grid`` parameter to create the topographic surface. But now we pass the +# PNG image which was loaded into an :class:`xarray.DataArray` to the ``drapgrid`` # parameter. fig = pygmt.Figure() From 377ae47685c26224e6f7750f99025cb6b4bc3928 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sat, 10 Aug 2024 17:56:40 +0200 Subject: [PATCH 44/48] Add elevation to DataFrame and use plot3d for cities --- examples/tutorials/advanced/draping_on_3d_surface.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) mode change 100644 => 100755 examples/tutorials/advanced/draping_on_3d_surface.py diff --git a/examples/tutorials/advanced/draping_on_3d_surface.py b/examples/tutorials/advanced/draping_on_3d_surface.py old mode 100644 new mode 100755 index 052a30d7e92..84be8faf55c --- a/examples/tutorials/advanced/draping_on_3d_surface.py +++ b/examples/tutorials/advanced/draping_on_3d_surface.py @@ -125,6 +125,8 @@ # a normalization via a cumulative Laplace distribution for the shading shading="+a0/270+ne0.6", perspective=[157.5, 30], # Define azimuth, elevation for the 3-D plot + zsize="1c", + plane="+gdarkgray", frame=True, ) @@ -146,15 +148,17 @@ # Set up a pandas.DataFrame with coordinates and names of three cities cities = pd.DataFrame( { - "longitude": [7.10, 4.35, 5.69], - "latitude": [50.73, 50.85, 50.85], + "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.plot( +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", From 28f6de1e5274bd2c6fb00bb08d1c7c2119f750bd Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sat, 10 Aug 2024 18:03:42 +0200 Subject: [PATCH 45/48] Remove execution permission --- examples/tutorials/advanced/draping_on_3d_surface.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 examples/tutorials/advanced/draping_on_3d_surface.py diff --git a/examples/tutorials/advanced/draping_on_3d_surface.py b/examples/tutorials/advanced/draping_on_3d_surface.py old mode 100755 new mode 100644 From 5f423b36aa68a5147068153d0bbc37936c689682 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sat, 31 Aug 2024 23:45:18 +0200 Subject: [PATCH 46/48] Remove code part for plotting features on top of topography --- .../advanced/draping_on_3d_surface.py | 48 +------------------ 1 file changed, 1 insertion(+), 47 deletions(-) diff --git a/examples/tutorials/advanced/draping_on_3d_surface.py b/examples/tutorials/advanced/draping_on_3d_surface.py index 84be8faf55c..522bc7843b0 100644 --- a/examples/tutorials/advanced/draping_on_3d_surface.py +++ b/examples/tutorials/advanced/draping_on_3d_surface.py @@ -132,50 +132,4 @@ fig.show() -# %% -# 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, -) - -fig.show() - -# sphinx_gallery_thumbnail_number = 3 +# sphinx_gallery_thumbnail_number = 2 From cb3b095e565528137a8b24dd26d2a54117d85a17 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sat, 31 Aug 2024 23:50:38 +0200 Subject: [PATCH 47/48] Remove un-needed import of pandas --- examples/tutorials/advanced/draping_on_3d_surface.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/tutorials/advanced/draping_on_3d_surface.py b/examples/tutorials/advanced/draping_on_3d_surface.py index 522bc7843b0..ccf93960d05 100644 --- a/examples/tutorials/advanced/draping_on_3d_surface.py +++ b/examples/tutorials/advanced/draping_on_3d_surface.py @@ -15,7 +15,6 @@ # %% # Load the required packages -import pandas as pd import pygmt import rasterio import xarray as xr From ede2232668e69cc3cc5b25ea8be7488a27a3ebc4 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 1 Sep 2024 15:48:18 +0200 Subject: [PATCH 48/48] Add comment regarding considering the aspect ratio of the image --- examples/tutorials/advanced/draping_on_3d_surface.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/tutorials/advanced/draping_on_3d_surface.py b/examples/tutorials/advanced/draping_on_3d_surface.py index ccf93960d05..4ff311b0357 100644 --- a/examples/tutorials/advanced/draping_on_3d_surface.py +++ b/examples/tutorials/advanced/draping_on_3d_surface.py @@ -26,7 +26,7 @@ # In the first example, the seafloor crustal age is plotted with color-coding on top of # the topographic map of an area of the Mid-Atlantic Ridge. -# Define study area in degrees East or North +# Define the study area in degrees East or North region_2d = [-50, 0, 36, 70] # [lon_min, lon_max, lat_min, lat_max] # Download elevation and crustal age grids for the study region with a resolution of 10 @@ -82,8 +82,11 @@ # In the second example, the flag of the European Union (EU) is plotted on top of a # topographic map of northwest Europe. This example is modified from # :gmt-docs:`GMT example 32 `. +# We have to consider the dimension of the image we want to drap. The image we will +# download in this example has 1000 x 667 pixels, i.e. a aspect ratio of 3 x 2. -# Define study area in degrees East or North +# Define the study area in degrees East or North, with an extend of 6 degrees for +# the longitude and 4 degrees for the latitude region_2d = [3, 9, 50, 54] # [lon_min, lon_max, lat_min, lat_max] # Download elevation grid for the study region with a resolution of 30 arc-seconds and