1919except ImportError :
2020 rq = None
2121
22- class WindTurbine (object ):
22+ class WindTurbine (object ): # todo add data_source
2323 r"""
2424 Defines a standard set of wind turbine attributes.
2525
@@ -104,7 +104,8 @@ class WindTurbine(object):
104104
105105 def __init__ (self , name , hub_height , rotor_diameter = None ,
106106 power_coefficient_curve = None , power_curve = None ,
107- nominal_power = None , fetch_curve = None , coordinates = None ):
107+ nominal_power = None , fetch_curve = None , coordinates = None ,
108+ data_source = 'oedb' ):
108109
109110 self .name = name
110111 self .hub_height = hub_height
@@ -117,9 +118,9 @@ def __init__(self, name, hub_height, rotor_diameter=None,
117118 self .power_output = None
118119
119120 if self .power_coefficient_curve is None and self .power_curve is None :
120- self .fetch_turbine_data (fetch_curve )
121+ self .fetch_turbine_data (fetch_curve , data_source )
121122
122- def fetch_turbine_data (self , fetch_curve ):
123+ def fetch_turbine_data (self , fetch_curve , data_source ): # todo add parameter description
123124 r"""
124125 Fetches data of the requested wind turbine.
125126
@@ -144,7 +145,7 @@ def fetch_turbine_data(self, fetch_curve):
144145 ... 'name': 'ENERCON E 126 7500',
145146 ... 'fetch_curve': 'power_coefficient_curve'}
146147 >>> e126 = wind_turbine.WindTurbine(**enerconE126)
147- >>> print(e126.power_coefficient_curve['power coefficient'][5])
148+ >>> print(e126.power_coefficient_curve['power coefficient'][5]) # todo adapt example
148149 0.423
149150 >>> print(e126.nominal_power)
150151 7500000
@@ -168,38 +169,45 @@ def restructure_data():
168169 the corresponding wind speeds in m/s.
169170
170171 """
171- df = read_turbine_data (filename = filename )
172- wpp_df = df [df .turbine_id == self .name ]
173- # if turbine not in data file
174- if wpp_df .shape [0 ] == 0 :
175- pd .set_option ('display.max_rows' , len (df ))
176- logging .info ('Possible types: \n {0}' .format (df .turbine_id ))
177- pd .reset_option ('display.max_rows' )
178- sys .exit ('Cannot find the wind converter type: {0}' .format (
179- self .name ))
180- # if turbine in data file write power (coefficient) curve values
181- # to 'data' array
182- ncols = ['turbine_id' , 'p_nom' , 'source' , 'modificationtimestamp' ]
183- data = np .array ([0 , 0 ])
184- for col in wpp_df .keys ():
185- if col not in ncols :
186- if wpp_df [col ].iloc [0 ] is not None and not np .isnan (
187- float (wpp_df [col ].iloc [0 ])):
188- data = np .vstack ((data , np .array (
189- [float (col ), float (wpp_df [col ])])))
190- data = np .delete (data , 0 , 0 )
172+ df = read_turbine_data (source = data_source )
173+ if data_source == 'oedb' :
174+ df .set_index ('wea_type' , inplace = True )
175+ data = df .loc [self .name ]['power_curve' ]
176+ nominal_power = df .loc [self .name ][
177+ 'installed_capacity_kw' ] * 1000
178+ else :
179+ wpp_df = df [df .turbine_id == self .name ]
180+ # if turbine not in data file
181+ if wpp_df .shape [0 ] == 0 :
182+ pd .set_option ('display.max_rows' , len (df ))
183+ logging .info ('Possible types: \n {0}' .format (df .turbine_id ))
184+ pd .reset_option ('display.max_rows' )
185+ sys .exit ('Cannot find the wind converter type: {0}' .format (
186+ self .name ))
187+ # if turbine in data file write power (coefficient) curve values
188+ # to 'data' array
189+ ncols = ['turbine_id' , 'p_nom' , 'source' , 'modificationtimestamp' ]
190+ data = np .array ([0 , 0 ])
191+ for col in wpp_df .keys ():
192+ if col not in ncols :
193+ if wpp_df [col ].iloc [0 ] is not None and not np .isnan (
194+ float (wpp_df [col ].iloc [0 ])):
195+ data = np .vstack ((data , np .array (
196+ [float (col ), float (wpp_df [col ])])))
197+ data = np .delete (data , 0 , 0 )
198+ nominal_power = wpp_df ['p_nom' ].iloc [0 ]
191199 if fetch_curve == 'power_curve' :
192200 df = pd .DataFrame (data , columns = ['wind_speed' , 'power' ])
201+ if data_source == 'oedb' :
202+ # power values in W
203+ df ['power' ] = df ['power' ] * 1000
193204 if fetch_curve == 'power_coefficient_curve' :
194205 df = pd .DataFrame (data , columns = ['wind_speed' ,
195206 'power coefficient' ])
196- nominal_power = wpp_df ['p_nom' ].iloc [0 ]
197207 return df , nominal_power
198208 if fetch_curve == 'power_curve' :
199- filename = 'power_curves.csv'
200209 self .power_curve , p_nom = restructure_data ()
201210 elif fetch_curve == 'power_coefficient_curve' :
202- filename = 'power_coefficient_curves.csv'
203211 self .power_coefficient_curve , p_nom = restructure_data ()
204212 else :
205213 raise ValueError ("'{0}' is an invalid value. " .format (
@@ -242,8 +250,7 @@ def read_turbine_data(source='oedb', **kwargs):
242250
243251 """
244252 if source == 'oedb' :
245- # todo: add connection to oedb
246- pass
253+ df = load_turbine_data_from_oedb ()
247254 else :
248255 if 'datapath' not in kwargs :
249256 kwargs ['datapath' ] = os .path .join (os .path .dirname (__file__ ),
@@ -325,3 +332,5 @@ def get_turbine_types(print_out=True):
325332 pd .reset_option ('display.max_rows' )
326333 return curves_df
327334
335+ if __name__ == "__main__" :
336+ get_turbine_types (print_out = True ) # todo delete
0 commit comments