-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into fix_warnings_atmosphere
- Loading branch information
Showing
10 changed files
with
291 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# | ||
# Add project labels | ||
# | ||
|
||
# Add 'Documentation' label to any changes in the documentation | ||
|
||
'Documentation': | ||
- book_source/** | ||
- documentation/** | ||
- CONTRIBUTING.md | ||
- DEBUGING.md | ||
- DEV-INTRO.md | ||
- README.md | ||
|
||
# Add 'Dockerfile' label to any changes in the docker directory | ||
'Dockerfile': | ||
- docker/** | ||
|
||
|
||
# Add 'Website' label to any changes in the web directory | ||
|
||
'Website': | ||
- web/** | ||
|
||
# Add 'Base' label to any changes in the base directory | ||
|
||
'Base': | ||
- base/** | ||
|
||
# Add 'Models' label to any changes in the models directory | ||
|
||
'Models': | ||
- models/** | ||
|
||
# Add 'Modules' label to any changes in the modules directory | ||
|
||
'Modules': | ||
- modules/** | ||
|
||
# Add 'GitHub Actions' label to any changes in the .github/workflows directory | ||
|
||
'GitHub Actions': | ||
- .github/workflows/** | ||
|
||
# Add 'Scripts' label to any changes in the scripts directory | ||
|
||
'Scripts': | ||
- scripts/** | ||
|
||
# Add 'Tests' label to any changes in the tests directory | ||
|
||
'Tests': | ||
- tests/** | ||
- '**/tests/**' | ||
- '!**/tests/Rcheck_reference.log' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#Define the colour of labels over here | ||
|
||
labels: | ||
|
||
- name: "Documentation" | ||
color: a2dcf2 | ||
|
||
- name: "Dockerfile" | ||
color: 0052CC | ||
|
||
- name: "Website" | ||
color: 84b6eb | ||
|
||
- name: "Base" | ||
color: 1ED626 | ||
|
||
- name: "Models" | ||
color: C5DEF5 | ||
|
||
- name: "Modules" | ||
color: FBCA04 | ||
|
||
- name: "GitHub Actions" | ||
color: 84b6eb | ||
|
||
- name: "Scripts" | ||
color: 3B8924 | ||
|
||
- name: "Tests" | ||
color: ff8c00 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# This workflow is based on github action official label action v4. | ||
# This workflow action is triggered on pull request event(on both fork & inside repo) | ||
# Labels will be applied based on filepath modification in PR. | ||
# This workflow uses a regex based labeling config file(.github/labeler.yml) to take labeling decision. | ||
|
||
name: "PR Labeler" | ||
on: | ||
- pull_request_target | ||
jobs: | ||
label: | ||
permissions: | ||
contents: read | ||
pull-requests: write | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/labeler@v4 | ||
with: | ||
repo-token: "${{ secrets.GITHUB_TOKEN }}" | ||
configuration-path: ".github/labeler.yml" | ||
sync-labels: false | ||
dot: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
##' @title North America Downscale Function | ||
##' @name NA_downscale | ||
##' @author Joshua Ploshay | ||
##' | ||
##' @param data In quotes, file path for .rds containing ensemble data. | ||
##' @param focus_year In quotes, if SDA site run, format is yyyy/mm/dd, if NEON, yyyy-mm-dd. Restricted to years within file supplied to 'data'. | ||
##' @param C_pool In quotes, carbon pool of interest. Name must match carbon pool name found within file supplied to 'data'. | ||
##' @param covariates In quotes, file path of SpatRaster stack, used as predictors in randomForest. Layers within stack should be named. | ||
##' @param cords In quotes, file path for .csv file containing the site coordinates, columns named "lon" and "lat". | ||
##' @details This function will downscale forecast data to unmodeled locations using covariates and site locations | ||
##' | ||
##' @description This function uses the randomForest model. | ||
##' | ||
##' @return It returns the `downscale_output` list containing lists for the training and testing data sets, models, and predicted maps for each ensemble member. | ||
|
||
|
||
NA_downscale <- function(data, cords, covariates, focus_year, C_pool){ | ||
|
||
# Read in the covariates and set CRS to EPSG:4326 | ||
covariates <- terra::rast(covariates) # ADD package to every function | ||
terra::crs(covariates) <- "EPSG:4326" | ||
|
||
# Read the input data and site coordinates | ||
input_data <- readRDS(data) | ||
site_coordinates <- terra::vect(readr::read_csv(cords), geom=c("lon", "lat"), crs="EPSG:4326") | ||
|
||
# Extract the carbon data for the specified focus year | ||
index <- which(names(input_data) == focus_year) | ||
data <- input_data[[index]] | ||
carbon_data <- as.data.frame(t(data[which(names(data) == C_pool)])) | ||
names(carbon_data) <- paste0("ensemble",seq(1:ncol(carbon_data))) | ||
|
||
# Extract predictors from covariates raster using site coordinates | ||
predictors <- as.data.frame(terra::extract(covariates, site_coordinates)) | ||
predictors <- dplyr::select(predictors, -1) | ||
|
||
# Combine each ensemble member with all predictors | ||
ensembles <- list() | ||
for (i in seq_along(carbon_data)) { | ||
ensembles[[i]] <- cbind(carbon_data[[i]], predictors) | ||
} | ||
|
||
# Rename the carbon_data column for each ensemble member | ||
for (i in 1:length(ensembles)) { | ||
ensembles[[i]] <- dplyr::rename(ensembles[[i]], "carbon_data" = "carbon_data[[i]]") | ||
} | ||
|
||
# Split the observations in each data frame into two data frames based on the proportion of 3/4 | ||
ensembles <- lapply(ensembles, function(df) { | ||
sample <- sample(1:nrow(df), size = round(0.75*nrow(df))) | ||
train <- df[sample, ] | ||
test <- df[-sample, ] | ||
split_list <- list(train, test) | ||
return(split_list) | ||
}) | ||
|
||
# Rename the training and testing data frames for each ensemble member | ||
for (i in 1:length(ensembles)) { | ||
# names(ensembles) <- paste0("ensemble",seq(1:length(ensembles))) | ||
names(ensembles[[i]]) <- c("training", "testing") | ||
} | ||
|
||
# Train a random forest model for each ensemble member using the training data | ||
output <- list() | ||
for (i in 1:length(ensembles)) { | ||
output[[i]] <- randomForest::randomForest(ensembles[[i]][[1]][["carbon_data"]] ~ land_cover+tavg+prec+srad+vapr+nitrogen+phh2o+soc+sand, | ||
data = ensembles[[i]][[1]], | ||
ntree = 1000, | ||
na.action = stats::na.omit, | ||
keep.forest = T, | ||
importance = T) | ||
} | ||
|
||
# Generate predictions (maps) for each ensemble member using the trained models | ||
maps <- list(ncol(output)) | ||
for (i in 1:length(output)) { | ||
maps[[i]] <- terra::predict(object = covariates, | ||
model = output[[i]],na.rm = T) | ||
} | ||
|
||
# Organize the results into a single output list | ||
downscale_output <- list(ensembles, output, maps) | ||
|
||
# Rename each element of the output list with appropriate ensemble numbers | ||
for (i in 1:length(downscale_output)) { | ||
names(downscale_output[[i]]) <- paste0("ensemble",seq(1:length(downscale_output[[i]]))) | ||
} | ||
|
||
# Rename the main components of the output list | ||
names(downscale_output) <- c("data", "models", "maps") | ||
|
||
return(downscale_output) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.