Skip to content

Commit

Permalink
Merge pull request #183 from CeresBarros/columnNames_and_DT
Browse files Browse the repository at this point in the history
Refer to columns by name, not index + using `data.table`
  • Loading branch information
CeresBarros authored Jan 26, 2024
2 parents 1fe1307 + 1116a20 commit 395ae06
Show file tree
Hide file tree
Showing 43 changed files with 843 additions and 627 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ jobs:
matrix:
config:
- {os: macOS-latest, r: 'release'}
- {os: windows-latest, r: 'devel'}
# - {os: windows-latest, r: 'devel'}
- {os: windows-latest, r: 'release'}
- {os: windows-latest, r: 'oldrel'}
- {os: windows-latest, r: '4.1'}
- {os: ubuntu-20.04, r: 'devel'}
# - {os: windows-latest, r: 'oldrel'}
# - {os: windows-latest, r: '4.1'}
# - {os: ubuntu-20.04, r: 'devel'}
- {os: ubuntu-20.04, r: 'release'}
- {os: ubuntu-20.04, r: 'oldrel'}
- {os: ubuntu-20.04, r: '4.1'}
# - {os: ubuntu-20.04, r: 'oldrel'}
# - {os: ubuntu-20.04, r: '4.1'}

env:
_SP_EVOLUTION_STATUS_: 2
Expand Down
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
Package: climr
Title: Downscaling of global climate data
Version: 0.0.1.9000
Date: 16-01-2024
Version: 0.0.1.9001
Date: 25-01-2024
Authors@R: c(
person("Kiri","Daust", email = "[email protected]", role = "aut"),
person("Colin", "Mahony", email = "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-6111-5675")),
person("Bruno", "Tremblay", email = "[email protected]", role = c("aut"),
comment = c(ORCID = "0000-0002-2945-356X")),
person("Ceres", "Barros", email = "[email protected]", role = c("aut"),
comment = c(ORCID = "0000-0003-4036-977X")),
person("Francois", "Bornais", email = "[email protected]", role = c("aut")),
person(family = "Province of British Columbia", role = c("cph", "fnd")))
Description: This package replicate the basic approach of ClimateNA (climatena.ca),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ importFrom(pool,dbPool)
importFrom(pool,poolClose)
importFrom(sf,st_as_sf)
importFrom(sf,st_join)
importFrom(stats,as.formula)
importFrom(stats,complete.cases)
importFrom(terra,"crs<-")
importFrom(terra,as.list)
Expand Down
14 changes: 14 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# `climr` 0.0.2
## Enhancements
* new tests comparing to reference outputs
* code further streamlined
* new messages warn user about meaningless `downscale`/`climr_downscale` argument combinations
* argument options in `climr_downscale(..., which_normal)` now match the options of `normal_input(..., normal)`

## Behaviour changes
* `xyz` (argument to `climr_downscale` and `downscale`) must now be a 4 column `data.table` (or coercible class) with `lon`, `lat`, `elev` and `id` columns. All other columns are ignored and NOT returned.

## Bugfixes
* fixed temperature values of composite anomalies
* name of composite anomalies changed to "normal_composite" in `normal_input(..., normal)`.

# `climr` 0.0.1

