direl-ts-tool-kit 0.2.0__py3-none-any.whl → 0.2.2__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.
- direl_ts_tool_kit/__init__.py +1 -0
- direl_ts_tool_kit/plot/plot_ts.py +50 -0
- direl_ts_tool_kit/utilities/__init__.py +1 -0
- direl_ts_tool_kit/utilities/data_prep.py +35 -0
- {direl_ts_tool_kit-0.2.0.dist-info → direl_ts_tool_kit-0.2.2.dist-info}/METADATA +3 -2
- direl_ts_tool_kit-0.2.2.dist-info/RECORD +11 -0
- direl_ts_tool_kit-0.2.0.dist-info/RECORD +0 -9
- {direl_ts_tool_kit-0.2.0.dist-info → direl_ts_tool_kit-0.2.2.dist-info}/WHEEL +0 -0
- {direl_ts_tool_kit-0.2.0.dist-info → direl_ts_tool_kit-0.2.2.dist-info}/licenses/LICENCE +0 -0
- {direl_ts_tool_kit-0.2.0.dist-info → direl_ts_tool_kit-0.2.2.dist-info}/top_level.txt +0 -0
direl_ts_tool_kit/__init__.py
CHANGED
|
@@ -41,6 +41,16 @@ def plot_time_series(
|
|
|
41
41
|
-----
|
|
42
42
|
Major grid lines are displayed with a dashed line ('--'), and minor grid
|
|
43
43
|
lines are displayed with a dotted line (':') for detailed temporal analysis.
|
|
44
|
+
|
|
45
|
+
Available Colors
|
|
46
|
+
----------------
|
|
47
|
+
The 'color' parameter accepts any key from the 'paper_colors' dictionary.
|
|
48
|
+
|
|
49
|
+
Lines: 'BLUE_LINES', 'ORANGE_LINES', 'GREEN_LINES', 'RED_LINES',
|
|
50
|
+
'GRAY_LINES', 'PURPLE_LINES', 'MAROON_LINES', 'GOLD_LINES'.
|
|
51
|
+
|
|
52
|
+
Bars: 'BLUE_BARS', 'ORANGE_BARS', 'GREEN_BARS', 'RED_BARS',
|
|
53
|
+
'GRAY_BARS', 'PURPLE_BARS', 'MAROON_BARS', 'GOLD_BARS'.
|
|
44
54
|
"""
|
|
45
55
|
|
|
46
56
|
fig, ax = plt.subplots()
|
|
@@ -97,3 +107,43 @@ def plot_time_series(
|
|
|
97
107
|
ax.grid(which="major", alpha=0.8, linestyle="--")
|
|
98
108
|
|
|
99
109
|
return fig
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def save_figure(
|
|
113
|
+
fig,
|
|
114
|
+
file_name,
|
|
115
|
+
variable_name="",
|
|
116
|
+
path="./",
|
|
117
|
+
):
|
|
118
|
+
"""
|
|
119
|
+
Saves a Matplotlib figure in three common high-quality formats (PNG, PDF, SVG).
|
|
120
|
+
|
|
121
|
+
The function creates a consistent file name structure:
|
|
122
|
+
{path}/{file_name}_{variable_name}.{extension}.
|
|
123
|
+
|
|
124
|
+
Parameters
|
|
125
|
+
----------
|
|
126
|
+
fig : matplotlib.figure.Figure
|
|
127
|
+
The Matplotlib figure object to be saved.
|
|
128
|
+
file_name : str
|
|
129
|
+
The primary name for the file (e.g., 'timeseries_report').
|
|
130
|
+
variable_name : str, optional
|
|
131
|
+
An optional secondary name, often the name of the plotted variable,
|
|
132
|
+
to be appended to the file name. Defaults to "".
|
|
133
|
+
path : str, optional
|
|
134
|
+
The directory path where the figure files will be saved.
|
|
135
|
+
Defaults to the current directory ('./').
|
|
136
|
+
|
|
137
|
+
Returns
|
|
138
|
+
-------
|
|
139
|
+
None
|
|
140
|
+
"""
|
|
141
|
+
|
|
142
|
+
if variable_name:
|
|
143
|
+
base_name = f"{path}/{file_name}_{variable_name}"
|
|
144
|
+
else:
|
|
145
|
+
base_name = f"{path}/{file_name}"
|
|
146
|
+
|
|
147
|
+
fig.savefig(f"{base_name}.png")
|
|
148
|
+
fig.savefig(f"{base_name}.pdf")
|
|
149
|
+
fig.savefig(f"{base_name}.svg")
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .data_prep import *
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def parse_datetime_index(df_raw, date_column="date"):
|
|
5
|
+
"""
|
|
6
|
+
Parses a specified column into datetime objects and sets it as the DataFrame index.
|
|
7
|
+
|
|
8
|
+
This function is crucial for preparing raw data (df_raw) for time series analysis
|
|
9
|
+
by ensuring the DataFrame is indexed by the correct datetime type.
|
|
10
|
+
|
|
11
|
+
Parameters
|
|
12
|
+
----------
|
|
13
|
+
df_raw : pd.DataFrame
|
|
14
|
+
The raw DataFrame containing the data, including the column with date strings.
|
|
15
|
+
date_column : str, optional
|
|
16
|
+
The name of the column in 'df_raw' that contains the date/time information.
|
|
17
|
+
Defaults to "date".
|
|
18
|
+
|
|
19
|
+
Returns
|
|
20
|
+
-------
|
|
21
|
+
df_ts : pd.DataFrame
|
|
22
|
+
A copy of the original DataFrame with the specified date column removed
|
|
23
|
+
and set as the DatetimeIndex. Ready for time series plotting.
|
|
24
|
+
original_dates : pd.Series
|
|
25
|
+
The original Series containing the date strings/objects, which was used
|
|
26
|
+
to create the new index.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
date_parsed = pd.to_datetime(df_raw[date_column])
|
|
30
|
+
df_ts = df_raw.copy()
|
|
31
|
+
original_dates = df_raw[date_column]
|
|
32
|
+
df_ts.drop(columns=[date_column], inplace=True)
|
|
33
|
+
df_ts.set_index(date_parsed, inplace=True)
|
|
34
|
+
|
|
35
|
+
return df_ts, original_dates
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: direl-ts-tool-kit
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: A toolbox for time series analysis and visualization.
|
|
5
5
|
Home-page: https://gitlab.com/direl/direl_tool_kit
|
|
6
|
-
Author:
|
|
6
|
+
Author: Diego Restrepo-Leal
|
|
7
7
|
Author-email: diegorestrepoleal@gmail.com
|
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
|
9
9
|
Classifier: Programming Language :: Python :: 3.9
|
|
@@ -17,6 +17,7 @@ License-File: LICENCE
|
|
|
17
17
|
Requires-Dist: pandas>=1.0.0
|
|
18
18
|
Requires-Dist: numpy>=1.18.0
|
|
19
19
|
Requires-Dist: matplotlib>=3.0.0
|
|
20
|
+
Requires-Dist: openpyxl
|
|
20
21
|
Dynamic: author
|
|
21
22
|
Dynamic: author-email
|
|
22
23
|
Dynamic: classifier
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
direl_ts_tool_kit/__init__.py,sha256=W99Wd3BeEFKOxT51TApURElbDJvqIjD8u_-qDoCYSJ0,94
|
|
2
|
+
direl_ts_tool_kit/plot/__init__.py,sha256=CMwyv-kiE74nwr3MJPL7gWIJmcfZ8UQCRu7mBGGQ4rI,49
|
|
3
|
+
direl_ts_tool_kit/plot/plot_style.py,sha256=vhzcDa3LzgkHuy-GnliofGZ8TDntkm3_1C5kgl2Gx3E,1010
|
|
4
|
+
direl_ts_tool_kit/plot/plot_ts.py,sha256=uYkPWz-8aWIjZGW22n5uH19CYHv-bLGrZaHPW9f3-3I,4814
|
|
5
|
+
direl_ts_tool_kit/utilities/__init__.py,sha256=jMtxYZUtwlhgI99sxe_8MMzsDnxtbTP7Ivh9tUOeIwQ,25
|
|
6
|
+
direl_ts_tool_kit/utilities/data_prep.py,sha256=KqVICzfjvsQqbekYiL21MLdno6spjwzF2PXCv6D-kNc,1225
|
|
7
|
+
direl_ts_tool_kit-0.2.2.dist-info/licenses/LICENCE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
direl_ts_tool_kit-0.2.2.dist-info/METADATA,sha256=SwDvWNWSkGCfMnU6UlieG9lurQsvUZoeTxmFZjia-VA,950
|
|
9
|
+
direl_ts_tool_kit-0.2.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
10
|
+
direl_ts_tool_kit-0.2.2.dist-info/top_level.txt,sha256=vMCRudnGnsdRg_6fUftnG8PF2Y1m0bjBDMf3pCAp6bc,18
|
|
11
|
+
direl_ts_tool_kit-0.2.2.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
direl_ts_tool_kit/__init__.py,sha256=E7sCCqFQm9KG6fdpVX7vdVK1QIMPlygEyS_6hqpN1Bw,59
|
|
2
|
-
direl_ts_tool_kit/plot/__init__.py,sha256=CMwyv-kiE74nwr3MJPL7gWIJmcfZ8UQCRu7mBGGQ4rI,49
|
|
3
|
-
direl_ts_tool_kit/plot/plot_style.py,sha256=vhzcDa3LzgkHuy-GnliofGZ8TDntkm3_1C5kgl2Gx3E,1010
|
|
4
|
-
direl_ts_tool_kit/plot/plot_ts.py,sha256=MopIqV4uBaJ9wCdjOhuKaiW5McmXejoA2Co46DzAiIQ,3334
|
|
5
|
-
direl_ts_tool_kit-0.2.0.dist-info/licenses/LICENCE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
-
direl_ts_tool_kit-0.2.0.dist-info/METADATA,sha256=D0pY1HYO1EClxT0wlr9i1urdHWNjYoIpY_KRuJuEu2E,922
|
|
7
|
-
direl_ts_tool_kit-0.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
8
|
-
direl_ts_tool_kit-0.2.0.dist-info/top_level.txt,sha256=vMCRudnGnsdRg_6fUftnG8PF2Y1m0bjBDMf3pCAp6bc,18
|
|
9
|
-
direl_ts_tool_kit-0.2.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|