From 626c5fffee21997e2de690cc588a330e04e39aed Mon Sep 17 00:00:00 2001 From: Alexander Morgan Date: Tue, 19 Mar 2024 13:24:23 +0100 Subject: [PATCH] Refactor read_timeseries to reuse more code --- reView/utils/functions.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/reView/utils/functions.py b/reView/utils/functions.py index 9d1a7df..f244ba7 100644 --- a/reView/utils/functions.py +++ b/reView/utils/functions.py @@ -485,12 +485,6 @@ def read_timeseries(file, gids=None, nsteps=None): if "bespoke" not in str(file): # Break down time entries time = [t.decode() for t in ds["time_index"][:nsteps]] - dtime = [dt.datetime.strptime(t, TIME_PATTERN) for t in time] - minutes = [t.minute for t in dtime] - hours = [t.hour for t in dtime] - days = [t.timetuple().tm_yday for t in dtime] - weeks = [t.isocalendar().week for t in dtime] - months = [t.month for t in dtime] # Process generation data cf = ds["rep_profiles_0"][:nsteps, idx] @@ -524,15 +518,16 @@ def read_timeseries(file, gids=None, nsteps=None): # This will only take the average across the year time = [t.decode() for t in time] - dtime = [dt.datetime.strptime(t, TIME_PATTERN) for t in time] - days = [t.timetuple().tm_yday for t in dtime] - weeks = [t.isocalendar().week for t in dtime] - months = [t.month for t in dtime] - hours = [t.hour for t in dtime] - minutes = [t.minute for t in dtime] ds.close() + dtime = [dt.datetime.strptime(t, TIME_PATTERN) for t in time] + minutes = [t.minute for t in dtime] + hours = [t.hour for t in dtime] + days = [t.timetuple().tm_yday for t in dtime] + weeks = [t.isocalendar().week for t in dtime] + months = [t.month for t in dtime] + data = pd.DataFrame({ "time": time, "minute": minutes,