Skip to content

Commit

Permalink
Fixed DataChecker not using provided parameters: parameters use_virtu…
Browse files Browse the repository at this point in the history
…al_flows and virtual_flows_epsilon was always returning the default values instead of values read from file.

Added tqdm progress bars to FlowSolver to indicate what timestep is currently being solved.

Added transformation stage "Other" to transformation stage color mapping.
  • Loading branch information
jjarvik committed Sep 13, 2024
1 parent 0f2c1a4 commit 7f191ca
Show file tree
Hide file tree
Showing 5 changed files with 1,527 additions and 88 deletions.
11 changes: 9 additions & 2 deletions core/datachecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ def build_flowsolver_data(self, epsilon: float = 0.1):

model_params = self._dataprovider.get_model_params()
detect_year_range = model_params[ParameterName.DetectYearRange.value]

# Virtual flows
use_virtual_flows = model_params[ParameterName.UseVirtualFlows.value]
virtual_flows_epsilon = 0.1
if use_virtual_flows and ParameterName.VirtualFlowsEpsilon in model_params:
virtual_flows_epsilon = model_params[ParameterName.VirtualFlowsEpsilon.value]

self._year_start = model_params[ParameterName.StartYear.value]
self._year_end = model_params[ParameterName.EndYear.value]

Expand Down Expand Up @@ -114,8 +121,8 @@ def build_flowsolver_data(self, epsilon: float = 0.1):
"all_stocks": stocks,
"unique_process_id_to_process": unique_process_ids,
"unique_flow_id_to_flow": unique_flow_ids,
"use_virtual_flows": False,
"virtual_flows_epsilon": 0.1,
"use_virtual_flows": use_virtual_flows,
"virtual_flows_epsilon": virtual_flows_epsilon,
}
return flowsolver_data

Expand Down
2 changes: 2 additions & 0 deletions core/dataprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ def __init__(self, filename: str = "",
found_param_value = param_name_to_value[param_name]
found_param_type = type(found_param_value)
try:
if param_type is bool:
found_param_value = self._to_bool(found_param_value)
param_value = param_type(found_param_value)
self._param_name_to_value[param_name] = param_value
except ValueError as e:
Expand Down
7 changes: 6 additions & 1 deletion core/flowsolver.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import copy

import numpy as np
import pandas as pd
import tqdm as tqdm
from pandas import DataFrame
from core.datastructures import Process, Flow, Stock
from lib.odym.modules.dynamic_stock_model import DynamicStockModel
Expand Down Expand Up @@ -250,10 +250,15 @@ def solve_timesteps(self) -> None:
:return: None
"""
print("Solving flows for years {} - {}...".format(self._year_start, self._year_end))
print("Using virtual flows = {}".format(self._use_virtual_flows))
bar = tqdm.tqdm(total=self._year_end + 1, desc="Solving flows", initial=self._year_start)
self._create_dynamic_stocks()
for _ in self._years:
self._solve_timestep()
self._advance_timestep()
bar.update()
bar.close()

def get_year_to_process_to_flows(self):
year_to_process_to_flows = {}
Expand Down
Loading

0 comments on commit 7f191ca

Please sign in to comment.