Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	.gitignore
  • Loading branch information
andre-barbe committed Jun 28, 2018
2 parents 6deed6e + 1bfbf7f commit 024f36d
Show file tree
Hide file tree
Showing 51 changed files with 59 additions and 47 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
venv/
WorkFiles/
WorkFiles/
**/__pycache__
68 changes: 25 additions & 43 deletions Main.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,14 @@
__author__ = "Andre Barbe"
__project__ = "Auto-GTAP"
__created__ = "2018-3-9"

# Import methods
# Methods from other sources
import os
import subprocess
import shutil
import distutils.dir_util
# Methods defined in this program
from CleanWorkFiles import CleanWorkFiles
from CopyInputFiles import CopyInputFiles
from CreateSTI import CreateSTI
from SimulationCMF import SimulationCMF
from CreateMAP import CreateMAP
from ImportCSV_SL4 import ImportCSV_SL4
from ModifyDatabase import ModifyDatabase
from ExportDictionary import ExportDictionary
from CreateOutput import CreateOutput
from CreateConfig import CreateConfig
from ModifyHAR import ModifyHAR
from MoveDatabaseFiles import MoveDatabaseFiles
from SplitCommodities import SplitCommodities
from AggregateModelData import AggregateModelData
from GTAPAdjustCMF import GTAPAdjustCMF
# noinspection PyPep8Naming
import AutoGTAP as ag

# Call Methods
# Load config files that will control program
config = CreateConfig("config-gtap.yaml")
config = ag.CreateConfig("config-gtap.yaml")
# Delete working files directory
CleanWorkFiles()
ag.CleanWorkFiles()
# For each simulation, perform the different subparts (data aggregation, splitting,
# experiment simulation, etc) that make up that simulation
for simulation_name in config.simulation_list:
Expand All @@ -42,7 +21,7 @@
part_work_folder = config.yaml_file["simulations"][simulation_name]["subparts"][part_num]["work_folder"]

# Copy input files for this part to the appropriate work directory
CopyInputFiles(simulation_name, part_input_folder, part_work_folder).copy()
ag.CopyInputFiles(simulation_name, part_input_folder, part_work_folder).copy()

for additional_input_folder in config.part_additional_input_folders(simulation_name, part_num):
# need to use this copy method to overwrite files/folders (or copy files to folders taht already exist)
Expand All @@ -55,31 +34,32 @@
prev_part_work_folder = config.yaml_file["simulations"][simulation_name]["subparts"][prev_part_num][
"work_folder"]
prev_part_type = config.yaml_file["simulations"][simulation_name]["subparts"][prev_part_num]["type"]
MoveDatabaseFiles(simulation_name, prev_part_type, part_type, prev_part_work_folder, part_work_folder)
ag.MoveDatabaseFiles(simulation_name, prev_part_type, part_type, prev_part_work_folder, part_work_folder)

# Run the actual work for this part, depending on which type of part it is
if part_type == "GTPAg2":
agg_scheme_file = config.yaml_file["simulations"][simulation_name]["subparts"][part_num][
"agg_scheme_file"]
data_subfolder = config.yaml_file["simulations"][simulation_name]["subparts"][part_num][
"data_subfolder"]
AggregateModelData(simulation_name, part_work_folder, agg_scheme_file, data_subfolder)
ag.AggregateModelData(simulation_name, part_work_folder, agg_scheme_file, data_subfolder)

if part_type == "MSplitCom-Exe":
SplitCommodities(simulation_name)
ag.SplitCommodities(simulation_name)

if part_type == "modify_har":
# Modify_HAR directly modifies a HAR file
# This module should be rarely used
ModifyHAR("WorkFiles\\" + simulation_name, "olddefault", "default",
config.yaml_file["parameter_modifications"][
config.sim_property(simulation_name, "parameter_modifications")])
ag.ModifyHAR("WorkFiles\\" + simulation_name, "olddefault", "default",
config.yaml_file["parameter_modifications"][
config.sim_property(simulation_name, "parameter_modifications")])

if part_type == "GTPVEW-V6" or part_type == "Shocks-V6":
model_file_name = config.yaml_file["simulations"][simulation_name]["subparts"][part_num]["model_file_name"]
cmf_file_name = config.yaml_file["simulations"][simulation_name]["subparts"][part_num]["cmf_file_name"]

