Skip to content
Snippets Groups Projects
Commit 72f40811 authored by Megha Gupta's avatar Megha Gupta Committed by Mads M. Pedersen
Browse files

Update file hpp_pars.yml

parent 6de50ef9
No related branches found
No related tags found
No related merge requests found
......@@ -81,7 +81,7 @@ compressor_opex_cost : 0 #[EUR/MW]
# Shared costs
# --------------------------------------------------------------------------------------------
hpp_BOS_soft_cost: 119_940 # [Euro/MW]
hpp_grid_connection_cost: 37_074 # [Euro/MW]
hpp_grid_connection_cost: 50_000 # [Euro/MW]
#land cost not same format in excel it's per MW
land_cost: 300_000 # [Euro/km**2] from Hybridize imputs 6-12k Euro/acre. 1km2 = 247.105acre
......
......@@ -32,7 +32,7 @@ def run_evaluation_design_1():
sim_pars_fn = sim_pars_fn,
input_ts_fn = input_ts_fn)
clearance = output_df.loc['clearance [m]','Design 1']
sp = output_df.loc['sp [m2/W]','Design 1']
sp = output_df.loc['sp [W/m2]','Design 1']
p_rated = output_df.loc['p_rated [MW]','Design 1']
Nwt = output_df.loc['Nwt','Design 1']
wind_MW_per_km2 = output_df.loc['wind_MW_per_km2 [MW/km2]','Design 1']
......@@ -92,7 +92,7 @@ def run_evaluation_design_2():
sim_pars_fn = sim_pars_fn,
input_ts_fn = input_ts_fn)
clearance = output_df.loc['clearance [m]','Design 2']
sp = output_df.loc['sp [m2/W]','Design 2']
sp = output_df.loc['sp [W/m2]','Design 2']
p_rated = output_df.loc['p_rated [MW]','Design 2']
Nwt = output_df.loc['Nwt','Design 2']
wind_MW_per_km2 = output_df.loc['wind_MW_per_km2 [MW/km2]','Design 2']
......@@ -153,7 +153,7 @@ def run_evaluation_design_3():
sim_pars_fn = sim_pars_fn,
input_ts_fn = input_ts_fn)
clearance = output_df.loc['clearance [m]','Design 3']
sp = output_df.loc['sp [m2/W]','Design 3']
sp = output_df.loc['sp [W/m2]','Design 3']
p_rated = output_df.loc['p_rated [MW]','Design 3']
Nwt = output_df.loc['Nwt','Design 3']
wind_MW_per_km2 = output_df.loc['wind_MW_per_km2 [MW/km2]','Design 3']
......
......@@ -3,7 +3,7 @@ longitude,-0.864258,-0.864258,-0.864258
latitude,48.744116,48.744116,48.744116
altitude,302.0,302.0,302.0
clearance [m],10.0,10.0,10.0
sp [m2/W],350.0,350.0,350.0
sp [W/m2],350.0,350.0,350.0
p_rated [MW],5.0,5.0,5.0
Nwt,60.0,0.0,30.0
wind_MW_per_km2 [MW/km2],7.0,7.0,7.0
......@@ -14,11 +14,11 @@ DC_AC_ratio,1.5,1.5,1.5
b_P [MW],0.0,0.0,60.0
b_E_h [h],3.0,3.0,3.0
cost_of_battery_P_fluct_in_peak_price_ratio,5.0,5.0,5.0
NPV_over_CAPEX,-0.091516375173002,-0.2924408869047613,-0.1759404483375621
NPV [MEuro],-26.47134437325197,-43.19574154657373,-40.17395557772567
NPV_over_CAPEX,-0.1043501609557263,-0.3120635515585524,-0.1905275253737894
NPV [MEuro],-30.58819861937114,-47.30427828842379,-44.24357264124394
IRR,0.0,0.0,0.0
LCOE [Euro/MWh],33.10730420766112,30.489368450675165,33.43601942186266
CAPEX [MEuro],289.2525444021433,147.7076,228.33837220107165
LCOE [Euro/MWh],33.49128914790927,31.214773851378425,33.93405203441529
CAPEX [MEuro],293.1303444021433,151.5854,232.21617220107169
OPEX [MEuro],4.847159865683619,2.025,3.4423195612098536
Wind CAPEX [MEuro],229.29120154500043,0.0,114.64560077250022
Wind OPEX [MEuro],4.847159865683619,0.0,2.429819561209854
......@@ -26,7 +26,7 @@ PV CAPEX [MEuro],0.0,99.5,49.75
PV OPEX [MEuro],0.0,2.025,1.0125
Batt CAPEX [MEuro],0.0,0.0,10.41
Batt OPEX [MEuro],0.0,0.0,0.0
Shared CAPEX [MEuro],59.96134285714286,48.2076,53.53277142857142
Shared CAPEX [MEuro],63.83914285714286,52.0854,57.41057142857142
Shared OPEX [MEuro],0.0,0.0,0.0
penalty lifetime [MEuro],0.0,0.0,0.0
AEP [GWh],787.9598336543876,411.51231843921175,606.6775192948046
......
from git import Repo # pip install GitPython
import os
# make directory to install MSVR
msvr_dir = os.sep.join([os.getcwd(), 'msvr'])
# clone MSVR
if not os.path.exists(msvr_dir):
Repo.clone_from("https://github.com/Analytics-for-Forecasting/msvr", msvr_dir)
# clone country flags for plotting
if not os.path.exists(os.sep.join([os.getcwd(), 'plotting'])):
os.mkdir('plotting')
if not os.path.exists(os.sep.join([os.getcwd(), 'plotting', 'country-flags'])):
Repo.clone_from("https://github.com/hampusborgos/country-flags", os.sep.join([os.getcwd(), 'plotting', 'country-flags']))
This diff is collapsed.
Welcome to our surrogate model repo. Follow these steps to complete installation:
0. Make sure you have ~ 2 GB of memory available
1. Activate a conda environment
(more info here: https://conda.io/projects/conda/en/latest/user-guide/install/index.html)
2. unzip the model by running:
`tar -xzvf model.tar.gz`
(if tar is not available, you can install it with `conda install -c conda-forge tar`)
3. Make sure GitPython, xarray, pandas, numpy, etc are installed
`pip install xarray pandas numpy matplotlib jupyter scikit-learn chaospy`
(if pip isn't available, you can install it with `conda install pip`)
4. Install git dependancies by running
`python INSTALL.py`
... and that's it! Now open and run the quickstart notebook
import numpy as np
import os
import pandas as pd
import matplotlib.pyplot as plt
import sys
sys.path.append(os.path.join(os.getcwd(), 'msvr'))
from model.MSVR import MSVR
from model.utility import create_dataset, rmse
from sklearn.preprocessing import StandardScaler, PowerTransformer, QuantileTransformer, MinMaxScaler
import xarray as xr
class mvsr_predictor:
'''
Wrapper for the MSVR predictor (https://github.com/Analytics-for-Forecasting/msvr)
'''
def __init__(self, scaler_x, scaler_y, kernel='poly', degree=1, gamma=1):
'''
Initialize MSVR predictor
Parameters
---------
scaler_x : sklearn scalar to preprocess input data (the inputs to the predictor)
scaler_y : sklearn scalar to preprocess output data (the outputs to be predicted)
kernel : kernel for building the regressor. Used in sklearn's `pairwise_kernels`
valid entries are:
[‘additive_chi2’, ‘chi2’, ‘linear’, ‘poly’, ‘polynomial’, ‘rbf’, ‘laplacian’, ‘sigmoid’, ‘cosine’]
degree : degree of kernel if the kernel is specified as a polynomial
gamma : argument to sklearn's `pairwise_kernels`
'''
self.scaler_x = scaler_x
self.scaler_y = scaler_y
self.msvr = MSVR(kernel=kernel, degree=degree, gamma=gamma)
def fit(self, train_x, train_y):
'''
Fit the MSVR predictor to a given set of data
Parameters
---------
train_x : input data (the inputs to the predictor)
train_y : output data (the outputs to be predicted)
'''
self.scaler_x.fit(train_x)
train_input = self.scaler_x.transform(train_x)
self.scaler_y.fit(train_y)
train_target = self.scaler_y.transform(train_y)
self.msvr.fit(train_input, train_target)
def predict(self, test_x):
'''
Use the MSVR predictor to predict the responses associated with
a set of inputs
Parameters
---------
test_x : input data (the inputs to the predictor)
'''
test_input = self.scaler_x.transform(test_x)
test_predict = self.msvr.predict(test_input)
return self.scaler_y.inverse_transform(test_predict)
# This function accepts the xarray dataframe
# it outputs
def tall_vector(ds, list_vars=None):
'''
Helper function to re-organize data
'''
# determine number of successful runs
N_realize_nr = len(ds.realize_nr)
#print('OK')
#N_realize_nr = 200
# option to only include a subset of the output variables
if list_vars is None:
list_vars = ds.data_vars
# sizes is a dictionary describing the size of the output data associated with each output variable
sizes = dict()
# shapes is a dictionary describing the ...
# question: how is this different than the sizes dictionary?
shapes = dict()
for ii, var in enumerate(list_vars):
# record the shape of the data associated with each variable
shapes[var] = ds[var].values.shape
data = ds[var].values.reshape(-1, N_realize_nr)
#data = ds[var].values.reshape([-1, N_realize_nr])
sizes[var] = data.shape[0]
if ii == 0:
out = data
else:
out = np.vstack([ out, data] )
return out, sizes, shapes
def loo_score(degree, i_loo=12):
'''
Validation helper function.
'''
i_left = [ii for ii in range(X_all.shape[0]) if ii!=i_loo]
X_train = X_all[i_left,:]
Y_train = Y_all[i_left,:]
X_test = X_all[[i_loo],:]
Y_test = Y_all[[i_loo],:]
model = mvsr_predictor(scaler_x=MinMaxScaler(), scaler_y=QuantileTransformer( n_quantiles=100, output_distribution='uniform'), degree=degree)
model.fit(X_train, Y_train)
Y_pred = model.predict(X_test)
return np.sqrt(np.mean((Y_test - Y_pred) ** 2))
def total_score(degree):
'''
Validation helper function.
'''
scores = []
for i_loo in range(X_all.shape[0]):
scores.append(loo_score(degree, i_loo=i_loo))
return scores
outputLabelName = 'realization_of_inputs'
class bigModel:
'''
This is a class containing several models. Together, these act as a surrogate for the output of REALIZE.
Each model is trained to predict a specified output of a specified region during a specified year.
'''
def __init__(self, datax, regions=None, outputs=None, years=None, scalerx=MinMaxScaler, scalerx_opts={}, scalery=QuantileTransformer, scalery_opts=dict(n_quantiles=100, output_distribution='uniform'), degree=1, gamma=1):
'''
Initialization of REALIZE surrogate class.
Parameters
----------
datax : xarray of data associated with parsed REALIZE samples
regions : regions to include in surrogate. If `None` is passed, include all regions
outputs : outputs to include in surrogate. If `None` is passed, include all outputs
years : years to include in surrogate. If `None` is passed, include all years
scalerx : scaler used to preprocess the input data
scalery : the scaler used to preprocess the output data
scalerx_opts : dictionary of options to pass to the input scaler
scalery_opts = dictionary of options to pass to the output scaler
degree : kernel polynomial degree
gamma : sklearn kernel parameter
'''
# isolate inputs (they only depend on realize_nr)
inputs_df = datax[[var for var in datax.data_vars if set(datax[var].dims) == {'realize_nr'}]].to_dataframe()
# record the input names
self.input_cols = inputs_df.columns
self.weathertime = datax.weather_time.values
X_train = inputs_df.values
#X_train = inputs_df.iloc[:,1:].values
if regions: self.regions = np.array(regions)
else: self.regions = datax.region
if outputs: self.outputs = np.array(outputs)
else: self.outputs = np.array([var for var in datax.data_vars if set(datax[var].dims) != {'realize_nr'}])
if years: self.years = years
else: self.years = datax.year.values
self.cross_regions = datax.region.values
self.output_sizes = {output:datax[output].shape[1] for output in self.outputs}
self.models = {}
to_save = {}
for output in self.outputs:
for yy, year in enumerate(self.years):
for rr, region in enumerate(self.regions):
model = mvsr_predictor(scaler_x=scalerx(**scalerx_opts), scaler_y=scalery(**scalery_opts), degree=degree, gamma=gamma)
ds_sel = datax.sel(year=year, region=region)
out, sizes, shapes = tall_vector(ds=ds_sel, list_vars=[output])
Y_train=out.T
model.fit(X_train, Y_train)
self.models[(output, yy, rr)] = model
def predict(self, new_scenarios, scenario_numbers=None, output=None):
'''
Predict outputs based in unseen inputs using the MSVR models
Parameters
----------
new_scenarios : numpy array or pandas dataframe of new input prices to evaluate.
If numpy array, the columns of the matrix should be ordered according to self.input_cols
If pandas array, the columns should be named using the names in self.input_cols
scenario_numbers : the numbers to associate with each prediction output by the model.
Each number corresponds to a row of input variables. Default in 1:N-1
output : output to be predicted. If None, predict all outputs the model has been trained on.
'''
n_scenarios = new_scenarios.shape[0]
if type(new_scenarios) == pd.DataFrame and scenario_numbers is None:
scenario_numbers = new_scenarios.index.values
if type(new_scenarios) in [list, np.ndarray]:
new_scenarios = pd.DataFrame(new_scenarios, columns=self.input_cols)
x_in = new_scenarios[self.input_cols].values
if 'realize_nr' in new_scenarios.columns:
scenario_nums = new_scenarios['realize_nr']
elif scenario_numbers is not None: scenario_nums=scenario_numbers
else:
scenario_nums = range(n_scenarios)
if output: outputs_to_predict = output
else: outputs_to_predict = self.outputs
to_save = {}
for oo, output in enumerate(outputs_to_predict):
if output in ['VRE_Capacities_Wind_Onshore', 'VRE_Capacities_Wind_Offshore', 'VRE_Capacities_Solar_PV']:
saver = np.zeros((len(self.years), self.regions.size, n_scenarios))
elif output in ['Transmission_Lines_Capacities']:
saver = np.zeros((len(self.years), self.regions.size, self.regions.size, n_scenarios, ))
else:
saver = np.zeros((len(self.years), self.regions.size, self.output_sizes[output], n_scenarios, ))
for yy, year in enumerate(self.years):
for rr, region in enumerate(self.regions):
saver[yy, rr, :] = self.models[outputs_to_predict[oo], yy, rr].predict(x_in).T
#saver[yy, rr, oo] = np.split(self.models[yy, rr].predict(x_in).T, len(self.outputs))[oo]
if output in ['VRE_Capacities_Wind_Onshore', 'VRE_Capacities_Wind_Offshore', 'VRE_Capacities_Solar_PV']:
to_save[output] = xr.DataArray(saver, dims=['year', 'region', outputLabelName])
elif output in ['Transmission_Lines_Capacities']:
to_save[output] = xr.DataArray(saver, dims=['year', 'region', 'cross_region', outputLabelName])
else:
to_save[output] = xr.DataArray(saver, dims=['year', 'region', 'weathertime', outputLabelName])
# save input
for col in self.input_cols:
to_save[col] = xr.DataArray(new_scenarios[col].values, dims=[outputLabelName])
#to_save[col] = new_scenarios[col]
return xr.Dataset(data_vars=to_save, coords={'year': self.years, 'weathertime': self.weathertime, 'region': self.regions, 'cross_region': self.cross_regions, outputLabelName: scenario_nums}).transpose("year", "weathertime", "region", outputLabelName, 'cross_region')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment