direl-ts-tool-kit 0.8.1__tar.gz → 0.9.1__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: direl-ts-tool-kit
3
- Version: 0.8.1
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)
@@ -56,6 +56,7 @@ This function automatically sets major and minor time-based locators
56
56
  on the x-axis based on the specified time unit, and formats the y-axis
57
57
  to use scientific notation.
58
58
 
59
+
59
60
  #### plot_interpolation_analysis
60
61
  `plot_interpolation_analysis(df_original, variable, units="", method="polynomial", order=2, imputation_se=None, time_unit="Year", rot=90)`
61
62
 
@@ -72,6 +73,7 @@ Saves a Matplotlib figure in three common high-quality formats (PNG, PDF, SVG).
72
73
  The function creates a consistent file name structure:
73
74
  {path}/{file_name}_{variable_name}.{extension}.
74
75
 
76
+
75
77
  #### heat_map
76
78
  `heat_map(X, y, colors="Blues")`
77
79
 
@@ -80,6 +82,7 @@ Generates a correlation heatmap plot for a set of features and a target variable
80
82
  This function concatenates the feature DataFrame (X) and the target Series (y)
81
83
  to compute and visualize the full pairwise correlation matrix using Seaborn.
82
84
 
85
+
83
86
  #### pair_plot
84
87
  `pair_plot(X, y)`
85
88
 
@@ -110,6 +113,15 @@ DataFrame or for a single specified variable.
110
113
  The function applies consistent styling for the boxes, outliers, and median
111
114
  lines using predefined colors from 'paper_colors'.
112
115
 
116
+
117
+ #### plot_periodogram
118
+
119
+ `plot_periodogram(ts, detrend="linear", ax=None, fs=365.0, color="BLUE_LINES")`
120
+
121
+ Plots the power spectrum (periodogram) of a time series to identify
122
+ dominant frequencies (periodicity).
123
+
124
+
113
125
  # Examples
114
126
  - [Example 1](https://gitlab.com/direl/direl_tool_kit/-/blob/main/example/example_01.md?ref_type=heads)
115
127
  - [Example 2](https://gitlab.com/direl/direl_tool_kit/-/blob/main/example/example_02.md?ref_type=heads)
@@ -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
- ax.ticklabel_format(style="sci", axis="y", scilimits=(0, 0))
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.8.1
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)
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="direl-ts-tool-kit",
5
- version="0.8.1",
5
+ version="0.9.1",
6
6
  description="A toolbox for time series analysis and visualization.",
7
7
  long_description=open("README.md", encoding="utf-8").read(),
8
8
  long_description_content_type="text/markdown",