Pygplates.reconstruct(): FeatureCollection question

Hi all,

is there some way to maintain a grouping of feature collections when these are fed to pygplates.reconstruct()? So the basic workflow is:

  • read multiple files into myFC = pygplates.FeatureCollection.read(["Mycoastline.shp", "mypolygons.shp", "mypoints.shp"]) - here I still have a list of 3 feature collections.
  • pygplates.reconstruct( myFC, rotFC, notBayernMunichFC, reconTime). This now seems to return a concatenated feature collection of the above SHP files

Can I maintain the separate reconstructed geometry feature collections (as per input feature collection) while still calling pygplates.reconstruct() just once?

Thanks,
Christian

Hi Christian,

The output is always a single sequence of features. So if you output to a file then it’s always a single file containing whatever conglomeration of input features you passed it. Note that the features are output in the order of the input features (even if there are multiple input feature collections / files).

You’d have to do multiple pygplates.reconstruct calls with something like:

rotation_model = pygplates.RotationModel(rotFC)

pygplates.reconstruct("MyCoastline.shp", rotation_model, "MyReconCoastline.shp", reconTime)
pygplates.reconstruct("MyPolygons.shp", rotation_model, "MyReconPolygons.shp", reconTime)
pygplates.reconstruct("MyPoints.shp", rotation_model, "MyReconPoints.shp", reconTime)

…or, even better, process a list of input filenames in a loop.

@john.cannon - clear, thanks for the explanation!

I guess one could try to untangle the sequence of reconstructed features by looking at the length of the input feature collections or something similar but that’s probably the same as running a couple of calls to pygplates.reconstruct() for different FCs from a compute time perspective.

That could work, although some features might disappear (outside their time period) and not get included in the output. And some features could have more than one geometry (but you could get around that with the group_with_feature option).

Yes I think they’re probably roughly similar, as long as the rotations (in the form of feature collections or files) have been pre-loaded into a pygplates.RotationModel. This way each pygplates.reconstruct() call doesn’t have to do that internally (resulting in duplicated work). It’s also the reason why, in general, I pre-load any input files into pygplates.FeatureCollection’s (as you have done) before I reconstruct features, resolve topologies, etc.

1 Like

@john.cannon - yes, am pre-loading the data into the rotation model and feature collections, so that’s good to hear that I’ve got that right :slight_smile:

On this note - is there a plan to have pygplates.reconstruct to return a Pandas or GeoPandas dataframe object? I’d like to avoid writing files to disk for later plotting but would like to retain the option to filter/select the returned data without writing temporary files to disk.

You could output to a Python list (instead of a temporary file).

For example, to filter all features whose reconstructed geometries are in the Northern hemisphere (at a specified time):

# Reconstruct features to 'reconTime'.
recon_features = []
pygplates.reconstruct("my_features.shp", rotation_model, recon_features, reconTime, group_with_feature=True)

# Find those features with any reconstructed geometry overlapping Northern hemisphere.
filtered_features = []
for feature, recon_feature_geometries in recon_features:
    if any(pygplates.GeometryOnSphere.distance(recon_feat_geom.get_reconstructed_geometry(), pygplates.PointOnSphere.north_pole) < 0.5*math.pi for recon_feat_geom in recon_feature_geometries):
        filtered_features.append(feature)

# Write filtered features to a file.
pygplates.FeatureCollection(filtered_features).write("my_filtered_features.gpml")