ebtools 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ebtools/__init__.py +169 -0
- ebtools/_version.py +33 -0
- ebtools/data/__init__.py +38 -0
- ebtools/data/dateformats.py +65 -0
- ebtools/data/dno.py +103 -0
- ebtools/data/powerenergy.py +19 -0
- ebtools/data/ukbankholidays.py +181 -0
- ebtools/data/ukclockchangedays.py +110 -0
- ebtools/data/units.py +22 -0
- ebtools/general/__init__.py +260 -0
- ebtools/general/_sp_efa_helpers.py +89 -0
- ebtools/general/array_selection.py +293 -0
- ebtools/general/dataframe_base.py +407 -0
- ebtools/general/dataframe_conversion.py +203 -0
- ebtools/general/dataframe_dates.py +128 -0
- ebtools/general/dataframe_filtering.py +212 -0
- ebtools/general/dataframe_formatting.py +71 -0
- ebtools/general/dataframe_helpers.py +154 -0
- ebtools/general/dataframe_plotting.py +639 -0
- ebtools/general/dataframe_processing.py +159 -0
- ebtools/general/dataframe_selection.py +345 -0
- ebtools/general/datetime_adjustments.py +160 -0
- ebtools/general/datetime_calendar.py +158 -0
- ebtools/general/datetime_conversion.py +435 -0
- ebtools/general/datetime_dataframe.py +228 -0
- ebtools/general/datetime_funcs.py +56 -0
- ebtools/general/datetime_helpers.py +322 -0
- ebtools/general/datetime_parsing.py +432 -0
- ebtools/general/datetime_timezone.py +112 -0
- ebtools/general/df_tools.py +58 -0
- ebtools/general/df_tools_string_dates.py +234 -0
- ebtools/general/file_reading_tools.py +282 -0
- ebtools/general/helper.py +197 -0
- ebtools/general/inspect_funcs.py +85 -0
- ebtools/general/online.py +46 -0
- ebtools/general/read_data.py +594 -0
- ebtools/general/save_data.py +211 -0
- ebtools/general/sp_efa_conversion.py +251 -0
- ebtools/general/sp_efa_dataframe.py +315 -0
- ebtools/general/sp_efa_datetime.py +99 -0
- ebtools/general/sp_efa_strings.py +119 -0
- ebtools-0.1.0.dist-info/METADATA +432 -0
- ebtools-0.1.0.dist-info/RECORD +46 -0
- ebtools-0.1.0.dist-info/WHEEL +5 -0
- ebtools-0.1.0.dist-info/licenses/LICENSE +201 -0
- ebtools-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Created on Tue Apr 4 17:36:46 2023
|
|
4
|
+
|
|
5
|
+
@author: Eamonn.Bell
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# =============================================================================
|
|
10
|
+
# ---- Clock Change days - DAYLIGHT SAVINGS
|
|
11
|
+
# =============================================================================
|
|
12
|
+
|
|
13
|
+
# Maintain a list of clock change days here.
|
|
14
|
+
# The official place to look for clock change days is here:
|
|
15
|
+
# https://www.gov.uk/when-do-the-clocks-change
|
|
16
|
+
#
|
|
17
|
+
# The Daylight Savings Clock Change dates and times can be found as part of
|
|
18
|
+
# the Market Domain Data (MDD) on the Elexon portal page here (may have to be
|
|
19
|
+
# logged in):
|
|
20
|
+
# www.elexonportal.co.uk/mddviewer
|
|
21
|
+
#
|
|
22
|
+
# An alternative source can be found here:
|
|
23
|
+
# https://www.timeanddate.com/time/change/uk/london
|
|
24
|
+
#
|
|
25
|
+
# Clock change dates should be checked against the gov.uk site on a regular
|
|
26
|
+
# basis and then set moved to the 'Confirmed' section.
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# LAST SUNDAY IN MARCH - These days will have 46 SPs
|
|
30
|
+
uk_clock_change_forward = [
|
|
31
|
+
|
|
32
|
+
# Confirmed
|
|
33
|
+
'1998-03-29',
|
|
34
|
+
'1999-03-28',
|
|
35
|
+
'2000-03-26',
|
|
36
|
+
'2001-03-25',
|
|
37
|
+
'2002-03-31',
|
|
38
|
+
'2003-03-30',
|
|
39
|
+
'2004-03-28',
|
|
40
|
+
'2005-03-27',
|
|
41
|
+
'2006-03-26',
|
|
42
|
+
'2007-03-25',
|
|
43
|
+
'2008-03-30',
|
|
44
|
+
'2009-03-29',
|
|
45
|
+
'2010-03-28',
|
|
46
|
+
'2011-03-27',
|
|
47
|
+
'2012-03-25',
|
|
48
|
+
'2013-03-31',
|
|
49
|
+
'2014-03-30',
|
|
50
|
+
'2015-03-29',
|
|
51
|
+
'2016-03-27',
|
|
52
|
+
'2017-03-26',
|
|
53
|
+
'2018-03-25',
|
|
54
|
+
'2019-03-31',
|
|
55
|
+
'2020-03-29',
|
|
56
|
+
'2021-03-28',
|
|
57
|
+
'2022-03-27',
|
|
58
|
+
'2023-03-26',
|
|
59
|
+
'2024-03-31',
|
|
60
|
+
'2025-03-30',
|
|
61
|
+
'2026-03-29',
|
|
62
|
+
|
|
63
|
+
# Unconfirmed
|
|
64
|
+
'2027-03-28',
|
|
65
|
+
'2028-03-26',
|
|
66
|
+
'2029-03-25',
|
|
67
|
+
'2030-03-31'
|
|
68
|
+
]
|
|
69
|
+
|
|
70
|
+
# LAST SUNDAY IN OCTOBER - These days will have 50 SPs
|
|
71
|
+
uk_clock_change_backward = [
|
|
72
|
+
|
|
73
|
+
# Confirmed
|
|
74
|
+
'1998-10-25',
|
|
75
|
+
'1999-10-31',
|
|
76
|
+
'2000-10-29',
|
|
77
|
+
'2001-10-28',
|
|
78
|
+
'2002-10-27',
|
|
79
|
+
'2003-10-26',
|
|
80
|
+
'2004-10-31',
|
|
81
|
+
'2005-10-30',
|
|
82
|
+
'2006-10-29',
|
|
83
|
+
'2007-10-28',
|
|
84
|
+
'2008-10-26',
|
|
85
|
+
'2009-10-25',
|
|
86
|
+
'2010-10-31',
|
|
87
|
+
'2011-10-30',
|
|
88
|
+
'2012-10-28',
|
|
89
|
+
'2013-10-27',
|
|
90
|
+
'2014-10-26',
|
|
91
|
+
'2015-10-25',
|
|
92
|
+
'2016-10-30',
|
|
93
|
+
'2017-10-29',
|
|
94
|
+
'2018-10-28',
|
|
95
|
+
'2019-10-27',
|
|
96
|
+
'2020-10-25',
|
|
97
|
+
'2021-10-31',
|
|
98
|
+
'2022-10-30',
|
|
99
|
+
'2023-10-29',
|
|
100
|
+
'2024-10-27',
|
|
101
|
+
'2025-10-26',
|
|
102
|
+
'2026-10-25',
|
|
103
|
+
|
|
104
|
+
# Unconfirmed
|
|
105
|
+
'2027-10-31',
|
|
106
|
+
'2028-10-29',
|
|
107
|
+
'2029-10-28',
|
|
108
|
+
'2030-10-27'
|
|
109
|
+
]
|
|
110
|
+
|
ebtools/data/units.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
Created on Sun Dec 31 13:52:29 2023
|
|
5
|
+
|
|
6
|
+
@author: eamonnbell
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
# Dictionary to reference strings to the number of potential periods per
|
|
11
|
+
# day in a dataset. Add here if there are more.
|
|
12
|
+
|
|
13
|
+
unit_dict = {
|
|
14
|
+
'5min' : 288,
|
|
15
|
+
'15min': 96,
|
|
16
|
+
'30min': 48,
|
|
17
|
+
'60min': 24,
|
|
18
|
+
'hh' : 48,
|
|
19
|
+
'hour' : 24,
|
|
20
|
+
'efa' : 6
|
|
21
|
+
}
|
|
22
|
+
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
Created on Tue Oct 24 21:12:28 2023
|
|
5
|
+
|
|
6
|
+
@author: eamonnbell
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
from ebtools.general.helper import (
|
|
11
|
+
|
|
12
|
+
# Dict Tools
|
|
13
|
+
sort_dict_by_keys,
|
|
14
|
+
make_dict_keys_from_list,
|
|
15
|
+
|
|
16
|
+
# Force to Type
|
|
17
|
+
force_to_list,
|
|
18
|
+
force_to_np_array
|
|
19
|
+
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
from ebtools.general.read_data import (
|
|
24
|
+
|
|
25
|
+
# Reading different file_types into dataframes
|
|
26
|
+
read_from_csv,
|
|
27
|
+
read_from_xlsx,
|
|
28
|
+
read_from_parquet,
|
|
29
|
+
|
|
30
|
+
# Reading HH Data into a dataframe
|
|
31
|
+
load_hh_data
|
|
32
|
+
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
from ebtools.general.save_data import (
|
|
37
|
+
|
|
38
|
+
save_to_csv,
|
|
39
|
+
save_to_xlsx,
|
|
40
|
+
save_to_parquet
|
|
41
|
+
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
from ebtools.general.inspect_funcs import (
|
|
46
|
+
|
|
47
|
+
get_call_func_name,
|
|
48
|
+
get_function_arguments
|
|
49
|
+
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
from ebtools.general.file_reading_tools import (
|
|
54
|
+
|
|
55
|
+
does_file_exist,
|
|
56
|
+
get_file_type,
|
|
57
|
+
list_all_files_in_folder,
|
|
58
|
+
zip_checker
|
|
59
|
+
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
from ebtools.general.datetime_calendar import (
|
|
64
|
+
|
|
65
|
+
# Helper funcs
|
|
66
|
+
is_year_leap_year,
|
|
67
|
+
get_daylight_savings_dates,
|
|
68
|
+
bst_date_range,
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
from ebtools.general.datetime_conversion import (
|
|
72
|
+
|
|
73
|
+
# Helper funcs
|
|
74
|
+
convert_single_datetime_to_sp_start,
|
|
75
|
+
convert_single_datetime_to_sp_end,
|
|
76
|
+
|
|
77
|
+
# Convert Datetime
|
|
78
|
+
convert_date_to_standard_date_str,
|
|
79
|
+
convert_date_to_datetime,
|
|
80
|
+
convert_datetime_to_date,
|
|
81
|
+
convert_date_to_datetime_str,
|
|
82
|
+
convert_date_to_first_of_month,
|
|
83
|
+
convert_date_to_last_of_month,
|
|
84
|
+
|
|
85
|
+
# Month-start and Month-end
|
|
86
|
+
move_date_to_start_of_month,
|
|
87
|
+
move_date_to_end_of_month
|
|
88
|
+
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
from ebtools.general.datetime_timezone import (
|
|
92
|
+
|
|
93
|
+
# Convert timezone-aware datetime columns
|
|
94
|
+
convert_datetime_remove_tz_aware,
|
|
95
|
+
convert_datetime_by_tz,
|
|
96
|
+
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
from ebtools.general.datetime_dataframe import (
|
|
100
|
+
|
|
101
|
+
# Add dataframe datetime columns
|
|
102
|
+
convert_datetime_sp_start,
|
|
103
|
+
convert_datetime_sp_end,
|
|
104
|
+
add_first_of_month_col_from_int_cols,
|
|
105
|
+
add_first_of_month_col_from_date_col,
|
|
106
|
+
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
from ebtools.general.datetime_parsing import (
|
|
110
|
+
|
|
111
|
+
# Check Datetime
|
|
112
|
+
check_datetime_formats,
|
|
113
|
+
check_datetime_formats_tz,
|
|
114
|
+
check_string_datetime_formats,
|
|
115
|
+
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
from ebtools.general.datetime_adjustments import (
|
|
119
|
+
|
|
120
|
+
# Adjust Dates
|
|
121
|
+
start_of_delivery_year,
|
|
122
|
+
roll_back_by_month_str,
|
|
123
|
+
roll_back_by_month_df,
|
|
124
|
+
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
from ebtools.general.sp_efa_conversion import (
|
|
129
|
+
|
|
130
|
+
# General
|
|
131
|
+
sp_to_efa,
|
|
132
|
+
hour_to_efa,
|
|
133
|
+
current_sp,
|
|
134
|
+
current_efa,
|
|
135
|
+
make_sp_efa_table,
|
|
136
|
+
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
from ebtools.general.sp_efa_datetime import (
|
|
140
|
+
|
|
141
|
+
# EFA date and datetime
|
|
142
|
+
convert_date_to_efa_datetime,
|
|
143
|
+
convert_datetime_to_date_and_efa,
|
|
144
|
+
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
from ebtools.general.sp_efa_strings import (
|
|
148
|
+
|
|
149
|
+
# SP and EFA from strings
|
|
150
|
+
make_sp_from_string,
|
|
151
|
+
make_efa_from_string,
|
|
152
|
+
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
from ebtools.general.sp_efa_dataframe import (
|
|
156
|
+
|
|
157
|
+
# Add cols to df
|
|
158
|
+
add_sp_from_datetime_col,
|
|
159
|
+
add_sp_start_end_datetimes,
|
|
160
|
+
add_sp_to_efa_column,
|
|
161
|
+
add_efa_datetime_col,
|
|
162
|
+
add_date_efa_cols,
|
|
163
|
+
add_sp_and_efa_from_datetime
|
|
164
|
+
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
from ebtools.general.dataframe_dates import (
|
|
169
|
+
|
|
170
|
+
# Dataframe - Augmentation
|
|
171
|
+
add_buffer_days,
|
|
172
|
+
add_columns,
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
from ebtools.general.dataframe_selection import (
|
|
176
|
+
|
|
177
|
+
# Dataframe - Date Range Selection
|
|
178
|
+
select_year,
|
|
179
|
+
select_weeks,
|
|
180
|
+
select_days,
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
from ebtools.general.dataframe_plotting import (
|
|
184
|
+
|
|
185
|
+
# Dataframe - Analysis and Plotting
|
|
186
|
+
make_full_year_pivot,
|
|
187
|
+
make_full_plotting_df,
|
|
188
|
+
make_pivot_calendar,
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
from ebtools.general.dataframe_base import (
|
|
192
|
+
|
|
193
|
+
# Dataframe - BASE
|
|
194
|
+
adjust_for_clock_change,
|
|
195
|
+
base_df,
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
from ebtools.general.dataframe_filtering import (
|
|
199
|
+
|
|
200
|
+
# Dataframe - Filtering
|
|
201
|
+
df_filter,
|
|
202
|
+
df_cutoff,
|
|
203
|
+
drop_empty_df_cols,
|
|
204
|
+
melt_df,
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
from ebtools.general.dataframe_processing import (
|
|
208
|
+
|
|
209
|
+
# Dataframe - Processing
|
|
210
|
+
unique_element_count,
|
|
211
|
+
non_numeric_pivot,
|
|
212
|
+
df_round_to_decimal,
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
from ebtools.general.dataframe_formatting import (
|
|
216
|
+
|
|
217
|
+
# Dataframe - Formatting
|
|
218
|
+
remove_df_index_name,
|
|
219
|
+
remove_df_column_name,
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
from ebtools.general.dataframe_conversion import (
|
|
223
|
+
|
|
224
|
+
# Dataframe - Correct Strings
|
|
225
|
+
correct_str_elements_float,
|
|
226
|
+
correct_str_elements_int,
|
|
227
|
+
|
|
228
|
+
# Dataframe - Create df from JSON
|
|
229
|
+
create_df_from_json,
|
|
230
|
+
create_df_from_json_from_file
|
|
231
|
+
)
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
from ebtools.general.df_tools_string_dates import (
|
|
235
|
+
|
|
236
|
+
# STRING date functions
|
|
237
|
+
week_starting,
|
|
238
|
+
week_number,
|
|
239
|
+
weekday_number,
|
|
240
|
+
day_of_the_year_number
|
|
241
|
+
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
from ebtools.general.array_selection import (
|
|
245
|
+
|
|
246
|
+
# General
|
|
247
|
+
add_newaxis,
|
|
248
|
+
|
|
249
|
+
# Select data from ROWS
|
|
250
|
+
n_smallest_values_per_row,
|
|
251
|
+
n_largest_values_per_row
|
|
252
|
+
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
from ebtools.general.online import (
|
|
257
|
+
|
|
258
|
+
is_online
|
|
259
|
+
|
|
260
|
+
)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""Private helpers for Settlement Period and EFA conversions."""
|
|
4
|
+
|
|
5
|
+
import datetime
|
|
6
|
+
|
|
7
|
+
import numpy as np
|
|
8
|
+
import pandas as pd
|
|
9
|
+
|
|
10
|
+
import ebtools.general.helper as helper
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
EFA_START_HOURS = {
|
|
14
|
+
1: -1,
|
|
15
|
+
2: 3,
|
|
16
|
+
3: 7,
|
|
17
|
+
4: 11,
|
|
18
|
+
5: 15,
|
|
19
|
+
6: 19,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
TIME_TO_EFA = {
|
|
23
|
+
datetime.time(23, 0): 1,
|
|
24
|
+
datetime.time(3, 0): 2,
|
|
25
|
+
datetime.time(7, 0): 3,
|
|
26
|
+
datetime.time(11, 0): 4,
|
|
27
|
+
datetime.time(15, 0): 5,
|
|
28
|
+
datetime.time(19, 0): 6,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def as_integer_array(values: object, name: str) -> np.ndarray:
|
|
33
|
+
"""Return values as an integer NumPy array, preserving integer semantics."""
|
|
34
|
+
value_array = helper.force_to_np_array(values)
|
|
35
|
+
|
|
36
|
+
try:
|
|
37
|
+
value_int = value_array.astype(int)
|
|
38
|
+
except (TypeError, ValueError):
|
|
39
|
+
raise ValueError(f"{name} values must be integer-like.") from None
|
|
40
|
+
|
|
41
|
+
try:
|
|
42
|
+
integer_like = np.all(np.equal(value_array, value_int))
|
|
43
|
+
except TypeError:
|
|
44
|
+
integer_like = False
|
|
45
|
+
|
|
46
|
+
if not integer_like:
|
|
47
|
+
raise ValueError(f"{name} values must be integer-like.")
|
|
48
|
+
|
|
49
|
+
return value_int
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def return_scalar_or_array(
|
|
53
|
+
values: np.ndarray,
|
|
54
|
+
scalar_input: bool
|
|
55
|
+
) -> int | np.ndarray:
|
|
56
|
+
"""Return a scalar integer for scalar input, otherwise return an array."""
|
|
57
|
+
if scalar_input:
|
|
58
|
+
return int(values[0])
|
|
59
|
+
|
|
60
|
+
return values
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def require_columns(
|
|
64
|
+
df: pd.DataFrame,
|
|
65
|
+
columns: list[str]
|
|
66
|
+
) -> None:
|
|
67
|
+
"""Raise a KeyError if any expected DataFrame columns are missing."""
|
|
68
|
+
missing_cols = [col for col in columns if col not in df.columns]
|
|
69
|
+
|
|
70
|
+
if missing_cols:
|
|
71
|
+
raise KeyError(f"Column(s) not found in dataframe: {missing_cols}")
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def validate_range(
|
|
75
|
+
values: np.ndarray | pd.Series,
|
|
76
|
+
name: str,
|
|
77
|
+
min_value: int,
|
|
78
|
+
max_value: int
|
|
79
|
+
) -> None:
|
|
80
|
+
"""Raise a ValueError if values fall outside an inclusive range."""
|
|
81
|
+
if np.any((values < min_value) | (values > max_value)):
|
|
82
|
+
raise ValueError(
|
|
83
|
+
f"{name} values must be in the range {min_value} to {max_value}."
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def validate_sp_values(values: np.ndarray | pd.Series) -> None:
|
|
88
|
+
"""Validate that values are valid Settlement Period numbers."""
|
|
89
|
+
validate_range(values, "SP", 1, 48)
|