Skip to content

Commit

Permalink
refresh data
Browse files Browse the repository at this point in the history
  • Loading branch information
mstrimas committed Nov 30, 2023
1 parent 73a047c commit 420d893
Show file tree
Hide file tree
Showing 49 changed files with 77,769 additions and 78,067 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ Imports:
tidyverse,
units,
unmarked,
verification,
viridis
Encoding: UTF-8
RoxygenNote: 7.2.3
8 changes: 6 additions & 2 deletions abundance.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@ The relative abundance model presented here is similar to and a natural extensio

## Data preparation {#sec-encounter-data}

Let's get started by loading the necessary packages and data. If you worked through the previous chapters, you should have all the data required for this chapter. However, you may want to [download the data package](https://github.com/ebird/ebird-best-practices/raw/main/data/ebird-best-practices-data.zip), and unzip it to your project directory, to ensure you're working with exactly the same data as was used in the creation of this guide.
Let's get started by loading the necessary packages and data. If you worked through the previous chapters, you should have all the data required for this chapter. However, you may want to [download the data package](https://github.com/ebird/ebird-best-practices/raw/main/data-raw/ebird-best-practices-data.zip), and unzip it to your project directory, to ensure you're working with exactly the same data as was used in the creation of this guide.

```{r}
#| label: encounter-data-load
library(dplyr)
library(ebirdst)
library(fields)
library(ggplot2)
library(gridExtra)
library(lubridate)
library(mccf1)
library(ranger)
library(readr)
library(scam)
library(sf)
library(terra)
library(tidyverse)
library(tidyr)
# set random number seed to insure fully repeatable results
set.seed(1)
Expand Down
Binary file added data-raw/ebird-best-practices-data.zip
Binary file not shown.
Binary file removed data-raw/landcover_mcd12q1_umd_us-ga_2013-2021.tif
Binary file not shown.
Binary file not shown.
31,612 changes: 15,302 additions & 16,310 deletions data/checklists-zf_woothr_jun_us-ga.csv

Large diffs are not rendered by default.

Binary file removed data/ebird-best-practices-data.zip
Binary file not shown.
87,483 changes: 43,238 additions & 44,245 deletions data/environmental-variables_checklists_jun_us-ga.csv

Large diffs are not rendered by default.

33,816 changes: 16,908 additions & 16,908 deletions data/environmental-variables_prediction-grid_us-ga.csv

Large diffs are not rendered by default.

Binary file modified data/gis-data.gpkg
Binary file not shown.
102 changes: 53 additions & 49 deletions docs/abundance.html

Large diffs are not rendered by default.

Binary file modified docs/abundance_files/figure-html/abundance-predict-map-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
603 changes: 321 additions & 282 deletions docs/ebird.html

Large diffs are not rendered by default.

Binary file modified docs/ebird_files/figure-html/ebird-effort-sol-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/ebird_files/figure-html/ebird-explore-distance-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/ebird_files/figure-html/ebird-explore-duration-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/ebird_files/figure-html/ebird-explore-map-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/ebird_files/figure-html/ebird-explore-observers-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/ebird_files/figure-html/ebird-explore-time-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/ebird_files/figure-html/ebird-import-distance-sol-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
177 changes: 91 additions & 86 deletions docs/encounter.html

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/encounter_files/figure-html/encounter-habitat-pd-sol-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/encounter_files/figure-html/encounter-habitat-pi-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/encounter_files/figure-html/encounter-predict-map-er-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/encounter_files/figure-html/encounter-predict-map-range-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/encounter_files/figure-html/encounter-rf-cal-plot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/encounter_files/figure-html/encounter-sss-map-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 15 additions & 15 deletions docs/envvar.html
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ <h2 data-number="3.1" class="anchored" data-anchor-id="sec-envvar-intro"><span c
</section>
<section id="sec-envvar-landcover" class="level2" data-number="3.2">
<h2 data-number="3.2" class="anchored" data-anchor-id="sec-envvar-landcover"><span class="header-section-number">3.2</span> Landcover</h2>
<p>For the examples in this guide, we’ll use land cover variables derived from the <a href="https://lpdaac.usgs.gov/products/mcd12q1v006/">MODIS MCD12Q1 v006</a> land cover product <span class="citation" data-cites="friedlMCD12Q1MODISTerra2015">(<a href="references.html#ref-friedlMCD12Q1MODISTerra2015" role="doc-biblioref">Friedl and Sulla-Menashe 2015</a>)</span>. This product has global coverage at 500m spatial resolution and annual temporal resolution from 2001-2021. These data are available for several different classification schemes. We’ll use the University of Maryland classification system, which provides a globally accurate classification of land cover in our experience. This system classifies pixels into one of 15 different land cover classes. The <code>terra</code> package includes a <a href="https://rspatial.org/modis/1-introduction.html">nice tutorial</a> for how to download and pre-processing MODIS data like this using the <a href="https://github.com/rspatial/luna"><code>luna</code> R package</a>.</p>
<p>A subset of the 2013-2021 data for our study region (i.e., Georgia) is in the <a href="./intro.html#sec-intro-setup-data">data package</a>. The file <code>landcover_mcd12q1_umd_us-ga_2013-2021.tif</code> should be in the <code>data-raw/</code> subdirectory of your RStudio project. This is a multi-band <a href="https://en.wikipedia.org/wiki/GeoTIFF">GeoTIFF</a> in which each band corresponds to a year of landcover data. In R, we’ll use the <a href="https://rspatial.github.io/terra/"><code>terra</code> package</a> to work with <a href="https://www.gislounge.com/geodatabases-explored-vector-and-raster-data/">raster data</a>.</p>
<p>For the examples in this guide, we’ll use land cover variables derived from the <a href="https://lpdaac.usgs.gov/products/mcd12q1v006/">MODIS MCD12Q1 v006</a> land cover product <span class="citation" data-cites="friedlMCD12Q1MODISTerra2015">(<a href="references.html#ref-friedlMCD12Q1MODISTerra2015" role="doc-biblioref">Friedl and Sulla-Menashe 2015</a>)</span>. This product has global coverage at 500m spatial resolution and annual temporal resolution from 2001-2022. These data are available for several different classification schemes. We’ll use the University of Maryland classification system, which provides a globally accurate classification of land cover in our experience. This system classifies pixels into one of 15 different land cover classes. The <code>terra</code> package includes a <a href="https://rspatial.org/modis/1-introduction.html">nice tutorial</a> for how to download and pre-processing MODIS data like this using the <a href="https://github.com/rspatial/luna"><code>luna</code> R package</a>.</p>
<p>A subset of the 2014-2022 data for our study region (i.e., Georgia) is in the <a href="./intro.html#sec-intro-setup-data">data package</a>. The file <code>landcover_mcd12q1_umd_us-ga_2014-2022.tif</code> should be in the <code>data-raw/</code> subdirectory of your RStudio project. This is a multi-band <a href="https://en.wikipedia.org/wiki/GeoTIFF">GeoTIFF</a> in which each band corresponds to a year of landcover data. In R, we’ll use the <a href="https://rspatial.github.io/terra/"><code>terra</code> package</a> to work with <a href="https://www.gislounge.com/geodatabases-explored-vector-and-raster-data/">raster data</a>.</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(dplyr)</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(exactextractr)</span>
Expand All @@ -268,21 +268,21 @@ <h2 data-number="3.2" class="anchored" data-anchor-id="sec-envvar-landcover"><sp
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(viridis)</span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true" tabindex="-1"></a><span class="co"># load and inspect the landcover data</span></span>
<span id="cb1-13"><a href="#cb1-13" aria-hidden="true" tabindex="-1"></a>landcover <span class="ot">&lt;-</span> <span class="fu">rast</span>(<span class="st">"data-raw/landcover_mcd12q1_umd_us-ga_2013-2021.tif"</span>)</span>
<span id="cb1-13"><a href="#cb1-13" aria-hidden="true" tabindex="-1"></a>landcover <span class="ot">&lt;-</span> <span class="fu">rast</span>(<span class="st">"data-raw/landcover_mcd12q1_umd_us-ga_2014-2022.tif"</span>)</span>
<span id="cb1-14"><a href="#cb1-14" aria-hidden="true" tabindex="-1"></a><span class="fu">print</span>(landcover)</span>
<span id="cb1-15"><a href="#cb1-15" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; class : SpatRaster </span></span>
<span id="cb1-16"><a href="#cb1-16" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; dimensions : 1174, 1249, 9 (nrow, ncol, nlyr)</span></span>
<span id="cb1-17"><a href="#cb1-17" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; resolution : 463, 463 (x, y)</span></span>
<span id="cb1-18"><a href="#cb1-18" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; extent : -8132528, -7553851, 3362724, 3906653 (xmin, xmax, ymin, ymax)</span></span>
<span id="cb1-19"><a href="#cb1-19" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; coord. ref. : +proj=sinu +lon_0=0 +x_0=0 +y_0=0 +R=6371007.181 +units=m +no_defs </span></span>
<span id="cb1-20"><a href="#cb1-20" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; source : landcover_mcd12q1_umd_us-ga_2013-2021.tif </span></span>
<span id="cb1-21"><a href="#cb1-21" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; names : 2013, 2014, 2015, 2016, 2017, 2018, ... </span></span>
<span id="cb1-20"><a href="#cb1-20" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; source : landcover_mcd12q1_umd_us-ga_2014-2022.tif </span></span>
<span id="cb1-21"><a href="#cb1-21" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; names : 2014, 2015, 2016, 2017, 2018, 2019, ... </span></span>
<span id="cb1-22"><a href="#cb1-22" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; min values : 0, 0, 0, 0, 0, 0, ... </span></span>
<span id="cb1-23"><a href="#cb1-23" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; max values : 15, 15, 15, 15, 15, 15, ...</span></span>
<span id="cb1-24"><a href="#cb1-24" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-25"><a href="#cb1-25" aria-hidden="true" tabindex="-1"></a><span class="co"># map the data for 2021</span></span>
<span id="cb1-26"><a href="#cb1-26" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">as.factor</span>(landcover[[<span class="st">"2021"</span>]]), </span>
<span id="cb1-27"><a href="#cb1-27" aria-hidden="true" tabindex="-1"></a> <span class="at">main =</span> <span class="st">"MODIS Landcover 2021"</span>,</span>
<span id="cb1-25"><a href="#cb1-25" aria-hidden="true" tabindex="-1"></a><span class="co"># map the data for 2022</span></span>
<span id="cb1-26"><a href="#cb1-26" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">as.factor</span>(landcover[[<span class="st">"2022"</span>]]), </span>
<span id="cb1-27"><a href="#cb1-27" aria-hidden="true" tabindex="-1"></a> <span class="at">main =</span> <span class="st">"MODIS Landcover 2022"</span>,</span>
<span id="cb1-28"><a href="#cb1-28" aria-hidden="true" tabindex="-1"></a> <span class="at">axes =</span> <span class="cn">FALSE</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
Expand Down Expand Up @@ -419,14 +419,14 @@ <h2 data-number="3.2" class="anchored" data-anchor-id="sec-envvar-landcover"><sp
</div>
</div>
</div>
<p>We’ll start by finding the full set of unique checklists locations for each year in the eBird data and buffer the points by 1.5km to generate 3 km diameter circular neighborhoods centered on each checklist location. Note that the MODIS landcover data are not available for 2022 and 2023, so we use the 2021 layer for 2022-2023 checklists.</p>
<div class="cell" data-layout-align="center" data-cahce-path="cache" data-hash="cache/envvar-landcover-buffer_9372201e81d15ad5945c04ca545c2a8d">
<p>We’ll start by finding the full set of unique checklists locations for each year in the eBird data and buffer the points by 1.5km to generate 3 km diameter circular neighborhoods centered on each checklist location. Note that the MODIS landcover data are not available for 2023, so we use the 2022 layer for 2023 checklists.</p>
<div class="cell" data-layout-align="center" data-cahce-path="cache" data-hash="cache/envvar-landcover-buffer_018ae04f8189ddcd91c8dc88de97c848">
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="co"># ebird checklist locations</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a>checklists <span class="ot">&lt;-</span> <span class="fu">read_csv</span>(<span class="st">"data/checklists-zf_woothr_jun_us-ga.csv"</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> <span class="co"># landcover data not availble for the full period, so we use the closest year</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">year_lc =</span> <span class="fu">as.character</span>(<span class="fu">pmin</span>(year, <span class="dv">2021</span>)))</span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">year_lc =</span> <span class="fu">as.character</span>(<span class="fu">pmin</span>(year, <span class="dv">2022</span>)))</span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a><span class="co"># generate circular neighborhoods for all checkists</span></span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a><span class="co"># generate circular neighborhoods for all checklists</span></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a>buffers <span class="ot">&lt;-</span> checklists <span class="sc">%&gt;%</span> </span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a> <span class="co"># identify unique location/year combinations</span></span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">distinct</span>(locality_id, year_lc, latitude, longitude) <span class="sc">%&gt;%</span> </span>
Expand Down Expand Up @@ -540,15 +540,15 @@ <h2 data-number="3.4" class="anchored" data-anchor-id="sec-envvar-pred"><span cl
<span id="cb9-5"><a href="#cb9-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">st_transform</span>(<span class="at">crs =</span> <span class="dv">4326</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb9-6"><a href="#cb9-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">st_buffer</span>(<span class="fu">set_units</span>(<span class="dv">3</span>, <span class="st">"km"</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Now we can calculate the landcover and elevation variables exactly as we did for the eBird checklists in the previous two sections. First, the landscape metrics <code>pland</code> and <code>ed</code> from the landcover data. Note that we use the most recent year of landcover data (i.e.&nbsp;2021) in this case.</p>
<div class="cell" data-layout-align="center" data-hash="cache/envvar-pred-lsm_2419031a91839fb1a177b98e6ed1d184">
<p>Now we can calculate the landcover and elevation variables exactly as we did for the eBird checklists in the previous two sections. First, the landscape metrics <code>pland</code> and <code>ed</code> from the landcover data. Note that we use the most recent year of landcover data (i.e.&nbsp;2022) in this case.</p>
<div class="cell" data-layout-align="center" data-hash="cache/envvar-pred-lsm_b61f523467b783cb1dcf76a97070c3ba">
<div class="sourceCode cell-code" id="cb10"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="co"># estimate landscape metrics for each cell in the prediction grid</span></span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a>lsm_pg <span class="ot">&lt;-</span> <span class="cn">NULL</span></span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> (i <span class="cf">in</span> <span class="fu">seq_len</span>(<span class="fu">nrow</span>(buffers_pg))) {</span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true" tabindex="-1"></a> buffer_i <span class="ot">&lt;-</span> <span class="fu">st_transform</span>(buffers_pg[i, ], <span class="at">crs =</span> <span class="fu">crs</span>(landcover))</span>
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb10-6"><a href="#cb10-6" aria-hidden="true" tabindex="-1"></a> <span class="co"># crop and mask landcover raster so all values outside buffer are missing</span></span>
<span id="cb10-7"><a href="#cb10-7" aria-hidden="true" tabindex="-1"></a> lsm_pg[[i]] <span class="ot">&lt;-</span> <span class="fu">crop</span>(landcover[[<span class="st">"2021"</span>]], buffer_i) <span class="sc">%&gt;%</span> </span>
<span id="cb10-7"><a href="#cb10-7" aria-hidden="true" tabindex="-1"></a> lsm_pg[[i]] <span class="ot">&lt;-</span> <span class="fu">crop</span>(landcover[[<span class="st">"2022"</span>]], buffer_i) <span class="sc">%&gt;%</span> </span>
<span id="cb10-8"><a href="#cb10-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">mask</span>(buffer_i) <span class="sc">%&gt;%</span> </span>
<span id="cb10-9"><a href="#cb10-9" aria-hidden="true" tabindex="-1"></a> <span class="co"># calcualte landscape metrics</span></span>
<span id="cb10-10"><a href="#cb10-10" aria-hidden="true" tabindex="-1"></a> <span class="fu">calculate_lsm</span>(<span class="at">level =</span> <span class="st">"class"</span>, <span class="at">metric =</span> <span class="fu">c</span>(<span class="st">"pland"</span>, <span class="st">"ed"</span>)) <span class="sc">%&gt;%</span> </span>
Expand Down
Binary file modified docs/envvar_files/figure-html/envvar-landcover-map-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/envvar_files/figure-html/envvar-pred-map-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 420d893

Please sign in to comment.