wind-python / windpowerlib

The windpowerlib is a library to model the output of wind turbines and farms.
https://oemof.org/
MIT License
332 stars 105 forks source link

ModelChain example #50

Closed lxlsygc closed 5 years ago

lxlsygc commented 5 years ago

**Hello,

I have installed oemof & windpowerlib and I am trying to run the ModelChain example. I downloaded the "ModelChain example (Python script)" and "Example data file" and put these two in the same folder. Then I used "Spyder" to open the "ModelChain example (Python script)" file and run it. Here is what I got from the console:**

Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] Type "copyright", "credits" or "license" for more information.

IPython 7.3.0 -- An enhanced Interactive Python.

runfile('C:/Python/Example/ModelChain/modelchain_example.py', wdir='C:/Python/Example/ModelChain') Traceback (most recent call last):

File "", line 1, in runfile('C:/Python/Example/ModelChain/modelchain_example.py', wdir='C:/Python/Example/ModelChain')

File "C:\Python\WPy64-3680\python-3.6.8.amd64\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 786, in runfile execfile(filename, namespace)

File "C:\Python\WPy64-3680\python-3.6.8.amd64\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "C:/Python/Example/ModelChain/modelchain_example.py", line 27, in from windpowerlib import ModelChain

ImportError: cannot import name 'ModelChain'

It was saying that "ImportError: cannot import name 'ModelChain'". Not sure what is wrong ...

SabineHaas commented 5 years ago

Hey @lxlsygc, for evaluating the problem it would help us if you could specify:

Could you try to run the script from the console or in another IDE apart from Spyder (to ensure its not a spyder problem)?

lxlsygc commented 5 years ago

**@ Sabine; Thanks for your quick reply. Here are my answers by points:

  1. The version of the windpowerlib: windpowerlib 0.0.4
  2. My operating system: Win10
  3. I am not using Virtualenv.

I have tried to run the script from the console; see below:**

%run modelchain_example.py C:\Python\WPy64-3680\python-3.6.8.amd64\lib\site-packages\ipykernel\ipkernel.py:448: DeprecationWarning: input_splitter is deprecated since IPython 7.0, prefer input_transformer_manager. status, indent_spaces = self.shell.input_splitter.check_complete(code) Traceback (most recent call last):

File "C:\Python\Example\ModelChain\modelchain_example.py", line 27, in from windpowerlib import ModelChain

ImportError: cannot import name 'ModelChain'

It gives me the same problem.

I also installed "Komodo" to try the script. However, it looks like this IDE is not "interacting" with oemof. Not sure what to do to get it run. Here is the command output:

Traceback (most recent call last): File "C:\Python\Example\ModelChain\modelchain_example.py", line 20, in import pandas as pd File "C:\Users\xiaol\Anaconda3\lib\site-packages\pandas__init__.py", line 19, in "Missing required dependencies {0}".format(missing_dependencies)) ImportError: Missing required dependencies ['numpy']

birgits commented 5 years ago

Is there a reason why you are using such an old version of the windpowerlib? If not I would advise you to upgrade to the newest version. Version 0.0.4 didn't have a ModelChain yet, therefore the example won't work. You can download the example given in version 0.0.4 here. The examples for each version of the windpowerlib can also be found in the documentation. At the bottom left you can choose the version of the documentation and navigate to the getting started section where we link to the corresponding examples. I hope this helps!

lxlsygc commented 5 years ago

**Thanks, birgits! I am not intended to install such an old version.

I have "WinPython 3.6.8.0Qt5-64bit" installed on my computer. I used "pip install windpowerlib" to install windpowerlib through "WinPython Command Prompt". Here is what I got:**

C:\Python\WPy64-3680\scripts>pip install windpowerlib Requirement already satisfied: windpowerlib in c:\python\wpy64-3680\python-3.6.8.amd64\lib\site-packages (0.0.4) Requirement already satisfied: pandas>=0.13.1 in c:\python\wpy64-3680\python-3.6.8.amd64\lib\site-packages (from windpowerlib) (0.23.4) Requirement already satisfied: numpy>=1.7.0 in c:\python\wpy64-3680\python-3.6.8.amd64\lib\site-packages (from windpowerlib) (1.15.4) Requirement already satisfied: pytz>=2011k in c:\python\wpy64-3680\python-3.6.8.amd64\lib\site-packages (from pandas>=0.13.1->windpowerlib) (2018.9) Requirement already satisfied: python-dateutil>=2.5.0 in c:\python\wpy64-3680\python-3.6.8.amd64\lib\site-packages (from pandas>=0.13.1->windpowerlib) (2.8.0) Requirement already satisfied: six>=1.5 in c:\python\wpy64-3680\python-3.6.8.amd64\lib\site-packages (from python-dateutil>=2.5.0->pandas>=0.13.1->windpowerlib) (1.12.0)

**Not sure why I got such an old version installed.

Could you please let me know how to update it?

Thank you in advance!**

lxlsygc commented 5 years ago

The version of that I installed is "oemof 0.2.3", which should be the latest version...

birgits commented 5 years ago

You already had windpowerlib installed, that's why pip didn't reinstall it. Maybe you had the oemof feedinlib installed which still requires that old version (hopefully we will release a new version of the feedinlib soon...). Anyhow, you can easily update the windpowerlib through pip install windpowerlib==0.1.1.

lxlsygc commented 5 years ago

**Hi birgits,

