Activate packages (or install)

# run every time you start a script
library(sp)
library(rgdal)
## rgdal: version: 1.4-4, (SVN revision 833)
##  Geospatial Data Abstraction Library extensions to R successfully loaded
##  Loaded GDAL runtime: GDAL 2.1.3, released 2017/20/01
##  Path to GDAL shared files: /Users/dsfernandez/Library/R/3.5/library/rgdal/gdal
##  GDAL binary built with GEOS: FALSE 
##  Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
##  Path to PROJ.4 shared files: /Users/dsfernandez/Library/R/3.5/library/rgdal/proj
##  Linking to sp version: 1.3-1
library(rgeos)
## rgeos version: 0.5-1, (SVN revision 614)
##  GEOS runtime version: 3.7.2-CAPI-1.11.2 
##  Linking to sp version: 1.3-1 
##  Polygon checking: TRUE
library(ggplot2)
library(ggthemes)
library(neonUtilities)
library(geoNEON)

options(stringsAsFactors=F)

Characteristics - metadata of Field Sites

In file: field-sites.csv

In folder: All_NEON_TOS_Plots_V5

Load data: Mammals

mam <- loadByProduct(dpID = "DP1.10072.001",
                     site = "ONAQ",
                     startdate = "2018-08",
                     enddate = "2018-08",
                     check.size = F)
View(mam$mam_pertrapnight)
# use of which and serial $ to filter
View(mam$mam_pertrapnight[which(mam$mam_pertrapnight$plotID=="ONAQ_003"),])

Locations of the traps appear identical. The coordinates are for the plot, not the traps. That is why the uncertainty is the size of the plot (45.4)

locating the traps

mam.loc <- getLocTOS(mam$mam_pertrapnight, "mam_pertrapnight")
#takes long time because the API: one by one location for each trap
# using setdiff to look for new data
setdiff(names(mam.loc), names(mam$mam_pertrapnight))
# plot traps
plot(mam.loc$easting,mam.loc$northing,
     pch=".", xlab="Easting", ylab="Northing")
# subset to one grid
plot(mam.loc$easting[which(mam.loc$plotID=="ONAQ_003")],
mam.loc$northing[which(mam.loc$plotID=="ONAQ_003")],
xlab="Easting", ylab="Northing", pch=".")

Locate actual mammals trapped

#base plot - necessary
plot(mam.loc$easting[which(mam.loc$plotID=="ONAQ_003")],
mam.loc$northing[which(mam.loc$plotID=="ONAQ_003")],
xlab="Easting", ylab="Northing", pch=".")
# traps with capture
points(mam.loc$easting[which(mam.loc$plotID=="ONAQ_003" & mam.loc$trapStatus=="5 - capture")],
       mam.loc$northing[which(mam.loc$plotID=="ONAQ_003" & mam.loc$trapStatus=="5 - capture")],
       pch=19, col="red")
# traps with taxon PEPA
points(mam.loc$easting[which(mam.loc$plotID=="ONAQ_003" & mam.loc$trapStatus=="5 - capture" & mam.loc$taxonID=="PEPA")],
       mam.loc$northing[which(mam.loc$plotID=="ONAQ_003" & mam.loc$trapStatus=="5 - capture" & mam.loc$taxonID=="PEPA")],
       pch=19, col="blue")

Sensor location

download PAR data and graph vertical distribution
pr <- loadByProduct(dpID="DP1.00024.001", site="TREE",
                    startdate = "2018-07", enddate = "2018-07",
                    avg=30, check.size = F)
View(pr$PARPAR_30min)
# get average by tower level
mystats <- function(x){
                m <- mean(x)
                md <- median(x)
                n <- length(x)
                s <- sd(x)
                return(c(n=n, mean=m, median=md, stdev=s))
}
pr.mn <- aggregate(pr$PARPAR_30min$PARMean,
                   by=list(pr$PARPAR_30min$verticalPosition),
                   FUN=mean, na.rm=T)
View(pr.mn)
# read sensro
pos <- read.delim("NEON.D05.TREE.DP1.00024.001.2018-07.basic.20190314T150344Z/NEON.D05.TREE.DP1.00024.001.sensor_positions.20190314T150344Z.csv",
                  sep=",")
plot(pos$zOffset ~ log(pr.mn$x), type="b",
     xlab="PAR",
     ylab="Height above ground (m)")