Examples
Use with pyGPlates
The Python code snippet below demonstrates how to use PMM with pyGPlates to reconstruct a point feature at (0,0) to 140 Ma using the Zahirovic2022 plate model. The static polygon and rotation model files are automatically downloaded by PMM.
1import pygplates
2
3from plate_model_manager import PlateModelManager
4
5pm_manager = PlateModelManager()
6model = pm_manager.get_model("Zahirovic2022")
7
8# create a point feature at (0,0)
9point_feature = pygplates.Feature()
10point_feature.set_geometry(pygplates.PointOnSphere(0, 0))
11
12# assign plate ID
13point_feature_with_PID = pygplates.partition_into_plates(
14 model.get_static_polygons(), # 👈👀 LOOK HERE
15 model.get_rotation_model(), # 👈👀 LOOK HERE
16 [point_feature],
17)
18
19# Reconstruct the point features.
20reconstructed_feature_geometries = []
21time = 140
22pygplates.reconstruct(
23 point_feature_with_PID,
24 model.get_rotation_model(), # 👈👀 LOOK HERE
25 reconstructed_feature_geometries,
26 time,
27)
28print(reconstructed_feature_geometries[0].get_reconstructed_geometry().to_lat_lon())
Use with GPlately
The Python code snippet below demonstrates how to use PMM with GPlately to create a PlateReconstruction object and PlotTopologies object. It also shows how to get present-day and paleo rasters from PMM and create Raster objects.
1from gplately import (
2PlateModelManager,
3PlateReconstruction,
4PlotTopologies,
5PresentDayRasterManager,
6Raster,
7)
8from plate_model_manager import ReferenceFrame, GenerationMethod
9
10model = PlateModelManager().get_model(
11 "Zahirovic2022", # model name
12 data_dir="plate-model-repo", # the folder to save the model files
13)
14
15recon_model = PlateReconstruction(
16 model.get_rotation_model(),
17 topology_features=model.get_layer("Topologies"),
18 static_polygons=model.get_layer("StaticPolygons"),
19)
20gplot = PlotTopologies(
21 recon_model,
22 coastlines=model.get_layer("Coastlines"),
23 COBs=model.get_layer("COBs", return_none_if_not_exist=True),
24 time=55,
25)
26# get present-day topography raster
27raster = Raster(PresentDayRasterManager().get_raster("topography"))
28# get paleo-agegrid raster at 100Ma from Zahirovic2022 model
29agegrid = Raster(
30 model.get_raster(
31 "AgeGrids",
32 time=100,
33 reference_frame=ReferenceFrame.PmagReferenceFrame,
34 generated_from=GenerationMethod.Topologies,
35 )
36)
See also
Examples of using PMM with GPlately:
Use without Internet
The Python code snippet below assumes you have already downloaded the Zahirovic2022 model into the plate-model-repo folder while connected to the Internet. When you run the code snippet below without Internet connection, PMM will try to load the model files from the local plate-model-repo folder. If the model files are found, PMM will load them in readonly mode and print a warning message. If the model files are not found, PMM will raise an exception.
See also
1from plate_model_manager import PlateModel
2
3try:
4 model = PlateModelManager().get_model("Zahirovic2022", data_dir="plate-model-repo")
5except:
6 # if unable to connect to the servers, try to use the local files
7 model = PlateModel(
8 model_name="Zahirovic2022", data_dir="plate-model-repo", readonly=True
9 )
10 print("Unable to connect to the servers. Using local files in readonly mode.")
11
12for layer in model.get_avail_layers():
13 print(model.get_layer(layer))
Use with joblib
For better performance, load static polygon files inside each worker process instead of loading them once in the main process and passing the loaded data to workers. pygplates.FeatureCollection objects can take a long time to pickle and unpickle.
1from joblib import Parallel, delayed
2import gplately
3from plate_model_manager import PlateModelManager
4
5
6def worker_task(index, static_polygons_files):
7 static_polygons = gplately.gpml.load_feature_collection_from_files(
8 static_polygons_files
9 )
10 print(f"Worker {index} is processing {len(static_polygons)} static polygons.")
11 return
12
13
14static_polygons_files = (
15 PlateModelManager().get_model("Zahirovic2022").get_static_polygons()
16)
17
18Parallel(n_jobs=4)(
19 delayed(worker_task)(idx, static_polygons_files) for idx in range(10)
20)