You are right. I have used pip install windpowerlib==0.1.1 to install windpowerlib. I got a notice "feedinlib 0.0.12 has requirement windpowerlib==0.0.4, but you'll have windpowerlib 0.1.1 which is incompatible." As you said, it should an issue from feedinlib. Anyhow, I got it installed.

However, I still can not run the "ModelChain example". Here is what I got from Spyder:**

runfile('C:/Python/Example/ModelChain/modelchain_example.py', wdir='C:/Python/Example/ModelChain') Traceback (most recent call last):

File "", line 1, in runfile('C:/Python/Example/ModelChain/modelchain_example.py', wdir='C:/Python/Example/ModelChain')

File "C:\Python\WPy64-3680\python-3.6.8.amd64\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 786, in runfile execfile(filename, namespace)

File "C:\Python\WPy64-3680\python-3.6.8.amd64\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "C:/Python/Example/ModelChain/modelchain_example.py", line 282, in run_example()

File "C:/Python/Example/ModelChain/modelchain_example.py", line 275, in run_example weather = get_weather_data('weather.csv')

File "C:/Python/Example/ModelChain/modelchain_example.py", line 77, in get_weather_data date_parser=lambda idx: pd.to_datetime(idx, utc=True))

File "C:\Python\WPy64-3680\python-3.6.8.amd64\lib\site-packages\pandas\io\parsers.py", line 678, in parser_f return _read(filepath_or_buffer, kwds)

File "C:\Python\WPy64-3680\python-3.6.8.amd64\lib\site-packages\pandas\io\parsers.py", line 440, in _read parser = TextFileReader(filepath_or_buffer, **kwds)

File "C:\Python\WPy64-3680\python-3.6.8.amd64\lib\site-packages\pandas\io\parsers.py", line 787, in init self._make_engine(self.engine)

File "C:\Python\WPy64-3680\python-3.6.8.amd64\lib\site-packages\pandas\io\parsers.py", line 1014, in _make_engine self._engine = CParserWrapper(self.f, **self.options)

File "C:\Python\WPy64-3680\python-3.6.8.amd64\lib\site-packages\pandas\io\parsers.py", line 1708, in init self._reader = parsers.TextReader(src, **kwds)

File "pandas_libs\parsers.pyx", line 384, in pandas._libs.parsers.TextReader.cinit

File "pandas_libs\parsers.pyx", line 695, in pandas._libs.parsers.TextReader._setup_parser_source

FileNotFoundError: File b'C:/Python/Example\example\weather.csv' does not exist

**I am not sure about the sentence of "FileNotFoundError: File b'C:/Python/Example\example\weather.csv' does not exist"

I simply put "ModelChain example (Python script)" and "Example data file (weather.csv)" in the same folder... ...**

birgits commented 5 years ago

Mmh, this looks like the path to the file is not created correctly, though I'm not sure if mixed slashes are a problem or not. Have you tried using this path in the file manager? Unfortunately we haven't tested the windpowerlib for windows yet, though how the path to the weather file is created should be correct... What you could try for now is to change file to filename in line 76 which would make the read_csv use a relative instead of a absolute path.

weather_df = pd.read_csv(
        filename, index_col=0, header=[0, 1],
       date_parser=lambda idx: pd.to_datetime(idx, utc=True))
lxlsygc commented 5 years ago

**Hi birgots:

After I fixed the line 76 as you suggested, I got a new AttributeError. See below:**

Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] Type "copyright", "credits" or "license" for more information.

IPython 7.3.0 -- An enhanced Interactive Python.

runfile('C:/Python/Example/ModelChain_v2/modelchain_example.py', wdir='C:/Python/Example/ModelChain_v2') Traceback (most recent call last):

File "", line 1, in runfile('C:/Python/Example/ModelChain_v2/modelchain_example.py', wdir='C:/Python/Example/ModelChain_v2')

File "C:\Python\WPy64-3680\python-3.6.8.amd64\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 786, in runfile execfile(filename, namespace)

File "C:\Python\WPy64-3680\python-3.6.8.amd64\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "C:/Python/Example/ModelChain_v2/modelchain_example.py", line 282, in run_example()

File "C:/Python/Example/ModelChain_v2/modelchain_example.py", line 275, in run_example weather = get_weather_data('weather.csv')

File "C:/Python/Example/ModelChain_v2/modelchain_example.py", line 83, in get_weather_data weather_df.axes[1].codes[0]],

AttributeError: 'MultiIndex' object has no attribute 'codes'

**I am a beginner in Pyhton or, more generally, in programming. Do you think it is better if I try this example in Linux?

Thanks in advance!**

birgits commented 5 years ago

This error is due to the deprecation of the labels attribute in pandas 0.24.0. We therefore changed labels to codes. What we missed, though, is to update the setup.py to require a higher pandas version (>=0.24.0). You can either now upgrade your pandas version to >=0.24.0 or change codes back to labels in lines 83 and 85. We will also push a fix once we've tested it further. Hope the example will work now for you!

lxlsygc commented 5 years ago

Hi birgits,

Thanks for your reply! I have modified the lines 83 and 85 as you suggested.

Then, I got an error "FileNotFoundError: The file 'C:/Python/Example/ModelChain_v2\data\example_power_coefficient_curves.csv' was not found."

I downloaded the file "example_power_coefficient_curves.csv" on Github and put it in the target folder.

Now the code works fine.

Thank you again!