Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1191 Initialization of ICU compartments after July 2024 #1192

Merged
12 changes: 12 additions & 0 deletions cpp/memilio/io/epi_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,18 @@ class DiviEntry
}
};

/**
* @brief Checks if DIVI data is available for a given date.
* @param date The date to check.
* @return True if date is within 2020-04-23 and 2024-07-21, false otherwise.
*/
inline bool is_divi_data_available(const Date& date)
{
static const Date divi_data_start(2020, 4, 23);
static const Date divi_data_end(2024, 7, 21);
return date >= divi_data_start && date <= divi_data_end;
}

/**
* Deserialize a list of DiviEntry from json.
* @param jsvalue Json value that contains DIVI data.
Expand Down
10 changes: 2 additions & 8 deletions cpp/models/ode_secir/parameters_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ IOResult<void> read_confirmed_cases_data(
auto date_df = region_entry.date;
auto age = size_t(region_entry.age_group);

bool read_icu = false; //params.populations.get({age, SecirCompartments::U}) == 0;

HenrZu marked this conversation as resolved.
Show resolved Hide resolved
if (date_df == offset_date_by_days(date, 0)) {
num_InfectedSymptoms[age] += scaling_factor_inf[age] * region_entry.num_confirmed;
num_rec[age] += region_entry.num_confirmed;
Expand All @@ -147,16 +145,12 @@ IOResult<void> read_confirmed_cases_data(
}
if (date_df == offset_date_by_days(date, -t_InfectedSymptoms[age] - t_InfectedSevere[age])) {
num_InfectedSevere[age] -= mu_I_H[age] * scaling_factor_inf[age] * region_entry.num_confirmed;
if (read_icu) {
num_icu[age] += mu_I_H[age] * mu_H_U[age] * scaling_factor_inf[age] * region_entry.num_confirmed;
}
num_icu[age] += mu_I_H[age] * mu_H_U[age] * scaling_factor_inf[age] * region_entry.num_confirmed;
}
if (date_df ==
offset_date_by_days(date, -t_InfectedSymptoms[age] - t_InfectedSevere[age] - t_InfectedCritical[age])) {
num_death[age] += region_entry.num_deaths;
if (read_icu) {
num_icu[age] -= mu_I_H[age] * mu_H_U[age] * scaling_factor_inf[age] * region_entry.num_confirmed;
}
num_icu[age] -= mu_I_H[age] * mu_H_U[age] * scaling_factor_inf[age] * region_entry.num_confirmed;
}
}
}
Expand Down
58 changes: 21 additions & 37 deletions cpp/models/ode_secir/parameters_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,12 @@ IOResult<void> set_confirmed_cases_data(std::vector<Model<FP>>& model, std::vect
num_InfectedSymptoms[node][i];
model[node].populations[{AgeGroup(i), InfectionState::InfectedSymptomsConfirmed}] = 0;
model[node].populations[{AgeGroup(i), InfectionState::InfectedSevere}] = num_InfectedSevere[node][i];
model[node].populations[{AgeGroup(i), InfectionState::Dead}] = num_death[node][i];
model[node].populations[{AgeGroup(i), InfectionState::Recovered}] = num_rec[node][i];
// Only set the number of ICU patients here, if the date is not available in the data.
if (!is_divi_data_available(date)) {
model[node].populations[{AgeGroup(i), InfectionState::InfectedCritical}] = num_icu[node][i];
}
model[node].populations[{AgeGroup(i), InfectionState::Dead}] = num_death[node][i];
model[node].populations[{AgeGroup(i), InfectionState::Recovered}] = num_rec[node][i];
}
}
else {
Expand Down Expand Up @@ -190,6 +194,12 @@ template <typename FP = double>
IOResult<void> set_divi_data(std::vector<Model<FP>>& model, const std::string& path, const std::vector<int>& vregion,
Date date, double scaling_factor_icu)
{
// DIVI dataset will no longer be updated from CW29 2024 on.
if (!is_divi_data_available(date)) {
log_warning("No DIVI data available for date: {}-{}-{}", date.year, date.month, date.day,
". ICU compartment will be set based on Case data.");
return success();
}
std::vector<double> sum_mu_I_U(vregion.size(), 0);
std::vector<std::vector<double>> mu_I_U{model.size()};
for (size_t region = 0; region < vregion.size(); region++) {
Expand Down Expand Up @@ -306,13 +316,7 @@ IOResult<void> export_input_data_county_timeseries(
for (int t = 0; t <= num_days; ++t) {
auto offset_day = offset_date_by_days(date, t);

if (offset_day > Date(2020, 4, 23)) {
BOOST_OUTCOME_TRY(details::set_divi_data(models, divi_data_path, region, offset_day, scaling_factor_icu));
}
else {
log_warning("No DIVI data available for date: {}-{}-{}", offset_day.day, offset_day.month, offset_day.year);
}

BOOST_OUTCOME_TRY(details::set_divi_data(models, divi_data_path, region, offset_day, scaling_factor_icu));
BOOST_OUTCOME_TRY(details::set_confirmed_cases_data(models, case_data, region, offset_day, scaling_factor_inf));
BOOST_OUTCOME_TRY(details::set_population_data(models, num_population, region));
for (size_t r = 0; r < region.size(); r++) {
Expand Down Expand Up @@ -355,13 +359,8 @@ IOResult<void> read_input_data_germany(std::vector<Model>& model, Date date,
const std::vector<double>& scaling_factor_inf, double scaling_factor_icu,
const std::string& dir)
{
if (date > Date(2020, 4, 23)) {
BOOST_OUTCOME_TRY(
details::set_divi_data(model, path_join(dir, "germany_divi.json"), {0}, date, scaling_factor_icu));
}
else {
log_warning("No DIVI data available for this date");
}
BOOST_OUTCOME_TRY(
details::set_divi_data(model, path_join(dir, "germany_divi.json"), {0}, date, scaling_factor_icu));
BOOST_OUTCOME_TRY(details::set_confirmed_cases_data(model, path_join(dir, "cases_all_age_ma7.json"), {0}, date,
scaling_factor_inf));
BOOST_OUTCOME_TRY(details::set_population_data(model, path_join(dir, "county_current_population.json"), {0}));
Expand All @@ -382,14 +381,9 @@ IOResult<void> read_input_data_state(std::vector<Model>& model, Date date, std::
const std::vector<double>& scaling_factor_inf, double scaling_factor_icu,
const std::string& dir)
{
if (date > Date(2020, 4, 23)) {
BOOST_OUTCOME_TRY(
details::set_divi_data(model, path_join(dir, "state_divi.json"), state, date, scaling_factor_icu));
}
else {
log_warning("No DIVI data available for this date");
}

BOOST_OUTCOME_TRY(
details::set_divi_data(model, path_join(dir, "state_divi.json"), state, date, scaling_factor_icu));
BOOST_OUTCOME_TRY(details::set_confirmed_cases_data(model, path_join(dir, "cases_all_state_age_ma7.json"), state,
date, scaling_factor_inf));
BOOST_OUTCOME_TRY(details::set_population_data(model, path_join(dir, "county_current_population.json"), state));
Expand All @@ -412,13 +406,8 @@ IOResult<void> read_input_data_county(std::vector<Model>& model, Date date, cons
const std::vector<double>& scaling_factor_inf, double scaling_factor_icu,
const std::string& dir, int num_days = 0, bool export_time_series = false)
{
if (date > Date(2020, 4, 23)) {
BOOST_OUTCOME_TRY(details::set_divi_data(model, path_join(dir, "pydata/Germany", "county_divi_ma7.json"),
county, date, scaling_factor_icu));
}
else {
log_warning("No DIVI data available for this date");
}
BOOST_OUTCOME_TRY(details::set_divi_data(model, path_join(dir, "pydata/Germany", "county_divi_ma7.json"), county,
date, scaling_factor_icu));
BOOST_OUTCOME_TRY(details::set_confirmed_cases_data(
model, path_join(dir, "pydata/Germany", "cases_all_county_age_ma7.json"), county, date, scaling_factor_inf));
BOOST_OUTCOME_TRY(details::set_population_data(
Expand Down Expand Up @@ -454,13 +443,8 @@ IOResult<void> read_input_data(std::vector<Model>& model, Date date, const std::
const std::vector<double>& scaling_factor_inf, double scaling_factor_icu,
const std::string& data_dir, int num_days = 0, bool export_time_series = false)
{
if (date > Date(2020, 4, 23)) {
BOOST_OUTCOME_TRY(details::set_divi_data(model, path_join(data_dir, "critical_cases.json"), node_ids, date,
scaling_factor_icu));
}
else {
log_warning("No DIVI data available for this date");
}
BOOST_OUTCOME_TRY(
details::set_divi_data(model, path_join(data_dir, "critical_cases.json"), node_ids, date, scaling_factor_icu));
BOOST_OUTCOME_TRY(details::set_confirmed_cases_data(model, path_join(data_dir, "confirmed_cases.json"), node_ids,
date, scaling_factor_inf));
BOOST_OUTCOME_TRY(details::set_population_data(model, path_join(data_dir, "population_data.json"), node_ids));
Expand Down
Loading