-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_cli_1.py
executable file
·73 lines (59 loc) · 2.91 KB
/
example_cli_1.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
# /usr/bin/env python
# -*- coding: utf-8 -*-
"""
This example CLI file shows how a simple application can be built that reads in all the values
from the command line and reports the values of the responses passed.
.. code-block:: bash
# Single response - with only setting the inlet temperature
python analysis_cli_ex1.py -f smoff/metamodels.json -i 18
# Multiple responses - with only setting the inlet temperature
python analysis_cli_ex1.py -f smoff/metamodels.json -i 18 -r HeatingElectricity DistrictHeatingHotWaterEnergy
.. moduleauthor:: Nicholas Long (nicholas.l.long@colorado.edu, nicholas.lee.long@gmail.com)
"""
import argparse
import json
import sys
import pandas as pd
sys.path.append('..') # Adds higher directory to python modules path.
from metamodeling.metamodels import Metamodels
parser = argparse.ArgumentParser()
parser.add_argument('-f', '--file', help='Description file to use', default='metamodels.json')
parser.add_argument('-a', '--analysis_id', default='smoff_parametric_sweep',
help='ID of the Analysis Models')
parser.add_argument('--model_type', default='RandomForest',
choices=['LinearModel', 'RandomForest', 'SVR'])
parser.add_argument('-r', '--responses', nargs='*', default=['HeatingElectricity'],
help='List of responses')
parser.add_argument('-d', '--day_of_week', type=int, default=0, help='Day of Week: 0-Sun to 6-Sat')
parser.add_argument('-m', '--month', type=int, default=1, help='Month: 1-Jan to 12-Dec')
parser.add_argument('-H', '--hour', type=int, default=9, help='Hour of Day: 0 to 23')
parser.add_argument('-T', '--outdoor_drybulb', type=float, default=-5,
help='Outdoor Drybulb Temperature')
parser.add_argument('-RH', '--outdoor_rh', type=float, default=50,
help='Percent Outdoor Relative Humidity')
parser.add_argument('-i', '--inlet_temp', type=float, default=20, help='Inlet Temperature')
parser.add_argument('--lpd', type=float, default=9.5, help='Lighting Power Density (W/m2)')
args = parser.parse_args()
# Print out the arguments that are being run
print(json.dumps(vars(args), indent=2, sort_keys=True))
metamodel = Metamodels(args.file)
metamodel.set_analysis(args.analysis_id)
# Load the exising models
if metamodel.models_exist(args.model_type, models_to_load=args.responses, root_path='smoff'):
metamodel.load_models(args.model_type, models_to_load=args.responses, root_path='smoff')
else:
raise Exception('Metamodels do not exist')
# put the data into a dataframe for evaluation
data = {
'Month': args.month,
'Hour': args.hour,
'DayofWeek': args.day_of_week,
'SiteOutdoorAirDrybulbTemperature': args.outdoor_drybulb,
'SiteOutdoorAirRelativeHumidity': args.outdoor_rh,
'lpd_average': args.lpd,
'ETSInletTemperature': args.inlet_temp,
}
df = pd.DataFrame([data])
for response in args.responses:
v = metamodel.yhat(response, df)
print(v[0])