direl-ts-tool-kit 0.8.0__py3-none-any.whl → 0.9.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.
- direl_ts_tool_kit/plot/plot_ts.py +76 -0
- {direl_ts_tool_kit-0.8.0.dist-info → direl_ts_tool_kit-0.9.0.dist-info}/METADATA +23 -1
- {direl_ts_tool_kit-0.8.0.dist-info → direl_ts_tool_kit-0.9.0.dist-info}/RECORD +6 -6
- {direl_ts_tool_kit-0.8.0.dist-info → direl_ts_tool_kit-0.9.0.dist-info}/licenses/LICENCE +0 -0
- {direl_ts_tool_kit-0.8.0.dist-info → direl_ts_tool_kit-0.9.0.dist-info}/top_level.txt +0 -0
- {direl_ts_tool_kit-0.8.0.dist-info → direl_ts_tool_kit-0.9.0.dist-info}/WHEEL +0 -0
|
@@ -2,6 +2,7 @@ import numpy as np
|
|
|
2
2
|
import pandas as pd
|
|
3
3
|
from .plot_style import *
|
|
4
4
|
from scipy.stats import pearsonr
|
|
5
|
+
from scipy.signal import periodogram
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
def plot_time_series(
|
|
@@ -548,3 +549,78 @@ def plot_data_boxplot(
|
|
|
548
549
|
ax.tick_params(axis="x")
|
|
549
550
|
|
|
550
551
|
return fig
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
def plot_periodogram(
|
|
555
|
+
ts,
|
|
556
|
+
detrend="linear",
|
|
557
|
+
ax=None,
|
|
558
|
+
fs=365.0,
|
|
559
|
+
color="BLUE_LINES",
|
|
560
|
+
):
|
|
561
|
+
"""
|
|
562
|
+
Plots the power spectrum (periodogram) of a time series to identify
|
|
563
|
+
dominant frequencies (periodicity).
|
|
564
|
+
|
|
565
|
+
Parameters
|
|
566
|
+
----------
|
|
567
|
+
ts : pd.Series or np.ndarray
|
|
568
|
+
The time series data to analyze.
|
|
569
|
+
detrend : str, optional
|
|
570
|
+
Method to remove the linear trend ('linear' or 'constant'). Defaults to 'linear'.
|
|
571
|
+
ax : matplotlib.axes.Axes, optional
|
|
572
|
+
Existing Axes to draw the plot on. If None, a new figure and axes are created.
|
|
573
|
+
fs : float, optional
|
|
574
|
+
The sampling frequency of the time series (cycles per unit of time).
|
|
575
|
+
Default value 365.0 assumes daily data, leading to frequencies in cycles/year.
|
|
576
|
+
color : str, optional
|
|
577
|
+
Key corresponding to the line color in the global 'paper_colors' dictionary.
|
|
578
|
+
Defaults to "BLUE_LINES".
|
|
579
|
+
|
|
580
|
+
Returns
|
|
581
|
+
-------
|
|
582
|
+
matplotlib.figure.Figure
|
|
583
|
+
The generated Matplotlib Figure object.
|
|
584
|
+
|
|
585
|
+
Notes
|
|
586
|
+
-----
|
|
587
|
+
The X-axis labels are hardcoded to common periodicities (Annual, Monthly, Weekly)
|
|
588
|
+
and assume a sampling frequency of 365.0 (daily data).
|
|
589
|
+
"""
|
|
590
|
+
|
|
591
|
+
freqencies, spectrum = periodogram(
|
|
592
|
+
ts,
|
|
593
|
+
fs=fs,
|
|
594
|
+
detrend=detrend,
|
|
595
|
+
window="boxcar",
|
|
596
|
+
scaling="spectrum",
|
|
597
|
+
)
|
|
598
|
+
|
|
599
|
+
if ax is None:
|
|
600
|
+
fig, ax = plt.subplots()
|
|
601
|
+
else:
|
|
602
|
+
fig = ax.figure
|
|
603
|
+
|
|
604
|
+
ax.step(freqencies, spectrum, linewidth=3, color=paper_colors[color])
|
|
605
|
+
ax.set_xscale("log")
|
|
606
|
+
ax.set_xticks([1, 2, 4, 6, 12, 26, 52, 104])
|
|
607
|
+
|
|
608
|
+
ax.set_xticklabels(
|
|
609
|
+
[
|
|
610
|
+
"Annual (1)",
|
|
611
|
+
"Semiannual (2)",
|
|
612
|
+
"Quarterly (4)",
|
|
613
|
+
"Bimonthly (6)",
|
|
614
|
+
"Monthly (12)",
|
|
615
|
+
"Biweekly (26)",
|
|
616
|
+
"Weekly (52)",
|
|
617
|
+
"Semiweekly (104)",
|
|
618
|
+
],
|
|
619
|
+
rotation=90,
|
|
620
|
+
)
|
|
621
|
+
|
|
622
|
+
ax.ticklabel_format(axis="y", style="sci", scilimits=(0, 0))
|
|
623
|
+
ax.set_ylabel("Variance")
|
|
624
|
+
ax.grid(alpha=0.8, linestyle="--")
|
|
625
|
+
|
|
626
|
+
return fig
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: direl-ts-tool-kit
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.9.0
|
|
4
4
|
Summary: A toolbox for time series analysis and visualization.
|
|
5
5
|
Home-page: https://gitlab.com/direl/direl_tool_kit
|
|
6
6
|
Author: Diego Restrepo-Leal
|
|
@@ -89,6 +89,7 @@ This function automatically sets major and minor time-based locators
|
|
|
89
89
|
on the x-axis based on the specified time unit, and formats the y-axis
|
|
90
90
|
to use scientific notation.
|
|
91
91
|
|
|
92
|
+
|
|
92
93
|
#### plot_interpolation_analysis
|
|
93
94
|
`plot_interpolation_analysis(df_original, variable, units="", method="polynomial", order=2, imputation_se=None, time_unit="Year", rot=90)`
|
|
94
95
|
|
|
@@ -105,6 +106,7 @@ Saves a Matplotlib figure in three common high-quality formats (PNG, PDF, SVG).
|
|
|
105
106
|
The function creates a consistent file name structure:
|
|
106
107
|
{path}/{file_name}_{variable_name}.{extension}.
|
|
107
108
|
|
|
109
|
+
|
|
108
110
|
#### heat_map
|
|
109
111
|
`heat_map(X, y, colors="Blues")`
|
|
110
112
|
|
|
@@ -113,6 +115,7 @@ Generates a correlation heatmap plot for a set of features and a target variable
|
|
|
113
115
|
This function concatenates the feature DataFrame (X) and the target Series (y)
|
|
114
116
|
to compute and visualize the full pairwise correlation matrix using Seaborn.
|
|
115
117
|
|
|
118
|
+
|
|
116
119
|
#### pair_plot
|
|
117
120
|
`pair_plot(X, y)`
|
|
118
121
|
|
|
@@ -133,6 +136,25 @@ Generates a histogram plot for a specified numerical variable.
|
|
|
133
136
|
The plot visualizes the distribution of the data, with the Y-axis dynamically
|
|
134
137
|
labeled as 'Density' or 'Count' based on the `density` parameter.
|
|
135
138
|
|
|
139
|
+
|
|
140
|
+
#### plot_data_boxplot
|
|
141
|
+
`plot_data_boxplot(df, variable=None, x_label="", y_label="", grid=False, notch=False)`
|
|
142
|
+
|
|
143
|
+
Generates a boxplot visualization, either for all numerical columns in the
|
|
144
|
+
DataFrame or for a single specified variable.
|
|
145
|
+
|
|
146
|
+
The function applies consistent styling for the boxes, outliers, and median
|
|
147
|
+
lines using predefined colors from 'paper_colors'.
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
#### plot_periodogram
|
|
151
|
+
|
|
152
|
+
`plot_periodogram(ts, detrend="linear", ax=None, fs=365.0, color="BLUE_LINES")`
|
|
153
|
+
|
|
154
|
+
Plots the power spectrum (periodogram) of a time series to identify
|
|
155
|
+
dominant frequencies (periodicity).
|
|
156
|
+
|
|
157
|
+
|
|
136
158
|
# Examples
|
|
137
159
|
- [Example 1](https://gitlab.com/direl/direl_tool_kit/-/blob/main/example/example_01.md?ref_type=heads)
|
|
138
160
|
- [Example 2](https://gitlab.com/direl/direl_tool_kit/-/blob/main/example/example_02.md?ref_type=heads)
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
direl_ts_tool_kit/__init__.py,sha256=W99Wd3BeEFKOxT51TApURElbDJvqIjD8u_-qDoCYSJ0,94
|
|
2
2
|
direl_ts_tool_kit/plot/__init__.py,sha256=CMwyv-kiE74nwr3MJPL7gWIJmcfZ8UQCRu7mBGGQ4rI,49
|
|
3
3
|
direl_ts_tool_kit/plot/plot_style.py,sha256=5YxoLXlYvzleTnBEGPwCmHQIJ0S96KPJspq_n-qMvpw,1069
|
|
4
|
-
direl_ts_tool_kit/plot/plot_ts.py,sha256=
|
|
4
|
+
direl_ts_tool_kit/plot/plot_ts.py,sha256=jAb_EruXvj0FIhvdm4BSqnGXY8dBAoPPusLE15owrwQ,19443
|
|
5
5
|
direl_ts_tool_kit/utilities/__init__.py,sha256=jMtxYZUtwlhgI99sxe_8MMzsDnxtbTP7Ivh9tUOeIwQ,25
|
|
6
6
|
direl_ts_tool_kit/utilities/data_prep.py,sha256=k3eOwQEEd5mxy2DtT_Gdo7BhkzEmSQqvMJ89y8mH5CQ,6024
|
|
7
|
-
direl_ts_tool_kit-0.
|
|
8
|
-
direl_ts_tool_kit-0.
|
|
9
|
-
direl_ts_tool_kit-0.
|
|
10
|
-
direl_ts_tool_kit-0.
|
|
11
|
-
direl_ts_tool_kit-0.
|
|
7
|
+
direl_ts_tool_kit-0.9.0.dist-info/licenses/LICENCE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
direl_ts_tool_kit-0.9.0.dist-info/METADATA,sha256=yGjaOHA9e78QX2x1YbEnDWeqMl-Cf2_Z9z7czZaLt20,5773
|
|
9
|
+
direl_ts_tool_kit-0.9.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
10
|
+
direl_ts_tool_kit-0.9.0.dist-info/top_level.txt,sha256=vMCRudnGnsdRg_6fUftnG8PF2Y1m0bjBDMf3pCAp6bc,18
|
|
11
|
+
direl_ts_tool_kit-0.9.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|