<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/moving-beyond-pattern-based-analysis-additional-applications-of-geopat-2/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://nowosad.github.io/post/geopat-2-extend/"> Rstats on Jakub Nowosad's website</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>This is the sixth and the last blog post in the series introducing <a rel="nofollow" href="http://sil.uc.edu/cms/index.php?id=geopat2" target="_blank">GeoPAT 2 – a software for pattern-based spatial and temporal analysis</a>.<br>
<a rel="nofollow" href="https://nowosad.github.io/post/geopat-2-segmentation" target="_blank">In the previous one</a> we presented the pattern-based spatial segmentation – a method for creating regions of homogenous patterns.<br>
Here, we will mention other pattern-based methods and show some examples of how you can use pieces of GeoPAT 2 in your own workflow.</p>
<div>
<h2>Introduction</h2>
<p>GeoPAT 2 gives its users a lot of freedom, having a large number of possible workflows:</p>
<div>
<img alt="Outline of the GeoPAT 2 architecture" src="https://i2.wp.com/nowosad.github.io/post/2018-08-28-geopat-2-extend_files/extend01.png?w=456&ssl=1" data-recalc-dims="1">
<p>Outline of the GeoPAT 2 architecture</p>
</div>
<p>Some of them can consist of only one step, while others require several steps.<br>
However, that is not the end of GeoPAT 2 capabilities – it is also possible to extract spatial signature or calculate distance matrix and use these outputs in further analysis outside of GeoPAT 2.<br>
For example, you can cluster areas of similar patterns or use machine learning methods to find numerical relationships between patterns descriptors and other variables.<br>
Finally, there are several experimental features of GeoPAT 2, including a set of methods for analysis of spatiotemporal data.</p>
<p>We are going to use land cover data of Australia from the year 2015 and <a rel="nofollow" href="http://maps.tnc.org/gis_data.html" target="_blank">TNC's terrestrial ecoregions</a> of the same area as examples in this blog post.<br>
To follow the subsequent calculations, you need to download these datasets, <a rel="nofollow" href="http://sil.uc.edu/cms/data/uploads/software_data/gpat2bp/cci_lc2015.zip" target="_blank">cci_lc2015.tif</a> and <a rel="nofollow" href="http://sil.uc.edu/cms/data/uploads/software_data/gpat2bp/tnc_terr_ecoregions.zip" target="_blank">tnc_terr_ecoregions.tif</a>, and install <a rel="nofollow" href="http://sil.uc.edu/cms/index.php?id=geopat2" target="_blank">GeoPAT 2</a>.<br>
Some examples also use <strong>rgeopat2</strong> – <a rel="nofollow" href="https://github.com/Nowosad/rgeopat2" target="_blank">an R package with additional functions for GeoPAT 2</a>:</p>
<pre><code>install.packages(&quot;rgeopat2&quot;)</code></pre>
</div>
<div>
<h2>Extracting information about spatial patterns</h2>
<p>Most of the GeoPAT 2 modules depends on spatial information about patterns in the form of <a rel="nofollow" href="https://nowosad.github.io/post/pattern-based-spatial-analysis-core-ideas/#signature" target="_blank">signatures</a>.<br>
We can then <a rel="nofollow" href="https://nowosad.github.io/post/geopat-2-search" target="_blank">find the most similar signatures (search)</a>, <a rel="nofollow" href="https://nowosad.github.io/post/geopat-2-compare" target="_blank">compare local signatures (comparison)</a>, or <a rel="nofollow" href="https://nowosad.github.io/post/geopat-2-segmentation" target="_blank">merge areas with similar signatures (segmentation)</a>.<br>
This information can be also used outside of GeoPAT 2 – it is possible to fit a spatial pattern information to your own workflow.</p>
<p>There are three main ways to extract information about spatial patterns.<br>
The first one extracts information from a regular grid of motifels.<br>
In the example below, we create a grid of motifels with information about the composition of land cover categories (<code>-s prod</code>).<br>
Next, using <code>gpat_grid2txt</code> we convert the output grid file into a text file that can be read by standard software, such as R, Python, Excel.</p>
<pre><code>gpat_gridhis -i cci_lc2015.tif -o patterns2015.grd -s prod -z 200 -f 200
gpat_grid2txt -i patterns2015.grd -o patterns2015.txt</code></pre>
<p>The second one extracts a spatial pattern information based on point coordinates within the given buffer.<br>
Below, we extract a land cover composition (Cartesian product) of a square area of 30 by 30 pixels (9km by 9km) around Australia's capital – Canberra:</p>
<pre><code>gpat_pointshis -i cci_lc2015.tif -o patterns_pts.txt -s prod -z 30 -x 1370000 -y -4050000</code></pre>
<p>The third one involves extracting information about spatial patterns using irregular polygons with <code>gpat_polygon</code>.<br>
Let's say, we are interested in extracting land cover composition in each of TNC's terrestrial ecoregions in Australia.<br>
<em>(Due to large sizes of some ecoregions, the below calculation can require about 16GB RAM available.)</em></p>
<pre><code>gpat_polygon -i cci_lc2015.tif -e tnc_terr_ecoregions.tif -o patterns_poly.txt -s prod</code></pre>
<p>To ease some of the non-standard GeoPAT 2 operations we created an R package called <strong>rgeopat2</strong>.</p>
<pre><code>library(rgeopat2)</code></pre>
<p>Its function <code>gpat_read_txt()</code> reads the output text from GeoPAT 2 and formats it in a convinent way:</p>
<pre><code>patterns_poly = gpat_read_txt(&quot;patterns_poly.txt&quot;)</code></pre>
<table>
<caption>Example of two lines from the gpat_read_txt() output</caption>
<colgroup>
<col width="2%">
<col width="4%">
<col width="4%">
<col width="2%">
<col width="4%">
<col width="4%">
<col width="4%">
<col width="4%">
<col width="4%">
<col width="4%">
<col width="3%">
<col width="4%">
<col width="3%">
<col width="4%">
<col width="4%">
<col width="4%">
<col width="4%">
<col width="3%">
<col width="4%">
<col width="4%">
<col width="4%">
<col width="3%">
<col width="4%">
<col width="5%">
</colgroup>
<thead>
<tr>
<th align="left"></th>
<th align="right">X1</th>
<th align="right">X2</th>
<th align="right">X3</th>
<th align="right">X4</th>
<th align="right">X5</th>
<th align="right">X6</th>
<th align="right">X7</th>
<th align="right">X8</th>
<th align="right">X9</th>
<th align="right">X10</th>
<th align="right">X11</th>
<th align="right">X12</th>
<th align="right">X13</th>
<th align="right">X14</th>
<th align="right">X15</th>
<th align="right">X16</th>
<th align="right">X17</th>
<th align="right">X18</th>
<th align="right">X19</th>
<th align="right">X20</th>
<th align="right">X21</th>
<th align="right">X22</th>
<th align="right">cat</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">1</td>
<td align="right">0.00</td>
<td align="right">0.00</td>
<td align="right">0</td>
<td align="right">0.00</td>
<td align="right">0.00</td>
<td align="right">0.00</td>
<td align="right">0.00</td>
<td align="right">0.00</td>
<td align="right">0.00</td>
<td align="right">0</td>
<td align="right">0.00</td>
<td align="right">0</td>
<td align="right">0.00</td>
<td align="right">0.00</td>
<td align="right">0.00</td>
<td align="right">0.00</td>
<td align="right">0</td>
<td align="right">0.00</td>
<td align="right">0.00</td>
<td align="right">0.00</td>
<td align="right">0</td>
<td align="right">1.00</td>
<td align="right">0</td>
</tr>
<tr>
<td align="left">34</td>
<td align="right">0.00</td>
<td align="right">0.00</td>
<td align="right">0</td>
<td align="right">0.00</td>
<td align="right">0.00</td>
<td align="right">0.00</td>
<td align="right">0.00</td>
<td align="right">0.00</td>
<td align="right">0.00</td>
<td align="right">0</td>
<td align="right">0.00</td>
<td align="right">0</td>
<td align="right">0.00</td>
<td align="right">0.00</td>
<td align="right">0.54</td>
<td align="right">0.45</td>
<td align="right">0</td>
<td align="right">0.00</td>
<td align="right">0.00</td>
<td align="right">0.00</td>
<td align="right">0</td>
<td align="right">0.00</td>
<td align="right">10072</td>
</tr>
</tbody>
</table>
<p>The last column in this table, <code>cat</code>, represents the id of the terrestrial ecoregion, while the rest of the columns are the land cover categories.<br>
For example, <code>cat</code> 0 is an ocean and 100% of its area is covered by water (class X22), while <code>cat</code> 10072, Gibson Desert, is located in the middle of the continent and is covered by grassland (X15) and sparse vegetation (X16).</p>
</div>
<div>
<h2>Visualize spatial grids</h2>
<p>Creating a grid of motifels is a basic task in many pattern-based analyses, which also includes selecting a size of the motifels.</p>
<pre><code>gpat_gridhis -i cci_lc2015.tif -o patterns2015.grd -s prod -z 200 -f 200</code></pre>
<p>To ease selection of a motifels' size, we can use another function from the <strong>rgeopat2</strong> package <code>gpat_create_grid()</code>.<br>
It takes a header output of the <code>gpat_gridhis</code> and produces a vectorized grid.</p>
<pre><code>my_grid = gpat_create_grid(&quot;patterns2015.grd.hdr&quot;)</code></pre>
<p>Now, you can impose it on top of your map to make a better decision about a motifel size.</p>
<div>
<img alt="A grid of motifels of 60 by 60 km imposed on the top of a land cover raster map" src="https://i2.wp.com/nowosad.github.io/post/2018-08-28-geopat-2-extend_files/extend02.png?w=456&ssl=1" data-recalc-dims="1">
<p>A grid of motifels of 60 by 60 km imposed on the top of a land cover raster map</p>
</div>
<p>This function also can be used to analyze and present the results.<br>
One of the examples here is to extract information about spatial patterns from a grid using <code>gpat_grid2txt</code>, read it to R with <code>gpat_read_txt()</code> and finally merge it with spatial data.</p>
<pre><code>library(sf)
library(dplyr)
patterns2015 = gpat_read_txt(&quot;patterns2015.txt&quot;)
my_patterns = bind_cols(my_grid, patterns2015)</code></pre>
<p>The output of this operation is a spatial object (grid of motifels) with attributes about land cover composition.</p>
</div>
<div>
<h2>Spatial pattern-based clustering</h2>
<p>Extracting spatial signatures is not the end of the GeoPAT 2 capabilities.<br>
You can also calculate similarity matrices between motifels, points, or polygons using <code>gpat_distmtx</code>.<br>
It accepts outputs from <code>gpat_grid2txt</code>, <code>gpat_pointshis</code>, or <code>gpat_polygon</code> and returns a CSV file containing a similarity matrix – also known as a distance matrix.<br>
Below, we focus on the output from <code>gpat_grid2txt</code>.<br>
Read <a rel="nofollow" href="https://zenodo.org/record/1291123" target="_blank">the GeoPAT 2 manual</a> to see examples of clustering based on the output of <code>gpat_pointshis</code> and <code>gpat_polygon</code>.</p>
<pre><code>gpat_distmtx -i patterns2015.txt -o similarity2015.csv</code></pre>
<p>The output, <code>similarity2015.csv</code>, can be read into your preferable software to apply any clustering method that depends on a distance matrix.<br>
For example, the <code>gpat_read_distmtx()</code> function can be used to read the data in R:</p>
<pre><code>dist_2015 = gpat_read_distmtx(&quot;similarity2015.csv&quot;)</code></pre>
<p>This new object, <code>dist_2015</code>, is of the <code>dist</code> class and therefore can be used by many clustering functions, including hierarchical clustering (<code>hclust()</code>), or k-medoids clustering methods (<code>cluster::pam()</code>).</p>
<p>Let's try a simple example:</p>
<pre><code>hclust_result = hclust(d = dist_2015, method = &quot;ward.D2&quot;)
plot(hclust_result, labels = FALSE)
rect.hclust(hclust_result, k = 12, border = &quot;blue&quot;)
hclust_cut = cutree(hclust_result, 12)
my_grid$class = hclust_cut
plot(my_grid[&quot;class&quot;])</code></pre>
<p>We cluster motifels based on the dissimilarity matrix output of GeoPAT 2 using hierarchical clustering (function <code>hclust()</code>).<br>
Based on the dendrogram visualization (<code>plot()</code>), we decide that the data should be divided into 12 clusters (<code>cutree()</code>):</p>
<div>
<img alt="Dendrogram representing hierarchical clustering" src="https://i0.wp.com/nowosad.github.io/post/2018-08-28-geopat-2-extend_files/extend03a.png?w=456&ssl=1" data-recalc-dims="1">
<p>Dendrogram representing hierarchical clustering</p>
</div>
<p>Finally, we add identifiers of the new clusters to our spatial object containing a grid of motifels and visualize it:</p>
<div>
<img alt="A map of Australia divided into twelve clusters based on the similarity of land cover composition" src="https://i2.wp.com/nowosad.github.io/post/2018-08-28-geopat-2-extend_files/extend03b.png?w=456&ssl=1" data-recalc-dims="1">
<p>A map of Australia divided into twelve clusters based on the similarity of land cover composition</p>
</div>
<p>The output is a map with motifels grouped into the areas of the similar land cover composition.<br>
Some of the clusters represent one dominant land cover category, e.g.Â cluster 1 is water, cluster 3 is shrubland, and cluster 7 is sparse vegetation.<br>
On the other hand, some of the clusters can consist of many land cover categories.<br>
For example, cluster 6 is a mosaic of grassland and sparse vegetation and cluster 8 is a mosaic of sparse vegetation and shrubland.</p>
</div>
<div>
<h2>Spatiotemporal pattern-based analysis</h2>
<p>GeoPAT 2 also offers several additional features, including spatiotemporal pattern-based analysis.<br>
It is highly experimental, but already can be executed and tested.<br>
Let's take a look at a couple examples from <a rel="nofollow" href="https://zenodo.org/record/1291123" target="_blank">the GeoPAT 2 manual</a>.</p>
<p>The input data is a set of twelve rasters of monthly sums of precipitation for the area of the British Isles from <a rel="nofollow" href="http://www.worldclim.org/" target="_blank">the WorldClim database</a>.<br>
Each raster has 76560 pixels (240 rows and 319 columns).<br>
In other words, each pixel has 12 values representing temporal precipitation pattern.</p>
<div>
<img alt="Monthly sums of precipitation for the area of the British Isles" src="https://i2.wp.com/nowosad.github.io/post/2018-08-28-geopat-2-extend_files/extend04a.png?w=456&ssl=1" data-recalc-dims="1">
<p>Monthly sums of precipitation for the area of the British Isles</p>
</div>
<p>Many GeoPAT 2 methods for spatial data also work with spatiotemporal datasets.<br>
For example, it is possible to regionalize the British Isles based on its annual precipitation patterns.<br>
Each region has similar temporal precipitation pattern.</p>
<p><center><br>
<img alt="Regions of the similar annual precipitation patterns for the British Isles" src="https://i0.wp.com/nowosad.github.io/post/2018-08-28-geopat-2-extend_files/extend04b.png?w=456&ssl=1" data-recalc-dims="1"><br>
</center></p>
<p>Another GeoPAT 2 application is clustering of spatiotemporal data.<br>
For example, we can extract temporal precipitation patterns of 97 largest cities in the British Isles and cluster them:</p>
<div>
<img alt="Example of a time series clustering" src="https://i0.wp.com/nowosad.github.io/post/2018-08-28-geopat-2-extend_files/extend04c.png?w=456&ssl=1" data-recalc-dims="1">
<p>Example of a time series clustering</p>
</div>
</div>
<div>
<h2>More information</h2>
<p>Previous blog posts in the series introducing <a rel="nofollow" href="http://sil.uc.edu/cms/index.php?id=geopat2" target="_blank">GeoPAT 2 – a software for pattern-based spatial and temporal analysis</a> are:</p>
<ol>
<li><a rel="nofollow" href="https://nowosad.github.io/post/geopat-2-software-for-pattern-based-spatial-and-temporal-analysis" target="_blank">GeoPAT 2: Software for Pattern-Based Spatial and Temporal Analysis</a></li>
<li><a rel="nofollow" href="https://nowosad.github.io/post/pattern-based-spatial-analysis-core-ideas" target="_blank">Pattern-based Spatial Analysis – core ideas</a></li>
<li><a rel="nofollow" href="https://nowosad.github.io/post/geopat-2-search" target="_blank">Finding similar local landscapes</a></li>
<li><a rel="nofollow" href="https://nowosad.github.io/post/geopat-2-compare" target="_blank">Quantifying temporal change of landscape pattern</a></li>
<li><a rel="nofollow" href="https://nowosad.github.io/post/geopat-2-segmentation" target="_blank">Pattern-based regionalization</a></li>
</ol>
<p>If you want to learn more about the pattern-based spatial analysis read <a rel="nofollow" href="https://zenodo.org/record/1291123" target="_blank">the official GeoPAT 2 manual</a>.<br>
It contains installation instructions, description of the GeoPAT 2 architecture, several workflow paths with examples, and explanations of numerical signatures, dissimilarity measures, and topologies available in GeoPAT 2.</p>
<p>We also encourage users to submit issues and enhancement requests so we may continue to improve our software.<br>
Furthermore, if you have any question related to GeoPAT 2 please email me at <a rel="nofollow" href="mailto:nowosad.jakub@gmail.com" target="_blank">nowosad.jakub@gmail.com</a>.</p>
</div>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://nowosad.github.io/post/geopat-2-extend/"> Rstats on Jakub Nowosad's website</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/Tt-s1BLvd58" height="1"></a></div>