From d54c44f2552596d0ab264a0d4036280872b5779f Mon Sep 17 00:00:00 2001 From: gomezcatalina Date: Fri, 20 Aug 2021 11:28:03 -0300 Subject: [PATCH 01/10] report_habitat_FR_caption_edits.Rmd Inserted French figure and table captions - Charlotte Smith --- app/Rmd/report_habitat_FR.Rmd | 63 +++++++++++------------------------ 1 file changed, 20 insertions(+), 43 deletions(-) diff --git a/app/Rmd/report_habitat_FR.Rmd b/app/Rmd/report_habitat_FR.Rmd index 8fc5da5..adcf7bb 100644 --- a/app/Rmd/report_habitat_FR.Rmd +++ b/app/Rmd/report_habitat_FR.Rmd @@ -21,60 +21,37 @@ Remarques sur les données : #### ***Résultats de la recherche sur la végétation intertidale et le fucus, par zone*** ```{r overlap rockweed, echo=FALSE, results='asis'} -rockweed_intersect <- st_intersection(studyArea,st_make_valid(rockweed_sf)) -rockweed_result<-as.numeric(nrow(rockweed_intersect)) +# define polygon dataset and attribute to plot +poly_sf=rockweed_sf +attribute="RWP" + +# intersect polyData with 3 polygons (region, map area, and study box) +clipped <- poly_intersect(poly_sf,Region,studyArea, bboxMap) ``` * ```{r overlap rockweed output, echo=FALSE, results='asis'} - Query_output_rockweed<-if(rockweed_result < 1){"There are no relevant records of predicted intertidal vegetation for this search area." - } else {"There are relevant records of predicted intertidal vegetation for this search area."} - Query_output_rockweed<-noquote(Query_output_rockweed) - writeLines(Query_output_rockweed) + +polyText<-if(is.null(clipped$studyPoly)){"Il n’existe aucun registre pertinent sur la végétation intertidale prévue pour cette zone de recherche." +} else {"Il existe des registres pertinentes sur la végétation intertidale prévue pour cette zone de recherche."} + + polyText<-noquote(polyText) + writeLines(polyText) ``` -```{r, fig.height=8, fig.width=11, fig.cap='Quality Tier: Medium. Security level: none. Map showing the search area defined by the user: location of the proposed project/activity is highlighted in yellow (input polygon), surrounded by an exposure zone or user-defined buffer area in blue. Figure shows overlap between the search area and satellite-based maps of intertidal vegetation and rockweed presence polygons.'} -plot_rockweed <- function(rockweed_sf, areaMap, bboxMap) { - - # crop rockweed layer to the map area to speed up plotting - rockweed=st_crop(st_make_valid(rockweed_sf),bboxMap) - - if (dim(rockweed)[1]==0){ - rockweedMap=NULL - }else{ - - # define axis limit - axLim=ggplot2::coord_sf(xlim = c(bboxMap["xmin"], bboxMap["xmax"]), ylim = c(bboxMap["ymin"], bboxMap["ymax"]),expand=FALSE) - - # replace codes with words - rockweed$Rockweed="" - rockweed$Rockweed[which(rockweed$RWP==1)]="1-Present" - rockweed$Rockweed[which(rockweed$RWP==2)]="2-Likely Present" - rockweed$Rockweed[which(rockweed$RWP==5)]="5-Unknown" - rockweed$Rockweed[which(rockweed$RWP==0)]="Not Present" - - rockweedMap <- areaMap + - geom_sf(data=rockweed, aes(fill=Rockweed), colour=NA)+ - scale_fill_manual(values=c("#009E73", "#E69F00", "#0072B2","#999999"))+ - studyBox_geom + - axLim - } - - return(rockweedMap) - -} -if(rockweed_result > 1){print( - plot_rockweed(rockweed_sf, areaMap, bboxMap))} +```{r, fig.height=8, fig.width=11, fig.cap='Niveau de qualité : Moyenne. Niveau de sécurité : Aucun. Carte montrant la zone de recherche définie par l’utilisateur : l’emplacement du projet ou de l’activité proposé est surligné en jaune (polygone d’entrée), entouré d’une zone exposée ou d’une zone tampon définie par l’utilisateur en bleu. La figure illustre le chevauchement entre la zone de recherche et les cartes satellitaires de la végétation intertidale et des polygones de présence de fucus.'} +if(!is.null(clipped$studyPoly)){print( + plot_polygons(areaMap,bboxMap,studyBox_geom, clipped$mapPoly,attribute))} ``` ```{r table rockweed, echo=FALSE, cache=FALSE, include = FALSE} -if(rockweed_result > 1){ - rwTable <- rockweedStats(rockweed_sf, studyArea)} +if(!is.null(clipped$studyPoly)){ + rwTable <- rockweedStats(clipped$studyPoly, studyArea)} ``` + ```{r} -if(rockweed_result > 1){ +if(!is.null(clipped$studyPoly)){ knitr::kable(rwTable,align="l", - caption = "Number of vegetation polygons and surface area occupied by each category for the study area. Total intertidal vegetations is a sum of all categories.", booktabs = T, escape = F, linesep="") %>% + caption = "Nombre de polygones de végétation et la superficie occupée par chaque catégorie pour la zone d’étude. La végétation intertidale totale est la somme de tous les catégories.", booktabs = T, escape = F, linesep="") %>% kable_styling(bootstrap_options = "striped", full_width = T, position = "left") } ``` - From e60e04ea1b6dd721d5c25695924bd5cb62659be1 Mon Sep 17 00:00:00 2001 From: gomezcatalina Date: Fri, 20 Aug 2021 12:24:14 -0300 Subject: [PATCH 02/10] report_planning_FR_caption_edits.Rmd Inserted French translations of figure captions and one bullet point - Charlotte Smith --- app/Rmd/report_planning_FR.Rmd | 51 ++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/app/Rmd/report_planning_FR.Rmd b/app/Rmd/report_planning_FR.Rmd index 7c2ab53..9b5288a 100644 --- a/app/Rmd/report_planning_FR.Rmd +++ b/app/Rmd/report_planning_FR.Rmd @@ -7,18 +7,57 @@ Consulté le : 21 janvier 2021 sur le Portail de données ouvertes Niveau de qualité : Élevée Niveau de sécurité : Aucun -Description de l’ensemble de données (tirée du dossier des données ouvertes): Les zones d'importance écologique et biologique (ZIEB) sont des zones au sein des eaux océaniques canadiennesque des évaluations scientifiques officielles ont désignées comme ayant une importance écologique et biologique particulière par rapport à l'écosystème marin environnant. Le fait qu'une zone n'ait pas été désignée comme ayant une importance écologique et biologique ne signifie pas pour autant qu'elle n'a pas une importance écologique. Toutes les zones assument des fonctions écologiques dans une certaine mesure et exigent une gestion durable. Les zones désignées comme des ZIEB devraient plutôt être vues comme des zones extrêmement importantes, où les connaissances, les législateurs et les utilisateurs des ressources marines doivent exercer une grande prudence eu égard au risque, afin de veiller à ce que les écosystèmes restent sains et productifs. Les renseignements relatifs à ces aires sont utilisés pour appuyer la planification marine, notamment l'évaluation environnementale et la mise en place d'activités marines: +Description de l’ensemble de données (tirée du dossier des données ouvertes): Les zones d'importance écologique et biologique (ZIEB) sont des zones au sein des eaux océaniques canadiennes que des évaluations scientifiques officielles ont désignées comme ayant une importance écologique et biologique particulière par rapport à l'écosystème marin environnant. Le fait qu'une zone n'ait pas été désignée comme ayant une importance écologique et biologique ne signifie pas pour autant qu'elle n'a pas une importance écologique. Toutes les zones assument des fonctions écologiques dans une certaine mesure et exigent une gestion durable. Les zones désignées comme des ZIEB devraient plutôt être vues comme des zones extrêmement importantes, où les connaissances, les législateurs et les utilisateurs des ressources marines doivent exercer une grande prudence eu égard au risque, afin de veiller à ce que les écosystèmes restent sains et productifs. Les renseignements relatifs à ces aires sont utilisés pour appuyer la planification marine, notamment l'évaluation environnementale et la mise en place d'activités marines: -- Informing and guiding project-specific or regional environmental assessments +- En informant et guidant les évaluations environnementales régionales ou spécifique à un projet - En informant et guidant les industries et les législateurs pour une planification et une conduite d'activités optimale, par exemple: les zones d'importance écologique et biologique ont été prises en compte et mentionnées dans les évaluations portant sur le pétrole et le gaz. -- Des renseignements ont été fournis aux promoteurs de projets de câbles sous-marins, afin de les aider à en déterminer les tracés. +- Des renseignements sur les ZIEB ont été fournis aux promoteurs de projets de câbles sous-marins, afin de les aider à en déterminer les tracés. - En information et en guidant le processus de gestion intégrée des océans dans cinq zones étendues de gestion des océans et 12 biorégions marines. - En servant de fondement pour la détermination des zones d'intérêt et des zones de protection marines (de manière individuelle et dans le cadre de la planification des réseaux biorégionaux de zones de protection marines). #### ***Résultats de la recherche des ZIEB par zone*** -**under-development** +* +```{r echo=FALSE, results='asis'} +#function for overlap +EBSA_overlap(EBSA_sf, studyArea) +``` + +```{r echo=FALSE, results='asis'} +#function for report +EBSA_report(EBSA_sf, studyArea) +``` + +```{r echo=FALSE, results='asis'} +#function for report url +EBSA_reporturl(EBSA_sf, studyArea) +``` + +```{r echo=FALSE, results='asis'} +#function for location +EBSA_location(EBSA_sf, studyArea) +``` + +```{r echo=FALSE, results='asis'} +#function for bioregion +EBSA_bioregion(EBSA_sf, studyArea) +``` +```{r overlap EBSA and plot, echo=FALSE, results='asis'} +# define polygon dataset and attribute to plot +poly_sf=EBSA_sf +attribute="NONE" + +# intersect polyData with 3 polygons (region, map area, and study box) +clipped <- poly_intersect(poly_sf,Region,studyArea, bboxMap) +``` + +```{r, fig.height=8, fig.width=11, fig.cap= 'Niveau de qualité : Élevée. Niveau de sécurité : Aucun. Carte montrant les zones d’importance écologique et biologique (ZIEB) par rapport à la zone de recherche définie par l’utilisateur (entourée de rouge).'} +if (!is.null(clipped$regionPoly)){ + plot_polygons(regionMap,regionBox,studyBox_geom, clipped$regionPoly,attribute) +} +``` -```{r, fig.height=8, fig.width=11, fig.cap= 'Quality Tier: High. Security level: none. Map showing Ecologically and Biologically Significant Areas (EBSA; pink) relative to the search area defined by the user: location of the proposed project/activity is highlighted in yellow (input polygon), surrounded by an exposure zone or user-defined buffer area in blue.'} -#plot_EBSA(EBSA_sf, studyArea, land10m_sf, 300) +```{r, fig.height=8, fig.width=11, fig.cap= 'Niveau de qualité : Élevée. Niveau de sécurité : Aucun. Carte montrant les zones d’importance écologique et biologique (ZIEB) dans la zone de recherche définie par l’utilisateur (entourée de rouge).'} +if(!is.null(clipped$studyPoly)){print( + plot_polygons(areaMap,bboxMap,studyBox_geom, clipped$mapPoly,attribute))} ``` From 80204d6a1808c743d4f796dff68bcf4a13c9cc07 Mon Sep 17 00:00:00 2001 From: Gomez Date: Fri, 27 Aug 2021 14:07:04 -0300 Subject: [PATCH 03/10] OCEARCH text for fish module, courtesy of Sean Butler. Quentin to update SecureData.Rdata to incorporate figure. --- app/Rmd/report_fish_EN.Rmd | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/app/Rmd/report_fish_EN.Rmd b/app/Rmd/report_fish_EN.Rmd index b76a839..49fb2ef 100644 --- a/app/Rmd/report_fish_EN.Rmd +++ b/app/Rmd/report_fish_EN.Rmd @@ -201,3 +201,33 @@ if (!is.null(outputList)) { knitr::kable(table_obis1, align="l", caption="Quality Tier: Medium. Security level: none. Ocean Biodiversity Information System (OBIS) observation records of species contained within the search area and listed by the Species At Risk Act (SARA), or assessed by the Committee on the Status of Endangered Wildlife in Canada (COSEWIC). The absence of a species in this figure should be interpreted as an absence of reporting, not necessarily as an absence of the species in the area.", booktabs = T, escape = F, linesep="") %>% kable_styling(bootstrap_options = "striped", full_width = F, position = "left") } ``` + +### **OCEARCH Shark Tracker** +Contact: Bryan Franks (bfranks@ju.edu) via Sean Butler (sean.butler@dfo-mpo.gc.ca) +URL: +Last retrieved on: July 22 2021 by Sean Butler +Quality Tier: High +Search year: 2013-2020 +Security level: none +Data use constraints: DFO INTERNAL USE ONLY + +OCEARCH is a data-centric organization built to help scientists collect previously unattainable data in the ocean while open sourcing our research and explorations. Open sourcing and inclusion at every level, and in real-time, allows the world to participate in their projects while being aware of the developing science. OCEARCH shares the data, including samples collected and tracking data, with collaborating institutions and students who request them for their studies. The tracking data is also open-sourced to the public via the OCEARCH Tracker. The OCEARCH Tracker is a free app that lets you observe the navigational pattern of animals that have been tagged with satellite tracking technology. White Shark locations from satellite trackers are summarized in this section from 1 Jan 2013 to 31 Oct 2020. Locations were clipped to only include locations within the Canadian EEZ. A speed filter was run with 3 m/s as the maximum speed and 2.5 km as the potential error of locations. This filter removed approximately 100 locations out of of 2,000. Resulting points ere then visualized in ArcGIS to identify potential errors and remove locations that seemed implausible. Each shark location was individually plotted to do a second visual examination and to remove or flag errors/outliers. There is additional QA/QC that could still be performed to this dataset to capture additional issues (e.g. there may be single shark locations in Canadian waters during a period of time that the speed filter would not remove or that were not captured in the visual inspection). The absence of White Sharks in this section map should be interpreted as an absence of tracking data, not necessarily as an absence of the species in the area. + +#### ***Area-specific OCEARCH Shark Tracker search results*** +* +```{r, echo=FALSE, results='asis',} +Report_ocearch <- if (is.null(outputList)) { + "There are no relevant White Shark records in the OCEARCH Shark Tracker for this search area." +} else { + "There are relevant White Shark records in OCEARCH Shark Tracker search results for this search area." +} +Report_obis<-noquote(Report_ocearch) +writeLines(Report_ocearch) +``` +```{r, fig.height=8, fig.width=11, fig.cap='Quality Tier: Medium. Security level: none. Map showing the search area defined by the user (red outline) was used to query information from OCEARCH Shark Tracker observation records, for White Shark. Dataset set has not yet been completely error-checked. The absence of a species in this figure should be interpreted as an absence of tracking data, not necessarily as an absence of the species in the area.'} +if (!is.null(outputList)) { + areaMap + + geom_point(data = Samples_bbox, aes(x = long, y = lat), size = 2, shape = 16, col = "black") +} +``` + From 1bf2976b6a20c2df053bb3e6c587e1d43c9d428c Mon Sep 17 00:00:00 2001 From: Stoyel Date: Fri, 27 Aug 2021 15:30:43 -0300 Subject: [PATCH 04/10] add plot and data preprocessing for ocearch data --- app/Rmd/report_fish_EN.Rmd | 11 ++++++++++- dataprocessing/SaveDataSets_asRdata.R | 9 ++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/Rmd/report_fish_EN.Rmd b/app/Rmd/report_fish_EN.Rmd index 49fb2ef..fdb9153 100644 --- a/app/Rmd/report_fish_EN.Rmd +++ b/app/Rmd/report_fish_EN.Rmd @@ -215,7 +215,16 @@ OCEARCH is a data-centric organization built to help scientists collect previous #### ***Area-specific OCEARCH Shark Tracker search results*** * -```{r, echo=FALSE, results='asis',} + + +```{r ocearch-results, include=FALSE, cache=FALSE} +outputList <- master_intersect(ocearch_sf, region, studyArea, mapBbox = bboxMap, Year = minYear) +Samples_bbox <- outputList$mapPoints + +``` + + +```{r ocearch-check, echo=FALSE, results='asis',} Report_ocearch <- if (is.null(outputList)) { "There are no relevant White Shark records in the OCEARCH Shark Tracker for this search area." } else { diff --git a/dataprocessing/SaveDataSets_asRdata.R b/dataprocessing/SaveDataSets_asRdata.R index 381d8a6..3012e0c 100644 --- a/dataprocessing/SaveDataSets_asRdata.R +++ b/dataprocessing/SaveDataSets_asRdata.R @@ -232,9 +232,16 @@ ISSPECIESCODES <- ISSPECIESCODES %>% rename("Common Name"= COMMON, MARFISSPECIESCODES <- SPECIES %>% rename("COMMONNAME"= SPECIES_NAME) +# LOAD OCEARCH DATA ############# +ocearchDatafile <- here::here("app/data/ocearch_raw.csv") +lines <- readLines(ocearchDatafile) +lines <- gsub('(^"|"$)', "", lines) +ocearch <- read.csv(textConnection(lines), quote = '""') +ocearch <- dplyr::select(ocearch, c("Date", "long", "lat", "ID")) +ocearch_sf <- st_as_sf(ocearch, coords = c("long","lat"), crs = 4326) # Save all objects to a single .Rdata file -save(isdb_sf,ISSPECIESCODES,leatherback_sf,Legend, marfis_sf,MARFISSPECIESCODES,narwc_sf, whitehead_sf, wsdb_sf, +save(isdb_sf,ISSPECIESCODES,leatherback_sf,Legend, marfis_sf,MARFISSPECIESCODES,narwc_sf, whitehead_sf, wsdb_sf, ocearch_sf, file = "../Data/Rdata/SecureData.Rdata") ########################################################- \ No newline at end of file From 366788751a562a0628bf34fce07cfbe55b97dacd Mon Sep 17 00:00:00 2001 From: Stoyel Date: Fri, 27 Aug 2021 15:45:31 -0300 Subject: [PATCH 05/10] add ocearch to test data generation --- app/Rmd/intro_EN.Rmd | 6 +++--- dataprocessing/MakeTestData.R | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Rmd/intro_EN.Rmd b/app/Rmd/intro_EN.Rmd index 6f83f4a..631f2ea 100644 --- a/app/Rmd/intro_EN.Rmd +++ b/app/Rmd/intro_EN.Rmd @@ -39,10 +39,10 @@ lapply(list.files(here::here("app/R"), pattern = ".[Rr]$", full.names = TRUE),so ``` ```{r Load-Search-Area, echo=FALSE, include=FALSE, cache=FALSE} -studyArea <- sf::st_read("{{path_to_geoms}}") +# studyArea <- sf::st_read("{{path_to_geoms}}") # studyArea <- sf::st_read(here::here("app/output/geoms_slc.geojson")) # Uncomment the following to test fixed polygon: -#studyArea <- st_read("../studyAreaTest/geoms_slc_test.geojson")#Offshore +studyArea <- st_read("../studyAreaTest/geoms_slc_test.geojson")#Offshore # studyArea <- st_read("../studyAreaTest/geoms_slc_coastal_test.geojson")#coastal # studyArea <- st_read("../studyAreaTest/geoms_slc_no_land.geojson") #no land region <- st_read(here::here("app/studyAreaTest/geoms_slc_MarBioRegion.geojson")) @@ -71,7 +71,7 @@ regionMap <- region_map(regionBox, studyArea, land10m_sf, bounds_sf) - diff --git a/dataprocessing/MakeTestData.R b/dataprocessing/MakeTestData.R index b9ee23d..7adf601 100644 --- a/dataprocessing/MakeTestData.R +++ b/dataprocessing/MakeTestData.R @@ -168,14 +168,14 @@ gen_all_test_data <- function() { listed_species, obis_cet_sf, obis_fish_sf, rockweed_sf, RVCatch_sf, RVGSSPECIES, sei_whale_sf, sardist_sf, isdb_sf, ISSPECIESCODES, leatherback_sf, Legend, marfis_sf, MARFISSPECIESCODES, narwc_sf, whitehead_sf, - wsdb_sf) + wsdb_sf, ocearch_sf) sf_names <- c("NBNW_ImpHab_sf", "bioregion_sf", "BlueWhale_ImpHab_sf", "bounds_sf", "ClippedCritHab_sf", "EBSA_sf", "fin_whale_sf", "harbour_porpoise_sf", "humpback_whale_sf", "land10m_sf", "land50k_sf", "listed_cetacean_species", "listed_fish_invert_species", "listed_other_species", "listed_species", "obis_cet_sf", "obis_fish_sf", "rockweed_sf", "RVCatch_sf", "RVGSSPECIES", "sei_whale_sf", "sardist_sf", "isdb_sf", "ISSPECIESCODES", "leatherback_sf", "Legend", "marfis_sf", "MARFISSPECIESCODES", "narwc_sf", "whitehead_sf", - "wsdb_sf") + "wsdb_sf", "ocearch_sf") exclude_list <- c("bounds_sf", "land10m_sf", "land50k_sf") From 76514ec4a9c3bf4f29fec1ed5a812f91901ebd59 Mon Sep 17 00:00:00 2001 From: Gomez Date: Fri, 27 Aug 2021 17:02:07 -0300 Subject: [PATCH 06/10] OCEARCH data updated in IN folder - metadata was updated. Here location of file was updated to include in SecureData.Rdata --- dataprocessing/SaveDataSets_asRdata.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dataprocessing/SaveDataSets_asRdata.R b/dataprocessing/SaveDataSets_asRdata.R index 3012e0c..de28e40 100644 --- a/dataprocessing/SaveDataSets_asRdata.R +++ b/dataprocessing/SaveDataSets_asRdata.R @@ -233,7 +233,7 @@ ISSPECIESCODES <- ISSPECIESCODES %>% rename("Common Name"= COMMON, MARFISSPECIESCODES <- SPECIES %>% rename("COMMONNAME"= SPECIES_NAME) # LOAD OCEARCH DATA ############# -ocearchDatafile <- here::here("app/data/ocearch_raw.csv") +ocearchDatafile <- ("../Data/NaturalResources/Species/Sharks/OCEARCH/OCEARCH_08-27-2021.csv") lines <- readLines(ocearchDatafile) lines <- gsub('(^"|"$)', "", lines) ocearch <- read.csv(textConnection(lines), quote = '""') From 29f5416e028e59e3e7bda5a68037dd55de6e9483 Mon Sep 17 00:00:00 2001 From: Stoyel Date: Wed, 1 Sep 2021 08:57:34 -0300 Subject: [PATCH 07/10] add copyRdata helper function, record number of records found for ocearch --- app/R/renderReport.R | 3 ++- app/Rmd/intro_EN.Rmd | 4 ++-- app/Rmd/report_fish_EN.Rmd | 13 +++++++------ dataprocessing/CopyRData.R | 6 ++++++ 4 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 dataprocessing/CopyRData.R diff --git a/app/R/renderReport.R b/app/R/renderReport.R index 7382273..44989f9 100644 --- a/app/R/renderReport.R +++ b/app/R/renderReport.R @@ -78,7 +78,8 @@ renderReport <- function(input, geoms, outFileName = NULL, dirOut = "output", ) } # end of language loop - + msgInfo("Render complete") + if (all(ok)) { # this is done to generate an html preview (see "report" tab) htmlName <- switch_ext(basename(inFile), "html") diff --git a/app/Rmd/intro_EN.Rmd b/app/Rmd/intro_EN.Rmd index 631f2ea..32bc926 100644 --- a/app/Rmd/intro_EN.Rmd +++ b/app/Rmd/intro_EN.Rmd @@ -39,10 +39,10 @@ lapply(list.files(here::here("app/R"), pattern = ".[Rr]$", full.names = TRUE),so ``` ```{r Load-Search-Area, echo=FALSE, include=FALSE, cache=FALSE} -# studyArea <- sf::st_read("{{path_to_geoms}}") +studyArea <- sf::st_read("{{path_to_geoms}}") # studyArea <- sf::st_read(here::here("app/output/geoms_slc.geojson")) # Uncomment the following to test fixed polygon: -studyArea <- st_read("../studyAreaTest/geoms_slc_test.geojson")#Offshore +# studyArea <- st_read("../studyAreaTest/geoms_slc_test.geojson")#Offshore # studyArea <- st_read("../studyAreaTest/geoms_slc_coastal_test.geojson")#coastal # studyArea <- st_read("../studyAreaTest/geoms_slc_no_land.geojson") #no land region <- st_read(here::here("app/studyAreaTest/geoms_slc_MarBioRegion.geojson")) diff --git a/app/Rmd/report_fish_EN.Rmd b/app/Rmd/report_fish_EN.Rmd index fdb9153..4b925f1 100644 --- a/app/Rmd/report_fish_EN.Rmd +++ b/app/Rmd/report_fish_EN.Rmd @@ -218,25 +218,26 @@ OCEARCH is a data-centric organization built to help scientists collect previous ```{r ocearch-results, include=FALSE, cache=FALSE} -outputList <- master_intersect(ocearch_sf, region, studyArea, mapBbox = bboxMap, Year = minYear) -Samples_bbox <- outputList$mapPoints +ocearchOutputList <- master_intersect(ocearch_sf, region, studyArea, mapBbox = bboxMap, Year = minYear) ``` ```{r ocearch-check, echo=FALSE, results='asis',} -Report_ocearch <- if (is.null(outputList)) { +Report_ocearch <- if (is.null(ocearchOutputList)) { "There are no relevant White Shark records in the OCEARCH Shark Tracker for this search area." } else { - "There are relevant White Shark records in OCEARCH Shark Tracker search results for this search area." + numRecords <- length(ocearchOutputList$studyData$geometry) + distinctIndv <- dplyr::n_distinct(ocearchOutputList$studyData$ID) + paste("There are", numRecords, "relevant White Shark records for", distinctIndv, "individuals in OCEARCH Shark Tracker search results for this search area.") } Report_obis<-noquote(Report_ocearch) writeLines(Report_ocearch) ``` ```{r, fig.height=8, fig.width=11, fig.cap='Quality Tier: Medium. Security level: none. Map showing the search area defined by the user (red outline) was used to query information from OCEARCH Shark Tracker observation records, for White Shark. Dataset set has not yet been completely error-checked. The absence of a species in this figure should be interpreted as an absence of tracking data, not necessarily as an absence of the species in the area.'} -if (!is.null(outputList)) { +if (!is.null(ocearchOutputList)) { areaMap + - geom_point(data = Samples_bbox, aes(x = long, y = lat), size = 2, shape = 16, col = "black") + geom_point(data = ocearchOutputList$mapPoints, aes(x = long, y = lat), size = 2, shape = 16, col = "black") } ``` diff --git a/dataprocessing/CopyRData.R b/dataprocessing/CopyRData.R new file mode 100644 index 0000000..08b9c65 --- /dev/null +++ b/dataprocessing/CopyRData.R @@ -0,0 +1,6 @@ + +copy_rdata_files <- function() { + rDataDir <- "\\\\ent.dfo-mpo.ca\\ATLShares\\Science\\BIODataSvc\\IN\\MSP\\Data\\Rdata\\data" + dataFileList <- list.files(rDataDir, full.names = TRUE) + file.copy(dataFileList, here::here("app/data/"), overwrite = TRUE) +} From bb75a63a7b4047b7be2fb072ac1a58d22170321c Mon Sep 17 00:00:00 2001 From: Stoyel Date: Wed, 1 Sep 2021 09:10:47 -0300 Subject: [PATCH 08/10] update readme --- README.md | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 72b5d27..ceadaed 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,8 @@ R Shiny App to select search area(s) and generate reproducible reports (R Markdo ## Installation ## Set up Revn: -```R + +``` r install.packages("renv") renv::activate() renv::equip() # loads needed installation libs @@ -17,13 +18,26 @@ renv::restore() # loads all needed packages (may take 15+ mins the first time) ``` Adding a package: -```R + +``` r install.packages("new_package") renv::snapshot() ``` After adding a new package, commit the updated renv.lock file to source control. +## Download necessary data + +After making sure that you have the necessary permissions to access the data, run: + +``` r +source(here::here("dataprocessing/CopyRData.R")) +copy_rdata_files() +``` + +## Unit Tests: + +Once Renv is setup and data has been loaded, running `testthat::test_local()` should pass all unit tests. ## Run the application @@ -43,6 +57,8 @@ See [demo.webm](https://github.com/dfo-mar-odis/shinySpatialApp/raw/main/demo.we - `app/R` includes the R files to be loaded (it loads packages and functions); - `app/Rmd` includes all the `.Rmd` files needed to generate the report(s); - `app/output` includes all outputs once generated: selected geometries as a `.geojson` and the report in all format (the different section are also added). +- `dataprocessing` contains all of the preprocessing scripts to prepare data for use in the application. +- `tests/testthat` contains the unit test scripts that are run when test_local() is called. # **Collaborative Workflow** From 6fcfaea2c8e00f6f6afc407cd36aa678d7e54ccd Mon Sep 17 00:00:00 2001 From: Stoyel Date: Wed, 1 Sep 2021 15:18:35 -0300 Subject: [PATCH 09/10] add data file syncer --- dataprocessing/CopyRData.R | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/dataprocessing/CopyRData.R b/dataprocessing/CopyRData.R index 08b9c65..e609bb5 100644 --- a/dataprocessing/CopyRData.R +++ b/dataprocessing/CopyRData.R @@ -1,6 +1,21 @@ copy_rdata_files <- function() { + rDataDir <- "\\\\ent.dfo-mpo.ca\\ATLShares\\Science\\BIODataSvc\\IN\\MSP\\Data\\Rdata\\data" - dataFileList <- list.files(rDataDir, full.names = TRUE) - file.copy(dataFileList, here::here("app/data/"), overwrite = TRUE) + + localDataDir <- here::here("app/data/") + remoteInfo <- file.info(list.files(rDataDir, full.names = TRUE)) + remoteInfo["filenames"] = list.files(rDataDir) + localInfo <- file.info(list.files(localDataDir, full.names = TRUE)) + localInfo["filenames"] = list.files(localDataDir) + + allInfo <- merge(remoteInfo, localInfo, by="filenames") + updateList <- allInfo$mtime.x > allInfo$mtime.y + if (any(updateList)) { + updateFileList <- filter(allInfo, updateList)$filenames + updateFilePath <- rownames(filter(remoteInfo, remoteInfo$filename %in% updateFileList)) + copyResults <- file.copy(updateFilePath, localDataDir, overwrite = TRUE) + } + return("Data files up to date") + } From c2a9968bab8c4098a2db338c01dc4da21ff88ed5 Mon Sep 17 00:00:00 2001 From: Stoyel Date: Fri, 3 Sep 2021 11:14:19 -0300 Subject: [PATCH 10/10] incorporate new plot_rr_sf and copy_rdata_file fns --- dataprocessing/CopyRData.R => app/R/copyRData.R | 2 +- app/Rmd/intro_EN.Rmd | 4 +++- app/Rmd/intro_FR.Rmd | 3 ++- app/Rmd/report_fish_EN.Rmd | 7 +++---- app/Rmd/report_habitat_FR.Rmd | 10 +++++----- 5 files changed, 14 insertions(+), 12 deletions(-) rename dataprocessing/CopyRData.R => app/R/copyRData.R (95%) diff --git a/dataprocessing/CopyRData.R b/app/R/copyRData.R similarity index 95% rename from dataprocessing/CopyRData.R rename to app/R/copyRData.R index e609bb5..9a52ae1 100644 --- a/dataprocessing/CopyRData.R +++ b/app/R/copyRData.R @@ -16,6 +16,6 @@ copy_rdata_files <- function() { updateFilePath <- rownames(filter(remoteInfo, remoteInfo$filename %in% updateFileList)) copyResults <- file.copy(updateFilePath, localDataDir, overwrite = TRUE) } - return("Data files up to date") + return("Data files up to date :)") } diff --git a/app/Rmd/intro_EN.Rmd b/app/Rmd/intro_EN.Rmd index ab2973f..ad27a81 100644 --- a/app/Rmd/intro_EN.Rmd +++ b/app/Rmd/intro_EN.Rmd @@ -30,12 +30,14 @@ knitr::opts_chunk$set(echo = FALSE, warning=FALSE, message=FALSE, fig.align="lef ```{r load-data-and-functions, echo=FALSE, include=FALSE, cache=FALSE} minYear <- 2010 +lapply(list.files(here::here("app/R"), pattern = ".[Rr]$", full.names = TRUE),source) # check helpers.R for a list of packages +copy_rdata_files() # make sure data files are up to date. load(here::here("app/data/testData.RData")) #load(here::here("app/data/OpenData.RData")) #load(here::here("app/data/OpenData_sardist.RData")) #load(here::here("app/data/SecureData.RData")) #load("\\\\ent.dfo-mpo.ca\\ATLShares\\Science\\BIODataSvc\\SRC\\Reproducible_Reporting\\data\\SecureData.Rdata") -lapply(list.files(here::here("app/R"), pattern = ".[Rr]$", full.names = TRUE),source) # check helpers.R for a list of packages + ``` ```{r Load-Search-Area, echo=FALSE, include=FALSE, cache=FALSE} diff --git a/app/Rmd/intro_FR.Rmd b/app/Rmd/intro_FR.Rmd index c88d898..d69e796 100644 --- a/app/Rmd/intro_FR.Rmd +++ b/app/Rmd/intro_FR.Rmd @@ -30,11 +30,12 @@ knitr::opts_chunk$set(echo = FALSE, warning=FALSE, message=FALSE, fig.align="lef ```{r load-data-and-functions, echo=FALSE, include=FALSE, cache=FALSE} minYear <- 2010 +lapply(list.files("../R", pattern = ".[Rr]$", full.names = TRUE),source) # check helpers.R for a list of packages +copy_rdata_files() # make sure data files are up do date. load("../data/OpenData.RData") load("../data/OpenData_sardist.RData") load("../data/SecureData.RData") #load("\\\\ent.dfo-mpo.ca\\ATLShares\\Science\\BIODataSvc\\SRC\\Reproducible_Reporting\\data\\SecureData.Rdata") -lapply(list.files("../R", pattern = ".[Rr]$", full.names = TRUE),source) # check helpers.R for a list of packages ``` ```{r Load-Search-Area, echo=FALSE, include=FALSE, cache=FALSE} diff --git a/app/Rmd/report_fish_EN.Rmd b/app/Rmd/report_fish_EN.Rmd index b6b9aa9..7cdc46b 100644 --- a/app/Rmd/report_fish_EN.Rmd +++ b/app/Rmd/report_fish_EN.Rmd @@ -226,7 +226,7 @@ OCEARCH is a data-centric organization built to help scientists collect previous ```{r ocearch-results, include=FALSE, cache=FALSE} -ocearchOutputList <- master_intersect(ocearch_sf, region, studyArea, mapBbox = bboxMap, Year = minYear) +ocearchOutputList <- master_intersect(ocearch_sf, mapDataList) ``` @@ -242,10 +242,9 @@ Report_ocearch <- if (is.null(ocearchOutputList)) { Report_obis<-noquote(Report_ocearch) writeLines(Report_ocearch) ``` -```{r, fig.height=8, fig.width=11, fig.cap='Quality Tier: Medium. Security level: none. Map showing the search area defined by the user (red outline) was used to query information from OCEARCH Shark Tracker observation records, for White Shark. Dataset set has not yet been completely error-checked. The absence of a species in this figure should be interpreted as an absence of tracking data, not necessarily as an absence of the species in the area.'} +```{r ocearch-plot, fig.height=8, fig.width=11, fig.cap='Quality Tier: Medium. Security level: none. Map showing the search area defined by the user (red outline) was used to query information from OCEARCH Shark Tracker observation records, for White Shark. Dataset set has not yet been completely error-checked. The absence of a species in this figure should be interpreted as an absence of tracking data, not necessarily as an absence of the species in the area.'} if (!is.null(ocearchOutputList)) { - areaMap + - geom_point(data = ocearchOutputList$mapPoints, aes(x = long, y = lat), size = 2, shape = 16, col = "black") + plot_rr_sf(areaMap, ocearchOutputList$mapPoints) } ``` diff --git a/app/Rmd/report_habitat_FR.Rmd b/app/Rmd/report_habitat_FR.Rmd index 56d078e..2da26d7 100644 --- a/app/Rmd/report_habitat_FR.Rmd +++ b/app/Rmd/report_habitat_FR.Rmd @@ -26,7 +26,7 @@ poly_sf <- rockweed_sf attribute <- "RWP" # intersect polyData with 3 polygons (region, map area, and study box) -clipped <- master_intersect(poly_sf, region, studyArea, bboxMap) +clipped <- master_intersect(poly_sf, mapDataList) ``` * ```{r overlap rockweed output, echo=FALSE, results='asis'} @@ -38,17 +38,17 @@ polyText<-if(is.null(clipped$studyData)){"Il n’existe aucun registre pertinent writeLines(polyText) ``` -```{r, fig.height=8, fig.width=11, fig.cap='Niveau de qualité : Moyenne. Niveau de sécurité : Aucun. Carte montrant la zone de recherche définie par l’utilisateur : l’emplacement du projet ou de l’activité proposé est surligné en jaune (polygone d’entrée), entouré d’une zone exposée ou d’une zone tampon définie par l’utilisateur en bleu. La figure illustre le chevauchement entre la zone de recherche et les cartes satellitaires de la végétation intertidale et des polygones de présence de fucus.'} +```{r rockweed-plot, fig.height=8, fig.width=11, fig.cap='Niveau de qualité : Moyenne. Niveau de sécurité : Aucun. Carte montrant la zone de recherche définie par l’utilisateur : l’emplacement du projet ou de l’activité proposé est surligné en jaune (polygone d’entrée), entouré d’une zone exposée ou d’une zone tampon définie par l’utilisateur en bleu. La figure illustre le chevauchement entre la zone de recherche et les cartes satellitaires de la végétation intertidale et des polygones de présence de fucus.'} if(!is.null(clipped$studyData)){print( - plot_polygons(areaMap, bboxMap, studyBox_geom, clipped$mapData,attribute))} + plot_rr_sf(areaMap, clipped$mapData, attribute))} ``` -```{r table rockweed, echo=FALSE, cache=FALSE, include = FALSE} +```{r table-rockweed, echo=FALSE, cache=FALSE, include = FALSE} if(!is.null(clipped$studyData)){ rwTable <- rockweedStats(clipped$studyData, studyArea)} ``` -```{r} +```{r rockweed-table} if(!is.null(clipped$studyData)){ knitr::kable(rwTable,align="l", caption = "Nombre de polygones de végétation et la superficie occupée par chaque catégorie pour la zone d’étude. La végétation intertidale totale est la somme de tous les catégories.", booktabs = T, escape = F, linesep="") %>%