Skip to content

Commit

Permalink
import defaults from package not relative path
Browse files Browse the repository at this point in the history
  • Loading branch information
jdebacker committed Aug 2, 2024
1 parent 0aa8bfc commit e584633
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
17 changes: 7 additions & 10 deletions examples/run_og_zaf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
import json
import time
import copy
import importlib.resources
import matplotlib.pyplot as plt
from ogzaf.calibrate import Calibration
from ogcore.parameters import Specifications
from ogcore import output_tables as ot
from ogcore import output_plots as op
from ogcore.execute import runner
from ogcore.utils import safe_read_pickle, param_dump_json
from ogcore.utils import safe_read_pickle

# Use a custom matplotlib style file for plots
plt.style.use("ogcore.OGcorePlots")
Expand Down Expand Up @@ -43,15 +44,11 @@ def main():
output_base=base_dir,
)
# Update parameters for baseline from default json file
p.update_specifications(
json.load(
open(
os.path.join(
CUR_DIR, "..", "ogzaf", "ogzaf_default_parameters.json"
)
)
)
)
with importlib.resources.open_text(
"ogzaf", "ogzaf_default_parameters.json"
) as file:
defaults = json.load(file)
p.update_specifications(defaults)
# Update parameters from calibrate.py Calibration class
c = Calibration(p)
updated_params = c.get_dict()
Expand Down
23 changes: 9 additions & 14 deletions examples/run_og_zaf_multiple_industry.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
import json
import time
import copy
import importlib.resources
import matplotlib.pyplot as plt
from ogzaf.calibrate import Calibration
from ogcore.parameters import Specifications
from ogcore import output_tables as ot
from ogcore import output_plots as op
from ogcore.execute import runner
from ogcore.utils import safe_read_pickle, param_dump_json
from ogcore.utils import safe_read_pickle

# Use a custom matplotlib style file for plots
plt.style.use("ogcore.OGcorePlots")
Expand Down Expand Up @@ -43,15 +44,12 @@ def main():
output_base=base_dir,
)
# Update parameters for baseline from default json file
p.update_specifications(
json.load(
open(
os.path.join(
CUR_DIR, "..", "ogzaf", "ogzaf_default_parameters.json"
)
)
)
)
with importlib.resources.open_text(
"ogzaf", "ogzaf_default_parameters.json"
) as file:
defaults = json.load(file)
p.update_specifications(defaults)

# Update parameters from calibrate.py Calibration class
p.M = 4
p.I = 5
Expand All @@ -67,12 +65,9 @@ def main():
}
p.update_specifications(updated_params_tax)

# dump params to json
param_dump_json(p, os.path.join(base_dir, "model_params.json"))

# Run model
start_time = time.time()
runner(p, time_path=True, client=client)
# runner(p, time_path=True, client=client)
print("run time = ", time.time() - start_time)

"""
Expand Down

0 comments on commit e584633

Please sign in to comment.