diff --git a/extreme_data/edf_data/weather_types.py b/extreme_data/edf_data/weather_types.py new file mode 100644 index 0000000000000000000000000000000000000000..e22672dd443a30c7e30ce8373d80af11379069f9 --- /dev/null +++ b/extreme_data/edf_data/weather_types.py @@ -0,0 +1,23 @@ +import os +import os.path as op +import numpy as np +import pandas as pd +from root_utils import get_full_path + +relative_path = r'local/EDF_data/Weather_types/CatalogueTT_EDF_France0_5308.txt' +edf_filepath = get_full_path(relative_path=relative_path) + + +def load_df_weather_types() -> pd.DataFrame: + global df + weather_types = [] + with open(edf_filepath, 'rb') as f: + for i, l in enumerate(f): + if i >= 7: + l = str(l).split('"')[1:] + weather_types.append((l[0], int(l[1][2]))) + df = pd.DataFrame(weather_types, columns=['Date', 'WP']) + df.set_index('Date', inplace=True) + return df + + diff --git a/test/test_extreme_data/test_edf_data/test_weather_types.py b/test/test_extreme_data/test_edf_data/test_weather_types.py new file mode 100644 index 0000000000000000000000000000000000000000..2616b49b9d16bf08cd158d588bee47be16f05f10 --- /dev/null +++ b/test/test_extreme_data/test_edf_data/test_weather_types.py @@ -0,0 +1,19 @@ +import unittest + +from extreme_data.edf_data.weather_types import load_df_weather_types +from extreme_data.meteo_france_data.scm_models_data.safran.safran import SafranTemperature + + +class TestWeatherTypes(unittest.TestCase): + + def test_df_weather_types(self): + df = load_df_weather_types() + self.assertEqual(len(df), 20354) + first = df.iloc[0].values[0] + last = df.iloc[-1].values[0] + self.assertEqual(first, 5) + self.assertEqual(last, 8) + + +if __name__ == '__main__': + unittest.main()