Line data Source code
1 : /*
2 : * Copyright (C) 2020-2025 MEmilio
3 : *
4 : * Authors: Wadim Koslow, Daniel Abele, Martin J. Kuehn, Lena Ploetzke
5 : *
6 : * Contact: Martin J. Kuehn <Martin.Kuehn@DLR.de>
7 : *
8 : * Licensed under the Apache License, Version 2.0 (the "License");
9 : * you may not use this file except in compliance with the License.
10 : * You may obtain a copy of the License at
11 : *
12 : * http://www.apache.org/licenses/LICENSE-2.0
13 : *
14 : * Unless required by applicable law or agreed to in writing, software
15 : * distributed under the License is distributed on an "AS IS" BASIS,
16 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 : * See the License for the specific language governing permissions and
18 : * limitations under the License.
19 : */
20 : #ifndef ODESECIR_PARAMETERS_IO_H
21 : #define ODESECIR_PARAMETERS_IO_H
22 :
23 : #include "memilio/config.h"
24 : #include <cassert>
25 :
26 : #ifdef MEMILIO_HAS_JSONCPP
27 :
28 : #include "ode_secir/model.h"
29 : #include "memilio/io/epi_data.h"
30 : #include "memilio/io/result_io.h"
31 :
32 : namespace mio
33 : {
34 :
35 : namespace osecir
36 : {
37 :
38 : namespace details
39 : {
40 : /**
41 : * @brief reads populations data from RKI.
42 : * @param[in] rki_data Vector of ConfirmedCasesDataEntry%s.
43 : * @param[in] vregion Vector of keys of the region of interest.
44 : * @param[in] date Date at which the data is read.
45 : * @param[in, out] vnum_* Output vector for number of people in the corresponding compartement.
46 : * @param[in] vt_* vector Average time it takes to get from one compartement to another for each age group.
47 : * @param[in] vmu_* vector Probabilities to get from one compartement to another for each age group.
48 : * @param[in] scaling_factor_inf Factors by which to scale the confirmed cases of rki data.
49 : */
50 : IOResult<void> read_confirmed_cases_data(
51 : std::vector<ConfirmedCasesDataEntry>& rki_data, std::vector<int> const& vregion, Date date,
52 : std::vector<std::vector<double>>& vnum_Exposed, std::vector<std::vector<double>>& vnum_InfectedNoSymptoms,
53 : std::vector<std::vector<double>>& vnum_InfectedSymptoms, std::vector<std::vector<double>>& vnum_InfectedSevere,
54 : std::vector<std::vector<double>>& vnum_icu, std::vector<std::vector<double>>& vnum_death,
55 : std::vector<std::vector<double>>& vnum_rec, const std::vector<std::vector<int>>& vt_Exposed,
56 : const std::vector<std::vector<int>>& vt_InfectedNoSymptoms,
57 : const std::vector<std::vector<int>>& vt_InfectedSymptoms, const std::vector<std::vector<int>>& vt_InfectedSevere,
58 : const std::vector<std::vector<int>>& vt_InfectedCritical, const std::vector<std::vector<double>>& vmu_C_R,
59 : const std::vector<std::vector<double>>& vmu_I_H, const std::vector<std::vector<double>>& vmu_H_U,
60 : const std::vector<double>& scaling_factor_inf);
61 :
62 : /**
63 : * @brief Sets populations data from already read case data with multiple age groups into a Model with one age group.
64 : * @tparam FP Floating point data type, e.g., double.
65 : * @param[in, out] model Vector of models in which the data is set.
66 : * @param[in] case_data List of confirmed cases data entries.
67 : * @param[in] region Vector of keys of the region of interest.
68 : * @param[in] date Date at which the data is read.
69 : * @param[in] scaling_factor_inf Factors by which to scale the confirmed cases of rki data.
70 : */
71 : template <typename FP = double>
72 97 : IOResult<void> set_confirmed_cases_data(std::vector<Model<FP>>& model, std::vector<ConfirmedCasesDataEntry>& case_data,
73 : const std::vector<int>& region, Date date,
74 : const std::vector<double>& scaling_factor_inf)
75 : {
76 97 : const size_t num_age_groups = ConfirmedCasesDataEntry::age_group_names.size();
77 97 : assert(scaling_factor_inf.size() == num_age_groups);
78 :
79 194 : std::vector<std::vector<int>> t_InfectedNoSymptoms{model.size()};
80 194 : std::vector<std::vector<int>> t_Exposed{model.size()};
81 194 : std::vector<std::vector<int>> t_InfectedSymptoms{model.size()};
82 194 : std::vector<std::vector<int>> t_InfectedSevere{model.size()};
83 194 : std::vector<std::vector<int>> t_InfectedCritical{model.size()};
84 :
85 194 : std::vector<std::vector<double>> mu_C_R{model.size()};
86 194 : std::vector<std::vector<double>> mu_I_H{model.size()};
87 194 : std::vector<std::vector<double>> mu_H_U{model.size()};
88 194 : std::vector<std::vector<double>> mu_U_D{model.size()};
89 :
90 194 : for (size_t node = 0; node < model.size(); ++node) {
91 679 : for (size_t group = 0; group < num_age_groups; group++) {
92 :
93 1164 : t_Exposed[node].push_back(
94 1164 : static_cast<int>(std::round(model[node].parameters.template get<TimeExposed<FP>>()[(AgeGroup)group])));
95 1164 : t_InfectedNoSymptoms[node].push_back(static_cast<int>(
96 1164 : std::round(model[node].parameters.template get<TimeInfectedNoSymptoms<FP>>()[(AgeGroup)group])));
97 1164 : t_InfectedSymptoms[node].push_back(static_cast<int>(
98 1164 : std::round(model[node].parameters.template get<TimeInfectedSymptoms<FP>>()[(AgeGroup)group])));
99 1164 : t_InfectedSevere[node].push_back(static_cast<int>(
100 1164 : std::round(model[node].parameters.template get<TimeInfectedSevere<FP>>()[(AgeGroup)group])));
101 1164 : t_InfectedCritical[node].push_back(static_cast<int>(
102 1164 : std::round(model[node].parameters.template get<TimeInfectedCritical<FP>>()[(AgeGroup)group])));
103 :
104 1164 : mu_C_R[node].push_back(
105 1164 : model[node].parameters.template get<RecoveredPerInfectedNoSymptoms<FP>>()[(AgeGroup)group]);
106 1164 : mu_I_H[node].push_back(
107 1164 : model[node].parameters.template get<SeverePerInfectedSymptoms<FP>>()[(AgeGroup)group]);
108 582 : mu_H_U[node].push_back(model[node].parameters.template get<CriticalPerSevere<FP>>()[(AgeGroup)group]);
109 582 : mu_U_D[node].push_back(model[node].parameters.template get<DeathsPerCritical<FP>>()[(AgeGroup)group]);
110 : }
111 : }
112 388 : std::vector<std::vector<double>> num_InfectedSymptoms(model.size(), std::vector<double>(num_age_groups, 0.0));
113 388 : std::vector<std::vector<double>> num_death(model.size(), std::vector<double>(num_age_groups, 0.0));
114 388 : std::vector<std::vector<double>> num_rec(model.size(), std::vector<double>(num_age_groups, 0.0));
115 388 : std::vector<std::vector<double>> num_Exposed(model.size(), std::vector<double>(num_age_groups, 0.0));
116 388 : std::vector<std::vector<double>> num_InfectedNoSymptoms(model.size(), std::vector<double>(num_age_groups, 0.0));
117 388 : std::vector<std::vector<double>> num_InfectedSevere(model.size(), std::vector<double>(num_age_groups, 0.0));
118 388 : std::vector<std::vector<double>> num_icu(model.size(), std::vector<double>(num_age_groups, 0.0));
119 :
120 97 : BOOST_OUTCOME_TRY(read_confirmed_cases_data(case_data, region, date, num_Exposed, num_InfectedNoSymptoms,
121 : num_InfectedSymptoms, num_InfectedSevere, num_icu, num_death, num_rec,
122 : t_Exposed, t_InfectedNoSymptoms, t_InfectedSymptoms, t_InfectedSevere,
123 : t_InfectedCritical, mu_C_R, mu_I_H, mu_H_U, scaling_factor_inf));
124 :
125 194 : for (size_t node = 0; node < model.size(); node++) {
126 97 : if (std::accumulate(num_InfectedSymptoms[node].begin(), num_InfectedSymptoms[node].end(), 0.0) > 0) {
127 79 : size_t num_groups = (size_t)model[node].parameters.get_num_groups();
128 553 : for (size_t i = 0; i < num_groups; i++) {
129 474 : model[node].populations[{AgeGroup(i), InfectionState::Exposed}] = num_Exposed[node][i];
130 474 : model[node].populations[{AgeGroup(i), InfectionState::InfectedNoSymptoms}] =
131 : num_InfectedNoSymptoms[node][i];
132 474 : model[node].populations[{AgeGroup(i), InfectionState::InfectedNoSymptomsConfirmed}] = 0;
133 474 : model[node].populations[{AgeGroup(i), InfectionState::InfectedSymptoms}] =
134 : num_InfectedSymptoms[node][i];
135 474 : model[node].populations[{AgeGroup(i), InfectionState::InfectedSymptomsConfirmed}] = 0;
136 474 : model[node].populations[{AgeGroup(i), InfectionState::InfectedSevere}] = num_InfectedSevere[node][i];
137 : // Only set the number of ICU patients here, if the date is not available in the data.
138 474 : if (!is_divi_data_available(date)) {
139 54 : model[node].populations[{AgeGroup(i), InfectionState::InfectedCritical}] = num_icu[node][i];
140 : }
141 474 : model[node].populations[{AgeGroup(i), InfectionState::Dead}] = num_death[node][i];
142 474 : model[node].populations[{AgeGroup(i), InfectionState::Recovered}] = num_rec[node][i];
143 : }
144 : }
145 : else {
146 18 : log_warning("No infections reported on date {} for region {}. Population data has not been set.", date,
147 : region[node]);
148 : }
149 : }
150 194 : return success();
151 97 : }
152 :
153 : /**
154 : * @brief Sets the infected population for a given model based on confirmed cases data. Here, we
155 : * read the case data from a file.
156 : * @tparam FP Floating point data type, e.g., double.
157 : * @param[in, out] Vector of models for which the confirmed cases data will be set.
158 : * @param[in] path Path to the confirmed cases data file.
159 : * @param[in] region Vector of keys of the region of interest.
160 : * @param[in] date Date at which the data is read.
161 : * @param[in] scaling_factor_inf Factors by which to scale the confirmed cases of rki data.
162 : */
163 : template <typename FP = double>
164 50 : IOResult<void> set_confirmed_cases_data(std::vector<Model<FP>>& model, const std::string& path,
165 : std::vector<int> const& region, Date date,
166 : const std::vector<double>& scaling_factor_inf)
167 : {
168 50 : BOOST_OUTCOME_TRY(auto&& case_data, mio::read_confirmed_cases_data(path));
169 50 : BOOST_OUTCOME_TRY(set_confirmed_cases_data(model, case_data, region, date, scaling_factor_inf));
170 100 : return success();
171 50 : }
172 :
173 : /**
174 : * @brief Reads number of ICU patients from DIVI register into Parameters.
175 : * @param[in] path Path to DIVI file.
176 : * @param[in] vregion Keys of the region of interest.
177 : * @param date Date for which we initialize.
178 : * @param vnum_icu Number of ICU patients.
179 : */
180 : IOResult<void> read_divi_data(const std::string& path, const std::vector<int>& vregion, Date date,
181 : std::vector<double>& vnum_icu);
182 :
183 : /**
184 : * @brief Sets populations data from DIVI register into Model.
185 : * @tparam FP floating point data type, e.g., double.
186 : * @param[in, out] model Vector of models in which the data is set.
187 : * @param[in] path Path to DIVI file.
188 : * @param[in] vregion Vector of keys of the regions of interest.
189 : * @param[in] date Date for which the arrays are initialized.
190 : * @param[in] scaling_factor_icu factor by which to scale the icu cases of divi data.
191 : */
192 : template <typename FP = double>
193 106 : IOResult<void> set_divi_data(std::vector<Model<FP>>& model, const std::string& path, const std::vector<int>& vregion,
194 : Date date, double scaling_factor_icu)
195 : {
196 : // DIVI dataset will no longer be updated from CW29 2024 on.
197 106 : if (!is_divi_data_available(date)) {
198 36 : log_warning("No DIVI data available for date: {}. "
199 : "ICU compartment will be set based on Case data.",
200 : date);
201 72 : return success();
202 : }
203 140 : std::vector<double> sum_mu_I_U(vregion.size(), 0);
204 140 : std::vector<std::vector<double>> mu_I_U{model.size()};
205 140 : for (size_t region = 0; region < vregion.size(); region++) {
206 70 : auto num_groups = model[region].parameters.get_num_groups();
207 490 : for (auto i = AgeGroup(0); i < num_groups; i++) {
208 840 : sum_mu_I_U[region] += model[region].parameters.template get<CriticalPerSevere<FP>>()[i] *
209 420 : model[region].parameters.template get<SeverePerInfectedSymptoms<FP>>()[i];
210 840 : mu_I_U[region].push_back(model[region].parameters.template get<CriticalPerSevere<FP>>()[i] *
211 420 : model[region].parameters.template get<SeverePerInfectedSymptoms<FP>>()[i]);
212 : }
213 : }
214 140 : std::vector<double> num_icu(model.size(), 0.0);
215 70 : BOOST_OUTCOME_TRY(read_divi_data(path, vregion, date, num_icu));
216 :
217 140 : for (size_t region = 0; region < vregion.size(); region++) {
218 70 : auto num_groups = model[region].parameters.get_num_groups();
219 490 : for (auto i = AgeGroup(0); i < num_groups; i++) {
220 420 : model[region].populations[{i, InfectionState::InfectedCritical}] =
221 420 : scaling_factor_icu * num_icu[region] * mu_I_U[region][(size_t)i] / sum_mu_I_U[region];
222 : }
223 : }
224 :
225 140 : return success();
226 70 : }
227 :
228 : /**
229 : * @brief Reads population data from census data.
230 : * @tparam FP floating point data type, e.g., double.
231 : * @param[in] path Path to RKI file.
232 : * @param[in] vregion Vector of keys of the regions of interest.
233 : * @param[in] accumulate_age_groups Specifies whether population data should be accumulated to one age group.
234 : */
235 : IOResult<std::vector<std::vector<double>>>
236 : read_population_data(const std::string& path, const std::vector<int>& vregion, bool accumulate_age_groups = false);
237 :
238 : /**
239 : * @brief Sets population data from census data which has been read into num_population.
240 : * @tparam FP floating point data type, e.g., double.
241 : * @param[in, out] model Vector of models in which the data is set. There should be one model per region.
242 : * @param[in] num_population Vector of population data. The size should be the same as vregion and model.
243 : * @param[in] vregion Vector of keys of the regions of interest.
244 : */
245 : template <typename FP = double>
246 88 : IOResult<void> set_population_data(std::vector<Model<FP>>& model,
247 : const std::vector<std::vector<double>>& num_population,
248 : const std::vector<int>& vregion)
249 : {
250 88 : assert(num_population.size() == vregion.size());
251 88 : assert(model.size() == vregion.size());
252 176 : for (size_t region = 0; region < vregion.size(); region++) {
253 88 : auto num_groups = model[region].parameters.get_num_groups();
254 616 : for (auto i = AgeGroup(0); i < num_groups; i++) {
255 528 : model[region].populations.template set_difference_from_group_total<AgeGroup>(
256 : {i, InfectionState::Susceptible}, num_population[region][size_t(i)]);
257 : }
258 : }
259 176 : return success();
260 : }
261 :
262 : /**
263 : * @brief Sets population data from census data into a Model.
264 : * @tparam FP Floating point data type, e.g., double.
265 : * @param[in, out] model Vector of models in which the data is set.
266 : * @param[in] path Path to RKI file containing population data.
267 : * @param[in] vregion Vector of keys of the regions of interest.
268 : */
269 : template <typename FP = double>
270 50 : IOResult<void> set_population_data(std::vector<Model<FP>>& model, const std::string& path,
271 : const std::vector<int>& vregion)
272 : {
273 : // Specifies whether population data should be accumulated to one age group.
274 50 : const bool is_single_age_group = static_cast<size_t>(model[0].parameters.get_num_groups()) == 1;
275 50 : BOOST_OUTCOME_TRY(const auto&& num_population, read_population_data(path, vregion, is_single_age_group));
276 50 : BOOST_OUTCOME_TRY(set_population_data(model, num_population, vregion));
277 100 : return success();
278 50 : }
279 :
280 : } //namespace details
281 :
282 : #ifdef MEMILIO_HAS_HDF5
283 :
284 : /**
285 : * @brief Uses the initialisation method, which uses the reported data to set the initial conditions for the model for a given day.
286 : * The initialisation is applied for a predefined number of days and finally saved in a timeseries for each region. In the end,
287 : * we save the files "Results_rki.h5" and "Results_rki_sum.h5" in the results_dir.
288 : * Results_rki.h5 contains a time series for each region and Results_rki_sum.h5 contains the sum of all regions.
289 : * @param[in] models Vector of models in which the data is set. Copy is made to avoid changing the original model.
290 : * @param[in] results_dir Path to result files.
291 : * @param[in] region Vector of keys of the region of interest.
292 : * @param[in] date Date for which the data should be read.
293 : * @param[in] scaling_factor_inf Factors by which to scale the confirmed cases of rki data.
294 : * @param[in] scaling_factor_icu Factor by which to scale the icu cases of divi data.
295 : * @param[in] num_days Number of days to be simulated/initialized.
296 : * @param[in] divi_data_path Path to DIVI file.
297 : * @param[in] confirmed_cases_path Path to confirmed cases file.
298 : * @param[in] population_data_path Path to population data file.
299 : */
300 : template <class Model>
301 19 : IOResult<void> export_input_data_county_timeseries(
302 : std::vector<Model> models, const std::string& results_dir, std::vector<int> const& region, Date date,
303 : const std::vector<double>& scaling_factor_inf, double scaling_factor_icu, int num_days,
304 : const std::string& divi_data_path, const std::string& confirmed_cases_path, const std::string& population_data_path)
305 : {
306 19 : const auto num_age_groups = (size_t)models[0].parameters.get_num_groups();
307 19 : assert(scaling_factor_inf.size() == num_age_groups);
308 19 : assert(num_age_groups == ConfirmedCasesDataEntry::age_group_names.size());
309 19 : assert(models.size() == region.size());
310 95 : std::vector<TimeSeries<double>> extrapolated_data(
311 38 : region.size(), TimeSeries<double>::zero(num_days + 1, (size_t)InfectionState::Count * num_age_groups));
312 :
313 19 : BOOST_OUTCOME_TRY(auto&& num_population, details::read_population_data(population_data_path, region));
314 19 : BOOST_OUTCOME_TRY(auto&& case_data, mio::read_confirmed_cases_data(confirmed_cases_path));
315 :
316 95 : for (int t = 0; t <= num_days; ++t) {
317 38 : auto offset_day = offset_date_by_days(date, t);
318 :
319 38 : BOOST_OUTCOME_TRY(details::set_divi_data(models, divi_data_path, region, offset_day, scaling_factor_icu));
320 38 : BOOST_OUTCOME_TRY(details::set_confirmed_cases_data(models, case_data, region, offset_day, scaling_factor_inf));
321 38 : BOOST_OUTCOME_TRY(details::set_population_data(models, num_population, region));
322 76 : for (size_t r = 0; r < region.size(); r++) {
323 38 : extrapolated_data[r][t] = models[r].get_initial_values();
324 : }
325 : }
326 :
327 38 : BOOST_OUTCOME_TRY(
328 : save_result(extrapolated_data, region, (int)num_age_groups, path_join(results_dir, "Results_rki.h5")));
329 :
330 95 : auto rki_data_sum = sum_nodes(std::vector<std::vector<TimeSeries<double>>>{extrapolated_data});
331 152 : BOOST_OUTCOME_TRY(
332 : save_result({rki_data_sum[0][0]}, {0}, (int)num_age_groups, path_join(results_dir, "Results_rki_sum.h5")));
333 :
334 38 : return success();
335 19 : }
336 : #else
337 : template <class Model>
338 : IOResult<void>
339 : export_input_data_county_timeseries(std::vector<Model> models, const std::string& dir, std::vector<int> const& region,
340 : Date date, const std::vector<double>& scaling_factor_inf, double scaling_factor_icu,
341 : int num_days, const std::string& divi_data_path,
342 : const std::string& confirmed_cases_path, const std::string& population_data_path)
343 : {
344 : mio::log_warning("HDF5 not available. Cannot export time series of extrapolated real data.");
345 : return success();
346 : }
347 : #endif // MEMILIO_HAS_HDF5
348 :
349 : /**
350 : * @brief Reads population data from population files for the whole country.
351 : * @param[in, out] model Vector of model in which the data is set.
352 : * @param[in] date Date for which the data should be read.
353 : * @param[in] scaling_factor_inf Factors by which to scale the confirmed cases of rki data.
354 : * @param[in] scaling_factor_icu Factor by which to scale the icu cases of divi data.
355 : * @param[in] dir Directory of files.
356 : */
357 : template <class Model>
358 1 : IOResult<void> read_input_data_germany(std::vector<Model>& model, Date date,
359 : const std::vector<double>& scaling_factor_inf, double scaling_factor_icu,
360 : const std::string& dir)
361 : {
362 4 : BOOST_OUTCOME_TRY(
363 : details::set_divi_data(model, path_join(dir, "germany_divi.json"), {0}, date, scaling_factor_icu));
364 4 : BOOST_OUTCOME_TRY(details::set_confirmed_cases_data(model, path_join(dir, "cases_all_age_ma7.json"), {0}, date,
365 : scaling_factor_inf));
366 4 : BOOST_OUTCOME_TRY(details::set_population_data(model, path_join(dir, "county_current_population.json"), {0}));
367 2 : return success();
368 1 : }
369 :
370 : /**
371 : * @brief Reads population data from population files for the specefied state.
372 : * @param[in, out] model Vector of model in which the data is set.
373 : * @param[in] date Date for which the data should be read.
374 : * @param[in] state Vector of region keys of states of interest.
375 : * @param[in] scaling_factor_inf Factors by which to scale the confirmed cases of rki data.
376 : * @param[in] scaling_factor_icu Factor by which to scale the icu cases of divi data.
377 : * @param[in] dir Directory of files.
378 : */
379 : template <class Model>
380 1 : IOResult<void> read_input_data_state(std::vector<Model>& model, Date date, std::vector<int>& state,
381 : const std::vector<double>& scaling_factor_inf, double scaling_factor_icu,
382 : const std::string& dir)
383 : {
384 :
385 2 : BOOST_OUTCOME_TRY(
386 : details::set_divi_data(model, path_join(dir, "state_divi.json"), state, date, scaling_factor_icu));
387 2 : BOOST_OUTCOME_TRY(details::set_confirmed_cases_data(model, path_join(dir, "cases_all_state_age_ma7.json"), state,
388 : date, scaling_factor_inf));
389 2 : BOOST_OUTCOME_TRY(details::set_population_data(model, path_join(dir, "county_current_population.json"), state));
390 2 : return success();
391 1 : }
392 :
393 : /**
394 : * @brief Reads population data from population files for the specefied county.
395 : * @param[in, out] model Vector of model in which the data is set.
396 : * @param[in] date Date for which the data should be read.
397 : * @param[in] county Vector of region keys of counties of interest.
398 : * @param[in] scaling_factor_inf Factors by which to scale the confirmed cases of rki data.
399 : * @param[in] scaling_factor_icu Factor by which to scale the icu cases of divi data.
400 : * @param[in] dir Directory of files.
401 : * @param[in] num_days [Default: 0] Number of days to be simulated; required to extrapolate real data.
402 : * @param[in] export_time_series [Default: false] If true, reads data for each day of simulation and writes it in the same directory as the input files.
403 : */
404 : template <class Model>
405 28 : IOResult<void> read_input_data_county(std::vector<Model>& model, Date date, const std::vector<int>& county,
406 : const std::vector<double>& scaling_factor_inf, double scaling_factor_icu,
407 : const std::string& dir, int num_days = 0, bool export_time_series = false)
408 : {
409 56 : BOOST_OUTCOME_TRY(details::set_divi_data(model, path_join(dir, "pydata/Germany", "county_divi_ma7.json"), county,
410 : date, scaling_factor_icu));
411 56 : BOOST_OUTCOME_TRY(details::set_confirmed_cases_data(
412 : model, path_join(dir, "pydata/Germany", "cases_all_county_age_ma7.json"), county, date, scaling_factor_inf));
413 56 : BOOST_OUTCOME_TRY(details::set_population_data(
414 : model, path_join(dir, "pydata/Germany", "county_current_population.json"), county));
415 :
416 28 : if (export_time_series) {
417 : // Use only if extrapolated real data is needed for comparison. EXPENSIVE !
418 : // Run time equals run time of the previous functions times the num_days !
419 : // (This only represents the vectorization of the previous function over all simulation days...)
420 0 : log_warning("Exporting time series of extrapolated real data. This may take some minutes. "
421 : "For simulation runs over the same time period, deactivate it.");
422 0 : BOOST_OUTCOME_TRY(
423 : export_input_data_county_timeseries(model, dir, county, date, scaling_factor_inf, scaling_factor_icu,
424 : num_days, path_join(dir, "pydata/Germany", "county_divi_ma7.json"),
425 : path_join(dir, "pydata/Germany", "cases_all_county_age_ma7.json"),
426 : path_join(dir, "pydata/Germany", "county_current_population.json")));
427 0 : }
428 56 : return success();
429 28 : }
430 :
431 : /**
432 : * @brief reads population data from population files for the specified nodes
433 : * @param[in, out] model vector of model in which the data is set
434 : * @param[in] date Date for which the data should be read
435 : * @param[in] county vector of region keys of interest
436 : * @param[in] scaling_factor_inf factors by which to scale the confirmed cases of rki data
437 : * @param[in] scaling_factor_icu factor by which to scale the icu cases of divi data
438 : * @param[in] dir directory of files
439 : * @param[in] age_group_names strings specifying age group names
440 : */
441 : template <class Model>
442 20 : IOResult<void> read_input_data(std::vector<Model>& model, Date date, const std::vector<int>& node_ids,
443 : const std::vector<double>& scaling_factor_inf, double scaling_factor_icu,
444 : const std::string& data_dir, int num_days = 0, bool export_time_series = false)
445 : {
446 40 : BOOST_OUTCOME_TRY(
447 : details::set_divi_data(model, path_join(data_dir, "critical_cases.json"), node_ids, date, scaling_factor_icu));
448 40 : BOOST_OUTCOME_TRY(details::set_confirmed_cases_data(model, path_join(data_dir, "confirmed_cases.json"), node_ids,
449 : date, scaling_factor_inf));
450 40 : BOOST_OUTCOME_TRY(details::set_population_data(model, path_join(data_dir, "population_data.json"), node_ids));
451 :
452 20 : if (export_time_series) {
453 : // Use only if extrapolated real data is needed for comparison. EXPENSIVE !
454 : // Run time equals run time of the previous functions times the num_days !
455 : // (This only represents the vectorization of the previous function over all simulation days...)
456 0 : log_warning("Exporting time series of extrapolated real data. This may take some minutes. "
457 : "For simulation runs over the same time period, deactivate it.");
458 0 : BOOST_OUTCOME_TRY(export_input_data_county_timeseries(
459 : model, data_dir, node_ids, date, scaling_factor_inf, scaling_factor_icu, num_days,
460 : path_join(data_dir, "critical_cases.json"), path_join(data_dir, "confirmed_cases.json"),
461 : path_join(data_dir, "population_data.json")));
462 0 : }
463 40 : return success();
464 20 : }
465 :
466 : } // namespace osecir
467 : } // namespace mio
468 :
469 : #endif // MEMILIO_HAS_JSONCPP
470 :
471 : #endif // ODESECIR_PARAMETERS_IO_H
|