# Change working directory to WorkFiles so all output (and logs) will go there when gemsim or sltoht is called
# Change working directory to WorkFiles so all output (and logs)
# will go there when gemsim or sltoht is called
os.chdir("WorkFiles\\{0}\\{1}".format(simulation_name, part_work_folder))
# Create GSS and GST files for shocks and model gemsim
subprocess.call("tablo -sti {0}.sti".format(model_file_name))
Expand All @@ -91,9 +71,10 @@
if part_type == "GTAP-Adjust":
part_shock = config.yaml_file["simulations"][simulation_name]["subparts"][part_num]["shock"]

GTAPAdjustCMF(simulation_name, part_solution_method, part_work_folder, part_shock)
ag.GTAPAdjustCMF(simulation_name, part_solution_method, part_work_folder, part_shock)

# Change working directory to WorkFiles so all output (and logs) will go there when gemsim or sltoht is called
# Change working directory to WorkFiles so all output (and logs)
# will go there when gemsim or sltoht is called
os.chdir("WorkFiles\\{0}\\{1}".format(simulation_name, part_work_folder))
subprocess.call("adjust.bat")
os.chdir("..")
Expand All @@ -108,16 +89,17 @@
model_file_name = config.yaml_file["simulations"][simulation_name]["subparts"][part_num]["model_file_name"]
map = config.yaml_file["simulations"][simulation_name]["subparts"][part_num]["map"]

SimulationCMF(simulation_name, part_solution_method, part_work_folder, part_shock, part_type)
# Change working directory to WorkFiles so all output (and logs) will go there when gemsim or sltoht is called
ag.SimulationCMF(simulation_name, part_solution_method, part_work_folder, part_shock, part_type)
# Change working directory to WorkFiles so all output (and logs)
# will go there when gemsim or sltoht is called
os.chdir("WorkFiles\\{0}\\{1}".format(simulation_name, part_work_folder))
# Create GSS and GST files for shocks and model gemsim
subprocess.call("tablo -sti {0}.sti".format(model_file_name))
subprocess.call("gemsim -cmf {0}.cmf".format(model_file_name))

# Use SLtoHT export the results of the simulation from sl4 to a CSV file
CreateMAP("sim", simulation_name, map) # Map file determines which variables to export
CreateSTI(model_file_name, simulation_name, "sltoht") # STI file controls running of sltoht
ag.CreateMAP("sim", simulation_name, map) # Map file determines which variables to export
ag.CreateSTI(model_file_name, simulation_name, "sltoht") # STI file controls running of sltoht
subprocess.call("sltoht -sti {0}_sltoht.sti".format(model_file_name))

# Change directory back to WorkFiles
Expand All @@ -128,11 +110,11 @@
# Import simulation results into a single database
os.chdir("WorkFiles")
# load the various CSV files created by the experiment simulation into a database
databaseSL4 = ImportCSV_SL4(config.csv_paths()).create()
databaseSL4 = ag.ImportCSV_SL4(config.csv_paths()).create()
# Modify the database to make it more readable
databaseMod = ModifyDatabase(databaseSL4).create()
databaseMod = ag.ModifyDatabase(databaseSL4).create()
# Export the database to a results csv file
ExportDictionary("Results.csv", databaseMod)
ag.ExportDictionary("Results.csv", databaseMod)
# Copy results.csv to the OutputFiles directory, and rename it with a timestamp
os.chdir("..")
CreateOutput()
ag.CreateOutput()
5 changes: 5 additions & 0 deletions OutputFiles/2018-06-27 14-26 Results.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
simulation name,commodities shocked,Commodity Description,variable,variable property,variable description,value
GTAP-V6//gtap2//gtap.csv,GTAP-V6//gtap2//gtap.csv,Unknown Sector,"pxwreg(""EU_28"")",Percent Change,No Variable Description Available,10.000000
GTAP-V6//gtap2//gtap.csv,GTAP-V6//gtap2//gtap.csv,Unknown Sector,"pxwreg(""EU_28"")",PreLevel,No Variable Description Available,1.0000000
GTAP-V6//gtap2//gtap.csv,GTAP-V6//gtap2//gtap.csv,Unknown Sector,"pxwreg(""EU_28"")",PostLevel,No Variable Description Available,1.1000000
GTAP-V6//gtap2//gtap.csv,GTAP-V6//gtap2//gtap.csv,Unknown Sector,"pxwreg(""EU_28"")",Absolute Change,No Variable Description Available,0.10000002
5 changes: 5 additions & 0 deletions OutputFiles/2018-06-28 10-09 Results.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
simulation name,commodities shocked,Commodity Description,variable,variable property,variable description,value
GTAP-V6//gtap2//gtap.csv,GTAP-V6//gtap2//gtap.csv,Unknown Sector,"pxwreg(""EU_28"")",Percent Change,No Variable Description Available,10.000000
GTAP-V6//gtap2//gtap.csv,GTAP-V6//gtap2//gtap.csv,Unknown Sector,"pxwreg(""EU_28"")",PreLevel,No Variable Description Available,1.0000000
GTAP-V6//gtap2//gtap.csv,GTAP-V6//gtap2//gtap.csv,Unknown Sector,"pxwreg(""EU_28"")",PostLevel,No Variable Description Available,1.1000000
GTAP-V6//gtap2//gtap.csv,GTAP-V6//gtap2//gtap.csv,Unknown Sector,"pxwreg(""EU_28"")",Absolute Change,No Variable Description Available,0.10000002
5 changes: 5 additions & 0 deletions OutputFiles/2018-06-28 10-12 Results.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
simulation name,commodities shocked,Commodity Description,variable,variable property,variable description,value
GTAP-V6//gtap2//gtap.csv,GTAP-V6//gtap2//gtap.csv,Unknown Sector,"pxwreg(""EU_28"")",Percent Change,No Variable Description Available,10.000000
GTAP-V6//gtap2//gtap.csv,GTAP-V6//gtap2//gtap.csv,Unknown Sector,"pxwreg(""EU_28"")",PreLevel,No Variable Description Available,1.0000000
GTAP-V6//gtap2//gtap.csv,GTAP-V6//gtap2//gtap.csv,Unknown Sector,"pxwreg(""EU_28"")",PostLevel,No Variable Description Available,1.1000000
GTAP-V6//gtap2//gtap.csv,GTAP-V6//gtap2//gtap.csv,Unknown Sector,"pxwreg(""EU_28"")",Absolute Change,No Variable Description Available,0.10000002
File renamed without changes.
Empty file.
Empty file.
File renamed without changes.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
__created__ = "2018-3-12"

