-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_samples.py
88 lines (66 loc) · 2.88 KB
/
make_samples.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"""
Take in a csv holding a list of design points, create change idfs by calling "change_idf.py" in their own folders based on a soure idf,
then maybe go through and run the idfs.
assign_params -> change_idf -> make samples -> get_sim_data
"""
from eppy import *
from eppy.modeleditor import IDF
import os
from change_idf import change_idf
import random
import pandas as pd
# ----- Prepare the Source IDF -------
class MakeSamples():
def prepare_idf(self, idf_dir, day_folder, batch_name):
# set the idd
iddfile = "/Applications/OpenStudioApplication-1.1.1/EnergyPlus/Energy+.idd"
IDF.setiddname(iddfile)
# get the idf
idf_path = f"/Users/julietnwagwuume-ezeoke/My Drive/CS361_Optim/_fplocal_cs361/eppy_energy_models/{idf_dir}"
# get the weather file
epw = "/Users/julietnwagwuume-ezeoke/Documents/cee256_local/weather_files/CA_PALO-ALTO-AP_724937S_19.epw"
# create our idf for exploring
idf0 = IDF(idf_path, epw)
# create folder to hold the batch
root = f"/Users/julietnwagwuume-ezeoke/My Drive/CS361_Optim/_fplocal_cs361/eppy_energy_models/{day_folder}"
# ensure the folder is uniquely named
i = 0
while True:
batch_dir = os.path.join(root, f"{batch_name}_0{i}")
if os.path.isdir(batch_dir):
i+=1
else:
break
return idf0, batch_dir
# Take in Samples and Make Changes, Save IDF in Folder
# random.seed(2)
# design_pt = [random.random() for i in range(0,61)]
def get_design_pts(self, samples_name):
# ------ Process the Design Points -------------
df = pd.read_csv (f'/Users/julietnwagwuume-ezeoke/My Drive/CS361_Optim/_fp_cs361/samples/{samples_name}')
design_pts = df.T.values.tolist()
return design_pts
def make_sims(self, design_pts, idfo, batch_dir):
# ------ Make the Simulations! --------
for ix, pt in enumerate(design_pts):
# print(f"make sims!!! {pt[0]} \n")
idf0 = change_idf(idfo, pt)
# make a new dir for the output
new_dir_name = os.path.join(batch_dir, f"sample_{ix+1}")
os.makedirs(new_dir_name)
# save the updated idf there
idf0.save(os.path.join(new_dir_name, "in3.idf"))
# run the idf
try:
idf0.run(output_directory=new_dir_name, verbose="q")
print(f"run of sample {ix} finished \n")
except:
print(f"run of sample {ix} failed \n")
def main():
m = MakeSamples()
idf0, batch_dir = m.prepare_idf(idf_dir="05_25/base/in.idf", day_folder="06_07", batch_name="06_07_batch_00")
dp = m.get_design_pts(samples_name="samples_0525_378_DGSM.csv")
# print(f"make sims {dp}")
m.make_sims(dp, idf0, batch_dir)
if __name__ == "__main__":
main()