GPlates / gplately

GPlately is a Python package to interrogate tectonic plate reconstructions.
https://gplates.github.io/gplately/
GNU General Public License v2.0
55 stars 11 forks source link

`gpml._load_FeatureCollection` does not assign `filenames` attribute #185

Closed cpalfonso closed 2 weeks ago

cpalfonso commented 4 weeks ago

If the input to gpml._load_FeatureCollection is one or more filenames, then the filenames attribute is never actually assigned (see lines 264-270 below): https://github.com/GPlates/gplately/blob/c5b0d1c075961643cb518ec227a896e6556b84de/gplately/gpml.py#L258-L274

This leads to several issues, most notably that attempting to pickle PlateReconstruction results in a reconstruction with no features:

import pickle
from gplately import PlateReconstruction
from plate_model_manager import PlateModelManager

pmm = PlateModelManager()
model = pmm.get_model("Muller2019")
plate_reconstruction = PlateReconstruction(
    rotation_model=model.get_rotation_model(),
    topology_features=model.get_layer("Topologies"),
)
pickled = pickle.loads(pickle.dumps(plate_reconstruction))
print(f"Original num. features: {len(plate_reconstruction.topology_features)}")
print(f"Pickled num. features: {len(pickled.topology_features)}")

This produces the following output:

Original num. features: 7941
Pickled num. features: 0
michaelchin commented 3 weeks ago

Maybe this is because the gplately.pygplates.FeatureCollection did not implement the getstate and setstate methods?

In fact, John told me that pygplates will support pickle very soon. In the near future, the gplately.pygplates may not be needed anymore.

michaelchin commented 2 weeks ago

Maybe this is because the gplately.pygplates.FeatureCollection did not implement the getstate and setstate methods?

In fact, John told me that pygplates will support pickle very soon. In the near future, the gplately.pygplates may not be needed anymore.

Just realised the getstate and setstate was implemented in PlateReconstruction class. Maybe better in FeatureCollection class? Anyway, it does not matter much since John will handle the pickle very soon.