Skip to content

Commit

Permalink
Update get_parameters_and_initial_conditions.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
Tortar authored Nov 28, 2024
1 parent 39c98e2 commit 6ae9e5f
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions examples/get_parameters_and_initial_conditions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@
import BeforeIT as Bit
using Dates, FileIO


# We start from loading the calibration oject for italy, which contains 4 datasets: calibration_data, figaro, data, and ea
# These are saved within BeforeIT for the Italian case, and would need to be appropriately generated for other countries
# We start from loading the calibration object for italy, which contains
# 4 datasets: `calibration_data`, `figaro`, `data`, and `ea`. These are
# saved within `BeforeIT.jl` for the Italian case, and would need to be
# appropriately generated for other countries.

cal = Bit.ITALY_CALIBRATION

fieldnames(typeof(cal))

# These are essentually 4 dictionaries with well defined keys, such as
# These are essentially 4 dictionaries with well defined keys, such as

println(keys(cal.calibration))
println(keys(cal.figaro))
println(keys(cal.data))
println(keys(cal.ea))

# The object also contains two time variables related to the data

println(cal.max_calibration_date)
println(cal.estimation_date)

Expand All @@ -26,29 +28,26 @@ println(cal.estimation_date)
calibration_date = DateTime(2010, 03, 31)
parameters, initial_conditions = Bit.get_params_and_initial_conditions(cal, calibration_date; scale = 0.01)

# In sgeneral, we might want to repeat this operation for multiple quarters.
# In the following, we loop over all quarters from 2010Q1 to 2019Q4
# In general, we might want to repeat this operation for multiple quarters.
# In the following, we loop over all quarters from `2010Q1` to `2019Q4`
# and save the parameters and initial conditions in separate files.
# We can then load these files later to run the model for each quarter.

start_calibration_date = DateTime(2010, 03, 31)
end_calibration_date = DateTime(2019, 12, 31)

for calibration_date in collect(start_calibration_date:Dates.Month(3):end_calibration_date)
params, init_conds = Bit.get_params_and_initial_conditions(cal, calibration_date; scale = 0.0005)
save(
"data/" *
"italy/" *
"/parameters/" *
"data/italy/parameters/" *
string(year(calibration_date)) *
"Q" *
string(Dates.quarterofyear(calibration_date)) *
".jld2",
params,
)
save(
"data/" *
"italy/" *
"/initial_conditions/" *
"data/italy/initial_conditions/" *
string(year(calibration_date)) *
"Q" *
string(Dates.quarterofyear(calibration_date)) *
Expand Down

0 comments on commit 6ae9e5f

Please sign in to comment.