Commit 312e7948 authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[contrasting project] add weather type loader

parent 5ea6a803
No related merge requests found
Showing with 42 additions and 0 deletions
+42 -0
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
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()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment