Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging irene-dev into main #1

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
^aspen\.Rproj$
^\.Rproj\.user$
^LICENSE\.md$
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
22 changes: 15 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
Package: aspen
Title: What the Package Does (One Line, Title Case)
Title: Aspen Protocol Data Tools
Version: 0.0.0.9000
Authors@R:
person("First", "Last", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "YOUR-ORCID-ID"))
Description: What the package does (one paragraph).
License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a
license
Authors@R: c(person("Sarah", "Wright", email = "[email protected]", role=c("aut","cre"), comment = c(ORCID = "0009-0004-5060-2189")),
person("Irene", "Foster", email = "[email protected]", role=c("aut"), ,
comment = c(ORCID = "0000-0001-9681-4786")))
Description: This R package is intended to provide automated QA/QC, visualization, and
basic analysis and statistical summaries of data collected for the Aspen
monitoring protocol.
License: CC0
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
Imports:
dplyr,
fetchagol,
magrittr
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
43 changes: 43 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
## creative commons

# CC0 1.0 Universal

CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER.

### Statement of Purpose

The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work").

Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others.

For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights.

1. __Copyright and Related Rights.__ A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following:

i. the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work;

ii. moral rights retained by the original author(s) and/or performer(s);

iii. publicity and privacy rights pertaining to a person's image or likeness depicted in a Work;

iv. rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below;

v. rights protecting the extraction, dissemination, use and reuse of data in a Work;

vi. database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and

vii. other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof.

2. __Waiver.__ To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose.

3. __Public License Fallback.__ Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose.

4. __Limitations and Disclaimers.__

a. No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document.

b. Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.

c. Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work.

d. Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work.
9 changes: 5 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Generated by roxygen2: do not edit by hand

export(fetchAGOLToken)
export(fetchAllRecords)
export(fetchLayerAndTableList)
export(fetchMetadata)
export(loadAndWrangleMOJNAspen)
export(loadAndWrangleUCBNAspen)
export(writeAspen)
import(dplyr)
import(fetchagol)
importFrom(magrittr,"%<>%")
importFrom(magrittr,"%>%")
80 changes: 80 additions & 0 deletions R/aspen_qc.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@

#' Check that there is at least one tree for every observation entry and flag entries with more than 250 trees
#' @param data Aspen dataset to run through QC functions
missingTreeQC <- function(data = fetchAndWrangleAspen()){

missingTreeQC <- data$data$Observations %>%
# Add up all trees in a row
dplyr::mutate(totalTreeCount = Class1+Class2+Class3+Class4+Class5+Class6) %>%
# Filter for any rows that have less than one trees or more than 250 trees
dplyr::filter(totalTreeCount < 1 | totalTreeCount > 250) %>%
dplyr::select(Park, Site, VisitDate, SpeciesCode, Class1, Class2, Class3, Class4, Class5, Class6, totalTreeCount)

return(missingTreeQC)
}

#' Check that no entries in the observation table have a SpeciesCode that is NA or missing
#' @param data Aspen dataset to run through QC functions
treeSpeciesQC <- function(data = fetchAndWrangleAspen()){

treeSpeciesQC <- data$data$Observations %>%
dplyr::filter(SpeciesCode == "" | is.na(SpeciesCode) | SpeciesCode == "NA") %>%
dplyr::select(Park, Site, VisitDate, SpeciesCode, Class1, Class2, Class3, Class4, Class5, Class6)

return(treeSpeciesQC)
}

#' Check that unknown species entries do not have any live trees
#' @param data Aspen dataset to run through QC functions
unknownSpeciesQC <- function(data = fetchAndWrangleAspen()){

unknownSpeciesQC <- data$data$Observations %>%
dplyr::filter(SpeciesCode == "UNK") %>%
dplyr::filter(Class1 != 0 | Class2 != 0 | Class3 != 0 | Class4 != 0 | Class5 != 0) %>%
dplyr::select(Park, Site, VisitDate, SpeciesCode, Class1, Class2, Class3, Class4, Class5, Class6)

return(unknownSpeciesQC)
}

#' Check that all plots have at least one live aspen each time they are visited
#' @param data Aspen dataset to run through QC functions
checkAspenQC <- function(data = fetchAndWrangleAspen()){

checkAspenQC <- data$data$Observations %>%
# Filter for aspen trees
dplyr::filter(SpeciesCode == "POTR5") %>%
dplyr::select(parentglobalid, SpeciesCode, Class1, Class2, Class3, Class4, Class5) %>%
# Join observations and visits
dplyr::full_join(data$data$SiteVisit, by = c("parentglobalid" = "globalid")) %>%
# Filter data for any visits that don't have aspen observations
dplyr::filter(is.na(SpeciesCode)) %>%
dplyr::select(Park, Site, VisitType, VisitDate, SpeciesCode)

return(checkAspenQC)
}

