Skip to content

Commit

Permalink
Merge pull request #204 from USEPA/methane_reorg_fixActions_issue203
Browse files Browse the repository at this point in the history
Methane reorg fix actions issue #203
  • Loading branch information
knoiva-indecon authored Nov 26, 2024
2 parents 4d30193 + 84208f5 commit 679b8dc
Show file tree
Hide file tree
Showing 59 changed files with 1,764 additions and 1,883 deletions.
229 changes: 122 additions & 107 deletions .github/workflows/build_fredi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,25 @@ on:
options:
- no
- yes
# update_results:
update_scenarios:
type: choice
description: Update scenarios?
required: true
options:
- no
- yes

# - "GDP"
# - "Population"
# - "Temp/SLR"
# - "O3/CH4/NOx"
# date_results:
# type: choice
# description: Update default results?
# required: true
# options:
# - no
# - yes
update_scenarios:
type: multi-choice
description: Update scenarios?
required: true
options:
- GDP
- Population
- Temps & SLR
- O3, CH4, & NOx

jobs:
compile_data:
Expand Down Expand Up @@ -64,153 +67,165 @@ jobs:
- name: Update Scenarios
run: |
Rscript -e '
require(tidyverse)
require(devtools)
require(ggpubr)
require(openxlsx)
###### Conditionals ######
### Which scenarios/documentation to update
do_docs <- "yes" %in% "${{ inputs.update_scenarios}}"
do_gdp <- "GDP" %in% "${{ inputs.update_scenarios}}"
do_pop <- "Pop" %in% "${{ inputs.update_scenarios}}"
do_temp <- "Temps & SLR" %in% "${{ inputs.update_scenarios}}"
do_o3 <- "${{ inputs.update_scenarios}}" |> str_detect(pattern="O3") |> any()
do_docs <- "true" %in% "${{ inputs.update_docs}}"
do_data <- "true" %in% "${{ inputs.update_scenarios}}"
do_gdp <- do_data
do_pop <- do_data
do_temp <- do_data
do_o3 <- do_data
# do_gdp <- "GDP" %in% "${{ inputs.update_scenarios}}"
# do_pop <- "Pop" %in% "${{ inputs.update_scenarios}}"
# do_temp <- "Temps & SLR" %in% "${{ inputs.update_scenarios}}"
# do_o3 <- "${{ inputs.update_scenarios}}" |> str_detect(pattern="O3") |> any()
c(do_docs, do_data) |> print()
###### File Paths ######
### - Main repo path, FrEDI project path
### - Data path, scenario csv path
rPath0 <- "."
pPath0 <- rPath0 |> file.path("FrEDI")
dPath0 <- rPath0 |> file.path("data" )
cPath0 <- rPath0 |> file.path("inst", "extdata", "scenarios")
###### Update Scenarios ######
### GDP
if(do_gdp) {
gdpDefault <- "gdp_default" |> get_frediDataObj("scenarioData")
fGdp <- "gdpDefault"
dGdp <- dPath0 |> paste0(fGdp, ".rda")
cGdp <- cPath0 |> paste0(fGdp, ".csv")
gdpDefault |> save(file=dGdp)
gdpDefault |> write.csv(filename=cGdp, row.names=F)
rm(fGdp, dGdp, cGdp, gdpDefault)
} ### End if(do_gdp)
### Population
if(do_pop) {
popDefault <- "pop_default" |> get_frediDataObj("scenarioData")
fPop <- "popDefault"
dPop <- dPath0 |> paste0(fPop, ".rda")
cPop <- cPath0 |> paste0(fPop, ".csv")
popDefault |> save(file=dPop)
popDefault |> write.csv(filename=cPop, row.names=F)
rm(fPop, dPop, cPop, popDefault)
} ### End if(do_pop)
### Temperature & CSV
if(do_temp) {
gcamScenarios <- "gcam_scenarios" |> get_frediDataObj("scenarioData")
fTemps <- "gcamScenarios"
dTemps <- dPath0 |> paste0(fTemps, ".rda")
cTemps <- cPath0 |> paste0(fTemps, ".csv")
gcamScenarios |> save(file=dTemps)
gcamScenarios |> write.csv(filename=cTemps, row.names=F)
rm(fTemps, dTemps, cTemps, gcamScenarios)
} ### End if(do_temp)
### O3, CH4, and NOx
if(do_o3) {
### Ozone
select0 <- c("region", "state", "postal", "model", "year", "O3_pptv")
o3Default <- "o3_default" |> get_frediDataObj(listSub="scenarioData", listName="listMethane")
o3Default <- o3Default |> select(all_of(select0))
rm(select0)
# ### Adjust the default scenario
# co_mods <- "co_models" |> get_frediDataObj(listSub="package", listName="listMethane")
# co_mods <- co_mods |> select(model, model_label)
# o3Default <- o3Default |> left_join(co_mods, by=c("model"))
# o3Default <- o3Default |> select(-model)
# o3Default <- o3Default |> rename(model=model_label)
# o3Default <- o3Default |> relocate(c("model"))
### Save ozone
fO3 <- "o3Default"
dO3 <- dPath0 |> paste0(fO3, ".rda")
cO3 <- cPath0 |> paste0(fO3, ".csv")
o3Default |> save(file=dO3)
o3Default |> write.csv(filename=cO3, row.names=F)
rm(fO3, dO3, cO3, o3Default)
### CH4
ch4Default <- "ch4_default" |> get_frediDataObj(listSub="scenarioData", listName="listMethane")
fCH4 <- "ch4Default"
dCH4 <- dPath0 |> paste0(fCH4, ".rda")
cCH4 <- cPath0 |> paste0(fCH4, ".csv")
ch4Default |> save(file=dCH4)
ch4Default |> write.csv(filename=cCH4, row.names=F)
rm(fCH4, dCH4, cCH4, ch4Default)
### NOx
noxDefault <- "nox_default" |> get_frediDataObj(listSub="scenarioData", listName="listMethane")
fNOx <- "noxDefault"
dNOx <- dPath0 |> paste0(fNOx, ".rda")
cNOx <- cPath0 |> paste0(fNOx, ".csv")
noxDefault |> save(file=dNOx)
noxDefault |> write.csv(filename=cNOx, row.names=F)
rm(fNOx, dNOx, cNOx, noxDefault)
} ### End if(do_o3)
# ###### Update Scenarios ######
# ### GDP
# if(do_gdp) {
# gdpDefault <- "gdp_default" |> get_frediDataObj("scenarioData")
# fGdp <- "gdpDefault"
# dGdp <- dPath0 |> paste0(fGdp, ".rda")
# cGdp <- cPath0 |> paste0(fGdp, ".csv")
# gdpDefault |> save(file=dGdp)
# gdpDefault |> write.csv(filename=cGdp, row.names=F)
# rm(fGdp, dGdp, cGdp, gdpDefault)
# } ### End if(do_gdp)
#
# ### Population
# if(do_pop) {
# popDefault <- "pop_default" |> get_frediDataObj("scenarioData")
# fPop <- "popDefault"
# dPop <- dPath0 |> paste0(fPop, ".rda")
# cPop <- cPath0 |> paste0(fPop, ".csv")
# popDefault |> save(file=dPop)
# popDefault |> write.csv(filename=cPop, row.names=F)
# rm(fPop, dPop, cPop, popDefault)
# } ### End if(do_pop)
#
# ### Temperature & CSV
# if(do_temp) {
# gcamScenarios <- "gcam_scenarios" |> get_frediDataObj("scenarioData")
# fTemps <- "gcamScenarios"
# dTemps <- dPath0 |> paste0(fTemps, ".rda")
# cTemps <- cPath0 |> paste0(fTemps, ".csv")
# gcamScenarios |> save(file=dTemps)
# gcamScenarios |> write.csv(filename=cTemps, row.names=F)
# rm(fTemps, dTemps, cTemps, gcamScenarios)
# } ### End if(do_temp)
#
# ### O3, CH4, and NOx
# if(do_o3) {
# ### Ozone
# select0 <- c("region", "state", "postal", "model", "year", "O3_pptv")
# o3Default <- "o3_default" |> get_frediDataObj(listSub="scenarioData", listName="listMethane")
# o3Default <- o3Default |> select(all_of(select0))
# rm(select0)
#
# # ### Adjust the default scenario
# # co_mods <- "co_models" |> get_frediDataObj(listSub="package", listName="listMethane")
# # co_mods <- co_mods |> select(model, model_label)
# # o3Default <- o3Default |> left_join(co_mods, by=c("model"))
# # o3Default <- o3Default |> select(-model)
# # o3Default <- o3Default |> rename(model=model_label)
# # o3Default <- o3Default |> relocate(c("model"))
#
# ### Save ozone
# fO3 <- "o3Default"
# dO3 <- dPath0 |> paste0(fO3, ".rda")
# cO3 <- cPath0 |> paste0(fO3, ".csv")
# o3Default |> save(file=dO3)
# o3Default |> write.csv(filename=cO3, row.names=F)
# rm(fO3, dO3, cO3, o3Default)
#
# ### CH4
# ch4Default <- "ch4_default" |> get_frediDataObj(listSub="scenarioData", listName="listMethane")
# fCH4 <- "ch4Default"
# dCH4 <- dPath0 |> paste0(fCH4, ".rda")
# cCH4 <- cPath0 |> paste0(fCH4, ".csv")
# ch4Default |> save(file=dCH4)
# ch4Default |> write.csv(filename=cCH4, row.names=F)
# rm(fCH4, dCH4, cCH4, ch4Default)
#
# ### NOx
# noxDefault <- "nox_default" |> get_frediDataObj(listSub="scenarioData", listName="listMethane")
# fNOx <- "noxDefault"
# dNOx <- dPath0 |> paste0(fNOx, ".rda")
# cNOx <- cPath0 |> paste0(fNOx, ".csv")
# noxDefault |> save(file=dNOx)
# noxDefault |> write.csv(filename=cNOx, row.names=F)
# rm(fNOx, dNOx, cNOx, noxDefault)
# } ### End if(do_o3)
###### Update Documentation ######
###### - Build Manual
###### - Add and build vignettes
###### - Generate Documentation
"got here1" |> print()
if(do_docs) {
roxygen2::roxygenise(pPath0)
devtools::document(pkg = pPath0)
# devtools::build_manual(pkg = pPath0)
# devtools::build_vignettes(pkg = pPath0)
roxygen2::roxygenise(rPath0)
"got here2" |> print()
devtools::document(pkg = rPath0)
"got here3" |> print()
# devtools::build_manual(pkg = rPath0)
# devtools::build_vignettes(pkg = rPath0)
} ### End if(do_docs)
###### Build Package ######
###### - Build Package but do not include vignettes
# devtools::build(pkg=pPath0, path=rPath0)
# devtools::build(pkg=rPath0, path=rPath0)
'
- name: Build Package
run: |
Rscript -e '
### Main repo path, FrEDI project path, scripts path
"got here4" |> print()
rPath0 <- ".";
pPath0 <- rPath0 |> file.path("FrEDI")
oPath0 <- pPath0 |> file.path("data", "defaultResults.rda")
# ###### Create Default Results ######
# pPath0 |> devtools::load_all()
# oPath0 <- rPath0 |> file.path("data", "defaultResults.rda")
# rPath0 |> devtools::load_all()
# defaultResults <- run_fredi()
# save(defaultResults, file=oPath0)
###### Update Documentation ######
###### - Build Manual
###### - Add and build vignettes
###### - Generate Documentation
roxygen2::roxygenise(pPath0)
devtools::document(pkg = pPath0)
# devtools::build_manual(pkg = pPath0)
# devtools::build_vignettes(pkg = pPath0)
roxygen2::roxygenise(rPath0)
devtools::document(pkg = rPath0)
# devtools::build_manual(pkg = rPath0)
# devtools::build_vignettes(pkg = rPath0)
###### Build Package ######
###### - Build Package but do not include vignettes
# devtools::build(pkg=pPath0, path=rPath0)
# devtools::build(pkg=rPath0, path=rPath0)
'
### git add FrEDI/data/defaultResults.rda
### git add data/defaultResults.rda
- name: Commit results
run: |
git config --local core.autocrlf false
git config --local user.email "${{ github.actor }}@users.noreply.github.com"
git config --local user.name "${{ github.actor }}"
git add FrEDI/man/*.Rd
git add man/*.Rd
git pull origin ${{ github.head_ref }} --autostash --rebase -X ours
git commit -am "Updated package documentation"
git push
Expand Down
18 changes: 13 additions & 5 deletions pkgdown.yaml → .github/workflows/deploy_github_pages.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
name: 6. Deploy github.io

on:
push:
branches: [main, master]
release:
types: [published]
# push:
# branches:
# - main
# - master
# release:
# types: [published]
workflow_dispatch:
branches:
- main
- master
release:
types: [published]

name: pkgdown

jobs:
pkgdown:
Expand Down
20 changes: 13 additions & 7 deletions .github/workflows/test_fredi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

- name: Send input status
run: |
echo "${{ inputs.ref_branch }} ${{ inputs.agg_types }}"
echo "$${{ github.ref_name }} ${{ inputs.ref_branch }} ${{ inputs.agg_types }}"
- name: Setup R
Expand Down Expand Up @@ -78,17 +78,21 @@ jobs:
urlRepo <- "https://github.com/USEPA/FrEDI"
newBranch <- "${{ github.ref_name }}"
refBranch <- "${{ inputs.ref_branch }}"
c(newBranch, refBranch) |> print()
aggTypes <- "${{ inputs.agg_types }}" == "true"
if(aggTypes) cAggLvls <- "all"
else cAggLvls <- c("national", "modelaverage", "impactyear")
if(aggTypes) {
cAggLvls <- "all"
} else {
cAggLvls <- c("national", "modelaverage", "impactyear")
} ### End if(aggTypes)
###### Run FrEDI for Reference Branch ######
### Install FrEDI from ref branch
### Load library
### Run FrEDI
devtools::install_github(repo=urlRepo, ref=refBranch, dependencies=F, upgrade="never", force=T, type="source")
devtools::install_github(repo=urlRepo, ref=refBranch, subdir="FrEDI", dependencies=F, upgrade="never", force=T, type="source")
library(FrEDI)
dfRef <- run_fredi(allLevels=cAggLvls)
dfRef <- run_fredi(aggLevels=cAggLvls)
dfRef |> save(file=oFileRef)
### Detach FrEDI package
Expand All @@ -98,16 +102,18 @@ jobs:
### Install FrEDI from new branch
devtools::install_github(repo=urlRepo, ref=newBranch, dependencies=F, upgrade="never", force=T, type="source")
library(FrEDI)
dfNew <- run_fredi(allLevels=cAggLvls)
dfNew <- run_fredi(aggLevels=cAggLvls)
dfNew |> save(file=oFileNew)
"got here4" |> print()
###### Test results ######
### Load testing scripts
tFiles0 <- tPath0 |> list.files(full.names=TRUE)
for(file_i in tFiles0){file_i |> source(); rm(file_i)}
### Get test results
dfTests <- general_fredi_test(newOutputs=dfNew, refOutputs=dfRef, outPath=oPath0)
'
"got here5" |> print()
'
- name: Upload Tests
uses: actions/upload-artifact@v4
Expand Down
Loading

0 comments on commit 679b8dc

Please sign in to comment.