Skip to content
Snippets Groups Projects
Commit b423313a authored by Mads M. Pedersen's avatar Mads M. Pedersen
Browse files

automatic detect args4deficit if not set + add all extra surrogate variable to TensorflowSurrogate

parent b8854cb2
No related branches found
No related tags found
No related merge requests found
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
import numpy as np import numpy as np
from numpy import newaxis as na from numpy import newaxis as na
import inspect
class DeficitModel(ABC): class DeficitModel(ABC):
deficit_initalized = False deficit_initalized = False
def __init__(self):
if not hasattr(self, 'args4deficit'):
self.args4deficit = set(inspect.getfullargspec(self.calc_deficit).args) - {'self'}
def _calc_layout_terms(self, **_): def _calc_layout_terms(self, **_):
"""Calculate layout dependent terms, which is not updated during simulation""" """Calculate layout dependent terms, which is not updated during simulation"""
......
...@@ -14,11 +14,11 @@ class BastankhahGaussianDeficit(ConvectionDeficitModel): ...@@ -14,11 +14,11 @@ class BastankhahGaussianDeficit(ConvectionDeficitModel):
A new analytical model for wind-turbine wakes. A new analytical model for wind-turbine wakes.
J. Renew. Energy. 2014;70:116-23. J. Renew. Energy. 2014;70:116-23.
""" """
args4deficit = ['WS_ilk', 'WS_eff_ilk', 'dw_ijlk', 'cw_ijlk', 'D_src_il', 'ct_ilk']
def __init__(self, k=0.0324555, use_effective_ws=False): def __init__(self, k=0.0324555, use_effective_ws=False):
self._k = k self._k = k
self.use_effective_ws = use_effective_ws self.use_effective_ws = use_effective_ws
ConvectionDeficitModel.__init__(self)
def k_ilk(self, **_): def k_ilk(self, **_):
return np.reshape(self._k, (1, 1, 1)) return np.reshape(self._k, (1, 1, 1))
......
...@@ -41,13 +41,8 @@ class TensorflowSurrogate(): ...@@ -41,13 +41,8 @@ class TensorflowSurrogate():
path = Path(path) path = Path(path)
with open(path / 'extra_data.json') as fid: with open(path / 'extra_data.json') as fid:
extra_data = json.load(fid) extra_data = json.load(fid)
for k, v in extra_data.items():
self.input_channel_names = extra_data['input_channel_names'] setattr(self, k, v)
self.output_channel_name = extra_data['output_channel_name']
self.wind_speed_cut_in = extra_data['wind_speed_cut_in']
self.wind_speed_cut_out = extra_data['wind_speed_cut_out']
if 'wohler_exponent' in extra_data:
self.wohler_exponent = extra_data['wohler_exponent']
# Create the MinMaxScaler scaler objects. # Create the MinMaxScaler scaler objects.
def json2scaler(d): def json2scaler(d):
...@@ -56,8 +51,8 @@ class TensorflowSurrogate(): ...@@ -56,8 +51,8 @@ class TensorflowSurrogate():
setattr(scaler, k, v) setattr(scaler, k, v)
return scaler return scaler
self.input_scaler = json2scaler(extra_data['input_scalers'][set_name]) self.input_scaler = json2scaler(self.input_scalers[set_name])
self.output_scaler = json2scaler(extra_data['output_scalers'][set_name]) self.output_scaler = json2scaler(self.output_scalers[set_name])
self.model = tf.keras.models.load_model(path / f'model_set_{set_name}.h5') self.model = tf.keras.models.load_model(path / f'model_set_{set_name}.h5')
......
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