|
1 | 1 | Plot sits objects. |
2 | 2 |
|
3 | | -Unified plotting function that dispatches on the type of the object passed |
4 | | -as `x`. It mirrors the many `plot` methods of the R `sits` package, |
5 | | -covering data cubes (raster, SAR, DEM, vector, RGB), probability and |
6 | | -uncertainty cubes, variance cubes, classified images, time series patterns |
7 | | -and predictions, machine learning / deep learning models, clustering and |
8 | | -self-organizing map (SOM) results, accuracy tables, and t-SNE / embedding |
9 | | -visualizations. The set of accepted keyword arguments depends on the type |
10 | | -of object being plotted. |
| 3 | +A single dispatching function that produces a plot appropriate to the type |
| 4 | +of the object passed as `x`. It covers data cubes (raster, SAR, DEM, |
| 5 | +vector), probability and uncertainty products, variance cubes, patterns, |
| 6 | +time-series predictions, embeddings, clustering and SOM outputs, accuracy |
| 7 | +tables, and trained models. Depending on the object type, the plot is |
| 8 | +rendered as a map, a chart, or a raster image. |
| 9 | + |
| 10 | +The accepted keyword arguments depend on the type of `x`. The sections |
| 11 | +below group the parameters by the kind of object being plotted. |
11 | 12 |
|
12 | 13 | Args: |
13 | | - x (SITSCubeModel | SITSTimeSeriesModel | SITSTimeSeriesPatternsModel | SITSMachineLearningMethod | SITSConfusionMatrix): Object to be |
14 | | - plotted. Supported objects include classified raster images, |
15 | | - classified segments, digital elevation model cubes, multi-year |
16 | | - land use/cover embedding predictions, sample distances, class |
17 | | - temporal patterns, probability cubes, raster, SAR, and vector |
18 | | - data cubes, confusion matrices / accuracy metrics, dendrograms, |
19 | | - trained models, time series predictions, t-SNE projections, SOM |
20 | | - results, uncertainty cubes, and variance cubes. |
| 14 | + x (SITSCubeModel | SITSTimeSeriesModel | SITSTimeSeriesPatternsModel | SITSMachineLearningMethod | SITSConfusionMatrix): |
| 15 | + Object to be plotted. Supported kinds include raster, SAR, DEM, |
| 16 | + and vector cubes; classified, probability, uncertainty, and |
| 17 | + variance cubes; patterns; time-series and embedding predictions; |
| 18 | + geographic distances; clustering and SOM outputs; accuracy |
| 19 | + tables; t-SNE projections; and trained models. |
21 | 20 | y: Ignored. Present for compatibility with the generic `plot`. |
22 | | - band (str): Band used for plotting a single-band (grey scale) image. |
23 | | - Applies to raster, SAR, DEM, and vector cubes, and to SOM maps. |
24 | | - red (str): Band assigned to the red channel of an RGB composite |
25 | | - (raster, SAR, and vector cubes). |
26 | | - green (str): Band assigned to the green channel of an RGB composite. |
27 | | - blue (str): Band assigned to the blue channel of an RGB composite. |
28 | | - tile (str): Tile to be plotted (data cubes, probability, uncertainty, |
29 | | - and variance cubes). |
| 21 | + band (str): For raster, SAR, DEM, and vector cubes, the band used to |
| 22 | + plot a grey (B/W) image. For SOM maps, the band to be plotted. |
| 23 | + red (str): Band assigned to the red channel for RGB plots of raster, |
| 24 | + SAR, and vector cubes. |
| 25 | + green (str): Band assigned to the green channel for RGB plots. |
| 26 | + blue (str): Band assigned to the blue channel for RGB plots. |
| 27 | + tile (str): Tile to be plotted (for cube objects). |
30 | 28 | dates (list[str]): Dates to be plotted (raster, SAR, and vector |
31 | 29 | cubes). |
32 | | - roi (dict | geopandas.GeoDataFrame): Spatial extent (region of |
33 | | - interest) to plot, in WGS 84. |
34 | | - labels (list[str]): Labels to plot (probability and variance cubes). |
35 | | - bands (list[str]): Bands to be viewed (patterns and time series |
36 | | - predictions). |
37 | | - legend (dict): Associates labels to colors, or a legend specification |
38 | | - for SOM plots. |
39 | | - legend_position (str): Where to place the legend (typically "inside" |
40 | | - or "outside", with defaults varying by plot type). |
41 | | - legend_title (str): Title of the legend (probability and variance |
| 30 | + roi (dict): Spatial extent (region of interest) to plot, in WGS 84. |
| 31 | + See notes. |
| 32 | + labels (list[str]): Labels to plot (probability, variance, and vector |
42 | 33 | cubes). |
43 | | - palette (str): An RColorBrewer or "cols4all" (or HCL) palette used |
44 | | - for color mapping. |
| 34 | + bands (list[str]): Bands to be viewed (for patterns and time-series |
| 35 | + predictions). |
| 36 | + legend (dict): Maps labels to colors (class cubes, SOM maps, and |
| 37 | + cluster confusion plots). |
| 38 | + legend_position (str): Where to place the legend. Typical default is |
| 39 | + `"inside"` for RGB/grey plots and `"outside"` for classified and |
| 40 | + probability maps. |
| 41 | + legend_title (str): Title of the legend for probability and variance |
| 42 | + cubes (for example `"probs"` or `"logvar"`). |
| 43 | + palette (str): An `RColorBrewer` or `cols4all` palette. For |
| 44 | + chart-based plots (predictions, embeddings, clusters, t-SNE), an |
| 45 | + HCL palette name. |
45 | 46 | rev (bool): Whether to reverse the color order in the palette. |
46 | | - scale (float): Relative scale of plot text and map (typically 0.4 to |
47 | | - 1.0). |
| 47 | + scale (float): Relative scale (roughly 0.4 to 1.0) of the plot text |
| 48 | + and map. |
48 | 49 | quantile (float): Minimum quantile to plot (probability and variance |
49 | 50 | cubes). |
50 | | - first_quantile (float): First quantile for stretching images. |
51 | | - last_quantile (float): Last quantile for stretching images. |
| 51 | + first_quantile (float): First quantile used for stretching images. |
| 52 | + last_quantile (float): Last quantile used for stretching images. |
52 | 53 | max_cog_size (int): Maximum size of COG (Cloud Optimized GeoTIFF) |
53 | | - overviews, in lines/columns or pixels. |
54 | | - seg_color (str): Color used to draw segment boundaries (vector cubes). |
55 | | - line_width (float): Line width used to draw segment boundaries |
56 | | - (vector cubes). |
57 | | - type (str): Type of plot; meaning depends on the object. For accuracy |
58 | | - objects it is "confusion_matrix" or "metrics"; for variance cubes |
59 | | - it is "map" or "hist"; for SOM maps it is "codes" or "mapping". |
60 | | - cluster: Cluster object produced by `sits_cluster_dendro`, used when |
61 | | - plotting a dendrogram. |
62 | | - cutree_height (float): Height at which to draw a dashed horizontal |
63 | | - line indicating where the dendrogram is cut. |
64 | | - name_cluster (str): Cluster to plot (SOM cluster evaluation). |
65 | | - title (str): Title of the plot (SOM cluster evaluation). |
66 | | - year_grid (bool): Whether to plot patterns as a grid of panels with |
67 | | - labels as columns and years as rows. Defaults to False. |
68 | | - tree_idx (int): Index of the tree to be plotted for an XGBoost model. |
69 | | - plot_embedding (str): For embedding predictions, either "none" (plot |
70 | | - only predicted class intervals) or "area" (overlay a smoothed |
71 | | - vertical embedding profile per year). |
72 | | - stretch (tuple[float, float]): For embedding plots, lower/upper |
73 | | - quantiles used to stretch embedding values before plotting. |
74 | | - class_alpha (float): Transparency of class polygons in embedding plots |
75 | | - (0-1). |
76 | | - area_alpha (float): Transparency of the embedding area in embedding |
77 | | - plots (0-1). |
78 | | - area_width (float): Horizontal width fraction of the embedding area. |
79 | | - area_spar (float): Smoothing parameter for the embedding area spline. |
80 | | - **kwargs (dict): Further specifications passed to the underlying plot. |
| 54 | + overviews, in lines/columns (pixels). |
| 55 | + seg_color (str): Color used for segment borders in vector cubes. |
| 56 | + line_width (float): Line width used for segment borders in vector |
| 57 | + cubes. |
| 58 | + type (str): Type of plot. For accuracy objects, either |
| 59 | + `"confusion_matrix"` or `"metrics"`. For variance cubes, `"map"` |
| 60 | + or `"hist"`. For SOM maps, `"codes"` (neuron weight time series) |
| 61 | + or `"mapping"` (number of samples per neuron). |
| 62 | + year_grid (bool): For patterns, whether to plot a grid of panels |
| 63 | + using labels as columns and years as rows (default `False`). |
| 64 | + cluster: For clustering plots, the cluster object produced by |
| 65 | + `sits_cluster_dendro`. |
| 66 | + cutree_height (float): For clustering plots, the height at which to |
| 67 | + draw a dashed horizontal line indicating where the dendrogram is |
| 68 | + cut. |
| 69 | + name_cluster (str): For SOM cluster evaluation, the cluster to plot. |
| 70 | + title (str): For SOM cluster evaluation, the title of the plot. |
| 71 | + tree_idx (int): For XGBoost models, the index of the tree to be |
| 72 | + plotted. |
| 73 | + plot_embedding (str): For embedding predictions, either `"none"` (plot |
| 74 | + only the predicted class intervals) or `"area"` (overlay a |
| 75 | + smoothed vertical embedding profile per year). |
| 76 | + stretch (list[float]): For embedding predictions, the lower and upper |
| 77 | + quantiles used to stretch embedding values before plotting |
| 78 | + (default `[0.02, 0.98]`). |
| 79 | + class_alpha (float): For embedding predictions, transparency of the |
| 80 | + class polygons in `[0, 1]` (default `0.7`). |
| 81 | + area_alpha (float): For embedding predictions, transparency of the |
| 82 | + embedding area in `[0, 1]` (default `0.25`). |
| 83 | + area_width (float): For embedding predictions, the horizontal width |
| 84 | + fraction of the embedding area along the time axis. |
| 85 | + area_spar (float): For embedding predictions, the smoothing parameter |
| 86 | + passed to the spline fit (default `0.6`); higher values produce |
| 87 | + smoother profiles. |
| 88 | + **kwargs (dict): Further specifications for the plot. The keywords |
| 89 | + understood depend on the type of `x` (see below). |
81 | 90 |
|
82 | 91 | Returns: |
83 | | - None: A plot is produced. Depending on the input type this may be a |
84 | | - color map of classified pixels, an RGB or grey-scale image, a |
85 | | - probability or uncertainty map, a variance map (optionally with |
86 | | - segment overlays), a dendrogram, a confusion matrix, a SOM map, a |
87 | | - model diagnostic plot, or a plot for patterns, predictions, |
88 | | - embeddings, and t-SNE projections. Some methods are called only for |
89 | | - their side effect of drawing the plot. |
| 92 | + None: A plot appropriate to the type of `x` is drawn. Maps of cubes |
| 93 | + yield color or B/W raster images (optionally overlaid with segment |
| 94 | + boundaries for vector cubes); probability, uncertainty, and |
| 95 | + variance cubes yield per-class or per-pixel maps; classified cubes |
| 96 | + yield color maps where each pixel is colored by its label. |
| 97 | + Chart-based plots (patterns, predictions, embeddings, clusters, |
| 98 | + t-SNE, model diagnostics) render the corresponding plot. Some |
| 99 | + methods (accuracy tables, SOM diagnostics, model summaries) are |
| 100 | + called only for their side effect of drawing the plot. |
90 | 101 |
|
91 | 102 | Notes: |
92 | | - The `roi` argument can be defined as a `dict` giving the spatial |
93 | | - extent (for example with `lon_min`, `lon_max`, `lat_min`, `lat_max`), |
94 | | - a `geopandas.GeoDataFrame`, or another spatial specification accepted |
95 | | - by `sits`. Vector cube plots overlay the segments produced by |
96 | | - `sits_segment` on top of the raster image; their appearance is |
97 | | - controlled by `seg_color` and `line_width`. |
| 103 | + The set of valid keyword arguments depends on the type of `x`; |
| 104 | + passing arguments that do not apply to a given object type has no |
| 105 | + effect. When a region of interest (`roi`) is supported, it defines |
| 106 | + the spatial extent to plot in WGS 84. |
98 | 107 |
|
99 | 108 | Examples: |
100 | 109 | from pysits import * |
101 | 110 |
|
102 | | - # Plot a set of time series patterns |
103 | | - patterns = sits_patterns(cerrado_2classes) |
| 111 | + # Plot a set of time-series patterns (one average pattern per label) |
| 112 | + patterns = sits_patterns(samples_modis_ndvi) |
104 | 113 | plot(patterns) |
105 | 114 |
|
106 | | - # Train a random forest model and plot variable importance |
107 | | - rfor_model = sits_train(samples_modis_ndvi, ml_method=sits_rfor()) |
108 | | - plot(rfor_model) |
109 | | - |
110 | | - # Plot a SOM map produced from a set of samples |
111 | | - som_map = sits_som_map(samples_modis_ndvi) |
112 | | - plot(som_map) |
| 115 | + # Train a random forest model and plot its important variables |
| 116 | + rf_model = sits_train(samples_modis_ndvi, ml_method=sits_rfor()) |
| 117 | + plot(rf_model) |
0 commit comments