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.
Files changed (46) hide show
  1. ebtools/__init__.py +169 -0
  2. ebtools/_version.py +33 -0
  3. ebtools/data/__init__.py +38 -0
  4. ebtools/data/dateformats.py +65 -0
  5. ebtools/data/dno.py +103 -0
  6. ebtools/data/powerenergy.py +19 -0
  7. ebtools/data/ukbankholidays.py +181 -0
  8. ebtools/data/ukclockchangedays.py +110 -0
  9. ebtools/data/units.py +22 -0
  10. ebtools/general/__init__.py +260 -0
  11. ebtools/general/_sp_efa_helpers.py +89 -0
  12. ebtools/general/array_selection.py +293 -0
  13. ebtools/general/dataframe_base.py +407 -0
  14. ebtools/general/dataframe_conversion.py +203 -0
  15. ebtools/general/dataframe_dates.py +128 -0
  16. ebtools/general/dataframe_filtering.py +212 -0
  17. ebtools/general/dataframe_formatting.py +71 -0
  18. ebtools/general/dataframe_helpers.py +154 -0
  19. ebtools/general/dataframe_plotting.py +639 -0
  20. ebtools/general/dataframe_processing.py +159 -0
  21. ebtools/general/dataframe_selection.py +345 -0
  22. ebtools/general/datetime_adjustments.py +160 -0
  23. ebtools/general/datetime_calendar.py +158 -0
  24. ebtools/general/datetime_conversion.py +435 -0
  25. ebtools/general/datetime_dataframe.py +228 -0
  26. ebtools/general/datetime_funcs.py +56 -0
  27. ebtools/general/datetime_helpers.py +322 -0
  28. ebtools/general/datetime_parsing.py +432 -0
  29. ebtools/general/datetime_timezone.py +112 -0
  30. ebtools/general/df_tools.py +58 -0
  31. ebtools/general/df_tools_string_dates.py +234 -0
  32. ebtools/general/file_reading_tools.py +282 -0
  33. ebtools/general/helper.py +197 -0
  34. ebtools/general/inspect_funcs.py +85 -0
  35. ebtools/general/online.py +46 -0
  36. ebtools/general/read_data.py +594 -0
  37. ebtools/general/save_data.py +211 -0
  38. ebtools/general/sp_efa_conversion.py +251 -0
  39. ebtools/general/sp_efa_dataframe.py +315 -0
  40. ebtools/general/sp_efa_datetime.py +99 -0
  41. ebtools/general/sp_efa_strings.py +119 -0
  42. ebtools-0.1.0.dist-info/METADATA +432 -0
  43. ebtools-0.1.0.dist-info/RECORD +46 -0
  44. ebtools-0.1.0.dist-info/WHEEL +5 -0
  45. ebtools-0.1.0.dist-info/licenses/LICENSE +201 -0
  46. ebtools-0.1.0.dist-info/top_level.txt +1 -0
