From 003c346a472d92926d9c6142eb4db4fb9348e34e Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Wed, 24 Jan 2024 16:00:28 +0000 Subject: [PATCH 1/8] Align themes naming with PyVista. --- src/geovista/{theme.py => themes.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/geovista/{theme.py => themes.py} (100%) diff --git a/src/geovista/theme.py b/src/geovista/themes.py similarity index 100% rename from src/geovista/theme.py rename to src/geovista/themes.py From a1c801b0ba41faac5c352e6e5b4ac0e0c30640ad Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Wed, 24 Jan 2024 18:01:12 +0000 Subject: [PATCH 2/8] Rename references to themes. --- README.md | 16 ++++++++-------- src/geovista/examples/clouds.py | 2 +- src/geovista/examples/clouds_robin.py | 2 +- .../examples/curvilinear/from_2d__orca.py | 2 +- .../examples/curvilinear/from_2d__orca_moll.py | 2 +- .../point_cloud/from_points__orca_cloud.py | 2 +- .../point_cloud/from_points__orca_cloud_eqc.py | 2 +- .../examples/rectilinear/from_1d__oisst.py | 2 +- .../examples/rectilinear/from_1d__oisst_eqc.py | 2 +- .../rectilinear/from_1d__synthetic_face_m1_n1.py | 2 +- .../from_1d__synthetic_face_m1_n1_robin.py | 2 +- .../rectilinear/from_1d__synthetic_node_m1_n1.py | 2 +- .../from_1d__synthetic_node_m1_n1_moll.py | 2 +- .../rectilinear/from_2d__synthetic_face_m1n1.py | 2 +- .../from_2d__synthetic_face_m1n1_robin.py | 2 +- .../rectilinear/from_2d__synthetic_node_m1n1.py | 2 +- .../from_2d__synthetic_node_m1n1_moll.py | 2 +- src/geovista/examples/scalar_data/earthquakes.py | 2 +- .../examples/scalar_data/earthquakes_wink1.py | 2 +- src/geovista/examples/spatial_index/uber_h3.py | 2 +- src/geovista/examples/unstructured/dynamico.py | 2 +- .../examples/unstructured/dynamico_poly.py | 2 +- src/geovista/examples/unstructured/fesom.py | 2 +- src/geovista/examples/unstructured/fesom_fouc.py | 2 +- src/geovista/examples/unstructured/icon.py | 2 +- src/geovista/examples/unstructured/icon_eqc.py | 2 +- .../examples/unstructured/lam_pacific.py | 2 +- .../examples/unstructured/lam_pacific_moll.py | 2 +- src/geovista/examples/unstructured/lfric_sst.py | 2 +- .../examples/unstructured/lfric_sst_bonne.py | 2 +- src/geovista/examples/unstructured/smc.py | 2 +- src/geovista/examples/unstructured/smc_sinu.py | 2 +- src/geovista/examples/unstructured/tri.py | 2 +- src/geovista/examples/unstructured/tri_hammer.py | 2 +- src/geovista/examples/vector_data/vectors.py | 2 +- .../examples/warp/from_unstructured__fvcom.py | 2 +- .../warp/from_unstructured__lfric_orog.py | 2 +- .../warp/from_unstructured__lfric_orog_eqc.py | 2 +- 38 files changed, 45 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 05c8d218..9c56c88d 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ colormap. ```python import geovista as gv from geovista.pantry.data import ww3_global_tri -import geovista.theme +import geovista.themes # Load the sample data. sample = ww3_global_tri() @@ -189,7 +189,7 @@ from an [FVCOM](http://fvcom.smast.umassd.edu/fvcom/) **unstructured** mesh, as ```python import geovista as gv from geovista.pantry.data import fvcom_tamar -import geovista.theme +import geovista.themes # Load the sample data. sample = fvcom_tamar() @@ -240,7 +240,7 @@ base layer. ```python import geovista as gv from geovista.pantry.data import lam_pacific -import geovista.theme +import geovista.themes # Load the sample data. sample = lam_pacific() @@ -284,7 +284,7 @@ import cartopy.crs as ccrs import geovista as gv from geovista.pantry.data import lam_pacific -import geovista.theme +import geovista.themes # Load the sample data. sample = lam_pacific() @@ -326,7 +326,7 @@ Now render a [Met Office LFRic](https://www.metoffice.gov.uk/research/approach/m ```python import geovista as gv from geovista.pantry.data import lfric_sst -import geovista.theme +import geovista.themes # Load the sample data. sample = lfric_sst() @@ -365,7 +365,7 @@ using Met Office Unified Model (UM) ORCA2 Sea Water Potential Temperature data, ```python import geovista as gv from geovista.pantry.data import um_orca2 -import geovista.theme +import geovista.themes # Load sample data. sample = um_orca2() @@ -403,7 +403,7 @@ Now let's render a [NOAA/NCEI Optimum Interpolation SST](https://www.ncei.noaa.g ```python import geovista as gv from geovista.pantry.data import oisst_avhrr_sst -import geovista.theme +import geovista.themes # Load sample data. sample = oisst_avhrr_sst() @@ -443,7 +443,7 @@ model uses hexagonal and pentagonal cells, and is a new dynamical core for ```python import geovista as gv from geovista.pantry.data import dynamico -import geovista.theme +import geovista.themes # Load sample data. sample = dynamico() diff --git a/src/geovista/examples/clouds.py b/src/geovista/examples/clouds.py index ad631914..0c3f66c3 100755 --- a/src/geovista/examples/clouds.py +++ b/src/geovista/examples/clouds.py @@ -40,7 +40,7 @@ import geovista as gv from geovista.pantry.data import cloud_amount -import geovista.theme +import geovista.themes #: The colormap to render the clouds. CMAP = cmocean.cm.gray diff --git a/src/geovista/examples/clouds_robin.py b/src/geovista/examples/clouds_robin.py index 629e1770..2c934092 100755 --- a/src/geovista/examples/clouds_robin.py +++ b/src/geovista/examples/clouds_robin.py @@ -40,7 +40,7 @@ import geovista as gv from geovista.pantry.data import cloud_amount -import geovista.theme +import geovista.themes #: The colormap to render the clouds. CMAP = cmocean.cm.gray diff --git a/src/geovista/examples/curvilinear/from_2d__orca.py b/src/geovista/examples/curvilinear/from_2d__orca.py index d9fb8e11..2e6568d1 100755 --- a/src/geovista/examples/curvilinear/from_2d__orca.py +++ b/src/geovista/examples/curvilinear/from_2d__orca.py @@ -30,7 +30,7 @@ import geovista as gv from geovista.pantry.data import um_orca2 -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/curvilinear/from_2d__orca_moll.py b/src/geovista/examples/curvilinear/from_2d__orca_moll.py index 34900ee4..0a118930 100755 --- a/src/geovista/examples/curvilinear/from_2d__orca_moll.py +++ b/src/geovista/examples/curvilinear/from_2d__orca_moll.py @@ -33,7 +33,7 @@ import geovista as gv from geovista.common import cast_UnstructuredGrid_to_PolyData as cast from geovista.pantry.data import um_orca2 -import geovista.theme +import geovista.themes from geovista.transform import transform_mesh diff --git a/src/geovista/examples/point_cloud/from_points__orca_cloud.py b/src/geovista/examples/point_cloud/from_points__orca_cloud.py index 13b17c76..c663ac61 100755 --- a/src/geovista/examples/point_cloud/from_points__orca_cloud.py +++ b/src/geovista/examples/point_cloud/from_points__orca_cloud.py @@ -32,7 +32,7 @@ import geovista as gv from geovista.pantry.data import um_orca2_gradient from geovista.pantry.meshes import ZLEVEL_SCALE_CLOUD -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/point_cloud/from_points__orca_cloud_eqc.py b/src/geovista/examples/point_cloud/from_points__orca_cloud_eqc.py index f78d35db..6da3ec15 100755 --- a/src/geovista/examples/point_cloud/from_points__orca_cloud_eqc.py +++ b/src/geovista/examples/point_cloud/from_points__orca_cloud_eqc.py @@ -34,7 +34,7 @@ import geovista as gv from geovista.pantry.data import um_orca2_gradient from geovista.pantry.meshes import ZLEVEL_SCALE_CLOUD -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/rectilinear/from_1d__oisst.py b/src/geovista/examples/rectilinear/from_1d__oisst.py index b785db43..7a8b9ac0 100755 --- a/src/geovista/examples/rectilinear/from_1d__oisst.py +++ b/src/geovista/examples/rectilinear/from_1d__oisst.py @@ -31,7 +31,7 @@ import geovista as gv from geovista.pantry.data import oisst_avhrr_sst -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/rectilinear/from_1d__oisst_eqc.py b/src/geovista/examples/rectilinear/from_1d__oisst_eqc.py index e86adc20..348a7e73 100755 --- a/src/geovista/examples/rectilinear/from_1d__oisst_eqc.py +++ b/src/geovista/examples/rectilinear/from_1d__oisst_eqc.py @@ -33,7 +33,7 @@ import geovista as gv from geovista.pantry.data import oisst_avhrr_sst -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/rectilinear/from_1d__synthetic_face_m1_n1.py b/src/geovista/examples/rectilinear/from_1d__synthetic_face_m1_n1.py index 6911e4f8..14872ca6 100755 --- a/src/geovista/examples/rectilinear/from_1d__synthetic_face_m1_n1.py +++ b/src/geovista/examples/rectilinear/from_1d__synthetic_face_m1_n1.py @@ -29,7 +29,7 @@ import numpy as np import geovista as gv -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/rectilinear/from_1d__synthetic_face_m1_n1_robin.py b/src/geovista/examples/rectilinear/from_1d__synthetic_face_m1_n1_robin.py index f9f7c117..e3bd8074 100755 --- a/src/geovista/examples/rectilinear/from_1d__synthetic_face_m1_n1_robin.py +++ b/src/geovista/examples/rectilinear/from_1d__synthetic_face_m1_n1_robin.py @@ -30,7 +30,7 @@ import numpy as np import geovista as gv -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/rectilinear/from_1d__synthetic_node_m1_n1.py b/src/geovista/examples/rectilinear/from_1d__synthetic_node_m1_n1.py index bfa83025..7cdeadcf 100755 --- a/src/geovista/examples/rectilinear/from_1d__synthetic_node_m1_n1.py +++ b/src/geovista/examples/rectilinear/from_1d__synthetic_node_m1_n1.py @@ -29,7 +29,7 @@ import numpy as np import geovista as gv -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/rectilinear/from_1d__synthetic_node_m1_n1_moll.py b/src/geovista/examples/rectilinear/from_1d__synthetic_node_m1_n1_moll.py index 11afd712..5f1f5b1f 100755 --- a/src/geovista/examples/rectilinear/from_1d__synthetic_node_m1_n1_moll.py +++ b/src/geovista/examples/rectilinear/from_1d__synthetic_node_m1_n1_moll.py @@ -30,7 +30,7 @@ import numpy as np import geovista as gv -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/rectilinear/from_2d__synthetic_face_m1n1.py b/src/geovista/examples/rectilinear/from_2d__synthetic_face_m1n1.py index 952e8563..7ea5b475 100755 --- a/src/geovista/examples/rectilinear/from_2d__synthetic_face_m1n1.py +++ b/src/geovista/examples/rectilinear/from_2d__synthetic_face_m1n1.py @@ -29,7 +29,7 @@ import numpy as np import geovista as gv -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/rectilinear/from_2d__synthetic_face_m1n1_robin.py b/src/geovista/examples/rectilinear/from_2d__synthetic_face_m1n1_robin.py index 22710d73..7cddd8d3 100755 --- a/src/geovista/examples/rectilinear/from_2d__synthetic_face_m1n1_robin.py +++ b/src/geovista/examples/rectilinear/from_2d__synthetic_face_m1n1_robin.py @@ -30,7 +30,7 @@ import numpy as np import geovista as gv -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/rectilinear/from_2d__synthetic_node_m1n1.py b/src/geovista/examples/rectilinear/from_2d__synthetic_node_m1n1.py index d7f69705..51fa89f8 100755 --- a/src/geovista/examples/rectilinear/from_2d__synthetic_node_m1n1.py +++ b/src/geovista/examples/rectilinear/from_2d__synthetic_node_m1n1.py @@ -29,7 +29,7 @@ import numpy as np import geovista as gv -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/rectilinear/from_2d__synthetic_node_m1n1_moll.py b/src/geovista/examples/rectilinear/from_2d__synthetic_node_m1n1_moll.py index 136b9d18..95d220e6 100755 --- a/src/geovista/examples/rectilinear/from_2d__synthetic_node_m1n1_moll.py +++ b/src/geovista/examples/rectilinear/from_2d__synthetic_node_m1n1_moll.py @@ -30,7 +30,7 @@ import numpy as np import geovista as gv -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/scalar_data/earthquakes.py b/src/geovista/examples/scalar_data/earthquakes.py index b50483a0..568b82cc 100755 --- a/src/geovista/examples/scalar_data/earthquakes.py +++ b/src/geovista/examples/scalar_data/earthquakes.py @@ -48,7 +48,7 @@ import geovista as gv from geovista.pantry.data import usgs_earthquakes -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/scalar_data/earthquakes_wink1.py b/src/geovista/examples/scalar_data/earthquakes_wink1.py index bc7de1b3..99cb7c1e 100755 --- a/src/geovista/examples/scalar_data/earthquakes_wink1.py +++ b/src/geovista/examples/scalar_data/earthquakes_wink1.py @@ -49,7 +49,7 @@ import geovista as gv from geovista.pantry.data import usgs_earthquakes -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/spatial_index/uber_h3.py b/src/geovista/examples/spatial_index/uber_h3.py index 313601aa..e75d8179 100755 --- a/src/geovista/examples/spatial_index/uber_h3.py +++ b/src/geovista/examples/spatial_index/uber_h3.py @@ -88,7 +88,7 @@ import geovista from geovista.geodesic import line -import geovista.theme +import geovista.themes # %% # As a convenience, we create some **type aliases** and **data containers** diff --git a/src/geovista/examples/unstructured/dynamico.py b/src/geovista/examples/unstructured/dynamico.py index 8d3d11c3..719f68c7 100755 --- a/src/geovista/examples/unstructured/dynamico.py +++ b/src/geovista/examples/unstructured/dynamico.py @@ -32,7 +32,7 @@ import geovista as gv from geovista.pantry.data import dynamico -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/unstructured/dynamico_poly.py b/src/geovista/examples/unstructured/dynamico_poly.py index fd2473aa..16261575 100755 --- a/src/geovista/examples/unstructured/dynamico_poly.py +++ b/src/geovista/examples/unstructured/dynamico_poly.py @@ -33,7 +33,7 @@ import geovista as gv from geovista.pantry.data import dynamico -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/unstructured/fesom.py b/src/geovista/examples/unstructured/fesom.py index 8870c10f..d5e16b1a 100755 --- a/src/geovista/examples/unstructured/fesom.py +++ b/src/geovista/examples/unstructured/fesom.py @@ -32,7 +32,7 @@ import geovista as gv from geovista.pantry.data import fesom -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/unstructured/fesom_fouc.py b/src/geovista/examples/unstructured/fesom_fouc.py index d59aac33..b9c57e82 100755 --- a/src/geovista/examples/unstructured/fesom_fouc.py +++ b/src/geovista/examples/unstructured/fesom_fouc.py @@ -33,7 +33,7 @@ import geovista as gv from geovista.pantry.data import fesom -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/unstructured/icon.py b/src/geovista/examples/unstructured/icon.py index 39a39769..c6ecb929 100755 --- a/src/geovista/examples/unstructured/icon.py +++ b/src/geovista/examples/unstructured/icon.py @@ -33,7 +33,7 @@ import geovista as gv from geovista.pantry.data import icon_soil -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/unstructured/icon_eqc.py b/src/geovista/examples/unstructured/icon_eqc.py index 6c10e561..9206a512 100755 --- a/src/geovista/examples/unstructured/icon_eqc.py +++ b/src/geovista/examples/unstructured/icon_eqc.py @@ -34,7 +34,7 @@ import geovista as gv from geovista.pantry.data import icon_soil -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/unstructured/lam_pacific.py b/src/geovista/examples/unstructured/lam_pacific.py index 8c33bd4b..feb5c923 100755 --- a/src/geovista/examples/unstructured/lam_pacific.py +++ b/src/geovista/examples/unstructured/lam_pacific.py @@ -31,7 +31,7 @@ import geovista as gv from geovista.pantry.data import lam_pacific -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/unstructured/lam_pacific_moll.py b/src/geovista/examples/unstructured/lam_pacific_moll.py index bcb997e9..aff3c94f 100755 --- a/src/geovista/examples/unstructured/lam_pacific_moll.py +++ b/src/geovista/examples/unstructured/lam_pacific_moll.py @@ -32,7 +32,7 @@ import geovista as gv from geovista.pantry.data import lam_pacific -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/unstructured/lfric_sst.py b/src/geovista/examples/unstructured/lfric_sst.py index 0c9d9e43..ae6e19a0 100755 --- a/src/geovista/examples/unstructured/lfric_sst.py +++ b/src/geovista/examples/unstructured/lfric_sst.py @@ -31,7 +31,7 @@ import geovista as gv from geovista.pantry.data import lfric_sst -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/unstructured/lfric_sst_bonne.py b/src/geovista/examples/unstructured/lfric_sst_bonne.py index 49a556b0..cb330a4f 100755 --- a/src/geovista/examples/unstructured/lfric_sst_bonne.py +++ b/src/geovista/examples/unstructured/lfric_sst_bonne.py @@ -32,7 +32,7 @@ import geovista as gv from geovista.pantry.data import lfric_sst -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/unstructured/smc.py b/src/geovista/examples/unstructured/smc.py index 74f52f08..74ccc78f 100755 --- a/src/geovista/examples/unstructured/smc.py +++ b/src/geovista/examples/unstructured/smc.py @@ -30,7 +30,7 @@ import geovista as gv from geovista.pantry.data import ww3_global_smc -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/unstructured/smc_sinu.py b/src/geovista/examples/unstructured/smc_sinu.py index 5212c8de..3a942214 100755 --- a/src/geovista/examples/unstructured/smc_sinu.py +++ b/src/geovista/examples/unstructured/smc_sinu.py @@ -32,7 +32,7 @@ import geovista as gv from geovista.pantry.data import ww3_global_smc -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/unstructured/tri.py b/src/geovista/examples/unstructured/tri.py index 5b025413..54b9355e 100755 --- a/src/geovista/examples/unstructured/tri.py +++ b/src/geovista/examples/unstructured/tri.py @@ -33,7 +33,7 @@ import geovista as gv from geovista.pantry.data import ww3_global_tri -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/unstructured/tri_hammer.py b/src/geovista/examples/unstructured/tri_hammer.py index bf2d4a5a..a6755258 100755 --- a/src/geovista/examples/unstructured/tri_hammer.py +++ b/src/geovista/examples/unstructured/tri_hammer.py @@ -34,7 +34,7 @@ import geovista as gv from geovista.pantry.data import ww3_global_tri -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/vector_data/vectors.py b/src/geovista/examples/vector_data/vectors.py index 5337b576..4cde80bc 100755 --- a/src/geovista/examples/vector_data/vectors.py +++ b/src/geovista/examples/vector_data/vectors.py @@ -27,7 +27,7 @@ import geovista as gv from geovista.pantry.meshes import regular_grid -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/warp/from_unstructured__fvcom.py b/src/geovista/examples/warp/from_unstructured__fvcom.py index 043ad182..4bb61058 100755 --- a/src/geovista/examples/warp/from_unstructured__fvcom.py +++ b/src/geovista/examples/warp/from_unstructured__fvcom.py @@ -32,7 +32,7 @@ import geovista as gv from geovista.pantry.data import fvcom_tamar -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/warp/from_unstructured__lfric_orog.py b/src/geovista/examples/warp/from_unstructured__lfric_orog.py index cd0f1e13..e77de188 100755 --- a/src/geovista/examples/warp/from_unstructured__lfric_orog.py +++ b/src/geovista/examples/warp/from_unstructured__lfric_orog.py @@ -33,7 +33,7 @@ import geovista as gv from geovista.pantry.data import lfric_orog -import geovista.theme +import geovista.themes def main() -> None: diff --git a/src/geovista/examples/warp/from_unstructured__lfric_orog_eqc.py b/src/geovista/examples/warp/from_unstructured__lfric_orog_eqc.py index 38088bf5..06d82b52 100755 --- a/src/geovista/examples/warp/from_unstructured__lfric_orog_eqc.py +++ b/src/geovista/examples/warp/from_unstructured__lfric_orog_eqc.py @@ -35,7 +35,7 @@ import geovista as gv from geovista.pantry.data import lfric_orog -import geovista.theme +import geovista.themes from geovista.transform import transform_mesh From 270fe4ecfaecac696fa5711c152ea886c0472895 Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Wed, 24 Jan 2024 18:30:50 +0000 Subject: [PATCH 3/8] Create set_plot_theme. --- src/geovista/themes.py | 90 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 79 insertions(+), 11 deletions(-) diff --git a/src/geovista/themes.py b/src/geovista/themes.py index 6e3c82a5..39f15ca2 100644 --- a/src/geovista/themes.py +++ b/src/geovista/themes.py @@ -12,21 +12,89 @@ """ from __future__ import annotations -import pyvista as pv +import contextlib +from enum import Enum + +from pyvista.plotting import themes as pv_themes from . import GEOVISTA_IMAGE_TESTING -theme = pv.themes.Theme() -theme.name = "geovista" -theme.background = (1.0, 1.0, 1.0) -theme.color = "lightgray" -theme.cmap = "balance" -theme.edge_color = "gray" -theme.font.color = (0.0, 0.0, 0.0) -theme.outline_color = (0.0, 0.0, 0.0) -theme.title = "GeoVista" + +class GeoVistaTheme(pv_themes.Theme): + """A PyVista theme optimised for typical GeoVista operations.""" + + def __init__(self) -> None: + super().__init__() + self.name = "geovista" + self.background = (1.0, 1.0, 1.0) + self.color = "lightgray" + self.cmap = "balance" + self.edge_color = "gray" + self.font.color = (0.0, 0.0, 0.0) + self.outline_color = (0.0, 0.0, 0.0) + self.title = "GeoVista" + + +class NATIVE_THEMES(Enum): # noqa: N801 (Python recommends UPPER_CASE for Enums) + """Global built-in themes available to GeoVista.""" + + # This class is public, unlike the PyVista equivalent, to improve + # the documentation of valid themes. + geovista = GeoVistaTheme + + +def set_plot_theme(theme: str | pv_themes.Theme) -> None: + """Set the plotting parameters to a predefined theme. + + Calls :func:`pyvista.set_plot_theme`, with a widened set of options + to include themes defined in :mod:`geovista.themes`. + + Parameters + ---------- + theme : str or pyvista.themes.Theme + The theme to apply. All inputs documented in + :func:`pyvista.set_plot_theme` are accepted, as well as those + documented in :data:`NATIVE_THEMES` (e.g. ``NATIVE_THEMES.foo`` OR + ``"foo"`` work the same). + + + Examples + -------- + >>> from geovista import themes + + The following are all equivalent: + + >>> themes.set_plot_theme("geovista") + >>> themes.set_plot_theme(themes.GeoVistaTheme()) + >>> themes.set_plot_theme(themes.NATIVE_THEMES.geovista.value()) + + References to PyVista themes are also accepted: + + >>> themes.set_plot_theme("document") + + """ + if isinstance(theme, str): + theme = theme.lower() + with contextlib.suppress(KeyError): + # Lookup a Theme matching the string reference if possible. + # String may still be a valid reference to a PyVista theme so + # keep going regardless of KeyError. + theme = NATIVE_THEMES[theme].value + + try: + pv_themes.set_plot_theme(theme) + except ValueError as err: + if "not found" in str(err) and isinstance(theme, str): + # Neither GeoVista nor PyVista could find a theme matching the + # string reference. + msg = f"Theme {theme} not found in GeoVista's native themes. {err}" + else: + # Don't modify any other ValueErrors. + msg = str(err) + raise ValueError(msg) from err + if not GEOVISTA_IMAGE_TESTING: # only load the geovista theme if we're not performing image testing, # as the default pyvista testing theme is adopted instead - pv.global_theme.load_theme(theme) + set_plot_theme(GeoVistaTheme()) From 880bc622ebf5fb9e43d001fb4e1df72f08a6e0cc Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Mon, 29 Jan 2024 16:59:24 +0000 Subject: [PATCH 4/8] versionadded tags. --- src/geovista/themes.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/geovista/themes.py b/src/geovista/themes.py index 39f15ca2..82ec9c16 100644 --- a/src/geovista/themes.py +++ b/src/geovista/themes.py @@ -21,7 +21,13 @@ class GeoVistaTheme(pv_themes.Theme): - """A PyVista theme optimised for typical GeoVista operations.""" + """A PyVista theme optimised for typical GeoVista operations. + + Notes + ----- + .. versionadded:: 0.5.0 + + """ def __init__(self) -> None: super().__init__() @@ -36,7 +42,13 @@ def __init__(self) -> None: class NATIVE_THEMES(Enum): # noqa: N801 (Python recommends UPPER_CASE for Enums) - """Global built-in themes available to GeoVista.""" + """Global built-in themes available to GeoVista. + + Notes + ----- + .. versionadded:: 0.5.0 + + """ # This class is public, unlike the PyVista equivalent, to improve # the documentation of valid themes. @@ -57,6 +69,9 @@ def set_plot_theme(theme: str | pv_themes.Theme) -> None: documented in :data:`NATIVE_THEMES` (e.g. ``NATIVE_THEMES.foo`` OR ``"foo"`` work the same). + Notes + ----- + .. versionadded:: 0.5.0 Examples -------- From 91ba59d5cb203a42ee8add67e49181cd84f4815d Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Mon, 29 Jan 2024 18:16:02 +0000 Subject: [PATCH 5/8] Name clash warning. --- src/geovista/themes.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/geovista/themes.py b/src/geovista/themes.py index 82ec9c16..018314e4 100644 --- a/src/geovista/themes.py +++ b/src/geovista/themes.py @@ -69,6 +69,14 @@ def set_plot_theme(theme: str | pv_themes.Theme) -> None: documented in :data:`NATIVE_THEMES` (e.g. ``NATIVE_THEMES.foo`` OR ``"foo"`` work the same). + Warnings + -------- + To use a theme from :func:`pyvista.set_plot_theme` that has a name clash + with a theme from :data:`NATIVE_THEMES`: either use a + :class:`pyvista.plotting.themes.Theme` instance (see PyVista's + :external+pyvista:doc:`api/plotting/theme`), or use + :func:`pyvista.set_plot_theme` directly. + Notes ----- .. versionadded:: 0.5.0 From 36331baf73bdc2b5e9ea2017714e8d7bf4a1e347 Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Mon, 29 Jan 2024 18:28:08 +0000 Subject: [PATCH 6/8] Better Enum documentation. --- src/geovista/themes.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/geovista/themes.py b/src/geovista/themes.py index 018314e4..527026d9 100644 --- a/src/geovista/themes.py +++ b/src/geovista/themes.py @@ -53,6 +53,7 @@ class NATIVE_THEMES(Enum): # noqa: N801 (Python recommends UPPER_CASE for Enums # This class is public, unlike the PyVista equivalent, to improve # the documentation of valid themes. geovista = GeoVistaTheme + """:class:`GeoVistaTheme`""" def set_plot_theme(theme: str | pv_themes.Theme) -> None: From 02c8571e93d0e4cc71e9eaedfed81330de4ba4c9 Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Mon, 29 Jan 2024 19:04:09 +0000 Subject: [PATCH 7/8] Modification of default theme setting. --- src/geovista/__init__.py | 9 ++++++++- src/geovista/themes.py | 36 +++++++++++++++++++++++++++--------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/geovista/__init__.py b/src/geovista/__init__.py index 7c971d3b..c7f2876a 100644 --- a/src/geovista/__init__.py +++ b/src/geovista/__init__.py @@ -34,7 +34,14 @@ except ModuleNotFoundError: __version__ = "unknown" -#: flag when performing image testing GEOVISTA_IMAGE_TESTING: bool = ( os.environ.get("GEOVISTA_IMAGE_TESTING", "false").lower() == "true" ) +"""Flag when performing image testing.""" + +if not GEOVISTA_IMAGE_TESTING: + # only load the geovista theme if we're not performing image testing, + # as the default pyvista testing theme is adopted instead + from .themes import _find_and_set_plot_theme + + _find_and_set_plot_theme() diff --git a/src/geovista/themes.py b/src/geovista/themes.py index 527026d9..bb851b83 100644 --- a/src/geovista/themes.py +++ b/src/geovista/themes.py @@ -3,7 +3,10 @@ # This file is part of GeoVista and is distributed under the 3-Clause BSD license. # See the LICENSE file in the package root directory for licensing details. -"""Configures a custom pyvista theme for geovista. +""":mod:`geovista` specialisation of PyVista :external+pyvista:doc:`api/plotting/theme`. + +To set a theme: either use :func:`set_plot_theme` or set the +``$GEOVISTA_THEME`` environment variable. Notes ----- @@ -14,11 +17,11 @@ import contextlib from enum import Enum +from os import environ +from warnings import warn from pyvista.plotting import themes as pv_themes -from . import GEOVISTA_IMAGE_TESTING - class GeoVistaTheme(pv_themes.Theme): """A PyVista theme optimised for typical GeoVista operations. @@ -67,8 +70,8 @@ def set_plot_theme(theme: str | pv_themes.Theme) -> None: theme : str or pyvista.themes.Theme The theme to apply. All inputs documented in :func:`pyvista.set_plot_theme` are accepted, as well as those - documented in :data:`NATIVE_THEMES` (e.g. ``NATIVE_THEMES.foo`` OR - ``"foo"`` work the same). + documented in :data:`NATIVE_THEMES` (e.g. ``NATIVE_THEMES.foo.value()`` + OR ``"foo"`` work the same). Warnings -------- @@ -118,7 +121,22 @@ def set_plot_theme(theme: str | pv_themes.Theme) -> None: raise ValueError(msg) from err -if not GEOVISTA_IMAGE_TESTING: - # only load the geovista theme if we're not performing image testing, - # as the default pyvista testing theme is adopted instead - set_plot_theme(GeoVistaTheme()) +def _find_and_set_plot_theme() -> None: + """:func:`set_plot_theme` from env var or default :class:`GeoVistaTheme`.""" + default_theme = NATIVE_THEMES.geovista + theme = environ.get("GEOVISTA_THEME", None) + if theme is not None: + try: + set_plot_theme(theme) + except ValueError: + message = ( + "Invalid GeoVista/PyVista theme set in $GEOVISTA_THEME: " + f"'{theme}'. Defaulting to {default_theme}. See the " + f"geovista.themes docs for other valid themes." + ) + warn(message, stacklevel=2) + theme = default_theme.value() + else: + theme = GeoVistaTheme() + + set_plot_theme(theme) From c3d55d8289b6d483f52f8cf3036af2f3241410d6 Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Tue, 30 Jan 2024 10:17:11 +0000 Subject: [PATCH 8/8] Better structure for _find_and_set_plot_theme. --- src/geovista/themes.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/geovista/themes.py b/src/geovista/themes.py index bb851b83..b312b232 100644 --- a/src/geovista/themes.py +++ b/src/geovista/themes.py @@ -135,8 +135,7 @@ def _find_and_set_plot_theme() -> None: f"geovista.themes docs for other valid themes." ) warn(message, stacklevel=2) - theme = default_theme.value() - else: - theme = GeoVistaTheme() + else: + return - set_plot_theme(theme) + set_plot_theme(default_theme.value())