Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
perceptualrobots committed Jul 24, 2023
1 parent 5da7d42 commit 9b08018
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 26 deletions.
17 changes: 13 additions & 4 deletions nbs/05_environments.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@
" \n",
" self.num_links=1\n",
" self.env_name='YawEnv'\n",
" self.env = YawEnv()\n",
"\n",
" \n",
" def __call__(self, verbose=False): \n",
Expand All @@ -667,7 +668,7 @@
" return self.value\n",
"\n",
" def set_properties(self, props):\n",
" self.initialise(props)\n",
" self.env.initialise(props)\n",
" # wind_timeseries,start_index,stop_index,ancestors,filter_duration,yaw_parameters,\n",
"\n",
" def early_terminate(self):\n",
Expand All @@ -677,14 +678,22 @@
" self.input = self.links[0].get_value()\n",
" \n",
" def process_actions(self):\n",
" raise Exception(f'TBD {self.__class__.__name__}:{self.env_name}.')\n",
" if self.input < 0:\n",
" self.action = 0\n",
" elif self.input > 0:\n",
" self.action = 2\n",
" else:\n",
" self.action = 1 \n",
" \n",
" \n",
" def apply_actions_get_obs(self):\n",
" return self.env.step([self.input])\n",
" return [self.env.step(self.input)]\n",
"\n",
" def parse_obs(self):\n",
" raise Exception(f'TBD {self.__class__.__name__}:{self.env_name}.')\n",
" self.value = self.obs[0][1]\n",
" self.reward = self.obs[1]\n",
" self.done = self.obs[2]\n",
" self.info = self.obs[3]\n",
"\n",
" def process_values(self):\n",
" raise Exception(f'TBD {self.__class__.__name__}:{self.env_name}.')\n",
Expand Down
60 changes: 53 additions & 7 deletions nbs/12_yaw_module.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,57 @@
" return wind_timeseries, wind_timeseries_not_agg"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "99025d46",
"metadata": {},
"outputs": [],
"source": [
"#| export\n",
"def get_properties(properties):\n",
"\n",
" keep_history=False\n",
" if 'keep_history' in properties:\n",
" keep_history=properties['keep_history'] \n",
"\n",
" if properties['series']=='steady':\n",
" dataset_file = 'steady_wind.csv'\n",
" else:\n",
" dataset_file = 'variable_wind.csv'\n",
"\n",
" power_curve = pd.read_excel('power_curve.xlsx')\n",
" (wind_timeseries, wind_timeseries_not_agg) = get_dataset_from_simu(dataset_file,\n",
" cycle_period=10,\n",
" rolling_average_duration=20)\n",
" \n",
" yaw_params = {\n",
" 'yaw_rate_max': 0.3,\n",
" 'yaw_consumption':18,\n",
" 'rated_speed': 14,\n",
" 'ref_speed': power_curve['ref_v'].to_list(),\n",
" 'ref_power': power_curve['ref_P'].to_list(),\n",
" 'cycle_period': 10,\n",
" 'w2': 40,\n",
" }\n",
"\n",
" model_params = {\n",
" 'wind_timeseries': wind_timeseries,\n",
" 'wind_timeseries_not_agg': wind_timeseries_not_agg,\n",
" 'start_index': 100,\n",
" 'stop_index': 1100, \n",
" 'start_index_test': 1100,\n",
" 'stop_index_test': 2100,\n",
" 'filter_duration': 1,\n",
" 'yaw_params': yaw_params,\n",
" 'ancestors': 12,\n",
" 'training_steps': 500000,\n",
" }\n",
"\n",
"\n",
" return wind_timeseries,model_params['start_index'], model_params['stop_index'], model_params['ancestors'], model_params['filter_duration'],yaw_params,keep_history"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -183,13 +234,8 @@
"\n",
" def initialise(self, properties ):\n",
"\n",
" wind_timeseries=properties['wind_timeseries']\n",
" start_index=properties['wind_timeseries']\n",
" stop_index=properties['wind_timeseries']\n",
" ancestors=properties['wind_timeseries']\n",
" filter_duration=properties['wind_timeseries']\n",
" params=properties['wind_timeseries']\n",
" keep_history=properties['wind_timeseries']\n",
" wind_timeseries,start_index,stop_index,ancestors,filter_duration,params,keep_history = get_properties(properties)\n",
" \n",
"\n",
" self.wind_timeseries = wind_timeseries\n",
" self.start_index = start_index\n",
Expand Down
1 change: 1 addition & 0 deletions pct/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,7 @@
'pct.yaw_module.YawEnv.step': ('yaw_module.html#yawenv.step', 'pct/yaw_module.py'),
'pct.yaw_module.get_comparaison_metrics': ('yaw_module.html#get_comparaison_metrics', 'pct/yaw_module.py'),
'pct.yaw_module.get_dataset_from_simu': ('yaw_module.html#get_dataset_from_simu', 'pct/yaw_module.py'),
'pct.yaw_module.get_properties': ('yaw_module.html#get_properties', 'pct/yaw_module.py'),
'pct.yaw_module.get_time_yawing': ('yaw_module.html#get_time_yawing', 'pct/yaw_module.py'),
'pct.yaw_module.get_yaw_count': ('yaw_module.html#get_yaw_count', 'pct/yaw_module.py'),
'pct.yaw_module.oriented_angle': ('yaw_module.html#oriented_angle', 'pct/yaw_module.py'),
Expand Down
17 changes: 13 additions & 4 deletions pct/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ def __init__(self, value=0, name="WindTurbine", links=None, new_name=True, names

self.num_links=1
self.env_name='YawEnv'
self.env = YawEnv()


def __call__(self, verbose=False):
Expand All @@ -521,7 +522,7 @@ def __call__(self, verbose=False):
return self.value

def set_properties(self, props):
self.initialise(props)
self.env.initialise(props)
# wind_timeseries,start_index,stop_index,ancestors,filter_duration,yaw_parameters,

def early_terminate(self):
Expand All @@ -531,14 +532,22 @@ def process_inputs(self):
self.input = self.links[0].get_value()

def process_actions(self):
raise Exception(f'TBD {self.__class__.__name__}:{self.env_name}.')
if self.input < 0:
self.action = 0
elif self.input > 0:
self.action = 2
else:
self.action = 1


def apply_actions_get_obs(self):
return self.env.step([self.input])
return [self.env.step(self.input)]

def parse_obs(self):
raise Exception(f'TBD {self.__class__.__name__}:{self.env_name}.')
self.value = self.obs[0][1]
self.reward = self.obs[1]
self.done = self.obs[2]
self.info = self.obs[3]

def process_values(self):
raise Exception(f'TBD {self.__class__.__name__}:{self.env_name}.')
Expand Down
60 changes: 49 additions & 11 deletions pct/yaw_module.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/12_yaw_module.ipynb.

# %% auto 0
__all__ = ['get_yaw_count', 'get_time_yawing', 'oriented_angle', 'get_dataset_from_simu', 'YawEnv', 'get_comparaison_metrics',
'test_model_wind']
__all__ = ['get_yaw_count', 'get_time_yawing', 'oriented_angle', 'get_dataset_from_simu', 'get_properties', 'YawEnv',
'get_comparaison_metrics', 'test_model_wind']

# %% ../nbs/12_yaw_module.ipynb 2
import warnings
Expand Down Expand Up @@ -115,17 +115,55 @@ def get_dataset_from_simu(path="dataset.csv", cycle_period=10, rolling_average_d
return wind_timeseries, wind_timeseries_not_agg

# %% ../nbs/12_yaw_module.ipynb 7
def get_properties(properties):

keep_history=False
if 'keep_history' in properties:
keep_history=properties['keep_history']

if properties['series']=='steady':
dataset_file = 'steady_wind.csv'
else:
dataset_file = 'variable_wind.csv'

power_curve = pd.read_excel('power_curve.xlsx')
(wind_timeseries, wind_timeseries_not_agg) = get_dataset_from_simu(dataset_file,
cycle_period=10,
rolling_average_duration=20)

yaw_params = {
'yaw_rate_max': 0.3,
'yaw_consumption':18,
'rated_speed': 14,
'ref_speed': power_curve['ref_v'].to_list(),
'ref_power': power_curve['ref_P'].to_list(),
'cycle_period': 10,
'w2': 40,
}

model_params = {
'wind_timeseries': wind_timeseries,
'wind_timeseries_not_agg': wind_timeseries_not_agg,
'start_index': 100,
'stop_index': 1100,
'start_index_test': 1100,
'stop_index_test': 2100,
'filter_duration': 1,
'yaw_params': yaw_params,
'ancestors': 12,
'training_steps': 500000,
}


return wind_timeseries,model_params['start_index'], model_params['stop_index'], model_params['ancestors'], model_params['filter_duration'],yaw_params,keep_history

# %% ../nbs/12_yaw_module.ipynb 8
class YawEnv(Env):

def initialise(self, properties ):

wind_timeseries=properties['wind_timeseries']
start_index=properties['wind_timeseries']
stop_index=properties['wind_timeseries']
ancestors=properties['wind_timeseries']
filter_duration=properties['wind_timeseries']
params=properties['wind_timeseries']
keep_history=properties['wind_timeseries']
wind_timeseries,start_index,stop_index,ancestors,filter_duration,params,keep_history = get_properties(properties)


self.wind_timeseries = wind_timeseries
self.start_index = start_index
Expand Down Expand Up @@ -307,7 +345,7 @@ def reset(self):

return self.state

# %% ../nbs/12_yaw_module.ipynb 8
# %% ../nbs/12_yaw_module.ipynb 9
def get_comparaison_metrics(wind_direction,power_control,power_simu,res_model, res_baseline_simu, yaw_rate, yaw_power, width_bin) :
res_model_diff = pd.Series(res_model).diff(1).fillna(0)
res_baseline_simu_diff = pd.Series(res_baseline_simu).diff(1).fillna(0)
Expand Down Expand Up @@ -343,7 +381,7 @@ def get_comparaison_metrics(wind_direction,power_control,power_simu,res_model, r



# %% ../nbs/12_yaw_module.ipynb 9
# %% ../nbs/12_yaw_module.ipynb 10
def test_model_wind(wind_timeseries,start_index,stop_index,ancestors,filter_duration,yaw_parameters,experiment=None,datatype='test'):
'''
test RLYCA
Expand Down

0 comments on commit 9b08018

Please sign in to comment.