Helper Utilities
Helper utilities for Macrodata Refinement (MDR).
This module provides utility functions for data validation, transformation, and management.
- mdr.utils.helpers.validate_numeric_array(arr, allow_nan=True, min_val=None, max_val=None)[source]
Validate that an array consists of numeric values.
- Parameters:
- Returns:
True if the array is valid, False otherwise
- Return type:
- mdr.utils.helpers.validate_range(value, min_val, max_val, inclusive=True)[source]
Check if a value is within a specified range.
- mdr.utils.helpers.moving_average(data, window_size, center=False)[source]
Calculate the moving average of a data array.
- mdr.utils.helpers.detect_seasonality(data, max_lag=365, threshold=0.3)[source]
Detect seasonality in a time series using autocorrelation.
- Parameters:
- Returns:
Tuple of (is_seasonal, period), where period is the detected seasonal period or None if no seasonality is detected
- Return type:
- mdr.utils.helpers.interpolate_missing(data, method='linear', max_gap=None, order=None)[source]
Interpolate missing values in a data array.
- Parameters:
- Returns:
Data array with missing values interpolated
- Return type:
<MagicMock id=’136017403852016’>
- mdr.utils.helpers.unflatten_dict(d, sep='.')[source]
Convert a flattened dictionary back to a nested dictionary.
- mdr.utils.helpers.get_memory_usage(obj=None, unit='MB')[source]
Get the memory usage of an object or the current process.
Overview
The helpers module provides utility functions that support various operations
across the MDR package. These helper functions include data type conversion,
validation utilities, statistical functions, and more.
Core Functions
Helper Functions
- mdr.utils.helpers.moving_average(data, window_size, center=False)[source]
Calculate the moving average of a data array.
Usage Examples
Moving average example:
import numpy as np
from mdr.utils.helpers import moving_average
# Create sample data
data = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
# Calculate moving average with window size 3
ma_data = moving_average(data, window_size=3)
print(f"Original data: {data}")
print(f"Moving average: {ma_data}")