Due: noon Wed, Feb 4 2015 via GauchoSpace

Introduction

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

Read County Data

plot of chunk read landcover data

Here are the available cities in Santa Barbara County.

CITY
Goleta
Guadalupe
Lompoc
Santa Maria
Solvang
Buellton
Carpinteria
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.

Explore Results

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:

  • model01.patch: patch metrics, each unique patch per row with columns of selected patch metrics
  • model01.class: class metrics, each unique landcover class per row with columns of selected class metrics
  • model01.land: landscape metrics, just one row for all patches across all metrics with columns of selected landscape metrics
  • model01.adj: class adjacency matrix, pair-wise counts of class edges shared

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.

4 Summarize Class Metrics as Table in R

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

5 Display Patch Metrics as Maps in R

As long as FragStats generated the patch output file fragstats/model01.patch, the following R code should output:

plot of chunk generate patch polygonsplot of chunk generate patch polygonsplot of chunk generate patch polygonsplot of chunk generate patch polygonsplot of chunk generate patch polygonsplot of chunk generate patch polygonsplot of chunk generate patch polygonsplot of chunk generate patch polygonsplot of chunk generate patch polygonsplot of chunk generate patch polygonsplot of chunk generate patch polygonsplot of chunk generate patch polygons

6 Explore Patch Metrics Spatially in ArcMap

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:

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.

Assignment

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: