I used Amir's current answer to make a working script for doe22, v48r:
import glob
import subprocess
# Check these environment variables for running doe2 on command line
doe22batlocation = 'C:\doe22\DOE22.BAT'
doe22version = 'EXE48r'
def weatherbatch():
for i in glob.glob('*.inp'):
for w in glob.glob('*.BIN'):
input = i.replace('.inp','')
weather = w.replace('.BIN','')
subprocess.call([doe22batlocation, doe22version, input, weather])
weatherbatch()
EDIT (10/12/2016): ... and following is a more developed, current version of the same script. I am retaining the relatively simple example above in this answer to facilitate comparison and clarity of concept for others traversing the bridges between python, doe2, and e+.
I was prompted in the answer commentary to try and make this script compatible when executed directly from notepad++. While I've pushed the module further in form/function, I'm not certain what made previous versions incompatible with notepad++ execution, and I only recently picked up the realization that was possible (I've been used to executing all python efforts to-date from powershell). The following is tested and working using Python 2.7 and the notepad++ plugin called "PyNPP" with the shortcut Alt+Shift+F5.
I was also prompted to get my act together with respect to docstring styling. As a self-learner I appreciate the encouragement, and hopefully this is a little easier on our French friends' sensibilities now =)!
"""Automate batch simulation for any number of doe2 input & weather files."""
import os
import glob
import subprocess
import shutil
import re
# Review these environment variables for running doe2 on command line
doe2_location = 'C:\doe22'
doe2_version = 'EXE48r' #<-- As would be entered for command line execution
doe2bat_location = doe2_location+'\DOE22.BAT'
doe2_weather_directory = doe2_location+'\weather'
def weatherbatch(target_path):
"""This function will simulate every unique combination possible between a
group of co-located weather files (*.bin) and input files (*.inp) via doe2
commandline.
The argument 'target_path' is the directory containing the weather (*.bin)
and input (*.inp) files.
When finished, BDL files and SIM output files with self-descriptive names
to indicate the associated weather / input combination should remain
alongside the targeted files.
Be mindful limits to doe2 command line execution apply to this script as
well. Excessive characters and the presence of any spaces in the input or
weather file names will result in errors.
"""
# store current working directory
start_dir = os.getcwd()
# move to the target directory containing the weather/input files
os.chdir(target_path)
for w in glob.glob('*.BIN'):
# ensure a copy of the weatherfile exists in the doe2 weather directory
shutil.copy(w, doe2_weather_directory)
# strip '.BIN' from w for commandline execution
# (done via regex to make this case-insensitive)
weather = re.sub('\.bin', '', w, flags=re.IGNORECASE)
for i in glob.glob('*.inp'):
# make a copy of 'Project.inp' called 'Project_in_weatherfile.inp'
# (done via regex to make this case-insensitive)
inputname = re.sub('\.inp', '', i, flags=re.IGNORECASE)
renamedinp = inputname + '_in_' + weather + '.inp'
shutil.copy(i, renamedinp)
# strip '.inp' from renamedinp for commandline execution
input = renamedinp.replace('.inp','')
# execute commandline doe2 for this weather + input combination
subprocess.call ...
(more)
Could you clarify if you are talking about 50 simulation where each idf file has one weather file that goes with it or if you are talking about 2500 simulations where each of the 50 idf files are run 50 times with different weather files each time.
it's the second case "2500 simulations where each of the 50 idf files are run 50 times with different weather files each time"