Due: noon Wed, Feb 4 2015 via GauchoSpace
In this lab, you’ll explore a variety of metrics used to quantify landscape ecology patterns, per the “patch mosaic paradigm”. To get a feel for these metrics, you’ll compare patterns between 2 cities in Santa Barbara County and focus on a specific landcover class.
Most of these metrics can be calculated at the level of the individual patch, in aggregate for all patches of a certain class or for all patches in every class for the entire extent of the landscape.
Patch - set of cells having the same class values connected by either 8 (default) or 4 neighbors
Class - all patches having the same landcover value
Landscape - all patches of all classess
For the purpose of this lab, the most interesting metrics are at the Class level, eg for all evergreen forest patches found in the given city, which as the extent represents the landscape. It is also interesting to visualize some of the metrics at the individual Patch level to get a feel for how the size, shape and spacing of patches is quantified by the metrics. The overall Landscape level as computed by FragStats for this lab’s data is much less interesting, since it is inclusive of all landcover types and patches.
You will explore the following broad categories of metrics as made available in FragStats (descriptions extracted from help manual):
Area and Edge are the simplest measures of a patch. At the class and landscape levels, these can be summarized with basic statistics (e.g., mean, median, max, variance, etc.). Also included is the patch radius of gyration, which can be considered the average distance an organism can move within a patch before encountering the patch boundary from a random starting point. When summarized for the class or landscape as a whole using an area-weighted mean, this metric is also known as correlation length and gives the distance that one might expect to traverse the map while staying in a particular patch, from a random starting point and moving in a random direction.
Shape, whether simple and compact or irregular and convoluted, is difficult to capture, so generally index overall shape complexity rather than attempt to assign a value to each unique shape or morphology. The most common measures of shape complexity are based on the relative amount of perimeter per unit area, usually indexed in terms of a perimeter-to-area ratio, or as a fractal dimension, and often standardized to a simple Euclidean shape (e.g., circle or square). In general, higher values mean greater shape complexity or greater departure from simple Euclidean geometry.
Core area refers to the interior area of patches after a user-specified edge buffer is eliminated. The edge buffer represents the distance at which the “core” or interior of a patch is unaffected by the edge of the patch. This “edge effect” distance is defined by the user to be relevant to the phenomenon under consideration and can either be treated as fixed or adjusted for each unique edge type. Core area integrates patch size, shape, and edge effect distance into a single measure. All else equal, smaller patches with greater shape complexity have less core area. Most metrics associated with patch area (e.g., mean patch size and variability) can be formulated in terms of core area.
Contrast refers to the relative difference among patch types (ie classes). For example, mature forest next to young forest might have a lower-contrast edge than mature forest adjacent to open field, depending on how the notion of contrast is defined. This can be computed as a contrast-weighted edge density, where each type of edge (i.e., between each pair of patch types) is assigned a contrast weight. Alternatively, this can be computed as a neighborhood contrast index, where the mean contrast between the focal patch and all patches within a user-specified neighborhood is computed based on assigned contrast weights. Note, contrast is an attribute of the edge itself, whereas core area is an attribute of the patch interior after accounting for adverse edge effects that penetrate into patches (and thus have a corresponding depth-of-edge effect).
Aggregation refers to the degree of aggregation or clumping of patch types. Aggregation is an umbrella term used to describe several closely related concepts: 1) dispersion, 2) interspersion, 3) subdivision, and 4) isolation. Each of these concepts relates to the broader concept of aggregation, but is distinct from the others in subtle but important ways. Aggregation metrics deal variously with the spatial properties of dispersion and interspersion. Dispersion refers to the spatial distribution of a patch type (i.e., how spread out or disperse it is) without explicit reference to any other patch types. Interspersion refers to the spatial intermixing of different patch types without explicit reference to the dispersion of any patch type. In the real world, however, these properties are often correlated. Not surprisingly, therefore, some aggregation metrics deal with dispersion solely, others deal with interspersion solely, and others deal with both, and thus there are a bewildering variety of metrics in this group. Many of the metrics in this group are derived from the cell adjacency matrix, in which the adjacency of patch types is first summarized in an adjacency or co-occurrence matrix, which shows the frequency with which different pairs of patch types (including like adjacencies between the same patch type) appear side-by-side on the map.
Diversity measures are influenced by 2 components: richness and evenness. Richness refers to the number of patch types present; evenness refers to the distribution of area among different types. Richness and evenness are generally referred to as the compositional and structural components of diversity, respectively. Some indices (e.g., Shannon’s diversity index) are more sensitive to richness than evenness. Thus, rare patch types have a disproportionately large influence on the magnitude of the index. Other indices (e.g., Simpson’s diversity index) are relatively less sensitive to richness and thus place more weight on the common patch types.
The overall steps are to:
Prepare data in R: crop landcover raster to chosen cities, plot maps and report landcover cell counts.
Calculate metrics in FragStats: generate patches from cropped city landcover rasters and calculate metrics.
Summarize metrics in R: output table of class metrics comparing cities, generate patches shapefile from FragStats patch id raster, join with patch metrics table and plot maps per patch metric.
Investigate results in ArcMap (optional): interactively explore patch metrics.
Instructions for your writeup are at the bottom of this document.
Download lab4_metrics.7z
from GauchoSpace into your course home directory (eg H:\esm215
). Right-click on the file -> 7-Zip -> Extract Here. Navigate into the newly expanded lab4_metrics
folder with Windows Explorer.
Right-click on lab4.Rmd
-> Open with… -> RStudio.
Set the working directory wd
variable in the first R code chunk below to wherever you extracted the lab4_metrics.z file. If you’re copying the path from the address bar of Windows Explorer (recommended to avoid misspellings), you’ll need to replace Windows backslashes \
with R friendly forward slashes /
.
Once you set the working directory, you should be able to run all the R code via the Knit HTML
button which “knits”: a) the results from executing the chunks of R code, and b) the normal text input as markdown, a text only language for rendering formatted text (headers, bold, lists, links, tables, etc). For more details, see rmarkdown.rstudio.com.
The rest of the R code will crop the landcover data to the city limits and generate an output raster to be used by FragStats. It will also produce landcover maps and landcover cell count summaries for the chosen cities.
You can initially run the code with the default cities, Santa Barbara and Goleta, to see the expected output for the remainder of the lab and ensure the basics work. Then substitute with alternative city names (see table below for exact spelling). You’ll need to choose two cities other than the default combination of Santa Barbara and Goleta, although including either with another is fine.
# set working directory
wd = 'H:/esm215/lab4_metrics'
setwd(wd)
# set city name. If city names are in alphabetical order,
# ie city_b later in alphabetical sort than city_b,
# then the tables will consistently line up.
city_a = 'Goleta'
city_b = 'Santa Barbara'
# set landcover code used to generate patches and merge metrics
patches_class = 'forest_evergreen'
Before you run the R code, you’ll need to ensure ArcMap and Fragstats are closed and not locking the files, otherwise you may get the following error:
cannot delete existing file. permission denied.
Here are the available cities in Santa Barbara County.
CITY |
---|
Goleta |
Guadalupe |
Lompoc |
Santa Maria |
Solvang |
Buellton |
Carpinteria |
Santa Barbara |
The rest of the lab is premised on choosing 2 cities (labeled *_a
and *_b
in code), so that we can zoom into a smaller area with mixed use. We’ll use “Santa Barbara” (a) and “Buellton” (b) for demonstration purposes for the rest of the lab, and you’ll choose a different combination of cities to similarly evaluate landcover metrics.
## class : RasterLayer
## dimensions : 128, 351, 44928 (nrow, ncol, ncell)
## resolution : 30, 30 (x, y)
## extent : -2158335, -2147805, 1533165, 1537005 (xmin, xmax, ymin, ymax)
## coord. ref. : +proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23 +lon_0=-96 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
## data source : H:\esm215\lab4_metrics\raster\city_a_lc11.tif
## names : city_a_lc11
## values : 11, 95 (min, max)
## class : RasterLayer
## dimensions : 270, 645, 174150 (nrow, ncol, ncell)
## resolution : 30, 30 (x, y)
## extent : -2153085, -2133735, 1527615, 1535715 (xmin, xmax, ymin, ymax)
## coord. ref. : +proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23 +lon_0=-96 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
## data source : H:\esm215\lab4_metrics\raster\city_b_lc11.tif
## names : city_b_lc11
## values : 11, 95 (min, max)
Let’s look at how many cells there are of each landcover type for both cities. When evaluating which landcover class to inspect patches, you’ll need to choose one that exists in both cities.
code | class | description | Goleta | Santa Barbara |
---|---|---|---|---|
11 | water | Open Water | 83 | 122 |
21 | dev_open | Developed, Open Space | 3077 | 16614 |
22 | dev_low | Developed, Low Intensity | 6311 | 15790 |
23 | dev_med | Developed, Medium Intensity | 8383 | 12269 |
24 | dev_hi | Developed, High Intensity | 487 | 599 |
31 | barren | Barren Land (Rock/Sand/Clay) | 150 | 91 |
42 | forest_evergreen | Evergreen Forest | 252 | 2090 |
43 | forest_mixed | Mixed Forest | 93 | 2920 |
52 | scrub_shrub | Shrub/Scrub | 372 | 3824 |
71 | grass | Grassland/Herbaceous | 2173 | 1670 |
81 | pasture | Pasture/Hay | 1113 | NA |
82 | crops | Cultivated Crops | 109 | NA |
90 | wetlands_woody | Woody Wetlands | 85 | 86 |
95 | wetlands_herb | Emergent Herbaceous Wetlands | 131 | 136 |
The following R code writes tables used as optional input files in FragStats:
Descriptors file provides landcover names to pixel values, and whether a given pixel is considered background.
Contrast file provides values to use in determining the magnitude of edge contrast for each pairwise combination of patch types. Only applicable to specific metrics. Defaulting with highest possible contrast between all patch types (1), but should be edited to something more reasonable.
Similarity file provides values to use in determining the similarity between each pairwise combination of patch types. Only applicable to specific metrics. Defaulting with lowest possible similarity between all patch types (0), but should be edited to something more reasonable.
These are all just comma-seperated value (CSV) files, so you can rename the file extension to *.csv in order to easily edit in Excel.
Let’s proceed to calculate metrics in Fragstats.
Open FragStats (eg via Start Menu and type “FragStats” in Search). Once the application opens, click New.
Register landcover rasters per city. Under the left pane Input Layers, click Add layer… GDAL GeoTiff grid (.tif) and browse (…) to the cropped landcover for city “a”, lab4_metric/raster/city_a_lc11.tif
path. Repeat for your comparison city “b”.
Note that if you change cities, you will need to Remove all layers and Add layer… again in order to register the correct number of rows and columns. Otherwise the patches might get truncated to a smaller boxed area.
Switch to the Analysis Parameters in the left pane. Select all the available levels for Sampling strategy and to generate the patch ID file. Tick the Automatically save results option and point to the lab4_metrics\fragstats
folder with the model01
(note 0
=zero) filename prefix (to be read later in R).
Parameterize Common Tables. Use the prepped common tables from above and a fixed depth of 60m (~ 2 cells) to start.
Choose some initial metrics, like the following:
Note that some metrics require parameters, such as Aggregation metrics requiring a Search Radius. If you select metrics withing specifying required parameters you’ll get an error message in the Activity Log and your run will be terminated without producing any results.
Save to file. I chose H:\esm215\lab4_metrics\fragstats\model01.fca
. You can Save over this file with further changes.
Run. Proceed. Look for any errors in the Activity Log. You’ll need to see that it output the patch id file to proceed, eg:
Patch ID file saved as: H:\esm215\lab4_metrics\raster\city_a_lc11_id8.tif
For your assignment you are expected to choose at least 2 metrics from each category (Area and Edge, Shape, Core area, Contrast, Aggregation,Diversity) which corresponds to the tabs available in the metric selection interface of Fragstats.
Notice how the available metrics and full descriptions are navigable by category via Help -> Help Contents.
Unfortunately equations are not appearing in the Help installed on the Bren lab machines (see X in upper left cell of table above). So you can also browse the fragstats.help.4.2.pdf
.
Besides being able to browse the Results pane in Fragstats, the following files are output into the fragstats folder with the prefix you specified above to Automatically save results:
These are all CSV files, which have a landscape ID (LID) column corresponding to each available landscape, ie city “a” or “b”. You will use these files to summarize class level results into table using R and explore spatially at the patch level in ArcMap.
You could also take a look in Excel (although not necessary) by adding a .csv extension to the filename and double-click to open. Or from within Excel, choose the Data tab, From Text, select All files (not just .txt, .csv) and navigate to the file (eg fragstats01.class), Delimited by comma.
As long as FragStats generated the class output file fragstats/model01.class
, the following R code will produce a table of each combination of class and metric by city.
class | metric | Goleta | Santa Barbara |
---|---|---|---|
barren | CA | 13.5000 | 8.1900 |
barren | PLAND | 0.6573 | 0.1619 |
barren | LPI | 0.4689 | 0.0463 |
crops | CA | 9.8100 | NA |
crops | PLAND | 0.4777 | NA |
crops | LPI | 0.2454 | NA |
dev_hi | CA | 43.8300 | 53.9100 |
dev_hi | PLAND | 2.1342 | 1.0656 |
dev_hi | LPI | 0.1841 | 0.0534 |
dev_low | CA | 567.9900 | 1421.1000 |
dev_low | PLAND | 27.6568 | 28.0906 |
dev_low | LPI | 4.4174 | 9.9660 |
dev_med | CA | 754.4700 | 1104.2100 |
dev_med | PLAND | 36.7369 | 21.8267 |
dev_med | LPI | 11.6438 | 13.5347 |
dev_open | CA | 276.9300 | 1495.2600 |
dev_open | PLAND | 13.4844 | 29.5565 |
dev_open | LPI | 1.4374 | 7.4647 |
forest_evergreen | CA | 22.6800 | 188.1000 |
forest_evergreen | PLAND | 1.1043 | 3.7181 |
forest_evergreen | LPI | 0.4338 | 0.5248 |
forest_mixed | CA | 8.3700 | 262.8000 |
forest_mixed | PLAND | 0.4076 | 5.1947 |
forest_mixed | LPI | 0.1271 | 0.4803 |
grass | CA | 195.5700 | 150.3000 |
grass | PLAND | 9.5228 | 2.9709 |
grass | LPI | 5.1887 | 0.3487 |
pasture | CA | 100.1700 | NA |
pasture | PLAND | 4.8775 | NA |
pasture | LPI | 3.9572 | NA |
scrub_shrub | CA | 33.4800 | 344.1600 |
scrub_shrub | PLAND | 1.6302 | 6.8029 |
scrub_shrub | LPI | 0.1402 | 0.7365 |
wetlands_herb | CA | 11.7900 | 12.2400 |
wetlands_herb | PLAND | 0.5741 | 0.2419 |
wetlands_herb | LPI | 0.2586 | 0.0498 |
wetlands_woody | CA | 7.6500 | 7.7400 |
wetlands_woody | PLAND | 0.3725 | 0.1530 |
wetlands_woody | LPI | 0.1578 | 0.0320 |
Note that you can uncomment (ie remove #
from beginning of line) the line of code above to filter the table to just the chosen patches class.
filter(str_trim(class) == patches_class) %>%
As long as FragStats generated the patch output file fragstats/model01.patch
, the following R code should output:
patch polygons per city, eg:
vector\patches_Goleta_forest_evergreen.shp
vector\patches_Santa_Barbara_forest_evergreen.shp
maps displayed below per Patch metric selected in FragStats
Now you can interactively explore the patch shapefiles generated in the previous step (vector\patches_[city]_[class].shp
) from within ArcMap.
You can add the shapefile to your map by simply dragging it over from your Catalog pane into your data frame (or use the Add Data + button).
In order to visualize difference in patch metrics you’ll want to change the Symbology of the layer(right-click on layer in Table of Contents -> Properties, Symbology tab) to Quantities, Graduated Colors and choose the Value of interest. Here’s an example of looking at GYRATE values in Goleta patches of evergreen forest.
Note how you can right-click on a given layer in the Table of Contents and select:
Properties to set Symbology, see Source and more.
Zoom to Layer to zoom the data frame to the extent of the layer.
Open Attribute Table to pull up the data for that layer. You can further select a row and see it highlighted in turquoise in the table and spatially in the map data frame. You can further right click on the left most record selector (arrow like play button) and Flash to show where the patch is or Zoom to Selected.
The screenshot above also shows landcover for the city with Transparency at 50% (right-click on layer city_a_lc11.tif or group landcover, Display tab). This makes the patches pop more visually, while still seeing neighboring landcover types, which affects the Contrast metrics.
Your assignment is to report on the metric differences between cities for a chosen class (ie patches_class
) at both the class and patch level. (The landscape level is uninformative for this lab).
You must choose at least two metrics (one at patch level, and one at class level) from each of the metric categories:
You’re encouraged to tweak parameters, including the Common Tables. You can generate your writeup as either an HTML file rendered from a reduced version of this lab4.Rmd (leave code but remove extraneous text with lab directions) or more simply as a Word document. Include:
table of class metrics by row and city by column as produced above, but for only the landcover class of your choice (not all classes, accomplished by uncommenting line of code mentioned above),
maps of patch metrics chosen (displayed above),
description of each of the chosen metrics in your own words, and
comments on comparing cities for class metrics and betwen patches for patch metrics.