Skip to content

Commit

Permalink
Merge pull request #19 from JGCRI/dev-pop
Browse files Browse the repository at this point in the history
Dev pop
  • Loading branch information
mengqi-z authored Dec 3, 2024
2 parents 14947a3 + 888c128 commit bae6a21
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 122 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: R-CMD-check

on:
push:
branches: [main]
pull_request:
branches: [main]

permissions: read-all

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.PAT }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
error-on: '"error"'
60 changes: 0 additions & 60 deletions .github/workflows/build.yml

This file was deleted.

60 changes: 60 additions & 0 deletions .github/workflows/test_coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: test_coverage

on:
push:
branches: [main]
pull_request:
branches: [main]

permissions: read-all

jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.PAT }}


steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr, any::xml2
needs: coverage

- name: Test coverage
run: |
cov <- covr::package_coverage(
quiet = FALSE,
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
covr::to_cobertura(cov)
shell: Rscript {0}

- uses: codecov/codecov-action@v4
with:
fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }}
file: ./cobertura.xml
plugin: noop
disable_search: true
token: ${{ secrets.CODECOV_TOKEN }}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v4
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
51 changes: 0 additions & 51 deletions .github/workflows/test_coverage.yml

This file was deleted.

16 changes: 8 additions & 8 deletions R/hdcd.R
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ hdcd <- function(ncdf = NULL,
print('Starting population weighting ...')

population_j_weighted <- population_j_grid %>%
dplyr::filter(lat %in% grid_intersect$lat,
lon %in% grid_intersect$lon) %>%
dplyr::group_by(region, ID, subRegion, year) %>%
dplyr::mutate(subRegion_total_value = sum(value, na.rm = T),
value = ifelse(is.na(value), 0, value)) %>%
Expand All @@ -221,8 +223,9 @@ hdcd <- function(ncdf = NULL,
dplyr::left_join(population_j_weighted %>%
dplyr::select(-value, -subRegion_total_value),
by = c('ID', 'region', 'subRegion', 'lat', 'lon', 'year')) %>%
dplyr::mutate(value = (((value - 273.15) * 9/5) + 32) - reference_temp_F,
value = dplyr::if_else(is.na(pop_weight), value, value * pop_weight))
dplyr::mutate(pop_weight = ifelse(is.na(pop_weight), 0, pop_weight),
value = (((value - 273.15) * 9/5) + 32) - reference_temp_F,
value = value * pop_weight)

} else {
print(paste0('Population data years: ', paste(names(population_j_grid)[!grepl('RID|lat|lon', names(population_j_grid))], collapse = ',')))
Expand All @@ -246,13 +249,10 @@ hdcd <- function(ncdf = NULL,
hdcd_region <- ncdf_hdcd_pop_weighted %>%
dplyr::filter(!is.na(subRegion)) %>%
dplyr::select(-lat, -lon) %>%
dplyr::group_by(region, subRegion, ID, year, datetime) %>%
dplyr::summarise(value = dplyr::if_else(any(is.na(pop_weight)), mean(value), sum(value))) %>%
dplyr::ungroup()

# Assign HDCD categories
hdcd_region <- hdcd_region %>%
dplyr::mutate(HDCD = dplyr::if_else(value < 0, 'HD', 'CD')) %>%
dplyr::group_by(region, subRegion, ID, year, datetime, HDCD) %>%
dplyr::summarise(value = sum(value)) %>%
dplyr::ungroup() %>%
dplyr::filter(value != 0)

#......................
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<!-- badges: start -->
[![build](https://github.com/JGCRI/helios/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/JGCRI/helios/actions/workflows/build.yml)
[![test_coverage](https://github.com/JGCRI/helios/actions/workflows/test_coverage.yml/badge.svg?branch=main)](https://github.com/JGCRI/helios/actions/workflows/test_coverage.yml)
[![R-CMD-check](https://github.com/JGCRI/helios/actions/workflows/R-CDM-check.yaml/badge.svg?branch=main)](https://github.com/JGCRI/helios/actions/workflows/R-CDM-check.yaml)
[![test-coverage](https://github.com/JGCRI/helios/actions/workflows/test-coverage.yaml/badge.svg)](https://github.com/JGCRI/helios/actions/workflows/test-coverage.yaml)
[![docs](https://github.com/JGCRI/helios/actions/workflows/docs.yaml/badge.svg?branch=main)](https://github.com/JGCRI/helios/actions/workflows/docs.yaml)
[![codecov](https://codecov.io/gh/JGCRI/helios/branch/main/graph/badge.svg?token=XQ913U4IYM)](https://codecov.io/gh/JGCRI/helios)
[![Github All Releases](https://img.shields.io/github/downloads/JGCRI/helios/total.svg)]()
[![DOI](https://joss.theoj.org/papers/10.21105/joss.06033/status.svg)](https://doi.org/10.21105/joss.06033)
[![DOI](https://zenodo.org/badge/429143355.svg)](https://zenodo.org/doi/10.5281/zenodo.8170310)
<!-- badges: end -->
Expand Down

0 comments on commit bae6a21

Please sign in to comment.