1313import warnings
1414import requests
1515import os
16- from collections import namedtuple
1716from windpowerlib .tools import WindpowerlibUserWarning
17+ from typing import NamedTuple
1818
1919
2020class WindTurbine (object ):
@@ -199,11 +199,14 @@ def __repr__(self):
199199 return turbine_repr
200200
201201 def to_group (self , number_turbines = None , total_capacity = None ):
202- """
203- Creates a WindTurbine group as a dictionary with the keys
204- 'number_of_turbines' and 'wind_turbine'. It can be used to calculate
205- the number of turbines for a given total capacity or to create a
206- dictionary that can be used to define a WindFarm object.
202+ r"""
203+ Creates a :class:`~windpowerlib.wind_turbine.WindTurbineGroup`, a
204+ NamedTuple data container with the fields 'number_of_turbines' and
205+ 'wind_turbine'.
206+
207+ It can be used to calculate the number of turbines for a given total
208+ capacity or to create a namedtuple that can be used to define a
209+ :class:`~windpowerlib.wind_farm.WindFarm` object.
207210
208211 Parameters
209212 ----------
@@ -214,7 +217,7 @@ def to_group(self, number_turbines=None, total_capacity=None):
214217
215218 Returns
216219 -------
217- namedtuple
220+ WindTurbineGroup
218221 A namedtuple with two fields: 'number_of_turbines' and
219222 'wind_turbine'.
220223
@@ -253,12 +256,24 @@ def to_group(self, number_turbines=None, total_capacity=None):
253256 number_turbines = total_capacity / self .nominal_power
254257 elif number_turbines is None :
255258 number_turbines = 1
256- wind_turbine_group = namedtuple ('WindTurbineGroup' ,
257- 'wind_turbine number_of_turbines' )
258- return wind_turbine_group (
259+
260+ return WindTurbineGroup (
259261 wind_turbine = self , number_of_turbines = number_turbines )
260262
261263
264+ # This is working for Python >= 3.5.
265+ # There a cleaner solutions for Python >= 3.6, once the support of 3.5 is
266+ # dropped: https://stackoverflow.com/a/50038614
267+ class WindTurbineGroup (NamedTuple ('WindTurbineGroup' , [
268+ ('wind_turbine' , WindTurbine ), ('number_of_turbines' , float )])):
269+ """
270+ A simple data container to define more than one turbine of the same type.
271+ Use the :func:`~windpowerlib.wind_turbine.WindTurbine.to_group` method to
272+ easily create a WindTurbineGroup from a :class:`~windpowerlib.wind_turbine.WindTurbine` object.
273+ """
274+ __slots__ = ()
275+
276+
262277def get_turbine_data_from_file (turbine_type , path ):
263278 r"""
264279 Fetches turbine data from a csv file.
0 commit comments