Spatiotemporal analysis#

class pylandstats.SpatioTemporalAnalysis(landscapes, *, dates=None, neighborhood_rule=None, **landscape_kws)[source]#

Spatio-temporal analysis.

__init__(landscapes, *, dates=None, neighborhood_rule=None, **landscape_kws)[source]#

Initialize the spatio-temporal analysis.

Parameters:
  • landscapes (list-like) – A list-like of Landscape instances or of strings/file-like/pathlib.Path objects so that each is passed as the landscape argument of Landscape.__init__.

  • dates (list-like, optional) – A list-like of ints or strings that label the date of each snapshot of landscapes (for DataFrame indices and plot labels).

  • neighborhood_rule ({'8', '4'}, optional) – Neighborhood rule to determine patch adjacencies, i.e: ‘8’ (queen’s case/Moore neighborhood) or ‘4’ (rook’s case/Von Neumann neighborhood). Ignored if the passed-in landscapes are Landscape instances. If no value is provided and the passed-in landscapes are file-like objects or paths, the default value set in settings.DEFAULT_NEIGHBORHOOD_RULE will be taken.

  • landscape_kws (dict, optional) –

    Other keyword arguments to be passed to the instantiation of pylandstats.Landscape for each element of landscapes. Ignored if the

    elements of landscapes are already instances of pylandstats.Landcape.

compute_class_metrics_df(*, metrics=None, classes=None, metrics_kws=None, fillna=None)[source]#

Compute the data frame of class-level metrics, which is multi-indexed by the class and date.

Parameters:
  • metrics (list-like, optional) – A list-like of strings with the names of the metrics that should be computed in the context of this analysis case.

  • classes (list-like, optional) – A list-like of ints or strings with the class values that should be considered in the context of this analysis case.

  • metrics_kws (dict, optional) – Dictionary mapping the keyword arguments (values) that should be passed to each metric method (key), e.g., to exclude the boundary from the computation of total_edge, metric_kws should map the string ‘total_edge’ (method name) to {‘count_boundary’: False}. The default empty dictionary will compute each metric according to FRAGSTATS defaults.

  • fillna (bool, optional) – Whether NaN values representing landscapes with no occurrences of patches of the provided class should be replaced by zero when appropriate, e.g., area and edge metrics (no ocurrences mean zero area/edge). If the provided value is None (default), the value will be taken from settings.CLASS_METRICS_DF_FILLNA.

Returns:

df – Dataframe with the values computed for each class, date (multi-index) and metric (columns).

Return type:

pandas.DataFrame

compute_landscape_metrics_df(*, metrics=None, metrics_kws=None)[source]#

Computes the data frame of landscape-level metrics, which is indexed by the date.

Parameters:
  • metrics (list-like, optional) – A list-like of strings with the names of the metrics that should be computed. If None, all the implemented landscape-level metrics will be computed.

  • metrics_kws (dict, optional) – Dictionary mapping the keyword arguments (values) that should be passed to each metric method (key), e.g., to exclude the boundary from the computation of total_edge, metric_kws should map the string ‘total_edge’ (method name) to {‘count_boundary’: False}. The default empty dictionary will compute each metric according to FRAGSTATS defaults.

Returns:

df – Dataframe with the values computed at the landscape level for each date (index) and metric (columns).

Return type:

pandas.DataFrame

plot_landscapes(*, cmap=None, legend=True, subplots_kws=None, show_kws=None, subplots_adjust_kws=None)#

Plot each landscape snapshot in a dedicated matplotlib axis.

Uses the Landscape.plot_landscape method of each instance.

Parameters:
  • cmap (str or ~matplotlib.colors.Colormap, optional) – A Colormap instance.

  • legend (bool, optional) – If True, display the legend of the land use/cover color codes.

  • subplots_kws (dict, default None) – Keyword arguments to be passed to matplotlib.pyplot.subplots.

  • show_kws (dict, default None) – Keyword arguments to be passed to rasterio.plot.show.

  • subplots_adjust_kws (dict, default None) – Keyword arguments to be passed to matplotlib.pyplot.subplots_adjust.

Returns:

fig – The figure with its corresponding plots drawn into its axes.

Return type:

matplotlib.figure.Figure

plot_metric(metric, *, class_val=None, ax=None, metric_legend=True, metric_label=None, fmt='--o', plot_kws=None, subplots_kws=None, metric_kws=None)#

Plot the metric.

Parameters:
  • metric (str) – A string indicating the name of the metric to plot.

  • class_val (int, optional) – If provided, the metric will be plotted at the level of the corresponding class, otherwise it will be plotted at the landscape level.

  • ax (axis object, optional) – Plot in given axis; if None creates a new figure.

  • metric_legend (bool, default True) – Whether the metric label should be displayed within the plot (as label of the y-axis).

  • metric_label (str, optional) – Label of the y-axis to be displayed if metric_legend is True. If the provided value is None, the label will be taken from the settings module.

  • fmt (str, default '--o') – A format string for matplotlib.pyplot.plot.

  • plot_kws (dict, default None) – Keyword arguments to be passed to matplotlib.pyplot.plot.

  • subplots_kws (dict, default None) – Keyword arguments to be passed to matplotlib.pyplot.plot.subplots only if no axis is given (through the ax argument).

  • metric_kws (dict, default None) – Keyword arguments to be passed to the method that computes the metric (specified in the metric argument) for each landscape.

Returns:

ax – Returns the Axes object with the plot drawn onto it.

Return type:

matplotlib.axes.Axes