Add example or function to make it easier to use your own weather data
Weather data in the ModelChain currently needs to be a MultiIndex DataFrame. This has on the one hand the drawback that the data height can only be a scalar and on the other hand that it is not easy to use for people who have not worked with pandas alot. Concerning the first issue I will wait for the feedinlib weather data class and maybe use ideas from it for the windpowerlib, so either also add a class or use xarray directly. Concerning the second issue we should provide an example how to create a MultiIndex DataFrame.
Assuming that weather is a pandas DataFrame with the following column names (pressure, temperature, wind_speed, roughness_length) I solved it the following way:
data_height = {
'pressure': 0,
'temperature': 2,
'wind_speed': 10,
'roughness_length': 0}
new_columns = [(key, data_height[key]) for key in weather.columns]
weather.columns = pd.MultiIndex.from_tuples(new_columns)
Concerning the first issue I will wait for the feedinlib weather data class [...]
I moved this issue to the v0.1.1 milestone as the feedinlib is not ready, yet.
Concerning the second issue we should provide an example how to create a MultiIndex DataFrame.
This is already done.
I wrote an example to change the structure of a typical DataFrame into our weather format. I put it here to keep it in mind.
import pandas as pd
import numpy as np
# This is random data but you could read a csv or excel sheet
# my_weather = pd.read_csv('my_path/my_file.csv')
my_wind_data_at_10m = np.random.rand(10)
my_temperature_data_at_2m = np.random.rand(10)
my_pressure_data_at_0m = np.random.rand(10)
column_names = ['windspeed', 'temp', 'pres']
my_weather = pd.DataFrame(np.array([
my_wind_data_at_10m,
my_temperature_data_at_2m,
my_pressure_data_at_0m]).transpose(),
columns=column_names)
# Rename your columns to the names used in the windpowerlib
translate = {
'windspeed': 'wind_speed',
'temp': 'temperature',
'pres': 'pressure'}
my_weather.rename(translate, inplace=True, axis=1)
# Add the heights of the data as a second column level
heights = [10, 2, 0]
my_weather.columns = pd.MultiIndex.from_arrays([my_weather.columns, heights])
print(my_weather)
oemof dev:
- allow heights as string in multiindex --> easy to read_csv()
- add function that builds weather multiindex from csv file / dictionaries / series / tupels in dictionary (wind_speed, 10)
allow heights as string in multiindex --> easy to read_csv()
Now addressed in #86.
As @uvchik fixed this in #86 I think we can close it. Do you agree @uvchik? And thank you by the way for implementing this :)
I would keep it open as a reminder, therefore I changed the title. I would like to do something similar to the cp-values examples/docs.