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.

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):

The overall steps are to:

  1. Prepare data in R: crop landcover raster to chosen cities, plot maps and report landcover cell counts.

  2. Calculate metrics in FragStats: generate patches from cropped city landcover rasters and calculate metrics.

  3. 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.

  4. Investigate results in ArcMap (optional): interactively explore patch metrics.

Instructions for your writeup are at the bottom of this document.

1 Download Zip

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.

2 Prepare Data in R

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'

# 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.

Read County Data

plot of chunk read landcover data

Here are the available cities in Santa Barbara County.

Santa Maria
Santa Barbara

Crop to Cities

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.

City A: Goleta

## 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)

plot of chunk crop city a

City B: Santa Barbara

## 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)

plot of chunk crop city b

Summarize Class Frequency

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

Create FragStats Tables

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.

3 Calculate Metrics in FragStats

Parameterize Model

Let’s proceed to calculate metrics in Fragstats.

  1. Open FragStats (eg via Start Menu and type “FragStats” in Search). Once the application opens, click New.

  2. 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.

  3. 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).

  4. Parameterize Common Tables. Use the prepped common tables from above and a fixed depth of 60m (~ 2 cells) to start.

  5. Choose some initial metrics, like the following:

    • Patch metrics, Area - Edge: AREA, PERIM, GYRATE
    • Class metrics, Area - Edge: CA/TA, PLAND, LPI
    • Landscape metrics, Area - Edge: CA/TA, LPI

    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.

  6. Save to file. I chose H:\esm215\lab4_metrics\fragstats\model01.fca. You can Save over this file with further changes.

  7. 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

Read Help

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.