## Enhancements
Expand Down
52 changes: 26 additions & 26 deletions R/append_clim_vars.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,40 +113,40 @@ append_clim_vars <- function(dt, vars) {
set(dt, j = "Tave12", value = (v("Tmax12") + v("Tmin12")) / 2)
},
"PET01" = function() {
set(dt, j = "PET01", value = calc_PET(v("Tave01"), v("Tmin01"), v("Tmax01"), v("Elev")))
set(dt, j = "PET01", value = calc_PET(v("Tave01"), v("Tmin01"), v("Tmax01"), v("elev")))
},
"PET02" = function() {
set(dt, j = "PET02", value = calc_PET(v("Tave02"), v("Tmin02"), v("Tmax02"), v("Elev")))
set(dt, j = "PET02", value = calc_PET(v("Tave02"), v("Tmin02"), v("Tmax02"), v("elev")))
},
"PET03" = function() {
set(dt, j = "PET03", value = calc_PET(v("Tave03"), v("Tmin03"), v("Tmax03"), v("Elev")))
set(dt, j = "PET03", value = calc_PET(v("Tave03"), v("Tmin03"), v("Tmax03"), v("elev")))
},
"PET04" = function() {
set(dt, j = "PET04", value = calc_PET(v("Tave04"), v("Tmin04"), v("Tmax04"), v("Elev")))
set(dt, j = "PET04", value = calc_PET(v("Tave04"), v("Tmin04"), v("Tmax04"), v("elev")))
},
"PET05" = function() {
set(dt, j = "PET05", value = calc_PET(v("Tave05"), v("Tmin05"), v("Tmax05"), v("Elev")))
set(dt, j = "PET05", value = calc_PET(v("Tave05"), v("Tmin05"), v("Tmax05"), v("elev")))
},
"PET06" = function() {
set(dt, j = "PET06", value = calc_PET(v("Tave06"), v("Tmin06"), v("Tmax06"), v("Elev")))
set(dt, j = "PET06", value = calc_PET(v("Tave06"), v("Tmin06"), v("Tmax06"), v("elev")))
},
"PET07" = function() {
set(dt, j = "PET07", value = calc_PET(v("Tave07"), v("Tmin07"), v("Tmax07"), v("Elev")))
set(dt, j = "PET07", value = calc_PET(v("Tave07"), v("Tmin07"), v("Tmax07"), v("elev")))
},
"PET08" = function() {
set(dt, j = "PET08", value = calc_PET(v("Tave08"), v("Tmin08"), v("Tmax08"), v("Elev")))
set(dt, j = "PET08", value = calc_PET(v("Tave08"), v("Tmin08"), v("Tmax08"), v("elev")))
},
"PET09" = function() {
set(dt, j = "PET09", value = calc_PET(v("Tave09"), v("Tmin09"), v("Tmax09"), v("Elev")))
set(dt, j = "PET09", value = calc_PET(v("Tave09"), v("Tmin09"), v("Tmax09"), v("elev")))
},
"PET10" = function() {
set(dt, j = "PET10", value = calc_PET(v("Tave10"), v("Tmin10"), v("Tmax10"), v("Elev")))
set(dt, j = "PET10", value = calc_PET(v("Tave10"), v("Tmin10"), v("Tmax10"), v("elev")))
},
"PET11" = function() {
set(dt, j = "PET11", value = calc_PET(v("Tave11"), v("Tmin11"), v("Tmax11"), v("Elev")))
set(dt, j = "PET11", value = calc_PET(v("Tave11"), v("Tmin11"), v("Tmax11"), v("elev")))
},
"PET12" = function() {
set(dt, j = "PET12", value = calc_PET(v("Tave12"), v("Tmin12"), v("Tmax12"), v("Elev")))
set(dt, j = "PET12", value = calc_PET(v("Tave12"), v("Tmin12"), v("Tmax12"), v("elev")))
},
"CMI" = function() {
set(dt, j = "CMI", value = v("PPT") - (v("PET01") + v("PET02") + v("PET03") + v("PET04") + v("PET05") + v("PET06") + v("PET07") + v("PET08") + v("PET09") + v("PET10") + v("PET11") + v("PET12")))
Expand Down Expand Up @@ -260,40 +260,40 @@ append_clim_vars <- function(dt, vars) {
set(dt, j = "RH12", value = calc_RH(v("Tmin12"), v("Tmax12")))
},
"Eref01" = function() {
set(dt, j = "Eref01", value = calc_Eref(1, v("Tmin01"), v("Tmax01"), v("Lat")))
set(dt, j = "Eref01", value = calc_Eref(1, v("Tmin01"), v("Tmax01"), v("lat")))
},
"Eref02" = function() {
set(dt, j = "Eref02", value = calc_Eref(2, v("Tmin02"), v("Tmax02"), v("Lat")))
set(dt, j = "Eref02", value = calc_Eref(2, v("Tmin02"), v("Tmax02"), v("lat")))
},
"Eref03" = function() {
set(dt, j = "Eref03", value = calc_Eref(3, v("Tmin03"), v("Tmax03"), v("Lat")))
set(dt, j = "Eref03", value = calc_Eref(3, v("Tmin03"), v("Tmax03"), v("lat")))
},
"Eref04" = function() {
set(dt, j = "Eref04", value = calc_Eref(4, v("Tmin04"), v("Tmax04"), v("Lat")))
set(dt, j = "Eref04", value = calc_Eref(4, v("Tmin04"), v("Tmax04"), v("lat")))
},
"Eref05" = function() {
set(dt, j = "Eref05", value = calc_Eref(5, v("Tmin05"), v("Tmax05"), v("Lat")))
set(dt, j = "Eref05", value = calc_Eref(5, v("Tmin05"), v("Tmax05"), v("lat")))
},
"Eref06" = function() {
set(dt, j = "Eref06", value = calc_Eref(6, v("Tmin06"), v("Tmax06"), v("Lat")))
set(dt, j = "Eref06", value = calc_Eref(6, v("Tmin06"), v("Tmax06"), v("lat")))
},
"Eref07" = function() {
set(dt, j = "Eref07", value = calc_Eref(7, v("Tmin07"), v("Tmax07"), v("Lat")))
set(dt, j = "Eref07", value = calc_Eref(7, v("Tmin07"), v("Tmax07"), v("lat")))
},
"Eref08" = function() {
set(dt, j = "Eref08", value = calc_Eref(8, v("Tmin08"), v("Tmax08"), v("Lat")))
set(dt, j = "Eref08", value = calc_Eref(8, v("Tmin08"), v("Tmax08"), v("lat")))
},
"Eref09" = function() {
set(dt, j = "Eref09", value = calc_Eref(9, v("Tmin09"), v("Tmax09"), v("Lat")))
set(dt, j = "Eref09", value = calc_Eref(9, v("Tmin09"), v("Tmax09"), v("lat")))
},
"Eref10" = function() {
set(dt, j = "Eref10", value = calc_Eref(10, v("Tmin10"), v("Tmax10"), v("Lat")))
set(dt, j = "Eref10", value = calc_Eref(10, v("Tmin10"), v("Tmax10"), v("lat")))
},
"Eref11" = function() {
set(dt, j = "Eref11", value = calc_Eref(11, v("Tmin11"), v("Tmax11"), v("Lat")))
set(dt, j = "Eref11", value = calc_Eref(11, v("Tmin11"), v("Tmax11"), v("lat")))
},
"Eref12" = function() {
set(dt, j = "Eref12", value = calc_Eref(12, v("Tmin12"), v("Tmax12"), v("Lat")))
set(dt, j = "Eref12", value = calc_Eref(12, v("Tmin12"), v("Tmax12"), v("lat")))
},
"CMD01" = function() {
set(dt, j = "CMD01", value = calc_CMD(v("Eref01"), v("PPT01")))
Expand Down Expand Up @@ -674,11 +674,11 @@ append_clim_vars <- function(dt, vars) {
}

# Remove unwanted variables
j_out <- names(dt)[!names(dt) %in% c("ID", "GCM", "SSP", "RUN", "PERIOD", vars)]
j_out <- names(dt)[!names(dt) %in% c("id", "GCM", "SSP", "RUN", "PERIOD", vars)]
if (length(j_out)) {
set(dt, j = j_out, value = NULL)
}

# Reorder to match vars
setcolorder(dt, c(names(dt)[names(dt) %in% c("ID", "GCM", "SSP", "RUN", "PERIOD")], vars))
setcolorder(dt, c(names(dt)[names(dt) %in% c("id", "GCM", "SSP", "RUN", "PERIOD")], vars))
}
4 changes: 2 additions & 2 deletions R/data-lists.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ list_run <- function(dbCon, gcm) {
#' Currently available normals (`list_normal()`) are:
#' * "normal_na" for Climate NA derived normals
#' * "normal_bc" for British Columbia PRISM climatologies derived normals
#' * "composite_normal" for a composite of BC PRISM, adjusted US PRISM and
#' * "normal_composite" for a composite of BC PRISM, adjusted US PRISM and
#' DAYMET (Alberta and Saskatchewan), covering western Canada and western
#' US.
#'
#' @rdname data-option-lists
#' @export
list_normal <- function() {
c("normal_na", "normal_bc","normal_composite")
c("normal_na", "normal_bc", "normal_composite")
}


Expand Down
Loading

0 comments on commit 395ae06

Please sign in to comment.