<jupyter_start><jupyter_text>Assigning plate ids to featuresTo reconstruct any feature geometries, each feature must have a plate id assigned. If they don't already, then the pygplates function 'PlatePartitioner' performs this function (analogous to the 'assign plate ids' menu option in GPlates GUI) In the first example, we partition magnetic anomaly picks from the Global Seafloor Fabric and Magnetic Lineation Database (or GSFML): http://www.soest.hawaii.edu/PT/GSFML/Magnetic picks from this database can be downloaded in GPlates-friendly data formats - however, none of the points are associated with any particular plate tectonic reconstruction or plate id system. Hence, to be able to reconstruct these points, we need to assign the plate id to each point ourselves. This involves using the 'Static Polygons' - for an overview, look at the 'Creating Features' tutorial for GPlates: https://sites.google.com/site/gplatestutorials/<jupyter_code>import pygplates

# The magnetic picks are the 'features to partition'
# Since they are already in OGR GMT format, gplates can read them directly 
mag_picks = pygplates.FeatureCollection('Data/GSFML.Gaina++_2009_JGeolSoc.picks.gmt')

# static polygons are the 'partitioning features'
static_polygons = pygplates.FeatureCollection('Data/Seton_etal_ESR2012_StaticPolygons_2012.1.gpmlz')

# The partition_into_plates function requires a rotation model, since sometimes this would be
# necessary even at present day (for example to resolve topological polygons)
rotation_model=pygplates.RotationModel('Data/Seton_etal_ESR2012_2012.1.rot')

# partition features
partitioned_mag_picks = pygplates.partition_into_plates(static_polygons,
                                                       rotation_model,
                                                       mag_picks)

# Write the partitioned data set to a file
output_feature_collection = pygplates.FeatureCollection(partitioned_mag_picks)
output_feature_collection.write('/tmp/GSFML.Gaina++_2009_JGeolSoc.picks.partitioned.gmt')<jupyter_output><empty_output><jupyter_text>As a second example, we take a dataset that currently could not be loaded directly into gplates (since it is not in a gplates-readable format).The points are paleoenvironmental indicators from a map compilation by Boucot et al (2013), downloaded in from <NAME>'s rsearchgate page in csv format (all data are lat,long points with a series of other attributes).There are a number of ways to deal with this data in python, here we use a pandas dataframe<jupyter_code>import pandas as pd

df = pd.read_csv('Data/Boucot_etal_Map24_Paleocene_v4.csv',sep=',')

df<jupyter_output><empty_output><jupyter_text>There are a few ways to assign plateids, but the simplest ways generally involve putting the points into a feature collection and using the same partitioning function we used above on the.<jupyter_code># put the points into a feature collection, using Lat,Long coordinates from dataframe
point_features = []
for index,row in df.iterrows():
    point = pygplates.PointOnSphere(float(row.LAT),float(row.LONG))
    point_feature = pygplates.Feature()
    point_feature.set_geometry(point)
    point_features.append(point_feature)
    
# The partition points function can then be used as before
partitioned_point_features = pygplates.partition_into_plates(static_polygons,
                                                       rotation_model,
                                                       point_features) 

# Reconstruct the points to 60 Ma (in the Paleocene)
#reconstructed_point_features = []
pygplates.reconstruct(partitioned_point_features,
                      rotation_model,
                      '/tmp/reconstructed_points.shp',
                     60.0)  

coastlines_filename = 'Data/Seton_etal_ESR2012_Coastlines_2012.1_Polygon.gpmlz'
pygplates.reconstruct(coastlines_filename,
                      rotation_model,
                      '/tmp/reconstructed_coastlines.shp',
                     60.0)<jupyter_output><empty_output><jupyter_text>Now we can plot the reconstructed points to see their distribution in the Paleocene<jupyter_code>import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
from matplotlib.patches import Polygon

%matplotlib inline

fig = plt.figure(figsize=(14,10))
ax_map = fig.add_axes([0,0,0.9,1.0])
m = Basemap(projection='robin', lon_0=0, resolution='c', ax=ax_map)

shp_info = m.readshapefile('/tmp/reconstructed_coastlines','shp',drawbounds=True,color='w')
    
for nshape,seg in enumerate(m.shp):
    poly = Polygon(seg,facecolor='khaki',edgecolor='k',alpha=0.7)
    ax_map.add_patch(poly)
    
m.readshapefile('/tmp/reconstructed_points', 'reconstructed_points')
 
for p in m.reconstructed_points:
    m.plot(p[0], p[1], marker='o', color='m', markersize=8, markeredgewidth=2)
    
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07499486336552291, 'fraction_numerical': 0.01397164577768646, 'mean_word_length': 4.070833333333334, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '110426', 'license': 'CC-BY-3.0', 'n_tokens_mistral': 1499, 'n_tokens_neox': 1390, 'n_words': 425, 'path': 'notebooks/pygplates-assign-plateids.ipynb', 'repo_name': 'saraemp/pygplates-tutorials', 'size': '4880'}