#' Flag large changes in number of tree between years
#' @param data Aspen dataset to run through QC functions
treeChangeQC <- function(data = fetchAndWrangleAspen()){

visits <- data$data$SiteVisit %>%
dplyr::group_by(Site) %>%
dplyr::arrange(Site, VisitDate) %>%
dplyr::mutate(visitNumber = seq_along(Site)) %>%
dplyr::select("globalid", "Park", "Site", "VisitType", "VisitDate", "visitNumber")

treeChangeQC <- data$data$Observations %>%
# join with site visit table
#dplyr::left_join(visits, by = c("parentglobalid" = "globalid")) %>%
dplyr::mutate(totalTrees = Class1+Class2+Class3+Class4+Class5) %>%
dplyr::group_by(Site, VisitDate) %>%
dplyr::summarise(totalTrees = sum(totalTrees)) %>%
dplyr::group_by(Site) %>%
dplyr::mutate(previousTrees = dplyr::lag(totalTrees),
treeChange = previousTrees - totalTrees)

# find percent change (in total number of trees both conifer and aspen or separate??) between year ((year 1 - year 2)/year 1)
# flag any with a large change (figure out what counts as a large change)
}

# Flag if there's more than one visit to a plot in a year
80 changes: 80 additions & 0 deletions R/aspen_qc_ucbn.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@

#' Check that there is at least one tree for every observation entry and flag entries with more than 250 trees
#' @param data Aspen dataset to run through QC functions
missingTreeUCBNQC <- function(data){

missingTreeQC <- data$data$Observations %>%
# Add up all trees in a row
dplyr::mutate(totalTreeCount = Class1+Class2+Class3+Class4+Class5+Class6) %>%
# Filter for any rows that have less than one trees or more than 250 trees
dplyr::filter(totalTreeCount < 1 | totalTreeCount > 250) %>%
dplyr::select(Park, Unique_ID, VisitDate, SpeciesCode, Class1, Class2, Class3, Class4, Class5, Class6, totalTreeCount)

return(missingTreeQC)
}

#' Check that no entries in the observation table have a SpeciesCode that is NA or missing
#' @param data Aspen dataset to run through QC functions
treeSpeciesUCBNQC <- function(data){

treeSpeciesQC <- data$data$Observations %>%
dplyr::filter(SpeciesCode == "" | is.na(SpeciesCode) | SpeciesCode == "NA") %>%
dplyr::select(Park, Unique_ID, VisitDate, SpeciesCode, Class1, Class2, Class3, Class4, Class5, Class6)

return(treeSpeciesQC)
}

#' Check that unknown species entries do not have any live trees
#' @param data Aspen dataset to run through QC functions
unknownSpeciesUCBNQC <- function(data){

unknownSpeciesQC <- data$data$Observations %>%
dplyr::filter(SpeciesCode == "UNK") %>%
dplyr::filter(Class1 != 0 | Class2 != 0 | Class3 != 0 | Class4 != 0 | Class5 != 0) %>%
dplyr::select(Park, Unique_ID, VisitDate, SpeciesCode, Class1, Class2, Class3, Class4, Class5, Class6)

return(unknownSpeciesQC)
}

#' Check that all plots have at least one live aspen for each visit
#' @param data Aspen dataset to run through QC functions
checkAspenUCBNQC <- function(data){

checkAspenQC <- data$data$Observations %>%
# Filter for aspen trees
dplyr::filter(SpeciesCode == "POPTRE") %>%
dplyr::select(parentglobalid, SpeciesCode, Class1, Class2, Class3, Class4, Class5) %>%
# Join observations and visits
dplyr::full_join(data$data$SiteVisit, by = c("parentglobalid" = "globalid")) %>%
# Filter data for any visits that don't have aspen observations
dplyr::filter(is.na(SpeciesCode)) %>% # Any visit without aspens should have a NA in SpeciesCode after joining with only aspen observations
dplyr::select(Park, Unique_ID, VisitDate, SpeciesCode)

return(checkAspenQC)
}

#' Flag large changes in number of tree between years
#' @param data Aspen dataset to run through QC functions
treeChangeUCBNQC <- function(data){

visits <- data$data$SiteVisit %>%
dplyr::group_by(Unique_ID) %>%
dplyr::arrange(Unique_ID, VisitDate) %>%
dplyr::mutate(visitNumber = seq_along(Unique_ID)) %>%
dplyr::select("globalid", "Park", "Unique_ID", "VisitDate", "visitNumber")

treeChangeQC <- data$data$Observations %>%
# join with site visit table
#dplyr::left_join(visits, by = c("parentglobalid" = "globalid")) %>%
dplyr::mutate(totalTrees = Class1+Class2+Class3+Class4+Class5) %>%
dplyr::group_by(Unique_ID, VisitDate) %>%
dplyr::summarise(totalTrees = sum(totalTrees)) %>%
dplyr::group_by(Unique_ID) %>%
dplyr::mutate(previousTrees = dplyr::lag(totalTrees),
treeChange = previousTrees - totalTrees)

# find percent change (in total number of trees both conifer and aspen or separate??) between year ((year 1 - year 2)/year 1)
# flag any with a large change (figure out what counts as a large change)
}

# Flag if there's more than one visit to a plot in a year
Loading