direl-ts-tool-kit 0.8.1__py3-none-any.whl → 0.9.1__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 +80 -1
- {direl_ts_tool_kit-0.8.1.dist-info → direl_ts_tool_kit-0.9.1.dist-info}/METADATA +13 -1
- {direl_ts_tool_kit-0.8.1.dist-info → direl_ts_tool_kit-0.9.1.dist-info}/RECORD +6 -6
- {direl_ts_tool_kit-0.8.1.dist-info → direl_ts_tool_kit-0.9.1.dist-info}/WHEEL +1 -1
- {direl_ts_tool_kit-0.8.1.dist-info → direl_ts_tool_kit-0.9.1.dist-info}/licenses/LICENCE +0 -0
- {direl_ts_tool_kit-0.8.1.dist-info → direl_ts_tool_kit-0.9.1.dist-info}/top_level.txt +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(
|
|
@@ -12,6 +13,7 @@ def plot_time_series(
|
|
|
12
13
|
time_unit="Year",
|
|
13
14
|
rot=90,
|
|
14
15
|
auto_format_label=True,
|
|
16
|
+
sci=False
|
|
15
17
|
):
|
|
16
18
|
"""
|
|
17
19
|
Plots a time series with custom styling and dual-level grid visibility.
|
|
@@ -92,7 +94,9 @@ def plot_time_series(
|
|
|
92
94
|
)
|
|
93
95
|
|
|
94
96
|
ax.set(xlabel=f"{time_unit}", ylabel=f"{variable} {units}")
|
|
95
|
-
|
|
97
|
+
|
|
98
|
+
if sci==True:
|
|
99
|
+
ax.ticklabel_format(style="sci", axis="y", scilimits=(0, 0))
|
|
96
100
|
|
|
97
101
|
if time_unit == "Year":
|
|
98
102
|
ax.xaxis.set_major_locator(mdates.YearLocator())
|
|
@@ -548,3 +552,78 @@ def plot_data_boxplot(
|
|
|
548
552
|
ax.tick_params(axis="x")
|
|
549
553
|
|
|
550
554
|
return fig
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
def plot_periodogram(
|
|
558
|
+
ts,
|
|
559
|
+
detrend="linear",
|
|
560
|
+
ax=None,
|
|
561
|
+
fs=365.0,
|
|
562
|
+
color="BLUE_LINES",
|
|
563
|
+
):
|
|
564
|
+
"""
|
|
565
|
+
Plots the power spectrum (periodogram) of a time series to identify
|
|
566
|
+
dominant frequencies (periodicity).
|
|
567
|
+
|
|
568
|
+
Parameters
|
|
569
|
+
----------
|
|
570
|
+
ts : pd.Series or np.ndarray
|
|
571
|
+
The time series data to analyze.
|
|
572
|
+
detrend : str, optional
|
|
573
|
+
Method to remove the linear trend ('linear' or 'constant'). Defaults to 'linear'.
|
|
574
|
+
ax : matplotlib.axes.Axes, optional
|
|
575
|
+
Existing Axes to draw the plot on. If None, a new figure and axes are created.
|
|
576
|
+
fs : float, optional
|
|
577
|
+
The sampling frequency of the time series (cycles per unit of time).
|
|
578
|
+
Default value 365.0 assumes daily data, leading to frequencies in cycles/year.
|
|
579
|
+
color : str, optional
|
|
580
|
+
Key corresponding to the line color in the global 'paper_colors' dictionary.
|
|
581
|
+
Defaults to "BLUE_LINES".
|
|
582
|
+
|
|
583
|
+
Returns
|
|
584
|
+
-------
|
|
585
|
+
matplotlib.figure.Figure
|
|
586
|
+
The generated Matplotlib Figure object.
|
|
587
|
+
|
|
588
|
+
Notes
|
|
589
|
+
-----
|
|
590
|
+
The X-axis labels are hardcoded to common periodicities (Annual, Monthly, Weekly)
|
|
591
|
+
and assume a sampling frequency of 365.0 (daily data).
|
|
592
|
+
"""
|
|
593
|
+
|
|
594
|
+
freqencies, spectrum = periodogram(
|
|
595
|
+
ts,
|
|
596
|
+
fs=fs,
|
|
597
|
+
detrend=detrend,
|
|
598
|
+
window="boxcar",
|
|
599
|
+
scaling="spectrum",
|
|
600
|
+
)
|
|
601
|
+
|
|
602
|
+
if ax is None:
|
|
603
|
+
fig, ax = plt.subplots()
|
|
604
|
+
else:
|
|
605
|
+
fig = ax.figure
|
|
606
|
+
|
|
607
|
+
ax.step(freqencies, spectrum, linewidth=3, color=paper_colors[color])
|
|
608
|
+
ax.set_xscale("log")
|
|
609
|
+
ax.set_xticks([1, 2, 4, 6, 12, 26, 52, 104])
|
|
610
|
+
|
|
611
|
+
ax.set_xticklabels(
|
|
612
|
+
[
|
|
613
|
+
"Annual (1)",
|
|
614
|
+
"Semiannual (2)",
|
|
615
|
+
"Quarterly (4)",
|
|
616
|
+
"Bimonthly (6)",
|
|
617
|
+
"Monthly (12)",
|
|
618
|
+
"Biweekly (26)",
|
|
619
|
+
"Weekly (52)",
|
|
620
|
+
"Semiweekly (104)",
|
|
621
|
+
],
|
|
622
|
+
rotation=90,
|
|
623
|
+
)
|
|
624
|
+
|
|
625
|
+
ax.ticklabel_format(axis="y", style="sci", scilimits=(0, 0))
|
|
626
|
+
ax.set_ylabel("Variance")
|
|
627
|
+
ax.grid(alpha=0.8, linestyle="--")
|
|
628
|
+
|
|
629
|
+
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.1
|
|
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
|
|
|
@@ -143,6 +146,15 @@ DataFrame or for a single specified variable.
|
|
|
143
146
|
The function applies consistent styling for the boxes, outliers, and median
|
|
144
147
|
lines using predefined colors from 'paper_colors'.
|
|
145
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
|
+
|
|
146
158
|
# Examples
|
|
147
159
|
- [Example 1](https://gitlab.com/direl/direl_tool_kit/-/blob/main/example/example_01.md?ref_type=heads)
|
|
148
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=XQfz9deexMLvzhM6ABD_eGghVpaAD3Vy0aRzSEny1Yc,19480
|
|
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.1.dist-info/licenses/LICENCE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
direl_ts_tool_kit-0.9.1.dist-info/METADATA,sha256=J8WGPY3VWni35UwIz0xm50qDhnFKLHA3mO_4vVb-Qek,5773
|
|
9
|
+
direl_ts_tool_kit-0.9.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
10
|
+
direl_ts_tool_kit-0.9.1.dist-info/top_level.txt,sha256=vMCRudnGnsdRg_6fUftnG8PF2Y1m0bjBDMf3pCAp6bc,18
|
|
11
|
+
direl_ts_tool_kit-0.9.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|