import shutil
from CreateConfig import CreateConfig


class CopyInputFiles(object):
Expand Down
Empty file.
Empty file.
File renamed without changes.
Empty file.
Empty file.
File renamed without changes.
Empty file.
Empty file.
File renamed without changes.
Empty file.
File renamed without changes.
Empty file.
Empty file.
File renamed without changes.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__project__ = "Auto-GTAP"
__created__ = "2018-5-4"

from Shocks import Shocks
from AutoGTAP.Shocks import Shocks


class GTAPAdjustCMF(object):
Expand Down
Empty file.
Empty file.
File renamed without changes.
Empty file.
File renamed without changes.
Empty file.
Empty file.
File renamed without changes.
Empty file.
Empty file.
File renamed without changes.
Empty file.
Empty file.
File renamed without changes.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__project__ = "Auto-GTAP"
__created__ = "2018-3-13"

from Shocks import Shocks
from AutoGTAP.Shocks import Shocks


class SimulationCMF(object):
Expand Down
Empty file.
File renamed without changes.
Empty file.
File renamed without changes.
Empty file.
15 changes: 15 additions & 0 deletions src/AutoGTAP/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from AutoGTAP.AggregateModelData.AggregateModelData import AggregateModelData
from AutoGTAP.CleanWorkFiles.CleanWorkFiles import CleanWorkFiles
from AutoGTAP.CopyInputFiles.CopyInputFiles import CopyInputFiles
from AutoGTAP.CreateConfig.CreateConfig import CreateConfig
from AutoGTAP.ExportDictionary.ExportDictionary import ExportDictionary
from AutoGTAP.CreateMAP.CreateMAP import CreateMAP
from AutoGTAP.CreateOutput.CreateOutput import CreateOutput
from AutoGTAP.CreateSTI.CreateSTI import CreateSTI
from AutoGTAP.GTAPAdjustCMF.GTAPAdjustCMF import GTAPAdjustCMF
from AutoGTAP.ImportCSV_SL4.ImportCSV_SL4 import ImportCSV_SL4
from AutoGTAP.ModifyDatabase.ModifyDatabase import ModifyDatabase
from AutoGTAP.ModifyHAR.ModifyHAR import ModifyHAR
from AutoGTAP.MoveDatabaseFiles.MoveDatabaseFiles import MoveDatabaseFiles
from AutoGTAP.SimulationCMF.SimulationCMF import SimulationCMF
from AutoGTAP.SplitCommodities.SplitCommodities import SplitCommodities

0 comments on commit 024f36d

Please sign in to comment.