diff --git a/cookbooks/convection-box/doc/plotting_scripts/plot_all_figures.sh b/cookbooks/convection-box/doc/plotting_scripts/plot_all_figures.sh new file mode 100755 index 00000000000..041e72f3412 --- /dev/null +++ b/cookbooks/convection-box/doc/plotting_scripts/plot_all_figures.sh @@ -0,0 +1,5 @@ +# Run every python script in this directory to quickly regenerate all of the figures for this cookbook. + +python3 plot_visit0000.py; +python3 plot_visit0001.py; + diff --git a/cookbooks/convection-box/doc/plotting_scripts/plot_visit0000.py b/cookbooks/convection-box/doc/plotting_scripts/plot_visit0000.py new file mode 100644 index 00000000000..fbb71f3c058 --- /dev/null +++ b/cookbooks/convection-box/doc/plotting_scripts/plot_visit0000.py @@ -0,0 +1,68 @@ +import pyvista as pv +import matplotlib.pyplot as plt +from matplotlib.colors import ListedColormap +from cmcrameri import cm # Fabio Crameri's color maps +import numpy as np +import os + +pv.set_plot_theme("document") +plotter = pv.Plotter(off_screen=True) + +mesh = pv.read("../../output-convection-box/solution/solution-00000.pvtu") +plot_spatial_bounds = [0, 1, 0, 1, 0, 0] +mesh = mesh.clip_box(bounds=plot_spatial_bounds, invert=False) +arrows = mesh.glyph(scale="velocity", factor=0.01,orient="velocity") + +# scale the meshes down to put the scale bar on the side (like in the docs) +mesh = mesh.scale(0.75) +arrows = arrows.scale(0.75) + +# Define properties for the scalar bar arguments +sargs = dict( + width=0.2, + height=0.6, + title="T", + label_font_size=24, + title_font_size=32, + color="black", + position_x=0.0, + position_y=0.20, + vertical=True +) + +mesh_actor = plotter.add_mesh(mesh, scalars="T", log_scale=False, scalar_bar_args=sargs,cmap=cm.vik) +arrows_actor = plotter.add_mesh(arrows,color='white') +plotter.view_xy() + +# Displace the meshes to make room for the scalar bar +mesh_actor.position = (0.225,0.15,0) +arrows_actor.position = (0.225,0.15,0) + +# shows the axes labels on the actual mesh (show_axes shows a widget in 3d space) +plotter.show_bounds( +use_3d_text=False,use_2d=True, # These parameters make it easier to plot 2D data +axes_ranges=[0,1,0,1,0,0], # We displaced mesh_actor earler, so we need to reset the axes ranges +grid='front',ticks='outside',location='outer', +xtitle='X Axis',ytitle='Y Axis'# Model bounds are in meters, kilometers make the labels more readable +) + +# Calculate Camera Position from Bounds +bounds_array = np.array(plot_spatial_bounds) +xmag = float(abs(bounds_array[1] - bounds_array[0])) +ymag = float(abs(bounds_array[3] - bounds_array[2])) +aspect_ratio = ymag / xmag +# Multiplying the xmagnitude here results in an image with less white space. +# Modifying plot_spatial_bounds directly will distort the actual pyvista mesh. +aspect_ratio = ymag / (xmag*1.2) +plotter.window_size = (1024, int(1024 * aspect_ratio)) +xmid = xmag / 2 + bounds_array[0] # X midpoint +ymid = ymag / 2 + bounds_array[2] # Y midpoint +zoom = xmag * aspect_ratio * 1.875 # Zoom level - not sure why 1.875 works + +position = (xmid, ymid, zoom) +focal_point = (xmid, ymid, 0) +viewup = (0, 1, 0) +camera = [position, focal_point, viewup] +plotter.camera_position = camera +plotter.camera_set = True +plotter.screenshot("../visit0000.png") diff --git a/cookbooks/convection-box/doc/plotting_scripts/plot_visit0001.py b/cookbooks/convection-box/doc/plotting_scripts/plot_visit0001.py new file mode 100644 index 00000000000..66c09e94b6b --- /dev/null +++ b/cookbooks/convection-box/doc/plotting_scripts/plot_visit0001.py @@ -0,0 +1,68 @@ +import pyvista as pv +import matplotlib.pyplot as plt +from matplotlib.colors import ListedColormap +from cmcrameri import cm # Fabio Crameri's color maps +import numpy as np +import os + +pv.set_plot_theme("document") +plotter = pv.Plotter(off_screen=True) + +mesh = pv.read("../../output-convection-box/solution/solution-00049.pvtu") +plot_spatial_bounds = [0, 1, 0, 1, 0, 0] +mesh = mesh.clip_box(bounds=plot_spatial_bounds, invert=False) +arrows = mesh.glyph(scale="velocity", factor=0.001,orient="velocity") + +# scale the meshes down to put the scale bar on the side (like in the docs) +mesh = mesh.scale(0.75) +arrows = arrows.scale(0.75) + +# Define properties for the scalar bar arguments +sargs = dict( + width=0.2, + height=0.6, + title="T", + label_font_size=24, + title_font_size=32, + color="black", + position_x=0.0, + position_y=0.20, + vertical=True +) + +mesh_actor = plotter.add_mesh(mesh, scalars="T", log_scale=False, scalar_bar_args=sargs,cmap=cm.vik) +arrows_actor = plotter.add_mesh(arrows,color='white') +plotter.view_xy() + +# Displace the meshes to make room for the scalar bar +mesh_actor.position = (0.225,0.15,0) +arrows_actor.position = (0.225,0.15,0) + +# shows the axes labels on the actual mesh (show_axes shows a widget in 3d space) +plotter.show_bounds( +use_3d_text=False,use_2d=True, # These parameters make it easier to plot 2D data +axes_ranges=[0,1,0,1,0,0], # We displaced mesh_actor earler, so we need to reset the axes ranges +grid='front',ticks='outside',location='outer', +xtitle='X Axis',ytitle='Y Axis'# Model bounds are in meters, kilometers make the labels more readable +) + +# Calculate Camera Position from Bounds +bounds_array = np.array(plot_spatial_bounds) +xmag = float(abs(bounds_array[1] - bounds_array[0])) +ymag = float(abs(bounds_array[3] - bounds_array[2])) + +# Multiplying the xmagnitude here results in an image with less white space. +# Modifying plot_spatial_bounds directly will distort the actual pyvista mesh. +aspect_ratio = ymag / (xmag*1.2) +plotter.window_size = (1024, int(1024 * aspect_ratio)) +xmid = xmag / 2 + bounds_array[0] # X midpoint +ymid = ymag / 2 + bounds_array[2] # Y midpoint +zoom = xmag * aspect_ratio * 1.875 # Zoom level - not sure why 1.875 works + +position = (xmid, ymid, zoom) +focal_point = (xmid, ymid, 0) +viewup = (0, 1, 0) +camera = [position, focal_point, viewup] +plotter.camera_position = camera +plotter.camera_set = True +plotter.screenshot("../visit0001.png") diff --git a/cookbooks/convection-box/doc/visit0000.png b/cookbooks/convection-box/doc/visit0000.png index 02c606a1150..d4632a7f5a9 100644 Binary files a/cookbooks/convection-box/doc/visit0000.png and b/cookbooks/convection-box/doc/visit0000.png differ diff --git a/cookbooks/convection-box/doc/visit0001.png b/cookbooks/convection-box/doc/visit0001.png index 171161e0ca2..fc3cba3d207 100644 Binary files a/cookbooks/convection-box/doc/visit0001.png and b/cookbooks/convection-box/doc/visit0001.png differ diff --git a/cookbooks/crustal_deformation/doc/fig108_viscocity_compression.png b/cookbooks/crustal_deformation/doc/fig108_viscocity_compression.png new file mode 100644 index 00000000000..987a80c6877 Binary files /dev/null and b/cookbooks/crustal_deformation/doc/fig108_viscocity_compression.png differ diff --git a/cookbooks/crustal_deformation/doc/fig108_viscocity_extension.png b/cookbooks/crustal_deformation/doc/fig108_viscocity_extension.png new file mode 100644 index 00000000000..86175a3d363 Binary files /dev/null and b/cookbooks/crustal_deformation/doc/fig108_viscocity_extension.png differ diff --git a/cookbooks/crustal_deformation/pyvista_doc.py b/cookbooks/crustal_deformation/pyvista_doc.py new file mode 100644 index 00000000000..a1fb1e8176a --- /dev/null +++ b/cookbooks/crustal_deformation/pyvista_doc.py @@ -0,0 +1,61 @@ +import pyvista as pv +import matplotlib.pyplot as plt +from matplotlib.colors import ListedColormap +from cmcrameri import cm # Fabio Crameri's color maps +import numpy as np +import os + +timereader = pv.get_reader("./output-crustal_model_2D/solution.pvd") +times = np.array(timereader.time_values) / 1e6 # convert yrs to Myrs + +pv.set_plot_theme("document") +plotter = pv.Plotter(off_screen=True) + +mesh = pv.read("output-crustal_model_2D/solution/solution-00020.pvtu") +plot_spatial_bounds = [0, 100e3, 0, 100e3, 0, 0] + +# Define properties for the scalar bar arguments +sargs = dict( + width=0.6, + height=0.1, + title="Viscosity (Pa s)", + label_font_size=24, + title_font_size=32, + color="black", + position_x=0.20, + position_y=0.05, + n_labels=2, + vertical=False +) + +mesh_actor = plotter.add_mesh(mesh, scalars="viscosity", log_scale=True, scalar_bar_args=sargs,cmap=cm.batlow_r) + +# Displace the mesh to make room for the scalar bar +mesh_actor.position = (10e3,25e3,0) +plotter.view_xy() + +plotter.show_bounds( +use_3d_text=False,use_2d=True, # These parameters make it easier to plot 2D data +axes_ranges=[0,80,0,16,0,0], # We displaced mesh_actor earler, so we need to reset the axes ranges +grid='front',ticks='outside',location='outer', +n_ylabels=3,n_xlabels=9,bold=False, +xtitle='X Axis (km)',ytitle='Y Axis (km)'# Model bounds are in meters, kilometers make the labels more readable +) + +# Calculate Camera Position from Bounds +bounds_array = np.array(plot_spatial_bounds) +xmag = float(abs(bounds_array[1] - bounds_array[0])) +ymag = float(abs(bounds_array[3] - bounds_array[2])) +aspect_ratio = ymag / xmag +plotter.window_size = (1024, int(1024 * aspect_ratio)) +xmid = xmag / 2 + bounds_array[0] # X midpoint +ymid = ymag / 2 + bounds_array[2] # Y midpoint +zoom = xmag * aspect_ratio * 1.875 # Zoom level + +position = (xmid, ymid, zoom) +focal_point = (xmid, ymid, 0) +viewup = (0, 1, 0) +camera = [position, focal_point, viewup] +plotter.camera_position = camera +plotter.camera_set = True +plotter.screenshot("fig108.png") diff --git a/doc/sphinx/environment.yml b/doc/sphinx/environment.yml index 99d3c2744cf..234b9702b1b 100644 --- a/doc/sphinx/environment.yml +++ b/doc/sphinx/environment.yml @@ -11,3 +11,4 @@ dependencies: - pip: - sphinxcontrib-tikz - sphinxcontrib-svg2pdfconverter[CairoSVG] + - cmcrameri