Pygplates functions

Hi!

I am new to pygplates. I am running it on Apple M1. I have been able to do a fair number of things using the pygplates documentation (functions such as pygplates.reconstruct(), pygplates.resolve_topologies() seem to work fine), but some things do not seem to work entirely.

  1. When I try to make a feature collection using:
collection = pygmt.FeatureCollection("features.shp")

Everything seems to work fine. However, if I want to create a feature collection of multiple files, I get the following errors:

collection_add.("features2.gpml")
TypeError: Expected Feature or sequence of Feature's

collection = pygmt.FeatureCollection(["features.shp", "features2.gpml"])
TypeError: Expected an optional filename, or sequence of features, or a single feature

As far as I understand, “features2.gpml” is a feature and [“features.shp”, “features2.gpml”] is a sequence of features, so I’m not sure what’s going on here.

  1. When I try the script to find the length of the subduction zones surrounding a plate, I get the following error:
----> 3 topological_model = pygplates.TopologicalModel(rotation_model, rotation_model)
      4 topological_snapshot = plate_model.topological_snapshot(reconstruction_time)
      5 resolved_topologies = topological_snapshot.get_resolved_topologies()

AttributeError: module 'pygplates' has no attribute 'TopologicalModel'

Why doesn’t it recognise the function “TopologicalModel”?

Many thanks!

Thomas

Hi Thomas,

Actually by feature it means a pygplates.Feature. So feature2.gpml is a filename (which is a string), and hence not strictly a feature, or even a sequence of features. And [“features.shp”, “features2.gpml”] is a sequence of filenames (ie, a sequence of strings).

The reason the following worked…

collection = pygmt.FeatureCollection("features.shp")

…is because features.shp is a filename which satisfies an optional filename, or sequence of features, or a single feature.

Whereas…

collection = pygmt.FeatureCollection(["features.shp", "features2.gpml"])

…does not work because ["features.shp", "features2.gpml"] is a sequence of filenames which does not satisfy an optional filename, or sequence of features, or a single feature.

A pygplates.FeatureCollection is a little more restrictive in this way than functions like pygplates.reconstruct.

This is mainly to keep the idea of a feature collection as a sequence of features that are either added manually or loaded from a single file. In other words, ["features.shp", "features2.shp"] is really two different files which ideally should correspond to two different feature collections. For example, those two files could have different sets of shapefile attributes, so when you combine them things can get a little messy.

Although that wouldn’t stop you from combining two feature collections into one if you really wanted. For example:

feature_collection1 = pygplates.FeatureCollection('features1.gpml')
feature_collection2 = pygplates.FeatureCollection('features2.gpml')

combined_feature_collection = pygplates.FeatureCollection(feature_collection1)
combined_feature_collection.add(feature_collection2)

…this works because a pygplates.FeatureCollection object can be treated as a sequence of features.

Note that functions like pygplates.reconstruct are more flexible because they can accept any arbitrary combination of features. That function accepts (as its first argument reconstructable_features):

a feature collection, or filename, or feature, or sequence of features, or a sequence (eg, list or tuple) of any combination of those four types

…so you can have something quite arbitrary like:

reconstructable_features = [
    'features1.gpml',              # a filename
    'features2.gpml',              # a filename
    [a_feature, another_feature],  # a sequence of features
    yet_another_feature,           # a feature
    a_feature_collection]          # a feature collection
pygplates.reconstruct(reconstructable_features, ...)

In this way, a lot of pyGPlates functions like this are essentially using pygplates.FeaturesFunctionArgument to parse their arguments.

It’s most likely your pyGPlates version is less than 0.30. The latest public release is 0.36.

New additions are usually noted in the docs (eg, for TopologicalModel it says New in version 0.30).

To see your version you can type:

print(pygplates.__version__)

…in your script.

Or type…

python -c "import pygplates; print(pygplates.__version__)"

…on the command line.

1 Like

Hi John,

Thank you so much! The issues are resolved now!

Cheers,
Thomas

1 Like

A post was split to a new topic: Predict the future position of the plates