Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue-250-ridge-transforms #298

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 153 additions & 7 deletions gplately/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,26 @@ def plot_subduction_teeth(*args, **kwargs):


class PlotTopologies(object):
"""A class with tools to read, reconstruct and plot topology features at specific

@property
def ridge_transforms(self):
"""Deprecated property that includes both `gpml:Transform` and `gpml:MidOceanRidge` features."""
logger.debug(
"Deprecated! The 'ridge_transforms' property will be removed in the next GPlately release. "
"You need to update your workflow to use the 'ridges' and 'transforms' properties instead, "
"otherwise your workflow will be broken by the next GPlately release.",
FutureWarning,
)
logger.debug(
"The 'ridge_transforms' property has been changed since GPlately release 1.3.0. "
"Now the 'ridge_transforms' property contains both `gpml:Transform` and `gpml:MidOceanRidge` "
"features in the reconstruction model. You need to check your workflow to make sure the new "
"'ridge_transforms' property still suits your purpose. In the previous GPlately releases, "
"the 'ridge_transforms' property contains only `gpml:MidOceanRidge` features.",
UserWarning,
)
return self.transforms + self.ridges
"""A class with tools to read, reconstruct and plot topology features at specific
reconstruction times.

`PlotTopologies` is a shorthand for PyGPlates and Shapely functionalities that:
Expand Down Expand Up @@ -692,7 +711,7 @@ def get_feature(
def plot_feature(self, ax, feature, feature_name="", color="black", **kwargs):
"""Plot pygplates.FeatureCollection or pygplates.Feature onto a map."""
if not feature:
logger.warning(
logger.warn(
f"The given feature({feature_name}:{feature}) in model:{self.plate_reconstruction.plate_model_name} is empty and will not be plotted."
)
return ax
Expand Down Expand Up @@ -723,7 +742,7 @@ def _plot_feature(self, ax, get_feature_func, **kwargs):
)

if len(gdf) == 0:
logger.warning("No feature found for plotting. Do nothing and return.")
logger.warn("No feature found for plotting. Do nothing and return.")
return ax

if hasattr(ax, "projection"):
Expand Down Expand Up @@ -837,6 +856,7 @@ def get_ridges(
tessellate_degrees=1,
):
"""Create a geopandas.GeoDataFrame object containing geometries of reconstructed mid-ocean ridge lines(gpml:MidOceanRidge)."""
logger.debug("Getting reconstructed mid-ocean ridge lines")
return self.get_feature(
self.ridges,
central_meridian=central_meridian,
Expand All @@ -846,7 +866,16 @@ def get_ridges(
@validate_topology_availability("ridges")
@append_docstring(PLOT_DOCSTRING.format("ridges"))
def plot_ridges(self, ax, color="black", **kwargs):
"""Plot reconstructed mid-ocean ridge lines(gpml:MidOceanRidge) onto a map.

logger.debug(
"The 'plot_ridges' function has been changed since GPlately release 1.3.0. "
"Now the 'plot_ridges' function plots all `gpml:MidOceanRidge` features in the reconstruction model. "
"You need to check your workflow to make sure the new 'plot_ridges' function still suits your purpose. "
"In the previous GPlately releases, the 'plot_ridges' function plots only the ridges in the "
"`gpml:MidOceanRidge` features (the transforms in the `gpml:MidOceanRidge` features are not plotted).",
UserWarning,
)
"""Plot reconstructed mid-ocean ridge lines(gpml:MidOceanRidge) onto a map.

Notes
-----
Expand All @@ -864,6 +893,7 @@ def plot_ridges(self, ax, color="black", **kwargs):
Point features near the poles (-89 & 89 degree latitude) are also clipped to ensure
compatibility with Cartopy.
"""
logger.debug("Plotting reconstructed mid-ocean ridge lines")
return self.plot_feature(
ax,
self.ridges,
Expand Down Expand Up @@ -1232,7 +1262,27 @@ def plot_plate_id(self, *args, **kwargs):
plot_plate_id.__doc__ = plot_plate_polygon_by_id.__doc__

def plot_grid(self, ax, grid, extent=[-180, 180, -90, 90], **kwargs):
"""Plot a `MaskedArray` raster or grid onto a standard map Projection.

def plot_ridges_and_transforms(self, ax, color="black", **kwargs):
"""Deprecated function to plot both ridges and transforms."""
logger.debug(
"Deprecated! The 'plot_ridges_and_transforms' function will be removed in the next GPlately release. "
"You need to update your workflow to use the 'plot_ridges' and 'plot_transforms' functions instead, "
"otherwise your workflow will be broken by the next GPlately release.",
FutureWarning,
)
logger.debug(
"The 'plot_ridges_and_transforms' function has been changed since GPlately release 1.3.0. "
"Now the 'plot_ridges_and_transforms' function plots both `gpml:Transform` and `gpml:MidOceanRidge` "
"features in the reconstruction model. You need to check your workflow to make sure the new "
"'plot_ridges_and_transforms' function still suits your purpose. In the previous GPlately releases, "
"the 'plot_ridges_and_transforms' function plots only `gpml:MidOceanRidge` features.",
UserWarning,
)
self.plot_ridges(ax, color=color, **kwargs)
self.plot_transforms(ax, color=color, **kwargs)
return ax
"""Plot a `MaskedArray` raster or grid onto a standard map Projection.

Notes
-----
Expand Down Expand Up @@ -1757,6 +1807,7 @@ def get_transforms(
tessellate_degrees=None,
):
"""Create a geopandas.GeoDataFrame object containing geometries of reconstructed transform lines(gpml:Transform)."""
logger.debug("Getting reconstructed transform boundary lines")
return self.get_feature(
self.transforms,
central_meridian=central_meridian,
Expand All @@ -1765,7 +1816,18 @@ def get_transforms(

@append_docstring(PLOT_DOCSTRING.format("transforms"))
def plot_transforms(self, ax, color="black", **kwargs):
"""Plot transform boundaries(gpml:Transform) onto a map."""

logger.debug(
"The 'plot_transforms' function has been changed since GPlately release 1.3.0. "
"Now the 'plot_transforms' function plots all the `gpml:Transform` features in the reconstruction model "
"(the transforms in the `gpml:MidOceanRidge` features are not included). "
"You need to check your workflow to make sure the new 'plot_transforms' function still suits your purpose. "
"In the previous GPlately releases, the 'plot_transforms' function plots only the transforms in the "
"`gpml:MidOceanRidge` features (the `gpml:Transform` features are not plotted).",
UserWarning,
)
"""Plot transform boundaries(gpml:Transform) onto a map."""
logger.debug("Plotting transform")
return self.plot_feature(
ax,
self.transforms,
Expand Down Expand Up @@ -1842,7 +1904,27 @@ def get_all_topologies(
@validate_topology_availability("all topologies")
@append_docstring(PLOT_DOCSTRING.format("topologies"))
def plot_all_topologies(self, ax, color="black", **kwargs):
"""Plot topological polygons and networks on a standard map projection."""

def get_ridges_and_transforms(self, central_meridian=0.0, tessellate_degrees=1):
"""Deprecated function to get both ridges and transforms."""
logger.debug(
"Deprecated! The 'get_ridges_and_transforms' function will be removed in the next GPlately release. "
"You need to update your workflow to use the 'get_ridges' and 'get_transforms' functions instead, "
"otherwise your workflow will be broken by the next GPlately release.",
FutureWarning,
)
logger.debug(
"The 'get_ridges_and_transforms' function has been changed since GPlately release 1.3.0. "
"Now the 'get_ridges_and_transforms' function returns both `gpml:Transform` and `gpml:MidOceanRidge` "
"features in the reconstruction model. You need to check your workflow to make sure the new "
"'get_ridges_and_transforms' function still suits your purpose. In the previous GPlately releases, "
"the 'get_ridges_and_transforms' function returns only `gpml:MidOceanRidge` features.",
UserWarning,
)
ridges_gdf = self.get_ridges(central_meridian=central_meridian, tessellate_degrees=tessellate_degrees)
transforms_gdf = self.get_transforms(central_meridian=central_meridian, tessellate_degrees=tessellate_degrees)
return ridges_gdf.append(transforms_gdf, ignore_index=True)
"""Plot topological polygons and networks on a standard map projection."""
if "edgecolor" not in kwargs.keys():
kwargs["edgecolor"] = color
if "facecolor" not in kwargs.keys():
Expand Down Expand Up @@ -1960,3 +2042,67 @@ def plot_topological_plate_boundaries(self, ax, color="black", **kwargs):
color=color,
**kwargs,
)

@property
def ridge_transforms(self):
"""Combine ridges and transforms into one feature set."""
if self.time is None:
raise ValueError(
"No topologies have been resolved. Set `PlotTopologies.time` to construct them."
)
logger.debug("Returning ridge_transforms property.")
return self.ridges + self.transforms

def get_ridge_transforms(self, central_meridian=0.0, tessellate_degrees=None):
"""Create a GeoDataFrame containing geometries of reconstructed ridge transforms."""
logger.debug("Getting reconstructed ridge transforms.")
return self.get_feature(
self.ridge_transforms,
central_meridian=central_meridian,
tessellate_degrees=tessellate_degrees
)

@validate_topology_availability("ridge transforms")
@append_docstring(PLOT_DOCSTRING.format("ridge transforms"))
def plot_ridge_transforms(self, ax, color="black", **kwargs):
"""Plot reconstructed ridge transforms onto a map."""
logger.debug("Plotting reconstructed ridge transforms.")
return self.plot_feature(
ax,
self.ridge_transforms,
feature_name="ridge_transforms",
edgecolor=color,
**kwargs,
)

@property
def misc_transforms(self):
"""Combine miscellaneous transforms into one feature set."""
if self.time is None:
raise ValueError(
"No topologies have been resolved. Set `PlotTopologies.time` to construct them."
)
logger.debug("Returning misc_transforms property.")
return self.transforms + self.unclassified_features

def get_misc_transforms(self, central_meridian=0.0, tessellate_degrees=None):
"""Create a GeoDataFrame containing geometries of reconstructed miscellaneous transforms."""
logger.debug("Getting reconstructed miscellaneous transforms.")
return self.get_feature(
self.misc_transforms,
central_meridian=central_meridian,
tessellate_degrees=tessellate_degrees
)

@validate_topology_availability("miscellaneous transforms")
@append_docstring(PLOT_DOCSTRING.format("miscellaneous transforms"))
def plot_misc_transforms(self, ax, color="black", **kwargs):
"""Plot reconstructed miscellaneous transforms onto a map."""
logger.debug("Plotting reconstructed miscellaneous transforms.")
return self.plot_feature(
ax,
self.misc_transforms,
feature_name="misc_transforms",
edgecolor=color,
**kwargs,
)