Skip to content

Commit 44f852d

Browse files
committed
Move data check to data module
1 parent ffed8bf commit 44f852d

File tree

2 files changed

+37
-27
lines changed

2 files changed

+37
-27
lines changed

windpowerlib/data.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import requests
1616

1717
from windpowerlib.wind_turbine import WindTurbine
18+
from windpowerlib.tools import WindpowerlibUserWarning
1819

1920

2021
def get_turbine_types(turbine_library="local", print_out=True, filter_=True):
@@ -322,3 +323,39 @@ def check_data_integrity(data, min_pc_length=5):
322323
)
323324
)
324325
return data
326+
327+
328+
def check_weather_data(weather_data):
329+
"""
330+
Check weather Data Frame.
331+
332+
- Raise warning if there are nan values.
333+
- Convert columns if heights are string and not numeric.
334+
335+
Parameters
336+
----------
337+
weather_data : pandas.DataFrame
338+
A weather table with MultiIndex columns (name, data height)
339+
340+
Returns
341+
-------
342+
pandas.DataFrame : A valid weather table.
343+
344+
"""
345+
# Convert data heights to integer. In some case they are strings.
346+
weather_data.columns = pd.MultiIndex.from_arrays(
347+
[
348+
weather_data.columns.get_level_values(0),
349+
pd.to_numeric(weather_data.columns.get_level_values(1)),
350+
]
351+
)
352+
353+
# check for nan values
354+
if weather_data.isnull().any().any():
355+
nan_columns = list(weather_data.columns[weather_data.isnull().any()])
356+
msg = (
357+
"The following columns of the weather data contain invalid "
358+
"values like 'nan': {0}"
359+
)
360+
warnings.warn(msg.format(nan_columns), WindpowerlibUserWarning)
361+
return weather_data

windpowerlib/tools.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -227,30 +227,3 @@ def estimate_turbulence_intensity(height, roughness_length):
227227
228228
"""
229229
return 1 / (np.log(height / roughness_length))
230-
231-
232-
def check_weather_data(weather_df):
233-
"""
234-
Check weather Data Frame.
235-
236-
- Raise warning if there are nan values.
237-
- Convert columns if heights are string and not numeric.
238-
239-
"""
240-
# Convert data heights to integer. In some case they are strings.
241-
weather_df.columns = pd.MultiIndex.from_arrays(
242-
[
243-
weather_df.columns.get_level_values(0),
244-
pd.to_numeric(weather_df.columns.get_level_values(1)),
245-
]
246-
)
247-
248-
# check for nan values
249-
if weather_df.isnull().any().any():
250-
nan_columns = list(weather_df.columns[weather_df.isnull().any()])
251-
msg = (
252-
"The following columns of the weather data contain invalid "
253-
"values like 'nan': {0}"
254-
)
255-
warnings.warn(msg.format(nan_columns), WindpowerlibUserWarning)
256-
return weather_df

0 commit comments

Comments
 (0)