ebtools/__init__.py ADDED
@@ -0,0 +1,169 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Created on Mon May 17 15:48:46 2021
4
+
5
+ @author: Eamonn.Bell
6
+ """
7
+
8
+
9
+
10
+ from ebtools.general import (
11
+
12
+ # HELPER functions
13
+ get_file_type,
14
+ force_to_list,
15
+ force_to_np_array,
16
+ sort_dict_by_keys,
17
+ adjust_for_clock_change,
18
+ base_df,
19
+ df_filter,
20
+ df_cutoff,
21
+ drop_empty_df_cols,
22
+ melt_df,
23
+ unique_element_count,
24
+ non_numeric_pivot,
25
+ df_round_to_decimal,
26
+ make_dict_keys_from_list,
27
+ remove_df_index_name,
28
+ remove_df_column_name,
29
+ correct_str_elements_float,
30
+ correct_str_elements_int,
31
+
32
+ # DF TOOLS - Create df from JSON
33
+ create_df_from_json,
34
+ create_df_from_json_from_file,
35
+
36
+ # READ data - general file_types
37
+ read_from_csv,
38
+ read_from_xlsx,
39
+ read_from_parquet,
40
+
41
+ # READ data - HH Data into a dataframe
42
+ load_hh_data,
43
+
44
+ # SAVE data
45
+ save_to_csv,
46
+ save_to_xlsx,
47
+ save_to_parquet,
48
+
49
+ # INSPECT functions
50
+ get_call_func_name,
51
+ get_function_arguments,
52
+
53
+ # FILE READING tools
54
+ does_file_exist,
55
+ list_all_files_in_folder,
56
+ zip_checker,
57
+
58
+ # DATETIME - Helper funcs
59
+ is_year_leap_year,
60
+ get_daylight_savings_dates,
61
+ bst_date_range,
62
+ convert_single_datetime_to_sp_start,
63
+ convert_single_datetime_to_sp_end,
64
+
65
+ # DATETIME - Convert Datetime
66
+ convert_date_to_standard_date_str,
67
+ convert_date_to_datetime,
68
+ convert_datetime_to_date,
69
+ convert_date_to_datetime_str,
70
+ convert_date_to_first_of_month,
71
+ convert_date_to_last_of_month,
72
+ convert_datetime_remove_tz_aware,
73
+ convert_datetime_by_tz,
74
+ convert_datetime_sp_start,
75
+ convert_datetime_sp_end,
76
+
77
+ # DATETIME - Check Datetime
78
+ check_datetime_formats,
79
+ check_datetime_formats_tz,
80
+ check_string_datetime_formats,
81
+
82
+ # DATETIME - Adjust Dates
83
+ start_of_delivery_year,
84
+ roll_back_by_month_str,
85
+ roll_back_by_month_df,
86
+
87
+ # DATETIME - Add first-of-month-col
88
+ add_first_of_month_col_from_int_cols,
89
+ add_first_of_month_col_from_date_col,
90
+
91
+ # DATETIME - Month-start and Month-end
92
+ move_date_to_start_of_month,
93
+ move_date_to_end_of_month,
94
+
95
+ # SP_EFA
96
+ sp_to_efa,
97
+ hour_to_efa,
98
+ current_sp,
99
+ current_efa,
100
+ make_sp_efa_table,
101
+ convert_date_to_efa_datetime,
102
+ convert_datetime_to_date_and_efa,
103
+ make_sp_from_string,
104
+ make_efa_from_string,
105
+ add_sp_from_datetime_col,
106
+ add_sp_start_end_datetimes,
107
+ add_sp_to_efa_column,
108
+ add_efa_datetime_col,
109
+ add_date_efa_cols,
110
+ add_sp_and_efa_from_datetime,
111
+
112
+ # DATAFRAME SELECTION - Dataframe Augmentation
113
+ add_columns,
114
+ add_buffer_days,
115
+
116
+ # Dataframe Date Range Selection
117
+ select_year,
118
+ select_weeks,
119
+ select_days,
120
+
121
+ # Analysis and Plotting dataframes
122
+ make_full_year_pivot,
123
+ make_full_plotting_df,
124
+ make_pivot_calendar,
125
+
126
+ # DATAFRAME SELECTION - STRING date functions
127
+ week_starting,
128
+ week_number,
129
+ weekday_number,
130
+ day_of_the_year_number,
131
+
132
+ # ARRAY GENERAL functions
133
+ add_newaxis,
134
+
135
+ # ARRAY SELECTION functions
136
+ n_smallest_values_per_row,
137
+ n_largest_values_per_row,
138
+
139
+ # ONLINE tools
140
+ is_online
141
+
142
+ )
143
+
144
+
145
+ from ebtools.data import (
146
+
147
+ # Date lists for quick formatting
148
+ format_list_standard,
149
+ format_list_tz,
150
+
151
+ )
152
+
153
+
154
+ import ebtools.data as data
155
+
156
+
157
+ from ebtools._version import __version__
158
+
159
+
160
+ # Module level doc_string
161
+ __doc__ = """
162
+
163
+ Write a docstring here which sets out what each high level component of the
164
+ module does.
165
+
166
+ State the the docstrings of each high level component will suggest the best
167
+ ways to use that module, the most useful functions, and the right order in
168
+ which to use them.
169
+ """
ebtools/_version.py ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Wed Oct 25 00:02:20 2023
5
+
6
+ @author: eamonnbell
7
+ """
8
+
9
+
10
+ __version__ = '0.1.0'
11
+
12
+ __doc__ = """
13
+
14
+ 0.1.0 Initial release. Module refactored to provide consistency:
15
+ -- NumPy style docstrings throughout.
16
+ -- Type hints for all existing functions.
17
+ -- Usage examples for all functions.
18
+ -- Tests added for all public functions.
19
+ -- Functions broken out into smaller helper private funcs where
20
+ this is helpful for clarity and maintenance.
21
+
22
+ 0.0.2 Module general update:
23
+ -- ebtools.ebdicts RENAMED as ebtools.data
24
+ -- df_tools funcs (and others) rearranged.
25
+
26
+ 0.0.1 Module rearanged so that general functions are spread over multiple
27
+ different sub-files and that general becomes a sub-module.
28
+
29
+ 0.0.1 Module created. Module containing helper functions for use within
30
+ other modules, so that the same helper functions do not need to be
31
+ re-written time and again.
32
+
33
+ """
@@ -0,0 +1,38 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Created on Fri Mar 24 16:33:39 2023
4
+
5
+ @author: Eamonn.Bell
6
+ """
7
+
8
+ from ebtools.data.dno import (
9
+ # DNO
10
+ dno_codes,
11
+ dno_names,
12
+ dno_to_gsp_group
13
+ )
14
+
15
+ from ebtools.data.powerenergy import (
16
+ # Power and Energy
17
+ power_conversion
18
+ )
19
+
20
+ from ebtools.data.ukbankholidays import (
21
+ uk_bank_hols
22
+ )
23
+
24
+ from ebtools.data.ukclockchangedays import (
25
+ uk_clock_change_forward,
26
+ uk_clock_change_backward
27
+ )
28
+
29
+ from ebtools.data.units import (
30
+ unit_dict
31
+ )
32
+
33
+ from ebtools.data.dateformats import (
34
+
35
+ format_list_standard,
36
+ format_list_tz
37
+
38
+ )
@@ -0,0 +1,65 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Created on Wed May 26 17:24:12 2021
4
+
5
+ @author: Eamonn.Bell
6
+ """
7
+
8
+ """
9
+ These are standard lists of DATETIME FORMAT codes to check when importing
10
+ data from sources with possibly different datetime formats.
11
+
12
+ =============
13
+ Format Codes:
14
+ =============
15
+ The user may wish to compile their own format code list for usage in
16
+ specific situations. In that case, the user should build a list of
17
+ FORMAT strings based on the set of acceptable python FORMAT CODES to be
18
+ found at the following link under the heading "strftime() and strptime()
19
+ Format Codes":
20
+ https://docs.python.org/3/library/datetime.html
21
+
22
+ """
23
+
24
+ # Non-timezone-specific dates: the most common datetime occurance
25
+ format_list_standard = [
26
+
27
+ # Year-first date formats
28
+ '%Y-%m-%d',
29
+ '%y-%m-%d',
30
+
31
+ # Year-first with TIME formats
32
+ '%Y-%m-%dT%H:%M:%S',
33
+ '%Y-%m-%d %H:%M:%S',
34
+ '%Y-%m-%d %H:%M',
35
+
36
+ # Day-first formats
37
+ '%d-%m-%y',
38
+ '%d-%b-%y',
39
+ '%d-%b-%Y',
40
+ '%d-%m-%Y',
41
+ '%d/%m/%Y',
42
+ '%d/%m/%y',
43
+
44
+ # Datetime formats
45
+ '%d/%m/%Y %H:%M',
46
+ '%d/%m/%Y %H:%M:%S'
47
+
48
+ ]
49
+
50
+ # Timezone-specific dates: when there is a timezone element in the datetime
51
+ format_list_tz = [
52
+
53
+ # Format code strings registering ZULU time (GMT)
54
+ '%Y-%m-%dT%H:%M:%SZ',
55
+ '%Y-%m-%dT%H:%M:%S Z',
56
+ '%Y-%m-%d %H:%M:%SZ',
57
+ '%Y-%m-%d %H:%M:%S Z',
58
+
59
+ # Format code strings with a UTC OFFSET: +01:00 / -0600 / etc
60
+ '%Y-%m-%dT%H:%M:%S%z',
61
+ '%Y-%m-%dT%H:%M:%S %z',
62
+ '%Y-%m-%d %H:%M:%S%z',
63
+ '%Y-%m-%d %H:%M:%S %z'
64
+ ]
65
+
ebtools/data/dno.py ADDED
@@ -0,0 +1,103 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Created on Mon Nov 19 14:09:47 2018
4
+
5
+ @author: Eamonn_Bell
6
+ This file contains the set of lists and dictionaries which may be useful.
7
+
8
+ """
9
+
10
+
11
+
12
+ """
13
+ ******************************************************************************
14
+ ******************************************************************************
15
+
16
+ # ---- DNO data
17
+
18
+ Region Names & GSP Group look-up codes
19
+
20
+ ******************************************************************************
21
+ ******************************************************************************
22
+ """
23
+
24
+
25
+ # Sources for the names and MPAS Operator IDs for each Licenced Distribution
26
+ # Network Owner (LDNO) come from:
27
+ # -- https://en.wikipedia.org/wiki/Distribution_network_operator
28
+ # -- https://www.elexonportal.co.uk/svallf
29
+ dno_codes = {
30
+ 10 : 'EELC',
31
+ 11 : 'EMEB',
32
+ 12 : 'LOND',
33
+ 13 : 'MANW',
34
+ 14 : 'MIDE',
35
+ 15 : 'NEEB',
36
+ 16 : 'NORW',
37
+ 17 : 'HYDE',
38
+ 18 : 'SPOW',
39
+ 19 : 'SEEB',
40
+ 20 : 'SOUT',
41
+ 21 : 'SWAE',
42
+ 22 : 'SWEB',
43
+ 23 : 'YELG',
44
+ 24 : 'IPNL',
45
+ 25 : 'LENG',
46
+ 26 : 'GUCL',
47
+ 27 : 'ETCL',
48
+ 28 : 'EDFI',
49
+ 29 : 'HARL',
50
+ 30 : 'PENL',
51
+ 31 : 'UKPD',
52
+ 32 : 'UDNL',
53
+ 33 : 'GGEN',
54
+ 34 : 'MPDL',
55
+ 35 : 'FEAL',
56
+ 36 : 'VATT',
57
+ 37 : 'FORB',
58
+ 38 : 'INDI'
59
+ }
60
+
61
+ dno_names = {
62
+ 10 : 'Eastern England',
63
+ 11 : 'East Midlands',
64
+ 12 : 'London',
65
+ 13 : 'Merseyside and Northern Wales',
66
+ 14 : 'West Midlands',
67
+ 15 : 'North Eastern England',
68
+ 16 : 'North Western_England',
69
+ 17 : 'Northern Scotland',
70
+ 18 : 'Southern Scotland',
71
+ 19 : 'South Eastern England',
72
+ 20 : 'Southern England',
73
+ 21 : 'Southern_Wales',
74
+ 22 : 'South Western England',
75
+ 23 : 'Yorkshire'
76
+ }
77
+
78
+ dno_to_gsp_group = {
79
+ 10 : '_A',
80
+ 11 : '_B',
81
+ 12 : '_C',
82
+ 13 : '_D',
83
+ 14 : '_E',
84
+ 15 : '_F',
85
+ 16 : '_G',
86
+ 17 : '_P',
87
+ 18 : '_N',
88
+ 19 : '_J',
89
+ 20 : '_H',
90
+ 21 : '_K',
91
+ 22 : '_L',
92
+ 23 : '_M'
93
+ }
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
@@ -0,0 +1,19 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Created on Tue Apr 4 17:40:57 2023
4
+
5
+ @author: Eamonn.Bell
6
+ """
7
+
8
+
9
+ # =============================================================================
10
+ # ---- Power conversion factors
11
+ # =============================================================================
12
+
13
+ # Dictionary to convert power units from one scale to another
14
+ power_conversion = {
15
+ 'W' : 1,
16
+ 'kW' : 10**3,
17
+ 'MW' : 10**6,
18
+ 'GW' : 10**9,
19
+ }
@@ -0,0 +1,181 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Created on Tue Apr 4 17:37:15 2023
4
+
5
+ @author: Eamonn.Bell
6
+ """
7
+
8
+ # =============================================================================
9
+ # ---- UK Bank Holidays
10
+ # =============================================================================
11
+
12
+ # Maintain a list of UK Bank Holidays here.
13
+ #
14
+ # The official source for UK Bank Holidays is:
15
+ # https://www.gov.uk/bank-holidays
16
+ # At this gov.uk site the list of UK bank holidays is available from 2016
17
+ # to one year ahead of the current year.
18
+ #
19
+ # For Bank Holidays ahead of the current and next year, dates are gathered
20
+ # from the Gottex multi-year calendar. A version is available here:
21
+ # https://vdocuments.site/gottex-calendar.html
22
+ # These dates should be indicated as being 'Unconfirmed' and should be
23
+ # confirmed closer to realtime via the gov.uk website above.
24
+
25
+ uk_bank_hols = [
26
+ # Confirmed
27
+ '2016-01-01',
28
+ '2016-03-25',
29
+ '2016-03-28',
30
+ '2016-05-02',
31
+ '2016-05-30',
32
+ '2016-08-29',
33
+ '2016-12-26',
34
+ '2016-12-27',
35
+
36
+ # Confirmed
37
+ '2017-01-02',
38
+ '2017-04-14',
39
+ '2017-04-17',
40
+ '2017-05-01',
41
+ '2017-05-29',
42
+ '2017-08-28',
43
+ '2017-12-25',
44
+ '2017-12-26',
45
+
46
+ # Confirmed
47
+ '2018-01-01',
48
+ '2018-03-30',
49
+ '2018-04-02',
50
+ '2018-05-07',
51
+ '2018-05-28',
52
+ '2018-08-27',
53
+ '2018-12-25',
54
+ '2018-12-26',
55
+
56
+ # Confirmed
57
+ '2019-01-01',
58
+ '2019-04-19',
59
+ '2019-04-22',
60
+ '2019-05-06',
61
+ '2019-05-27',
62
+ '2019-08-26',
63
+ '2019-12-25',
64
+ '2019-12-26',
65
+
66
+ # Confirmed
67
+ '2020-01-01',
68
+ '2020-04-10',
69
+ '2020-04-13',
70
+ '2020-05-08',
71
+ '2020-05-25',
72
+ '2020-08-31',
73
+ '2020-12-25',
74
+ '2020-12-28',
75
+
76
+ # Confirmed
77
+ # 2021 Bank Holiday days with description to compare with 2022.
78
+ '2021-01-01', # New Year's Day
79
+ '2021-04-02', # Good Friday
80
+ '2021-04-05', # Easter Monday
81
+ '2021-05-03', # Early May Bank Holiday
82
+ '2021-05-31', # Spring Bank Holiday
83
+ '2021-08-30', # Summer Bank Holiday
84
+ '2021-12-27', # Christmas Day (substitute day)
85
+ '2021-12-28', # Boxing Day (substitute day)
86
+
87
+ # Confirmed
88
+ # 2022 will have TWO EXTRA BANK HOLIDAYS - Queen's Platinum Jubilee Year
89
+ '2022-01-03', # New Year's Day
90
+ '2022-04-15', # Good Friday
91
+ '2022-04-18', # Easter Monday
92
+ '2022-05-02', # Early May Bank Holiday
93
+ '2022-06-02', # Spring Bank Holiday
94
+ '2022-06-03', # Platinum Jubilee Bank Holiday <--- EXTRA BANK HOLIDAY
95
+ '2022-08-29', # Summer Bank Holiday
96
+ '2022-09-19', # Queen's State Funeral <--- EXTRA BANK HOLIDAY
97
+ '2022-12-26', # Boxing Day
98
+ '2022-12-27', # Christmas Day (substitute day)
99
+
100
+ # Confirmed
101
+ # 2023 will have AN EXTRA BANK HOLIDAY - Conronation of Charles III
102
+ '2023-01-02', # New Year's Day
103
+ '2023-04-07', # Good Friday
104
+ '2023-04-10', # Easter Monday
105
+ '2023-05-01', # Early May Bank Holiday
106
+ '2023-05-08', # Bank Holiday for the coronation of King Charles III <--- EXTRA BANK HOLIDAY
107
+ '2023-05-29', # Spring Bank Holiday
108
+ '2023-08-28', # Summer Bank Holiday
109
+ '2023-12-25', # Christmas Day
110
+ '2023-12-26', # Boxing Day
111
+
112
+ # Confirmed
113
+ '2024-01-01', # New Year's Day
114
+ '2024-03-29', # Good Friday
115
+ '2024-04-01', # Easter Monday
116
+ '2024-05-06', # Early May Bank Holiday
117
+ '2024-05-27', # Spring Bank Holiday
118
+ '2024-08-26', # Summer Bank Holiday
119
+ '2024-12-25', # Christmas Day
120
+ '2024-12-26', # Boxing Day
121
+
122
+ # Confirmed
123
+ '2025-01-01', # New Year's Day
124
+ '2025-04-18', # Good Friday
125
+ '2025-04-21', # Easter Monday
126
+ '2025-05-05', # Early May Bank Holiday
127
+ '2025-05-26', # Spring Bank Holiday
128
+ '2025-08-25', # Summer Bank Holiday
129
+ '2025-12-25', # Christmas Day
130
+ '2025-12-26', # Boxing Day
131
+
132
+ ## Unconfirmed
133
+ '2026-01-01',
134
+ '2026-04-03',
135
+ '2026-04-06',
136
+ '2026-05-04',
137
+ '2026-05-25',
138
+ '2026-08-31',
139
+ '2026-12-25',
140
+ '2026-12-28',
141
+
142
+ ## Unconfirmed
143
+ '2027-01-01',
144
+ '2027-03-26',
145
+ '2027-03-29',
146
+ '2027-05-03',
147
+ '2027-05-21',
148
+ '2027-08-30',
149
+ '2027-12-27',
150
+ '2027-12-28',
151
+
152
+ ## Unconfirmed
153
+ '2028-01-03',
154
+ '2028-04-14',
155
+ '2028-04-17',
156
+ '2028-05-01',
157
+ '2028-05-29',
158
+ '2028-08-28',
159
+ '2028-12-25',
160
+ '2028-12-26',
161
+
162
+ ## Unconfirmed
163
+ '2029-01-01',
164
+ '2029-03-30',
165
+ '2029-04-02',
166
+ '2029-05-07',
167
+ '2029-05-28',
168
+ '2029-08-27',
169
+ '2029-12-25',
170
+ '2029-12-26',
171
+
172
+ ## Unconfirmed
173
+ '2030-01-01',
174
+ '2030-04-19',
175
+ '2030-04-22',
176
+ '2030-05-06',
177
+ '2030-05-27',
178
+ '2030-08-26',
179
+ '2030-12-25',
180
+ '2030-12-26'
181
+ ]