Skip to content

Commit

Permalink
Improved logging with MTS
Browse files Browse the repository at this point in the history
  • Loading branch information
squoilin committed Apr 15, 2020
1 parent ffe618d commit 9f37409
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
14 changes: 8 additions & 6 deletions dispaset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

from .common import commons

# Remove old log file:
for filename in (f for f in os.listdir('.') if f.endswith('.dispa.log')):
try:
os.remove(filename)
except OSError:
print ('Could not erase previous log file ' + filename)

# Logging: # TODO: Parametrize in dispacli or external config
_LOGCONFIG = {
"version": 1,
Expand Down Expand Up @@ -84,9 +91,4 @@

from .cli import *

# Remove old log file:
for filename in (f for f in os.listdir('.') if f.endswith('.dispa.log')):
try:
os.remove(filename)
except OSError:
print ('Could not erase previous log file ' + filename)

3 changes: 0 additions & 3 deletions dispaset/preprocessing/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,8 +728,5 @@ def build_single_run(config, profiles=None):
with open(os.path.join(sim, 'Inputs.p'), 'wb') as pfile:
pickle.dump(SimData, pfile, protocol=pickle.HIGHEST_PROTOCOL)
logging.info('Build finished')

if os.path.isfile(commons['logfile']):
shutil.copy(commons['logfile'], os.path.join(sim, 'warn_preprocessing.log'))

return SimData
20 changes: 11 additions & 9 deletions dispaset/preprocessing/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import datetime as dt
import logging
import sys
import os, shutil

import pandas as pd
import numpy as np
Expand All @@ -18,14 +19,7 @@
from ..misc.gdx_handler import gdx_to_dataframe, gdx_to_list
from ..postprocessing.data_handler import GAMSstatus
from .utils import pd_timestep

try:
from future.builtins import int
except ImportError:
logging.warning(
"Couldn't import future package. Numeric operations may differ among different versions due to incompatible "
"variable types")
pass
from ..common import commons


def build_simulation(config, mts_plot=None, MTSTimeStep=None):
Expand Down Expand Up @@ -53,7 +47,14 @@ def build_simulation(config, mts_plot=None, MTSTimeStep=None):
else:
new_profiles = mid_term_scheduling(config, mts_plot=mts_plot, TimeStep=MTSTimeStep)
# Build simulation data with new profiles
logging.info('\n\nBuilding final simulation\n')
SimData = build_single_run(config, new_profiles)

# Copy the log to the simulation folder:
if os.path.isfile(commons['logfile']):
shutil.copy(commons['logfile'], os.path.join(config['SimulationDirectory'], commons['logfile']))
else:
logging.error('Could not find log file in current directory')
return SimData

def _check_results(results):
Expand Down Expand Up @@ -139,7 +140,7 @@ def mid_term_scheduling(config, TimeStep=None, mts_plot=None):
temp_results = {}
profiles = pd.DataFrame(index=idx)
for i, c in enumerate(config['mts_zones']):
logging.info('(Currently simulating Zone): ' + str(i + 1) + ' out of ' + str(no_of_zones))
logging.info('\n\nLaunching Mid-Term Scheduling for zone '+ c + ' (Number ' + str(i + 1) + ' out of ' + str(no_of_zones) + ')\n')
temp_config['zones'] = [c] # Override zone that needs to be simulated
SimData = build_single_run(temp_config) # Create temporary SimData
units = SimData['units']
Expand Down Expand Up @@ -172,6 +173,7 @@ def mid_term_scheduling(config, TimeStep=None, mts_plot=None):

# Solving reservoir levels for all regions simultaneously
elif config['HydroScheduling'] == 'Regional':
logging.info('\n\nLaunching regional Mid-Term Scheduling \n')
SimData = build_single_run(temp_config) # Create temporary SimData
units = SimData['units']
r = solve_GAMS(sim_folder=temp_config['SimulationDirectory'],
Expand Down

0 comments on commit 9f37409

Please sign in to comment.