Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/development' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmseddy committed Nov 15, 2018
2 parents eeaf530 + 80c619e commit 54c4145
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Boreal_LBMRDataPrep.R
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ Save <- function(sim) {
targetFile = asPath(basename(biomassMapFilename)),
archive = asPath(c("kNN-StructureBiomass.tar",
"NFI_MODIS250m_kNN_Structure_Biomass_TotalLiveAboveGround_v0.zip")),
#url = extractURL("biomassMap"),
url = extractURL("biomassMap"),
destinationPath = dPath,
studyArea = sim$shpStudyArea,
rasterToMatch = sim$rasterToMatch,
Expand Down
10 changes: 5 additions & 5 deletions R/initialCommunityProducer.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
initialCommunityProducer <- function(speciesLayers, speciesPresence, studyArea, rstStudyArea) {
specieslayerInStudyArea <- crop(speciesLayers, studyArea)
specieslayerInStudyArea <- crop(speciesLayers, studyArea) ## TODO: Ceres: this is probably no longer necessary
#if(isTRUE(tryCatch(getCluster(), error=function(x) TRUE, silent=TRUE))) beginCluster()
specieslayerInStudyArea <- specieslayerInStudyArea * rstStudyArea
names(specieslayerInStudyArea) <- names(speciesLayers)
specieslayerInStudyArea <- specieslayerInStudyArea * rstStudyArea ## TODO: Ceres: this is probably no longer necessary
names(specieslayerInStudyArea) <- names(speciesLayers) ## TODO: Ceres: this is probably no longer necessary

#specieslayerInStudyArea <- specieslayerInStudyArea*(!is.na(rstStudyArea))
# specieslayerInStudyArea <- suppressWarnings(fastMask(specieslayerInStudyArea, # studyArea))
speciesNames <- names(specieslayerInStudyArea)[which(maxValue(specieslayerInStudyArea) >= speciesPresence)]
specieslayerBySpecies <- raster::subset(specieslayerInStudyArea, speciesNames[1])
speciesNames <- names(specieslayerInStudyArea)[which(maxValue(specieslayerInStudyArea) >= speciesPresence)] ## TODO: Ceres: this is probably no longer necessary
specieslayerBySpecies <- raster::subset(specieslayerInStudyArea, speciesNames[1]) ## TODO: Ceres: this is probably no longer necessary
specieslayerBySpecies[which(is.na(specieslayerBySpecies[]) & specieslayerBySpecies[] <= 5)] <- 0 ## Ceres: this is weird, shouldn't this be OR?
# specieslayerBySpecies[Which(is.na(specieslayerBySpecies) & specieslayerBySpecies<=5,
# cells = TRUE)] <- 0 # 5% or less presence removed
Expand Down
20 changes: 10 additions & 10 deletions R/loadkNNSpeciesLayers.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Function to load kNN species layers from online data repository
## ------------------------------------------------------------------

## dataPath: directory to data folder
## dPath: directory to data folder
## rasterToMatch: passed to prepInputs
## studyArea: passed to prepInputs
## species is either a character vector of species names to download,
Expand All @@ -12,7 +12,7 @@
## Defaults to 1
## url: is the source url for the data, passed to prepInputs.

loadkNNSpeciesLayers <- function(dataPath, rasterToMatch, studyArea,
loadkNNSpeciesLayers <- function(dPath, rasterToMatch, studyArea,
speciesList = NULL, thresh = 1, url, cachePath, ...) {


Expand All @@ -38,20 +38,20 @@ loadkNNSpeciesLayers <- function(dataPath, rasterToMatch, studyArea,

species1 <- Cache(loadFun, url = url, spp = speciesList, #[, "speciesNamesRaw"],
#loadFun,
dataPath = dataPath,
dPath = dPath,
suffix = suffix,
studyArea = studyArea, rasterToMatch = rasterToMatch,
userTags = "kNN_SppLoad")
# species1 <- Cache(lapply, seq_len(NROW(speciesList)),
# spp = speciesList, #[, "speciesNamesRaw"],
# loadFun, url = url, dataPath = dataPath,
# loadFun, url = url, dPath = dPath,
# suffix = suffix,
# studyArea = studyArea, rasterToMatch = rasterToMatch,
# userTags = "kNN_SppLoad")

## get all kNN species
if (FALSE) { #TODO This no longer does all species }
allSpp <- Cache(untar, tarfile = file.path(dataPath, "kNN-Species.tar"), list = TRUE)
allSpp <- Cache(untar, tarfile = file.path(dPath, "kNN-Species.tar"), list = TRUE)
allSpp <- allSpp %>%
grep(".zip", ., value = TRUE) %>%
sub("_v0.zip", "", .) %>%
Expand Down Expand Up @@ -83,7 +83,7 @@ loadkNNSpeciesLayers <- function(dataPath, rasterToMatch, studyArea,
sumSpecies <- spp2sum[[i]]
newLayerName <- names(spp2sum)[i]

fname <- .suffix(file.path(dataPath, paste0("KNN", newLayerName, ".tif")), suffix)
fname <- .suffix(file.path(dPath, paste0("KNN", newLayerName, ".tif")), suffix)
a <- Cache(sumRastersBySpecies,
speciesLayers = species1[sumSpecies],
newLayerName = newLayerName,
Expand Down Expand Up @@ -135,7 +135,7 @@ sumRastersBySpecies <- function(speciesLayers, layersToSum,
ras_out # Work around for Cache
}

loadFun <- function(speciesListIndex, spp, suffix, url, dataPath,
loadFun <- function(speciesListIndex, spp, suffix, url, dPath,
studyArea, rasterToMatch) {

if (is.null(spp)) {
Expand Down Expand Up @@ -173,7 +173,7 @@ loadFun <- function(speciesListIndex, spp, suffix, url, dataPath,
targetFile = targetFile,
url = url,
archive = archive,
destinationPath = asPath(dataPath),
destinationPath = asPath(dPath),
fun = "raster::raster")#,
#studyArea = studyArea,
#rasterToMatch = rasterToMatch,
Expand Down Expand Up @@ -203,7 +203,7 @@ loadFun <- function(speciesListIndex, spp, suffix, url, dataPath,
species1 <- Map(targetFile = targetFiles, archive = archives,
filename2 = postProcessedFilenames,
MoreArgs = list(url = url,
destinationPath = asPath(dataPath),
destinationPath = asPath(dPath),
fun = "raster::raster",
studyArea = studyArea,
rasterToMatch = rasterToMatch,
Expand All @@ -216,7 +216,7 @@ loadFun <- function(speciesListIndex, spp, suffix, url, dataPath,
# targetFile = targetFile,
# url = url,
# archive = archive,
# destinationPath = asPath(dataPath),
# destinationPath = asPath(dPath),
# fun = "raster::raster",
# studyArea = studyArea,
# rasterToMatch = rasterToMatch,
Expand Down

0 comments on commit 54c4145

Please sign in to comment.