Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example or function to make it easier to use your own weather data #9

Open
birgits opened this issue Mar 6, 2018 · 7 comments
Open
Assignees
Milestone

Comments

@birgits
Copy link
Member

birgits commented Mar 6, 2018

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.

@birgits birgits self-assigned this Mar 6, 2018
@uvchik
Copy link
Member

uvchik commented Mar 6, 2018

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)

@SabineHaas SabineHaas added this to the v0.1.0 milestone Dec 13, 2018
@SabineHaas SabineHaas modified the milestones: v0.1.0, v0.1.1 Jan 3, 2019
@SabineHaas
Copy link
Member

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.

@uvchik
Copy link
Member

uvchik commented Nov 18, 2019

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)

@SabineHaas
Copy link
Member

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)

@birgits
Copy link
Member Author

birgits commented Dec 5, 2019

allow heights as string in multiindex --> easy to read_csv()

Now addressed in #86.

@uvchik uvchik modified the milestones: Developer meeting, v0.2.1 Feb 14, 2020
@birgits
Copy link
Member Author

birgits commented Apr 23, 2020

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 :)

@uvchik uvchik changed the title Revise data structure of weather data in ModelChain Add example or function to make it easier to use your own weather data Apr 28, 2020
@uvchik
Copy link
Member

uvchik commented Apr 28, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants