From e7a9ca1d61e6ab503ee6d259dd072be638260b90 Mon Sep 17 00:00:00 2001 From: Ben Mather Date: Thu, 9 Nov 2023 11:40:44 +1100 Subject: [PATCH 1/3] add Band1 as a recognised z variable --- gplately/grids.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gplately/grids.py b/gplately/grids.py index 135fe45d..4938960e 100644 --- a/gplately/grids.py +++ b/gplately/grids.py @@ -180,7 +180,7 @@ def find_label(keys, labels): # possible permutations of lon/lat/z label_lon = ['lon', 'lons', 'longitude', 'x', 'east', 'easting', 'eastings'] label_lat = ['lat', 'lats', 'latitude', 'y', 'north', 'northing', 'northings'] - label_z = ['z', 'data', 'values'] + label_z = ['z', 'data', 'values', 'Band1'] # add capitalise and upper case permutations label_lon = label_lon + [label.capitalize() for label in label_lon] + [label.upper() for label in label_lon] From 6f8669daff9a3421a3cb8d7423cbd6cb8bf935c6 Mon Sep 17 00:00:00 2001 From: Ben Mather Date: Thu, 9 Nov 2023 11:47:24 +1100 Subject: [PATCH 2/3] fix anchor plate IDs for subduction zone, MOR tessellation functions --- gplately/reconstruction.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/gplately/reconstruction.py b/gplately/reconstruction.py index 358c2a6d..f191e9e5 100644 --- a/gplately/reconstruction.py +++ b/gplately/reconstruction.py @@ -45,21 +45,23 @@ def __init__( rotation_model, topology_features=None, static_polygons=None, - default_anchor_plate_id=0, + anchor_plate_id=0, ): if hasattr(rotation_model, "reconstruction_identifier"): self.name = rotation_model.reconstruction_identifier else: self.name = None + self.anchor_plate_id = int(anchor_plate_id) self.rotation_model = _RotationModel( - rotation_model, default_anchor_plate_id=default_anchor_plate_id + rotation_model, default_anchor_plate_id=anchor_plate_id ) self.topology_features = _load_FeatureCollection(topology_features) self.static_polygons = _load_FeatureCollection(static_polygons) def __getstate__(self): - filenames = {"rotation_model": self.rotation_model.filenames} + filenames = {"rotation_model": self.rotation_model.filenames, + "anchor_plate_id": self.anchor_plate_id} if self.topology_features: filenames["topology_features"] = self.topology_features.filenames @@ -78,7 +80,7 @@ def __getstate__(self): def __setstate__(self, state): # reinstate unpicklable items - self.rotation_model = _RotationModel(state["rotation_model"]) + self.rotation_model = _RotationModel(state["rotation_model"], default_anchor_plate_id=state["anchor_plate_id"]) self.topology_features = None self.static_polygons = None @@ -172,6 +174,8 @@ def tessellate_subduction_zones( The delta time interval used for velocity calculations is, by default, assumed to be 1Ma. """ + anchor_plate_id = kwargs.pop("anchor_plate_id", self.anchor_plate_id) + if ignore_warnings: with warnings.catch_warnings(): warnings.simplefilter("ignore") @@ -180,6 +184,7 @@ def tessellate_subduction_zones( self.topology_features, tessellation_threshold_radians, float(time), + anchor_plate_id=anchor_plate_id, **kwargs ) @@ -189,6 +194,7 @@ def tessellate_subduction_zones( self.topology_features, tessellation_threshold_radians, float(time), + anchor_plate_id=anchor_plate_id, **kwargs ) @@ -464,6 +470,8 @@ def tessellate_mid_ocean_ridges( * spreading velocity magnitude (in cm/yr) * length of arc segment (in degrees) that current point is on """ + anchor_plate_id = kwargs.pop("anchor_plate_id", self.anchor_plate_id) + if ignore_warnings: with warnings.catch_warnings(): warnings.simplefilter("ignore") @@ -474,6 +482,7 @@ def tessellate_mid_ocean_ridges( float(time), tessellation_threshold_radians, spreading_feature_types, + anchor_plate_id=anchor_plate_id, **kwargs ) @@ -485,6 +494,7 @@ def tessellate_mid_ocean_ridges( float(time), tessellation_threshold_radians, spreading_feature_types, + anchor_plate_id=anchor_plate_id, **kwargs ) @@ -599,7 +609,7 @@ def total_ridge_length(self, time, use_ptt=False, ignore_warnings=False): return total_ridge_length_kms - def reconstruct(self, feature, to_time, from_time=0, anchor_plate_id=0, **kwargs): + def reconstruct(self, feature, to_time, from_time=0, anchor_plate_id=None, **kwargs): """Reconstructs regular geological features, motion paths or flowlines to a specific geological time. Parameters @@ -657,6 +667,10 @@ def reconstruct(self, feature, to_time, from_time=0, anchor_plate_id=0, **kwargs from_time, to_time = float(from_time), float(to_time) reconstructed_features = [] + + if not anchor_plate_id: + anchor_plate_id = self.anchor_plate_id + pygplates.reconstruct( feature, self.rotation_model, @@ -780,7 +794,7 @@ def create_motion_path( lats, time_array, plate_id=None, - anchor_plate_id=0, + anchor_plate_id=None, return_rate_of_motion=False, ): """Create a path of points to mark the trajectory of a plate's motion @@ -846,6 +860,9 @@ def create_motion_path( query_plate_id = False plate_ids = np.ones(len(lons), dtype=int) * plate_id + if not anchor_plate_id: + anchor_plate_id = self.anchor_plate_id + seed_points = zip(lats, lons) for i, lat_lon in enumerate(seed_points): seed_points_at_digitisation_time = pygplates.PointOnSphere( From 6e33a7b2cafca09d9905f20f0c98f4888967d90c Mon Sep 17 00:00:00 2001 From: Ben Mather Date: Thu, 9 Nov 2023 12:06:40 +1100 Subject: [PATCH 3/3] implement in reconstruct and reconstruct_to_birth_age in Points object --- gplately/reconstruction.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/gplately/reconstruction.py b/gplately/reconstruction.py index f191e9e5..98e8e9e9 100644 --- a/gplately/reconstruction.py +++ b/gplately/reconstruction.py @@ -626,10 +626,10 @@ def reconstruct(self, feature, to_time, from_time=0, anchor_plate_id=None, **kwa The specific geological time to reconstruct from. By default, this is set to present day. Raises `NotImplementedError` if `from_time` is not set to 0.0 Ma (present day). - anchor_plate_id : int, default=0 + anchor_plate_id : int, default=None Reconstruct features with respect to a certain anchor plate. By default, reconstructions are made - with respect to the absolute reference frame, like a stationary geological element (e.g. a mantle - plume). This frame is given the plate ID of 0. + with respect to the absolute reference frame (anchor_plate_id = 0), like a stationary object in the mantle, + unless otherwise specified. **reconstruct_type : ReconstructType, default=ReconstructType.feature_geometry The specific reconstruction type to generate based on input feature geometry type. Can be provided as @@ -1420,7 +1420,7 @@ def get_geodataframe(self): """ return self.get_geopandas_dataframe() - def reconstruct(self, time, anchor_plate_id=0, return_array=False, **kwargs): + def reconstruct(self, time, anchor_plate_id=None, return_array=False, **kwargs): """Reconstructs regular geological features, motion paths or flowlines to a specific geological time and extracts the latitudinal and longitudinal points of these features. @@ -1432,10 +1432,10 @@ def reconstruct(self, time, anchor_plate_id=0, return_array=False, **kwargs): time : float The specific geological time (Ma) to reconstruct features to. - anchor_plate_id : int, default=0 + anchor_plate_id : int, default=None Reconstruct features with respect to a certain anchor plate. By default, reconstructions are made - with respect to the absolute reference frame, like a stationary geological element (e.g. a mantle - plume). This frame is given the plate ID of 0. + with respect to the anchor_plate_ID specified in the `gplately.PlateReconstruction` object, + which is a default plate ID of 0 unless otherwise specified. return_array : bool, default False Return a `numpy.ndarray`, rather than a `Points` object. @@ -1472,6 +1472,10 @@ def reconstruct(self, time, anchor_plate_id=0, return_array=False, **kwargs): """ from_time = self.time to_time = time + + if not anchor_plate_id: + anchor_plate_id = self.plate_reconstruction.anchor_plate_id + reconstructed_features = self.plate_reconstruction.reconstruct( self.features, to_time, from_time, anchor_plate_id=anchor_plate_id, **kwargs ) @@ -1490,7 +1494,7 @@ def reconstruct(self, time, anchor_plate_id=0, return_array=False, **kwargs): gpts.add_attributes(**self.attributes.copy()) return gpts - def reconstruct_to_birth_age(self, ages, anchor_plate_id=0, **kwargs): + def reconstruct_to_birth_age(self, ages, anchor_plate_id=None, **kwargs): """Reconstructs point features supplied to the `Points` object from the supplied initial time (`self.time`) to a range of times. The number of supplied times must equal the number of point features supplied to the Points object. @@ -1499,10 +1503,10 @@ def reconstruct_to_birth_age(self, ages, anchor_plate_id=0, **kwargs): ages : array Geological times to reconstruct features to. Must have the same length as the `Points `object's `self.features` attribute (which holds all point features represented on a unit length sphere in 3D Cartesian coordinates). - anchor_plate_id : int, default=0 + anchor_plate_id : int, default=None Reconstruct features with respect to a certain anchor plate. By default, reconstructions are made - with respect to the absolute reference frame, like a stationary geological element (e.g. a mantle - plume). This frame is given the plate ID of 0. + with respect to the anchor_plate_ID specified in the `gplately.PlateReconstruction` object, + which is a default plate ID of 0 unless otherwise specified. **kwargs Additional keyword arguments for the `gplately.PlateReconstruction.reconstruct` method. @@ -1534,6 +1538,9 @@ def reconstruct_to_birth_age(self, ages, anchor_plate_id=0, **kwargs): """ from_time = self.time + if not anchor_plate_id: + anchor_plate_id = self.plate_reconstruction.anchor_plate_id + ages = np.array(ages) if len(ages) != len(self.features):