diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 2c5bb50..f190d51 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -44,7 +44,7 @@ jobs: - name: Upload test results if: failure() - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: coverage-test-failures path: ${{ runner.temp }}/package diff --git a/DESCRIPTION b/DESCRIPTION index d0f802c..b75b439 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,20 +1,26 @@ Package: matilda Type: Package Title: A Probabilistic Framework for the Hector Simple Climate Model -Version: 0.1.0 -Author: c(person("Joseph", "Brown", - email = "joseph.brown@pnnl.gov", - role = "aut", - comment = c(ORCID = "0000-0002-3828-4729")), +Version: 1.0.0 +Authors@R: c( + person("Joseph", "Brown", + email = "joseph.brown@pnnl.gov", + role = c("aut", "cre"), + comment = c(ORCID = "0000-0002-3828-4729")), person("Ben", "Bond-Lamberty", - email = "bondlamberty@pnnl.gov", - role = "aut", - comment = c(ORCID = "0000-0001-9525-4633")), - person("Leeya", "Pressburger") - email = "leeya.pressburger@pnnl.gov", - role = "aut", - comment = c(ORCID = "0000-0002-6850-2504"))) -Maintainer: Joseph Brown + email = "bondlamberty@pnnl.gov", + role = "aut", + comment = c(ORCID = "0000-0001-9525-4633")), + person("Leeya", "Pressburger", + email = "leeya.pressburger@pnnl.gov", + role = "aut", + comment = c(ORCID = "0000-0002-6850-2504")), + person("Kalyn", "Dorheim", + email = "kalyn.dorheim@pnnl.gov", + role = "ctb", + comment = c(ORCID = "0000-0001-8093-8397")), + person("Melat", "Ghebreselassie", + role = "ctb")) Description: Provides a probabilistic framework for climate variable projections using the Hector simple climate model. Using this framework you can change parameters, run the model, retrieve targeted model outputs, and quantify diff --git a/NAMESPACE b/NAMESPACE index f3ec2b5..887ffb5 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,6 +5,7 @@ S3method(print,h_metric) export(RMSE_calc) export(criterion_co2_obs) export(criterion_gmst_obs) +export(criterion_ocean_c_uptake_obs) export(generate_params) export(hector_matrix) export(is.criterion) diff --git a/R/example_hector_result.R b/R/example_hector_result.R index 624d497..138353a 100644 --- a/R/example_hector_result.R +++ b/R/example_hector_result.R @@ -4,7 +4,7 @@ #' a single hector. The model results include the GMST() Hector variable for #' the years 1745:2300. #' -#' @format \code{hector_result} {is a data frame with 556 rows and 5 columns:} +#' @format hector_result is a data frame with 556 rows and 5 columns: #' \describe{ #' \item{scenario}{Scenario being used for the analysis} #' \item{year}{Years} diff --git a/R/example_matilda_result.R b/R/example_matilda_result.R index 8339d98..abab5e1 100644 --- a/R/example_matilda_result.R +++ b/R/example_matilda_result.R @@ -7,7 +7,7 @@ #' This ensures that data being saved from the core includes the data needed to #' score the Hector runs. #' -#' @format \code{matilda_result} {is a data frame with 2820 rows and 6 columns:} +#' @format matilda_result is a data frame with 2820 rows and 6 columns: #' \describe{ #' \item{scenario}{Scenario being used for the analysis} #' \item{year}{Years} diff --git a/R/new_criterion.R b/R/new_criterion.R index 850985f..2651676 100644 --- a/R/new_criterion.R +++ b/R/new_criterion.R @@ -84,9 +84,10 @@ is.criterion <- function(x) { #' @examples #' criterion_co2_obs() criterion_co2_obs <- function() { + get("observed_co2_data", envir = asNamespace("matilda")) new_criterion(CONCENTRATIONS_CO2(), - years = observed_data_co2$year, - obs_values = observed_data_co2$co2_ppm + years = observed_co2_data$year, + obs_values = observed_co2_data$co2_ppm ) } @@ -105,8 +106,30 @@ criterion_co2_obs <- function() { #' @examples #' criterion_gmst_obs() criterion_gmst_obs <- function() { + get("observed_gmst_data", envir = asNamespace("matilda")) new_criterion(GMST(), - years = adjusted_gmst_data$year, - obs_values = adjusted_gmst_data$anomaly_C + years = observed_gmst_data$year, + obs_values = observed_gmst_data$anomaly_C + ) +} + + +#' Screening criterion using Global Carbon Project ocean carbon uptake +#' +#' @description This is a criterion identifier for screening Hector runs using +#' observed ocean carbon uptake from the Global Carbon Project's 2023 Global Carbon Budget. +#' +#' @return A criterion identifier using GCP ocean carbon uptake +#' @note This function uses ocean carbon uptake data from +#' \href{ https://globalcarbonbudgetdata.org/latest-data.html}{ https://globalcarbonbudgetdata.org/latest-data.html} +#' @export +#' +#' @examples +#' criterion_ocean_c_uptake_obs() +criterion_ocean_c_uptake_obs <- function() { + get("observed_ocean_c_uptake_data", envir = asNamespace("matilda")) + new_criterion(OCEAN_UPTAKE(), + years = observed_ocean_c_uptake_data$year, + obs_values = observed_ocean_c_uptake_data$ocean_uptake ) } diff --git a/R/score_runs.R b/R/score_runs.R index 99eee66..8c60045 100644 --- a/R/score_runs.R +++ b/R/score_runs.R @@ -50,6 +50,9 @@ score_runs <- function(x, criterion, score_function, ...) { stop("criterion year and variable combination not represented in data") } + # retains run_number from x + run_numbers <- unique(x_subset$run_number) + # converts x_subset to matrix - columns are vectors of values for each model iteration model_matrix <- hector_matrix(x_subset, columns = "value") @@ -69,6 +72,6 @@ score_runs <- function(x, criterion, score_function, ...) { return(data.frame( weights = score_norm, - run_number = 1:length(scores) + run_number = run_numbers )) } diff --git a/R/sysdata.rda b/R/sysdata.rda index b507a40..cbaa4bc 100644 Binary files a/R/sysdata.rda and b/R/sysdata.rda differ diff --git a/data-raw/Had_temp_data-adjusted.R b/data-raw/Had_temp_data-adjusted.R deleted file mode 100644 index 16ff305..0000000 --- a/data-raw/Had_temp_data-adjusted.R +++ /dev/null @@ -1,57 +0,0 @@ -## code to prepare 'adjusted_gmst_data' - -## HADCRUT data as observed temperature anomaly values for scoring Hector runs. -## Temperature anomaly data were downloaded on 05/22/2023 from -## https://www.metoffice.gov.uk/hadobs/hadcrut5/data/current/download.html - -# Reading in HADCRUT5 global temperature anomaly data -observed_data_gmst <- read.csv("data-raw/temp_anomaly_annmean_hadcrut5.csv") - -# rename 'anomaly' to anomaly_C' to give unit information -colnames(observed_data_gmst)[colnames(observed_data_gmst) == "anomaly"] <- "temperature_C" - -# remove confidence bounds in df - leaving only year and mean anomaly cols -observed_data_gmst$Lower.confidence.limit..2.5.. <- NULL -observed_data_gmst$Upper.confidence.limit..97.5.. <- NULL - -# Subset temperature data to include data from 1959-2023 -subset_observed_gmst <- subset( - observed_data_gmst, - year >= 1950, - year <= 2023 -) - -#' Normalizing variables to reflect specific reference period -#' -#' @param observed_data Observed data frame. This function is specifically for adjusting observed temperature. -#' @param modeled_data Data from a Hector result that contains the global mean surface temperature. -#' @param reference_start_year Start year of reference period -#' @param reference_end_year End year of reference period -#' -#' @return A data frame of normalized temperature values -#' -normalize_temperature <- function(observed_data, modeled_data, reference_start_year, reference_end_year) { - # Filter modeled data for the reference period - modeled_reference_period <- subset( - modeled_data, - year >= reference_start_year & - year <= reference_end_year - ) - - # Calculate the mean anomaly_C for the modeled reference period - mean_modeled_anomaly <- mean(modeled_reference_period$value) - - # Calculate normalized anomaly_C for each year in the observed data - normalized_anomaly <- observed_data$temperature_C + mean_modeled_anomaly - - # Create a new data frame with the normalized data - normalized_data <- data.frame(year = observed_data$year, anomaly_C = normalized_anomaly) - - return(normalized_data) -} - -# producing adjusted gmst values using a hector result -adjusted_gmst_data <- normalize_temperature(subset_observed_gmst, matilda:::hector_result, 1961, 1990) - -# Add observed gmst data (adjusted) for internal use -usethis::use_data(adjusted_gmst_data, observed_data_co2, overwrite = TRUE, internal = TRUE) diff --git a/data-raw/MaunaLoa_co2_data.R b/data-raw/MaunaLoa_co2_data.R deleted file mode 100644 index 06e13da..0000000 --- a/data-raw/MaunaLoa_co2_data.R +++ /dev/null @@ -1,13 +0,0 @@ -## Mauna Loa data as the observed CO2 values for scoring Hector runs. - -## Co2 data were download on 01/03/2023 from -## https://gml.noaa.gov/ccgg/trends/data.html}{https://gml.noaa.gov/ccgg/trends/data.html - -# Reading in Mauna Loa annual mean CO2 data -observed_data_co2 <- read.csv("data-raw/co2_annmean_maunaloa.csv") - -# rename 'mean' to co2_ppm to represent unit of original CO2 measurements -colnames(observed_data_co2)[colnames(observed_data_co2) == "mean"] <- "co2_ppm" - -# remove 'unc' (standard deviation) column -observed_data_co2$unc <- NULL diff --git a/data-raw/co2_annmean_maunaloa.csv b/data-raw/csv/co2_maunaloa_raw.csv similarity index 100% rename from data-raw/co2_annmean_maunaloa.csv rename to data-raw/csv/co2_maunaloa_raw.csv diff --git a/data-raw/csv/gcp_data.csv b/data-raw/csv/gcp_data.csv new file mode 100644 index 0000000..ba0007c --- /dev/null +++ b/data-raw/csv/gcp_data.csv @@ -0,0 +1,274 @@ +Year,fossil_emissions_excluding_carbonation,land-use_change_emissions,atmospheric_growth,ocean_sink,land_sink,cement_carbonation_sink,budget_imbalance +1750,0.00253983,,,,0.062352581,, +1751,0.002567475,,-0.07434,,-0.41839894,, +1752,0.002594205,,-0.0707292,,-0.274563031,, +1753,0.00262295,,-0.0677556,,-0.17896831,, +1754,0.002656545,,-0.0641448,,-0.067778282,, +1755,0.00267289,,-0.05841,,-0.03785081,, +1756,0.002704671,,-0.0503388,,0.436237802,, +1757,0.002754895,,-0.0405684,,0.629884515,, +1758,0.002788307,,-0.0282492,,0.100096434,, +1759,0.00282174,,-0.0144432,,-0.53027817,, +1760,0.002869632,,0.0019116,,-0.025867218,, +1761,0.002933375,,0.020178,,-0.732103372,, +1762,0.002989137,,0.0405684,,-0.578992597,, +1763,0.003054474,,0.0628704,,0.443684818,, +1764,0.00311053,,0.0875088,,0.292558234,, +1765,0.003177807,,0.112572,,-0.276541822,, +1766,0.003241288,,0.1357236,,0.308144826,, +1767,0.003316733,,0.156114,,0.314763014,, +1768,0.003402548,,0.1748052,,0.377013174,, +1769,0.003488011,,0.19116,,-0.0130615,, +1770,0.003574568,,0.204966,,0.099768021,, +1771,0.003648878,,0.216648,,-0.322946597,, +1772,0.003718206,,0.2264184,,-0.121361844,, +1773,0.003768597,,0.23364,,-0.111397422,, +1774,0.003824349,,0.2387376,,0.170308119,, +1775,0.003913461,,0.2429856,,0.017587415,, +1776,0.003999488,,0.2489328,,0.450914811,, +1777,0.004082843,,0.257004,,0.787292541,, +1778,0.004160339,,0.266562,,0.209203139,, +1779,0.004239966,,0.278244,,-0.247731667,, +1780,0.004333713,,0.29205,,0.33676919,, +1781,0.004430781,,0.315414,0.07433,-0.583252889,, +1782,0.00452537,,0.3489732,0.082155,-0.378290917,, +1783,0.004656864,,0.3795588,0.08952,0.737490041,, +1784,0.004768311,,0.406746,0.10207,0.654705346,, +1785,0.004903146,,0.4303224,0.104205,-0.122695998,, +1786,0.005034797,,0.450288,0.11673,0.563156288,, +1787,0.005147142,,0.4666428,0.12393,0.524885627,, +1788,0.005263709,,0.4795992,0.131105,0.607727314,, +1789,0.00542124,,0.4889448,0.13301,0.137268837,, +1790,0.005567165,,0.4944672,0.14019,0.547798363,, +1791,0.005712814,,0.4968036,0.147095,-0.071528957,, +1792,0.005985048,,0.4953168,0.14901,0.036943633,, +1793,0.006085497,,0.4902192,0.15568,0.112543148,, +1794,0.006146194,,0.4817232,0.15749,0.388574686,, +1795,0.006090406,,0.4698288,0.163805,0.307312614,, +1796,0.006037493,,0.455598,0.164995,0.769306138,, +1797,0.006028951,,0.4400928,0.1658,1.056908393,, +1798,0.006306203,,0.4228884,0.16673,0.482459229,, +1799,0.007501421,,0.4027104,0.167235,-0.035725666,, +1800,0.008951515,,0.381258,0.17277,0.521160622,, +1801,0.008729817,,0.3623544,0.173235,-0.18002281,, +1802,0.011001767,,0.343026,0.173365,-0.207409054,, +1803,0.008061819,,0.3224232,0.17367,0.899272007,, +1804,0.008670627,,0.3009708,0.17359,0.781374565,, +1805,0.008529426,,0.2778192,0.17356,0.085135497,, +1806,0.008925934,,0.253818,0.173505,0.587999551,, +1807,0.009880091,,0.2287548,0.173135,0.720489195,, +1808,0.009688261,,0.2022048,0.17295,0.806915529,, +1809,0.009916434,,0.1748052,0.17259,0.341896918,, +1810,0.010778469,,0.1459188,0.17252,0.570182039,, +1811,0.010965251,,0.1159704,0.16692,-0.027572369,, +1812,0.011139335,,0.08496,0.16627,0.093460586,, +1813,0.011246217,,0.0526752,0.165735,0.130116315,, +1814,0.01152474,,0.0193284,0.16021,0.412190418,, +1815,0.011896088,,-0.0146556,0.15963,0.26643359,, +1816,0.012417188,,-0.0443916,0.15875,0.672768778,, +1817,0.013448669,,-0.0677556,0.15806,1.024418471,, +1818,0.014026204,,-0.08496,0.15751,0.193716641,, +1819,0.013900155,,-0.0957924,0.15205,-0.099521693,, +1820,0.013846363,,-0.1000404,0.15117,0.374131638,, +1821,0.014208338,,-0.0983412,0.15066,-0.385636174,, +1822,0.014743917,,-0.0898452,0.149595,-0.493869763,, +1823,0.015381486,,-0.0756144,0.144045,0.784456603,, +1824,0.015716058,,-0.0545868,0.14338,0.537632515,, +1825,0.016575018,,-0.0271872,0.14237,0.105323038,, +1826,0.016752765,,0.0061596,0.14153,0.40755945,, +1827,0.017941749,,0.0431172,0.1408,0.532438992,, +1828,0.018199178,,0.0683928,0.140145,0.643001633,, +1829,0.018097,,0.0883584,0.13505,0.083925847,, +1830,0.024287188,,0.1066248,0.13455,0.358431535,, +1831,0.022721238,,0.1225548,0.134,-0.168880458,, +1832,0.022404901,,0.1367856,0.13352,0.061138851,, +1833,0.022720716,,0.1488924,0.13358,0.070999754,, +1834,0.02422574,,0.1609992,0.1337,0.359852834,, +1835,0.026582859,,0.1796904,0.133975,0.212091248,, +1836,0.029174262,,0.2056032,0.13412,0.61834149,, +1837,0.028984558,,0.2374632,0.134745,0.854536444,, +1838,0.028887899,,0.2746332,0.13561,0.236119892,, +1839,0.029927138,,0.3166884,0.136535,-0.243767977,, +1840,0.032425904,,0.3619296,0.132865,0.432685409,, +1841,0.033342125,,0.409932,0.13897,-0.485134332,, +1842,0.035313534,,0.4553856,0.140425,-0.238795869,, +1843,0.036127017,,0.4804488,0.14147,0.765224677,, +1844,0.038739704,,0.4802364,0.14274,0.853938142,, +1845,0.042313689,,0.4570848,0.14418,0.023570711,, +1846,0.043028419,,0.4222512,0.150135,0.461381388,, +1847,0.046599592,,0.3778596,0.15123,0.604018832,, +1848,0.047374423,,0.3234852,0.1572,0.801735245,, +1849,0.050472707,,0.2597652,0.15831,0.298835387,, +1850,0.053698681,0.72141,0.1892484,0.164195,0.458675687,,-0.037010406 +1851,0.054221643,0.74588,0.1255284,0.165485,0.015269005,,0.493819238 +1852,0.056608683,0.758793333,0.0696672,0.171645,0.127951804,,0.446138013 +1853,0.059257762,0.774983333,0.0097704,0.172905,0.17704103,,0.474524665 +1854,0.069605123,0.78471,-0.0390816,0.17432,0.452845826,,0.266230897 +1855,0.070989191,0.787466667,-0.0635076,0.18083,0.172527295,,0.568606162 +1856,0.075681344,0.79182,-0.0632952,0.18227,0.621389077,,0.127137467 +1857,0.076400659,0.802533333,-0.0528876,0.18896,1.048241059,,-0.305379466 +1858,0.077572368,0.8079,-0.0363204,0.19561,0.281554919,,0.444627848 +1859,0.082282005,0.821333333,-0.013806,0.1976,-0.184797392,,0.90461873 +1860,0.090328215,0.77922,0.014868,0.19967,0.367418122,,0.287592093 +1861,0.094919709,0.75109,0.050976,0.206965,-0.462547289,,1.050615998 +1862,0.096749155,0.74433,0.0947304,0.219015,-0.362563063,,0.889896818 +1863,0.103215105,0.740703333,0.146556,0.22639,0.776360252,,-0.305387814 +1864,0.111278923,0.73348,0.20709,0.228825,0.64356807,,-0.234724147 +1865,0.118138409,0.720583333,0.2742084,0.236465,0.001067713,,0.326980629 +1866,0.121875979,0.725536667,0.3349548,0.244015,0.511556663,,-0.243113817 +1867,0.130502388,0.728933333,0.3859308,0.25209,0.639050581,,-0.41763566 +1868,0.134157193,0.721026667,0.4275612,0.259695,0.734867749,,-0.566940089 +1869,0.14245475,0.7168,0.4592088,0.26803,0.282096671,,-0.150080721 +1870,0.145561749,0.77875,0.4817232,0.271125,0.576282947,,-0.404819398 +1871,0.154719261,0.806343333,0.4957416,0.27913,-0.044013425,,0.23020442 +1872,0.171206673,0.819853333,0.4974408,0.287825,0.225305839,,-0.019511632 +1873,0.181899897,0.838233333,0.4866084,0.295945,0.222742706,,0.014837124 +1874,0.170369139,0.854086667,0.463032,0.30465,0.525399277,,-0.268625471 +1875,0.184801808,0.860353333,0.4313844,0.313115,0.403345072,,-0.102689331 +1876,0.187440018,0.868613333,0.4105692,0.3218,0.798478081,,-0.474793929 +1877,0.191158406,0.88457,0.4048344,0.33546,1.095020941,,-0.759586934 +1878,0.192678373,0.900653333,0.4143924,0.34427,0.608450602,,-0.273781295 +1879,0.20632928,0.90901,0.4381812,0.35277,0.083695481,,0.240692599 +1880,0.233055789,0.920753333,0.4685544,0.36152,0.668181175,,-0.344446452 +1881,0.241141938,0.911426667,0.50445,0.370275,-0.226475748,,0.504319353 +1882,0.254738028,0.929426667,0.5456556,0.37901,-0.117882745,,0.37738184 +1883,0.270948036,0.94857,0.5923836,0.38723,1.001893754,,-0.761989317 +1884,0.274054061,0.950763333,0.6473952,0.395745,0.944465261,,-0.762788066 +1885,0.276101837,0.94917,0.7198236,0.404035,0.335492686,,-0.234079449 +1886,0.28040871,0.96229,0.7833312,0.40716,0.802950246,,-0.750742737 +1887,0.294417803,0.978046667,0.8222004,0.415325,0.894644659,,-0.859705589 +1888,0.325969608,0.980613333,0.8396172,0.418595,0.990590691,,-0.942219949 +1889,0.326043686,0.978453333,0.8532108,0.426245,0.58897598,,-0.563934761 +1890,0.354902376,1.05047,0.8636184,0.433865,0.837296789,,-0.729407813 +1891,0.371656709,1.079663333,0.8619192,0.43643,0.177518856,,-0.024548014 +1892,0.374562358,1.091256667,0.84429,0.44394,0.577809138,,-0.400220113 +1893,0.369944689,1.11232,0.8128548,0.45139,0.59480256,,-0.376782671 +1894,0.382920078,1.122113333,0.7735608,0.45927,0.762396688,,-0.490194077 +1895,0.405958618,1.133036667,0.7276824,0.46162,0.658810636,,-0.309117751 +1896,0.419313758,1.144556667,0.6650244,0.46931,1.201496535,,-0.771960511 +1897,0.439200754,1.1484,0.5906844,0.47716,1.303298667,,-0.783542313 +1898,0.46320044,1.156936667,0.532062,0.479805,0.73543479,,-0.127164684 +1899,0.505925005,1.173176667,0.4965912,0.487715,0.361767253,,0.333028219 +1900,0.532808265,1.194683333,0.4825728,0.491055,0.841125916,,-0.087262117 +1901,0.550421528,1.205776667,0.4840596,0.499255,0.083831569,,0.689052026 +1902,0.564324222,1.22443,0.4989276,0.502425,-0.27239553,,1.059797151 +1903,0.615202006,1.22709,0.5259024,0.51101,1.398850023,,-0.593470417 +1904,0.622201805,1.250896667,0.5645592,0.519745,1.4319893,,-0.643195028 +1905,0.662477723,1.254903333,0.609588,0.52319,0.348852707,,0.435750349 +1906,0.691794006,1.262,0.6422976,0.531915,1.101772103,,-0.322190697 +1907,0.788296395,1.2736,0.66906,0.540975,1.219666917,,-0.367805523 +1908,0.757762264,1.284183333,0.6890256,0.549505,1.191492301,,-0.388077303 +1909,0.788890497,1.295266667,0.7007076,0.55817,0.735950809,,0.089328754 +1910,0.828081282,1.267113333,0.7079292,0.56192,1.030325684,,-0.204980269 +1911,0.840475439,1.257763333,0.725346,0.570295,0.384232628,,0.418365144 +1912,0.883177843,1.241756667,0.7559316,0.57396,0.563530358,,0.231512551 +1913,0.956952991,1.23871,0.7892784,0.582225,0.656554305,,0.167605286 +1914,0.868000977,1.238093333,0.8151912,0.58512,0.988691036,,-0.282907927 +1915,0.85558244,1.22549,0.8360064,0.593875,0.615117895,,0.036073145 +1916,0.924087991,1.212576667,0.8476884,0.596995,1.257899854,,-0.565918596 +1917,0.966273662,1.208616667,0.848538,0.6049,1.820010884,,-1.098558555 +1918,0.953401785,1.216,0.8360064,0.612745,0.918194436,,-0.197544052 +1919,0.826693927,1.204506667,0.8096688,0.61601,0.198347927,,0.407173867 +1920,0.961088263,1.257753333,0.7756848,0.62373,1.214381902,,-0.394955106 +1921,0.843367001,1.291436667,0.7493472,0.63178,1.167349728,,-0.41367326 +1922,0.884365141,1.308423333,0.7329924,0.634325,0.550151661,,0.275319413 +1923,1.003338739,1.306763333,0.7270452,0.642225,1.267516375,,-0.326684502 +1924,1.006337392,1.311943333,0.728532,0.644645,0.687868147,,0.257235578 +1925,1.017203543,1.33044,0.7334172,0.65195,0.902701862,,0.059574482 +1926,0.999189576,1.325956667,0.7459488,0.654085,0.409002103,,0.516110339 +1927,1.09064645,1.328283333,0.7618788,0.655995,1.205653913,,-0.20459793 +1928,1.085906982,1.330533333,0.7799328,0.662745,0.384377397,,0.589385118 +1929,1.165640794,1.334356667,0.7909776,0.66403,0.611468045,,0.433521816 +1930,1.074945008,1.35479,0.7920396,0.665485,0.806160914,,0.166049494 +1931,0.960672279,1.374263333,0.7914024,0.666855,-0.043587489,0.002159212,0.91810649 +1932,0.866123448,1.389633333,0.790128,0.67242,0.814244345,0.001819587,-0.02285515 +1933,0.911986409,1.395286667,0.7875792,0.67314,0.804776791,0.001846654,0.039930431 +1934,0.991878209,1.408676667,0.7835436,0.673565,0.710816251,0.002184915,0.230445109 +1935,1.041156755,1.409523333,0.7750476,0.673935,0.569352736,0.002514022,0.429830731 +1936,1.142334546,1.416566667,0.7591176,0.673925,0.526785251,0.002644795,0.596428568 +1937,1.221133412,1.412773333,0.739152,0.673775,0.520487379,0.003160841,0.697331526 +1938,1.14817166,1.420216667,0.7145136,0.673425,0.693768357,0.003407451,0.483273919 +1939,1.214860074,1.420933333,0.672246,0.673255,1.347922813,0.003619905,-0.061250311 +1940,1.326786429,1.457963333,0.6072516,0.673305,1.07480029,0.003366083,0.426026789 +1941,1.35666333,1.50509,0.523566,0.66803,0.331836073,0.003570779,1.334750478 +1942,1.353598818,1.514756667,0.43011,0.66835,1.004177629,0.003338273,0.762379582 +1943,1.376008271,1.51172,0.33453,0.668845,1.169409536,0.003167821,0.711775914 +1944,1.396809135,1.511916667,0.2597652,0.66985,0.197669936,0.00269145,1.778749216 +1945,1.161882188,1.50257,0.214524,0.671235,0.739565649,0.002476081,1.036651457 +1946,1.268046835,1.498293333,0.2036916,0.678325,0.487196502,0.003067788,1.394059279 +1947,1.404416436,1.485686667,0.2153736,0.681085,1.262666157,0.00354367,0.727434676 +1948,1.480609359,1.465226667,0.2504196,0.68902,1.052316444,0.004143361,0.949936622 +1949,1.414029949,1.451046667,0.3035196,0.69308,0.787403433,0.004707085,1.076366498 +1950,1.618270106,1.65586,0.3627792,0.702545,2.039277307,0.0054178,0.164110799 +1951,1.741650053,1.681996667,0.4192776,0.71233,0.92717179,0.006094872,1.358772458 +1952,1.765130202,1.720756667,0.4804488,0.7284,0.087761261,0.006662974,2.182613834 +1953,1.81519141,1.75142,0.5484168,0.74464,1.068156143,0.007394851,1.198003616 +1954,1.853028751,1.793736667,0.6231816,0.756845,0.906322547,0.008140695,1.352275575 +1955,2.031621392,1.8541,0.7004952,0.76967,1.915563298,0.009013705,0.490979189 +1956,2.163204266,1.90846,0.7758972,0.78329,2.316805134,0.009838912,0.18583302 +1957,2.234064852,1.957666667,0.8714772,0.792965,0.900615958,0.010521677,1.616151684 +1958,2.297259736,2.014696667,1.741158665,0.807815,0.032498061,0.011270259,1.719214418 +1959,2.416665456,2.121526667,2.03904,0.9924198,0.430358952,0.012542147,1.063831224 +1960,2.56179621,1.864403333,1.50804,0.936514292,1.25234663,0.013682051,0.715616571 +1961,2.569427515,1.787483333,1.65672,0.839508784,0.899619515,0.014547674,0.946514876 +1962,2.660086233,1.657756667,1.18944,0.923603275,1.293962035,0.015679867,0.895157723 +1963,2.801868781,1.604056667,1.21068,1.111697767,0.959731798,0.016652984,1.107162898 +1964,2.954044224,1.565253333,1.04076,1.229492259,1.644886173,0.018219985,0.585939141 +1965,3.086705587,1.42073,2.3364,1.337886751,0.366636244,0.01923258,0.447280012 +1966,3.237365852,1.374056667,2.3364,1.268381242,1.563293953,0.020642783,-0.57729546 +1967,3.339609301,1.411203333,1.29564,1.110075734,1.730972744,0.021656588,0.592467568 +1968,3.52192569,1.428043333,2.10276,1.200970226,2.4856318,0.023209644,-0.862602647 +1969,3.755687609,1.340483333,2.80368,1.299864718,0.765601269,0.024631991,0.202392965 +1970,4.066090712,1.395793333,2.40012,1.113059209,0.774795185,0.02612931,1.147780341 +1971,4.231109638,1.315316667,1.55052,1.229253701,2.306640669,0.027599823,0.432412111 +1972,4.42779468,1.31611,3.12228,1.531248193,1.253937953,0.030070061,-0.193631526 +1973,4.662527456,1.281466667,3.10104,1.371942685,1.686948679,0.032169588,-0.24810683 +1974,4.642298615,1.245676667,1.44432,1.318637176,3.765889699,0.032925987,-0.673797581 +1975,4.653378644,1.258953333,2.61252,1.238031668,2.522553245,0.033594479,-0.494367415 +1976,4.908636736,1.252953333,2.06028,1.44052616,2.997899716,0.035521518,-0.372637324 +1977,5.047666913,1.253063333,4.07808,1.530920652,1.417101717,0.037886836,-0.763258957 +1978,5.203044493,1.216276667,2.73996,1.555515143,2.538517653,0.040505965,-0.455177602 +1979,5.350164359,1.154373333,4.54536,1.525009635,1.165996657,0.041960836,-0.773789436 +1980,5.317259993,1.20265,3.63204,1.788404127,0.442966614,0.043189286,0.613309966 +1981,5.190215328,1.270446667,2.4426,1.762898619,2.174755512,0.044043595,0.036364269 +1982,5.148846395,1.27638,2.124,1.94709311,1.620518848,0.044840545,0.688773891 +1983,5.181741625,1.40821,3.88692,2.098487602,0.359767066,0.046303653,0.198473303 +1984,5.360733803,1.628533333,2.61252,1.874082094,2.841700739,0.047709806,-0.386745502 +1985,5.541793264,1.502266667,3.5046,1.766976586,2.650944873,0.049042438,-0.927503966 +1986,5.624321191,1.553716667,2.16648,1.834271078,2.435813351,0.051366814,0.690106615 +1987,5.79852154,1.505066667,5.6286,1.988565569,0.636851694,0.053740675,-1.004169732 +1988,6.025487138,1.44615,4.58784,1.809060061,2.096901296,0.056903743,-1.079067962 +1989,6.107797353,1.430363333,3.10104,1.846454553,3.552275667,0.056755168,-1.018364701 +1990,6.20979811,1.41018,2.59128,2.008756579,2.365148815,0.056125968,0.598666747 +1991,6.339922251,1.350036667,1.593,2.139805427,2.143846033,0.05952743,1.753780028 +1992,6.159170024,1.42552,1.52928,2.301725826,2.44388355,0.060295293,1.249505355 +1993,6.222257178,1.399853333,2.61252,2.245826043,2.996492445,0.064402526,-0.297130502 +1994,6.286783591,1.576536667,3.52584,2.034234618,1.480194982,0.067875021,0.755175638 +1995,6.420439935,1.53916,4.248,2.033206139,1.839646751,0.071508705,-0.23276166 +1996,6.618494234,1.63682,2.2302,2.028526559,3.416528128,0.074213619,0.505845928 +1997,6.658283437,2.041756667,4.18428,2.200500515,3.286812253,0.076982567,-1.048535231 +1998,6.640541938,1.682623333,6.03216,2.240400205,1.520810703,0.077747163,-1.547952799 +1999,6.777700499,1.638646667,2.82492,1.996638796,3.551686017,0.080512527,-0.037410174 +2000,6.959958454,1.467156667,2.655,1.936719566,3.816066037,0.083536938,-0.06420742 +2001,7.007349984,1.3745,3.90816,1.837084719,2.548707065,0.086109401,0.001788799 +2002,7.163834459,1.469753333,5.03388,2.237809127,1.29389719,0.090522969,-0.022521493 +2003,7.54602874,1.592123333,4.86396,2.343089908,2.557056323,0.097275016,-0.723229173 +2004,7.811187939,1.47211,3.31344,2.303435164,3.601998724,0.104064894,-0.039640841 +2005,8.076447288,1.335126667,5.24628,2.336899474,2.015976151,0.111160968,-0.298742637 +2006,8.353102395,1.428686667,3.75948,2.445972109,3.238899246,0.121018477,0.216419228 +2007,8.597088978,1.24346,4.50288,2.377707296,2.892153592,0.130367979,-0.062559888 +2008,8.745060733,1.293883333,3.75948,2.401370364,3.624921191,0.134660751,0.118511761 +2009,8.595323847,1.42908,3.35592,2.559065859,2.998521825,0.141512386,0.969383778 +2010,9.090155017,1.413076667,5.14008,2.51828282,3.344808578,0.150279147,-0.650218862 +2011,9.39860004,1.424126667,3.56832,2.556846706,4.132666979,0.162719085,0.402173936 +2012,9.534785309,1.45884,5.11884,2.617698426,2.591914894,0.169239681,0.495932308 +2013,9.61584801,1.326086667,5.2038,2.649486241,3.639193355,0.177229223,-0.727774143 +2014,9.679638329,1.423113333,4.33296,2.785954224,3.856130914,0.184932111,-0.057225586 +2015,9.678824989,1.536643333,6.2658,2.849992191,2.277525489,0.185938922,-0.363788278 +2016,9.677954599,1.255183333,6.03216,2.969237041,2.939957047,0.188003953,-1.196220108 +2017,9.832273843,1.245903333,4.54536,2.830498102,3.729804319,0.192072616,-0.21955786 +2018,10.03464659,1.169526667,5.07636,2.907491374,3.604710237,0.198195623,-0.582583977 +2019,10.10919852,1.25478,5.31,2.955931523,3.009866407,0.201583196,-0.113402602 +2020,9.554513897,1.172266667,4.97016,2.91436547,3.110043659,0.206857741,-0.474646305 +2021,10.04818298,1.17947,5.2038,2.825585012,3.542676978,0.216462506,-0.560871516 +2022,10.13913339,1.176296667,4.63032,2.779694058,3.780125554,0.217464615,-0.092174172 diff --git a/data-raw/temp_anomaly_annmean_hadcrut5.csv b/data-raw/csv/gmst_hadcrut5_raw.csv similarity index 100% rename from data-raw/temp_anomaly_annmean_hadcrut5.csv rename to data-raw/csv/gmst_hadcrut5_raw.csv diff --git a/data-raw/make_internal_criterion_data.R b/data-raw/make_internal_criterion_data.R new file mode 100644 index 0000000..99c27f2 --- /dev/null +++ b/data-raw/make_internal_criterion_data.R @@ -0,0 +1,111 @@ +## Ocean Carbon Uptake + +## code to prepare 'observed_ocean_c_uptake_data' + +## Ocean C uptake data from The Global Carbon Project's 2023 Global Carbon Budget. +## Friedlingstein et al. Global Carbon Budget 2023, Earth Sys. Sci. Data, 15, 5301-5369. +## Downloaded 03/26/2024 +## Accessed from: https://globalcarbonbudgetdata.org/latest-data.html + + +# Reading in ocean carbon uptake data +observed_data_ocean <- read.csv("data-raw/csv/gcp_data.csv", stringsAsFactors = FALSE) + +# Rename columns for consistency with internal package naming +names(observed_data_ocean)[names(observed_data_ocean) == "Year"] <- "year" +names(observed_data_ocean)[names(observed_data_ocean) == "ocean_sink"] <- "ocean_uptake" + +# Subset to retain only relevant columns +observed_ocean_c_uptake_data <- observed_data_ocean[,c("year", "ocean_uptake")] + +# Remove any rows with missing data +observed_ocean_c_uptake_data <- na.omit(observed_ocean_c_uptake_data) + + +#### GMST + +## code to prepare 'observed_gmst_data' + +## HADCRUT data as observed temperature anomaly values for scoring Hector runs. +## Morice et al. 2021. An updated assessment of near-surface temperature change from 1850: the HadCRUT5 data set. Journal of Geophysical Research. +## Downloaded 05/22/2023 +## Accessed from: https://www.metoffice.gov.uk/hadobs/hadcrut5/data/current/download.html + +# Reading in HADCRUT5 global temperature anomaly data +observed_data_gmst <- read.csv("data-raw/csv/gmst_hadcrut5_raw.csv") + +# rename 'anomaly' to anomaly_C' to give unit information +colnames(observed_data_gmst)[colnames(observed_data_gmst) == "anomaly"] <- "temperature_C" + +# remove confidence bounds in df - leaving only year and mean anomaly cols +observed_data_gmst$Lower.confidence.limit..2.5.. <- NULL +observed_data_gmst$Upper.confidence.limit..97.5.. <- NULL + +# Subset temperature data to include data from 1959-2023 +subset_observed_gmst <- subset( + observed_data_gmst, + year >= 1950, + year <= 2023 +) + +#' Normalizing variables to reflect specific reference period +#' +#' @param observed_data Observed data frame. This function is specifically for adjusting observed temperature. +#' @param modeled_data Data from a Hector result that contains the global mean surface temperature. +#' @param reference_start_year Start year of reference period +#' @param reference_end_year End year of reference period +#' +#' @return A data frame of normalized temperature values +#' +normalize_temperature <- function(observed_data, modeled_data, reference_start_year, reference_end_year) { + # Filter modeled data for the reference period + modeled_reference_period <- subset( + modeled_data, + year >= reference_start_year & + year <= reference_end_year + ) + + # Calculate the mean anomaly_C for the modeled reference period + mean_modeled_anomaly <- mean(modeled_reference_period$value) + + # Calculate normalized anomaly_C for each year in the observed data + normalized_anomaly <- observed_data$temperature_C + mean_modeled_anomaly + + # Create a new data frame with the normalized data + normalized_data <- data.frame(year = observed_data$year, anomaly_C = normalized_anomaly) + + return(normalized_data) +} + +# producing adjusted gmst values using a hector result + +observed_gmst_data <- normalize_temperature(subset_observed_gmst, matilda::hector_result, 1961, 1990) + + +#### CO2 Concentrations + +## code to prepare 'observed_co2_data' + +## Mauna Loa data as the observed CO2 values for scoring Hector runs. +## Lan et al. 2023. Trends in globally-averaged CO2 determined from NOAA global monitoring laboratory measurements. +## Downloaded 01/03/2023 +## Accessed from: https://gml.noaa.gov/ccgg/trends/data.html}{https://gml.noaa.gov/ccgg/trends/data.html + +# Reading in Mauna Loa annual mean CO2 data +observed_co2_data <- read.csv("data-raw/csv/co2_maunaloa_raw.csv") + +# rename 'mean' to co2_ppm to represent unit of original CO2 measurements +colnames(observed_co2_data)[colnames(observed_co2_data) == "mean"] <- "co2_ppm" + +# remove 'unc' (standard deviation) column +observed_co2_data$unc <- NULL + + +#### Add to package data + +# Add observed gmst data (adjusted) for internal use +usethis::use_data(observed_gmst_data, + observed_co2_data, + observed_ocean_c_uptake_data, + overwrite = TRUE, internal = TRUE) + diff --git a/man/criterion_ocean_c_uptake_obs.Rd b/man/criterion_ocean_c_uptake_obs.Rd new file mode 100644 index 0000000..cda92bb --- /dev/null +++ b/man/criterion_ocean_c_uptake_obs.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/new_criterion.R +\name{criterion_ocean_c_uptake_obs} +\alias{criterion_ocean_c_uptake_obs} +\title{Screening criterion using Global Carbon Project ocean carbon uptake} +\usage{ +criterion_ocean_c_uptake_obs() +} +\value{ +A criterion identifier using GCP ocean carbon uptake +} +\description{ +This is a criterion identifier for screening Hector runs using +observed ocean carbon uptake from the Global Carbon Project's 2023 Global Carbon Budget. +} +\note{ +This function uses ocean carbon uptake data from +\href{ https://globalcarbonbudgetdata.org/latest-data.html}{ https://globalcarbonbudgetdata.org/latest-data.html} +} +\examples{ +criterion_ocean_c_uptake_obs() +} diff --git a/man/hector_result.Rd b/man/hector_result.Rd index cfa4547..b6a050c 100644 --- a/man/hector_result.Rd +++ b/man/hector_result.Rd @@ -5,7 +5,7 @@ \alias{hector_result} \title{Example Hector result data} \format{ -\code{hector_result} {is a data frame with 556 rows and 5 columns:} +hector_result is a data frame with 556 rows and 5 columns: \describe{ \item{scenario}{Scenario being used for the analysis} \item{year}{Years} diff --git a/man/matilda_result.Rd b/man/matilda_result.Rd index c6e5717..99d33ee 100644 --- a/man/matilda_result.Rd +++ b/man/matilda_result.Rd @@ -5,7 +5,7 @@ \alias{matilda_result} \title{Example Matilda result data} \format{ -\code{matilda_result} {is a data frame with 2820 rows and 6 columns:} +matilda_result is a data frame with 2820 rows and 6 columns: \describe{ \item{scenario}{Scenario being used for the analysis} \item{year}{Years} diff --git a/matilda.Rproj b/matilda.Rproj index 270314b..07c332f 100644 --- a/matilda.Rproj +++ b/matilda.Rproj @@ -1,4 +1,5 @@ Version: 1.0 +ProjectId: e0c9daaf-d52e-4240-9c96-d3cdf792c086 RestoreWorkspace: Default SaveWorkspace: Default diff --git a/tests/testthat/test-criterion_ocean_c_uptake_obs.R b/tests/testthat/test-criterion_ocean_c_uptake_obs.R new file mode 100644 index 0000000..5272a9e --- /dev/null +++ b/tests/testthat/test-criterion_ocean_c_uptake_obs.R @@ -0,0 +1,18 @@ +# creating new_metric object for tests +ocean_c_uptake_crit <- criterion_ocean_c_uptake_obs() + +# Testing attribute class + +test_that("result has correct attribute class", { + expect_s3_class(ocean_c_uptake_crit, "criterion") +}) + +# Testing structure of result + +test_that("output has correct data structure", { + expect_true(is.integer(c(ocean_c_uptake_crit$year))) + + expect_true(is.character(c(ocean_c_uptake_crit$var))) + + expect_true(is.numeric(c(ocean_c_uptake_crit$obs_values))) +}) diff --git a/vignettes/matilda-vignette.Rmd b/vignettes/matilda-vignette.Rmd index 450fd65..17bc1a8 100644 --- a/vignettes/matilda-vignette.Rmd +++ b/vignettes/matilda-vignette.Rmd @@ -285,7 +285,7 @@ plot_co2 <- ggplot(subset( scale_color_gradient(high = "dodgerblue4", low = "lightblue1") + scale_alpha_continuous(range = c(0.1, 1)) + geom_line( - data = matilda:::observed_data_co2, + data = matilda:::observed_co2_data, aes(year, co2_ppm), color = "red", linewidth = 1