无法在具有PyCharm的Anaconda环境中使用windpowerlib?

2024-04-26 04:03:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图参考windpowerlib文档(https://windpowerlib.readthedocs.io/en/stable/getting_started.html#examplereference-label),并使用示例Python脚本和示例天气数据文件。我在anaconda3中创建了一个名为windproject1的新虚拟环境,并通过pip在该目录中安装了windpowerlib。你知道吗

我执行PyCharm Community Edition 2018.1中的示例代码,该代码可从上述链接获得,但未成功编译。根据Stacktrace,我提到了两种可能导致错误的方法下图:-你知道吗

def initialise_wind_turbines():
    r"""
    Initialises two :class:`~.wind_turbine.WindTurbine` objects.

    Function shows two ways to initialise a WindTurbine object. You can either
    specify your own turbine, as done below for 'myTurbine', or fetch power
    and/or power coefficient curve data from data files provided by the
    windpowerlib, as done for the 'enerconE126'.
    Execute ``windpowerlib.wind_turbine.get_turbine_types()`` or
    ``windpowerlib.wind_turbine.get_turbine_types(
    filename='power_coefficient_curves.csv')`` to get a list of all wind
    turbines for which power and power coefficient curves respectively are
    provided.

    Returns
    -------
    Tuple (WindTurbine, WindTurbine)

    """

    # specification of own wind turbine (Note: power coefficient values and
    # nominal power have to be in Watt)
    myTurbine = {
        'turbine_name': 'myTurbine',
        'nominal_power': 3e6,  # in W
        'hub_height': 105,  # in m
        'rotor_diameter': 90,  # in m
        'power_curve': pd.DataFrame(
            data={'values': [p * 1000 for p in [
                      0.0, 26.0, 180.0, 1500.0, 3000.0, 3000.0]],  # in W
                  'wind_speed': [0.0, 3.0, 5.0, 10.0, 15.0, 25.0]})  # in m/s
    }
    # initialise WindTurbine object
    my_turbine = WindTurbine(**myTurbine)

    # specification of wind turbine where power curve is provided
    # if you want to use the power coefficient curve add
    # {'fetch_curve': 'power_coefficient_curve'} to the dictionary
    enerconE126 = {
        'turbine_name': 'ENERCON E 126 7500',  # turbine name as in register
        'hub_height': 135,  # in m
        'rotor_diameter': 127  # in m
    }
    # initialise WindTurbine object
    e126 = WindTurbine(**enerconE126)

    return my_turbine, e126



def run_basic_example():
    r"""
    Run the basic example.

    """
    weather = get_weather_data('weather.csv')
    my_turbine, e126 = initialise_wind_turbines()
    calculate_power_output(weather, my_turbine, e126)
    plot_or_print(my_turbine, e126)


if __name__ == "__main__":
    run_basic_example()

但我无法成功地编译它。我从堆栈跟踪中得到了明显的错误下图:-你知道吗

/Users/joyjitchatterjee/anaconda3/envs/windproject1/bin/python /Users/joyjitchatterjee/Desktop/windAnalysis/test.py
Traceback (most recent call last):
  File "/Users/joyjitchatterjee/Desktop/windAnalysis/test.py", line 243, in <module>
    run_basic_example()
  File "/Users/joyjitchatterjee/Desktop/windAnalysis/test.py", line 237, in run_basic_example
    my_turbine, e126 = initialise_wind_turbines()
  File "/Users/joyjitchatterjee/Desktop/windAnalysis/test.py", line 111, in initialise_wind_turbines
    my_turbine = WindTurbine(**myTurbine)
TypeError: __init__() got an unexpected keyword argument 'name'

Process finished with exit code 1

这里要提到的关键是,我的桌面上有一个文件夹(/Users/joyjitchatterjee/Desktop/example),其中天气.csv文件。另外,我正在编译的代码存储在名为test.py的文件夹(/Users/joyjitchatterjee/Desktop/windAnalysis)中。我不知道为什么__init__()dunder方法会出现这个奇怪的错误,也不知道是否需要指定任何显式参数而不是名称来运行示例代码。我对将windpowerlib和Python与这样的软件包一起使用还很陌生,在此方面的任何帮助都将不胜感激。谢谢!你知道吗


Tags: inexamplemyuserswindpowercurvedesktop