diff --git a/SCRC/R/remotedata.R b/SCRC/R/remotedata.R index 1a3ab66..25ed007 100644 --- a/SCRC/R/remotedata.R +++ b/SCRC/R/remotedata.R @@ -45,8 +45,8 @@ unpack_intervention = function(config_loc, ngroups) # symptomatic infectiousness return( list( - contact = intervention[[1]][1:9], - fIs = rep(intervention[[1]][10], ngroups) + contact = intervention[1:9] %>% unlist, + fIs = rep(intervention[[10]], ngroups) ) ) } @@ -59,7 +59,7 @@ unpack_intervention = function(config_loc, ngroups) unpack_terms = function(config_loc) { read_table = StandardAPI(config_loc)$read_table - school_terms = read_table("school_terms", "school_terms") + school_terms = read_table("school/school_terms", "school_terms") return( list( @@ -103,8 +103,9 @@ unpack_seeding = function(config_loc) #' @param region Name of the subset region, default is the demo of Glasgow City unpack_populations = function(config_loc, region="Glasgow City") { + read_table = StandardAPI(config_loc)$read_table - pop_size = read_table("population_size/persons", "population_size/persons") + pop_size = read_table("population/population_sizes", "population_size/persons") return( list( @@ -135,17 +136,16 @@ unpack_matrices = function(config_loc) contact_matrices[["subset"]] = list() for(name in matrix_names) { - Array = read_array("subregion_matrices", file.path("contact_matrices", name)) + Array = read_array("contact_matrices/subregion", file.path("contact_matrices", name)) contact_matrices[["subset"]][[name]] = Array$data } contact_matrices[["region"]] = list() for(name in matrix_names) { - Array = read_array("national_contact_matrices", file.path("contact_matrices", name)) + Array = read_array("contact_matrices/national", file.path("contact_matrices", name)) contact_matrices[["region"]][[name]] = Array$data } - return(list(matrices=contact_matrices, group_names=Array$dimensions[[1]]$names)) } @@ -160,7 +160,7 @@ unpack_times = function(config_loc) return( list( - max = read_estimate("fixed-parameters/delay_gamma", "max_day_delay_gamma"), + max = read_estimate("fixed-parameters/delay_gamma", "max_delay_gamma"), step = read_estimate("fixed-parameters/delay_gamma", "time_step_delay_gamma"), end = read_estimate("run-configuration/time", "end_day"), start = read_estimate("run-configuration/time", "start_day"), @@ -177,14 +177,15 @@ unpack_times = function(config_loc) #' #' @param dis_label Name of the distribution in the API #' @param config_loc Location of the config.yaml API file + fetch_gamma_components <- function(dis_label, config_loc) { - distribution = StandardAPI(config_loc)$read_distribution(dis_label, dis_label) + distribution = StandardAPI(config_loc)$read_distribution(file.path("distributions", dis_label), dis_label) return( list( - loc = distribution$args[[1]], - scale = distribution$kwds[["scale"]] + distribution$args[[1]], + distribution$kwds[["scale"]] ) ) } @@ -205,28 +206,28 @@ unpack_dis_params = function(config_loc) for(comp in compartments) { - args <- fetch_gamma_components(file.path("distributions", comp), config_loc) + args <- fetch_gamma_components(comp, config_loc) - params[[comp]] = list(mu=args$k, - shape=args$theta) + params[[comp]] = list(mu=args[[1]], + shape=args[[2]]) } - args <- fetch_gamma_components("distributions/ip_to_hosp", config_loc) - params[["delay_Ip_to_hosp"]] = list(mu=args$k, - shape=args$theta) + args <- fetch_gamma_components("ip_to_hosp", config_loc) + params[["delay_Ip_to_hosp"]] = list(mu=args[[1]], + shape=args[[2]]) - args <- fetch_gamma_components("distributions/to_icu", config_loc) - params[["delay_to_icu"]] = list(mu=args$k, - shape=args$theta) + args <- fetch_gamma_components("to_icu", config_loc) + params[["delay_to_icu"]] = list(mu=args[[1]], + shape=args[[2]]) - args <- fetch_gamma_components("distributions/to_non_icu", config_loc) - params[["delay_to_non_icu"]] = list(mu=args$k, - shape=args$theta) + args <- fetch_gamma_components("to_non_icu", config_loc) + params[["delay_to_non_icu"]] = list(mu=args[[1]], + shape=args[[2]]) - args <- fetch_gamma_components("distributions/ip_to_death", config_loc) - params[["delay_Ip_to_death"]] = list(mu=args$k, - shape=args$theta) + args <- fetch_gamma_components("ip_to_death", config_loc) + params[["delay_Ip_to_death"]] = list(mu=args[[1]], + shape=args[[2]]) return(params) } @@ -311,7 +312,6 @@ objects = function(config_loc) params = append(params, unpack_dis_params(config_loc)) params$ngroups = params$contact_matrices$region$other %>% length %>% sqrt(.) params$intervention = unpack_intervention(config_loc, params$ngroups) - return(params) } diff --git a/SCRC/data_uploading/param_gen.R b/SCRC/data_uploading/param_gen.R index 84f073a..aa77df0 100644 --- a/SCRC/data_uploading/param_gen.R +++ b/SCRC/data_uploading/param_gen.R @@ -22,9 +22,6 @@ library(SCRCdataAPI) # Requires the latest SCRCdataAPI library library(progress) library(magrittr) -# Start constructing address locations: -# - LSHTM/fixed-parameters - namespace <- "LSHTM" prefix <- list(fixed="fixed-parameters", dist="distributions", @@ -116,28 +113,28 @@ distributions <- list( # Iterate through fixed parameters creating TOML objects and adding them # as statements within the DataRegistry -# pb <- progress_bar$new(total = length(params)) -# for(param in params) -# { -# name <- file.path(prefix$fixed, param$name) -# path <- paste("master", namespace, name, sep = "/") -# filename <- paste0(param$version, ".toml") -# component_name <- gsub("^.*/([^/]*)$", "\\1", name) - -# create_estimate(filename = filename, -# path = file.path("data-raw", path), -# parameters = as.list(setNames(param$value, component_name))) - -# upload_data_product(storage_root_id = storage_rootId, -# name = name, -# component_name = component_name, -# processed_path = file.path("data-raw", path, filename), -# product_path = file.path(path, filename), -# version = param$version, -# namespace_id = namespaceId, -# key = key) -# pb$tick() -# } +pb <- progress_bar$new(total = length(params)) +for(param in params) +{ + name <- file.path(prefix$fixed, param$name) + path <- paste("master", namespace, name, sep = "/") + filename <- paste0(param$version, ".toml") + component_name <- gsub("^.*/([^/]*)$", "\\1", name) + + create_estimate(filename = filename, + path = file.path("data-raw", path), + parameters = as.list(setNames(param$value, component_name))) + + upload_data_product(storage_root_id = storage_rootId, + name = name, + component_name = component_name, + processed_path = file.path("data-raw", path, filename), + product_path = file.path(path, filename), + version = param$version, + namespace_id = namespaceId, + key = key) + pb$tick() +} # Iterate through parameter sets creating TOML files with multiple items # and adding them as statements within the DataRegistry @@ -147,7 +144,7 @@ for(set in param_sets) name <- file.path(set$prefix, set$set_name) path <- paste("master", namespace, name, sep = "/") filename <- paste0(set$version, ".toml") - component_name <- set$set_name %>% gsub("^.*/([^/]*)$", "\\1", .) + component_names <- set$param_names %>% gsub("^.*/([^/]*)$", "\\1", .) args <- mapply(setNames, set$values, set$param_names) create_estimate(filename = filename, path = file.path("data-raw", path), @@ -155,7 +152,7 @@ for(set in param_sets) ) upload_data_product(storage_root_id = storage_rootId, name = name, - component_name = component_name, + component_name = component_names, processed_path = file.path("data-raw", path, filename), product_path = file.path(path, filename), version = set$version, @@ -166,29 +163,29 @@ for(set in param_sets) # Iterate through distibutions creating TOML objects and adding them # as statements within the DataRegistry -# pb <- progress_bar$new(total = length(distributions)) -# for(dis in distributions) -# { -# name <- file.path(prefix$dist, dis$name) -# path <- paste("master", namespace, name, sep = "/") -# filename <- paste0(dis$version, ".toml") -# component_name <- gsub("^.*/([^/]*)$", "\\1", name) - -# create_distribution( -# filename = filename, -# file.path("data-raw", path), -# name = dis$name, -# distribution = dis$type, -# parameters = dis$params -# ) +pb <- progress_bar$new(total = length(distributions)) +for(dis in distributions) +{ + name <- file.path(prefix$dist, dis$name) + path <- paste("master", namespace, name, sep = "/") + filename <- paste0(dis$version, ".toml") + component_name <- gsub("^.*/([^/]*)$", "\\1", name) + + create_distribution( + filename = filename, + file.path("data-raw", path), + name = dis$name, + distribution = dis$type, + parameters = dis$params + ) -# upload_data_product(storage_root_id = storage_rootId, -# name = name, -# component_name = component_name, -# processed_path = file.path("data-raw", path, filename), -# product_path = file.path(path, filename), -# version = dis$version, -# namespace_id = namespaceId, -# key = key) -# pb$tick() -# } \ No newline at end of file + upload_data_product(storage_root_id = storage_rootId, + name = name, + component_name = component_name, + processed_path = file.path("data-raw", path, filename), + product_path = file.path(path, filename), + version = dis$version, + namespace_id = namespaceId, + key = key) + pb$tick() +} \ No newline at end of file diff --git a/SCRC/pipeline_data/metadata.yaml b/SCRC/pipeline_data/metadata.yaml index b35142a..c1bf5c2 100644 --- a/SCRC/pipeline_data/metadata.yaml +++ b/SCRC/pipeline_data/metadata.yaml @@ -6,6 +6,22 @@ namespace: LSHTM verified_hash: 514a68328cd318172cb2be583b3db237fc084dd0 version: 0.1.0 +- accessibility: 0 + component: max_delay_gamma + data_product: fixed-parameters/delay_gamma + extension: toml + filename: fixed-parameters/delay_gamma/0.1.0/0.1.0.toml + namespace: LSHTM + verified_hash: 514a68328cd318172cb2be583b3db237fc084dd0 + version: 0.1.0 +- accessibility: 0 + component: time_step_delay_gamma + data_product: fixed-parameters/delay_gamma + extension: toml + filename: fixed-parameters/delay_gamma/0.1.0/0.1.0.toml + namespace: LSHTM + verified_hash: 514a68328cd318172cb2be583b3db237fc084dd0 + version: 0.1.0 - accessibility: 0 component: relative_infectiousness data_product: fixed-parameters/relative_infectiousness @@ -14,6 +30,30 @@ namespace: LSHTM verified_hash: 45e50c4dc8b1d14b8c00c4ae6824b9c46f57fb28 version: 0.1.0 +- accessibility: 0 + component: rel_preclinical + data_product: fixed-parameters/relative_infectiousness + extension: toml + filename: fixed-parameters/relative_infectiousness/0.1.0/0.1.0.toml + namespace: LSHTM + verified_hash: 45e50c4dc8b1d14b8c00c4ae6824b9c46f57fb28 + version: 0.1.0 +- accessibility: 0 + component: rel_symptomatic + data_product: fixed-parameters/relative_infectiousness + extension: toml + filename: fixed-parameters/relative_infectiousness/0.1.0/0.1.0.toml + namespace: LSHTM + verified_hash: 45e50c4dc8b1d14b8c00c4ae6824b9c46f57fb28 + version: 0.1.0 +- accessibility: 0 + component: rel_subclinical + data_product: fixed-parameters/relative_infectiousness + extension: toml + filename: fixed-parameters/relative_infectiousness/0.1.0/0.1.0.toml + namespace: LSHTM + verified_hash: 45e50c4dc8b1d14b8c00c4ae6824b9c46f57fb28 + version: 0.1.0 - accessibility: 0 component: rho data_product: fixed-parameters/rho @@ -110,6 +150,22 @@ namespace: LSHTM verified_hash: 8791ab1227a459ac6e5802e4331bbeb1c05e8dfd version: 0.1.0 +- accessibility: 0 + component: isnational + data_product: lockdown/config + extension: toml + filename: lockdown/config/0.1.0/0.1.0.toml + namespace: LSHTM + verified_hash: 8791ab1227a459ac6e5802e4331bbeb1c05e8dfd + version: 0.1.0 +- accessibility: 0 + component: duration + data_product: lockdown/config + extension: toml + filename: lockdown/config/0.1.0/0.1.0.toml + namespace: LSHTM + verified_hash: 8791ab1227a459ac6e5802e4331bbeb1c05e8dfd + version: 0.1.0 - accessibility: 0 component: seeding data_product: run-configuration/seeding @@ -118,6 +174,46 @@ namespace: LSHTM verified_hash: 4e9abcaeeb0210cee1a6273f4aee6d022b1420bf version: 0.1.0 +- accessibility: 0 + component: seed + data_product: run-configuration/seeding + extension: toml + filename: run-configuration/seeding/0.1.0/0.1.0.toml + namespace: LSHTM + verified_hash: 4e9abcaeeb0210cee1a6273f4aee6d022b1420bf + version: 0.1.0 +- accessibility: 0 + component: min_age + data_product: run-configuration/seeding + extension: toml + filename: run-configuration/seeding/0.1.0/0.1.0.toml + namespace: LSHTM + verified_hash: 4e9abcaeeb0210cee1a6273f4aee6d022b1420bf + version: 0.1.0 +- accessibility: 0 + component: max_age + data_product: run-configuration/seeding + extension: toml + filename: run-configuration/seeding/0.1.0/0.1.0.toml + namespace: LSHTM + verified_hash: 4e9abcaeeb0210cee1a6273f4aee6d022b1420bf + version: 0.1.0 +- accessibility: 0 + component: seeding_min_start_day + data_product: run-configuration/seeding + extension: toml + filename: run-configuration/seeding/0.1.0/0.1.0.toml + namespace: LSHTM + verified_hash: 4e9abcaeeb0210cee1a6273f4aee6d022b1420bf + version: 0.1.0 +- accessibility: 0 + component: seeding_max_start_day + data_product: run-configuration/seeding + extension: toml + filename: run-configuration/seeding/0.1.0/0.1.0.toml + namespace: LSHTM + verified_hash: 4e9abcaeeb0210cee1a6273f4aee6d022b1420bf + version: 0.1.0 - accessibility: 0 component: time data_product: run-configuration/time @@ -126,6 +222,30 @@ namespace: LSHTM verified_hash: f9300fc834cc4c267cb69e4b91177c244171e15f version: 0.1.0 +- accessibility: 0 + component: start_day + data_product: run-configuration/time + extension: toml + filename: run-configuration/time/0.1.0/0.1.0.toml + namespace: LSHTM + verified_hash: f9300fc834cc4c267cb69e4b91177c244171e15f + version: 0.1.0 +- accessibility: 0 + component: end_day + data_product: run-configuration/time + extension: toml + filename: run-configuration/time/0.1.0/0.1.0.toml + namespace: LSHTM + verified_hash: f9300fc834cc4c267cb69e4b91177c244171e15f + version: 0.1.0 +- accessibility: 0 + component: start_date_posix + data_product: run-configuration/time + extension: toml + filename: run-configuration/time/0.1.0/0.1.0.toml + namespace: LSHTM + verified_hash: f9300fc834cc4c267cb69e4b91177c244171e15f + version: 0.1.0 - accessibility: 0 component: triggers data_product: lockdown/triggers @@ -134,6 +254,22 @@ namespace: LSHTM verified_hash: 9c451b7d79b3b3765d25a7b68f4f845950ff509d version: 0.1.0 +- accessibility: 0 + component: intervention_shift + data_product: lockdown/triggers + extension: toml + filename: lockdown/triggers/0.1.0/0.1.0.toml + namespace: LSHTM + verified_hash: 9c451b7d79b3b3765d25a7b68f4f845950ff509d + version: 0.1.0 +- accessibility: 0 + component: icu_bed_usage + data_product: lockdown/triggers + extension: toml + filename: lockdown/triggers/0.1.0/0.1.0.toml + namespace: LSHTM + verified_hash: 9c451b7d79b3b3765d25a7b68f4f845950ff509d + version: 0.1.0 - accessibility: 0 component: population_size/females data_product: population/population_sizes @@ -244,7 +380,7 @@ extension: h5 filename: school/holiday_rates/0.20200811.0/0.20200811.0.h5 namespace: LSHTM - verified_hash: a3dfe177436f0d5a226cea49eeb635efd1c75776 + verified_hash: c4415e3e1bfb703910ee7ba90e47967cd30ac350 version: 0.20200811.0 - accessibility: 0 component: lockdown_rates diff --git a/data-raw/master/LSHTM/fixed-parameters/delay_gamma/0.1.0.toml b/data-raw/master/LSHTM/fixed-parameters/delay_gamma/0.1.0.toml new file mode 100644 index 0000000..3497793 --- /dev/null +++ b/data-raw/master/LSHTM/fixed-parameters/delay_gamma/0.1.0.toml @@ -0,0 +1,7 @@ +[max_delay_gamma] +type = "point-estimate" +value = 60 + +[time_step_delay_gamma] +type = "point-estimate" +value = 0.25 diff --git a/data-raw/master/LSHTM/fixed-parameters/relative_infectiousness/0.1.0.toml b/data-raw/master/LSHTM/fixed-parameters/relative_infectiousness/0.1.0.toml new file mode 100644 index 0000000..3be8c48 --- /dev/null +++ b/data-raw/master/LSHTM/fixed-parameters/relative_infectiousness/0.1.0.toml @@ -0,0 +1,11 @@ +[rel_preclinical] +type = "point-estimate" +value = 1 + +[rel_symptomatic] +type = "point-estimate" +value = 1 + +[rel_subclinical] +type = "point-estimate" +value = 0.5 diff --git a/data-raw/master/LSHTM/lockdown/config/0.1.0.toml b/data-raw/master/LSHTM/lockdown/config/0.1.0.toml new file mode 100644 index 0000000..9e4b142 --- /dev/null +++ b/data-raw/master/LSHTM/lockdown/config/0.1.0.toml @@ -0,0 +1,7 @@ +[isnational] +type = "point-estimate" +value = 1 + +[duration] +type = "point-estimate" +value = 84 diff --git a/data-raw/master/LSHTM/lockdown/triggers/0.1.0.toml b/data-raw/master/LSHTM/lockdown/triggers/0.1.0.toml new file mode 100644 index 0000000..c17b96f --- /dev/null +++ b/data-raw/master/LSHTM/lockdown/triggers/0.1.0.toml @@ -0,0 +1,7 @@ +[intervention_shift] +type = "point-estimate" +value = 0 + +[icu_bed_usage] +type = "point-estimate" +value = -1 diff --git a/data-raw/master/LSHTM/run-configuration/seeding/0.1.0.toml b/data-raw/master/LSHTM/run-configuration/seeding/0.1.0.toml new file mode 100644 index 0000000..fb01be7 --- /dev/null +++ b/data-raw/master/LSHTM/run-configuration/seeding/0.1.0.toml @@ -0,0 +1,19 @@ +[seed] +type = "point-estimate" +value = -1 + +[min_age] +type = "point-estimate" +value = 25 + +[max_age] +type = "point-estimate" +value = 50 + +[seeding_min_start_day] +type = "point-estimate" +value = 0 + +[seeding_max_start_day] +type = "point-estimate" +value = 20 diff --git a/data-raw/master/LSHTM/run-configuration/time/0.1.0.toml b/data-raw/master/LSHTM/run-configuration/time/0.1.0.toml new file mode 100644 index 0000000..c76dd66 --- /dev/null +++ b/data-raw/master/LSHTM/run-configuration/time/0.1.0.toml @@ -0,0 +1,11 @@ +[start_day] +type = "point-estimate" +value = 0 + +[end_day] +type = "point-estimate" +value = 365 + +[start_date_posix] +type = "point-estimate" +value = 18290 diff --git a/tests/regression/test_params.R b/tests/regression/test_params.R index 98d320c..16c875f 100644 --- a/tests/regression/test_params.R +++ b/tests/regression/test_params.R @@ -13,6 +13,12 @@ library(testit) # For 'assert' function # Retrieve the base parameters from the testing directory covid_uk_path = getwd() +if(!file.exists(file.path(covid_uk_path, "tests", "test_data", + "baseline", "params-Regional-stage1.pars"))) +{ + stop("Failed to find test data.") +} + base_params1 = dget(file.path(covid_uk_path, "tests", "test_data", "baseline", "params-Regional-stage1.pars")) base_params2 = dget(file.path(covid_uk_path, "tests", "test_data", @@ -32,7 +38,6 @@ cat(paste("Opening: ", file_stage1, "\n")) cat(paste("Opening: ", file_stage2, "\n")) new_params1 = dget(file_stage1) -new_params2 = dget(file_stage2) # Check that the column names are identical message("STAGE 1: ") @@ -64,6 +69,7 @@ for(col in names(base_params1)) message("Passed Stage 1") # Check that the column names are identical message("STAGE 2: ") +new_params2 = dget(file_stage2) message("Testing Column Names Match: ") print(names(base_params2)) assert(paste("\nColumn names do not match", "\n"),length(setdiff(names(base_params2),names(new_params2))) == 0) @@ -113,4 +119,4 @@ for(col in names(base_params2$pop[[1]])) message("PASS\n") } message("Passed Stage 2") -message("Success!\n") \ No newline at end of file +message("Success!\n")