NGI Utils¶
C M
pynasonde.vipir.ngi.utils — timezone conversion, outlier removal, smoothing, grid helpers.
pynasonde.vipir.ngi.utils
¶
Shared utilities for VIPIR NGI processing (time conversion, smoothing, etc.).
TimeZoneConversion
¶
Convert timestamps between UTC and a station's local timezone.
Source code in pynasonde/vipir/ngi/utils.py
__init__(local_tz=None, lat=37.8815, long=-75.4374)
¶
Initialize the converter with either a timezone name or coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
local_tz |
str
|
Explicit timezone name; inferred from lat/lon when None. |
None
|
lat |
float
|
Station latitude used when deriving the timezone. |
37.8815
|
long |
float
|
Station longitude used when deriving the timezone. |
-75.4374
|
Source code in pynasonde/vipir/ngi/utils.py
utc_to_local_time(dates)
¶
Translate an iterable of UTC datetimes to the configured local zone.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dates |
Iterable of naive or timezone-aware datetime objects. |
required |
Returns:
| Type | Description |
|---|---|
List of localized datetimes adjusted to |
Source code in pynasonde/vipir/ngi/utils.py
to_local_time(dates, tz1, tz2)
¶
Adjust naive datetimes from timezone tz1 into tz2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dates |
list
|
Iterable of datetime objects. |
required |
tz1 |
Origin timezone (pytz timezone). |
required | |
tz2 |
Destination timezone (pytz timezone). |
required |
Returns:
| Type | Description |
|---|---|
List of datetime objects converted to |
Source code in pynasonde/vipir/ngi/utils.py
remove_outliers(o, pname, quantiles=[0.05, 0.95])
¶
Trim rows where pname falls outside the provided quantile window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
o |
pd.DataFrame
|
Input dataframe. |
required |
pname |
str
|
Column name used to evaluate quantiles. |
required |
quantiles |
Lower and upper quantile thresholds. |
[0.05, 0.95]
|
Returns:
| Type | Description |
|---|---|
Filtered dataframe restricted to the quantile window. |
Source code in pynasonde/vipir/ngi/utils.py
running_median(arr, window=21)
¶
Compute a moving median with the given window size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr |
Sequence of values. |
required | |
window |
Sliding window length. |
21
|
Returns:
| Type | Description |
|---|---|
List of median values aligned with the input sequence. |
Source code in pynasonde/vipir/ngi/utils.py
smooth(x, window_len=11, window='hanning')
¶
Apply a windowed smoothing convolution to a 1-D array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x |
Input NumPy array (1-D). |
required | |
window_len |
Length of the smoothing window. |
11
|
|
window |
Window function name (flat, hanning, hamming, bartlett, blackman). |
'hanning'
|
Returns:
| Type | Description |
|---|---|
Smoothed NumPy array with edge handling. |
Source code in pynasonde/vipir/ngi/utils.py
setsize(size=8)
¶
Configure matplotlib/scienceplots defaults for a consistent style.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size |
Base font size applied to the plot configuration. |
8
|
Source code in pynasonde/vipir/ngi/utils.py
to_namespace(d)
¶
Recursively convert dicts/lists into SimpleNamespace instances.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d |
object
|
Arbitrary nested structure of dicts/lists/primitives. |
required |
Returns:
| Type | Description |
|---|---|
SimpleNamespace
|
Equivalent structure with dicts converted to |
Source code in pynasonde/vipir/ngi/utils.py
load_toml(fpath=None)
¶
Load a TOML configuration file into nested SimpleNamespace objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fpath |
str
|
Optional explicit path to a TOML file; defaults to bundled config. |
None
|
Returns:
| Type | Description |
|---|---|
SimpleNamespace
|
SimpleNamespace representation of the parsed TOML. |
Source code in pynasonde/vipir/ngi/utils.py
get_color_by_index(index, total_indices, cmap_name='viridis')
¶
Pick a color from a colormap using an index within [0, total).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index |
Position within the available color slots. |
required | |
total_indices |
Total number of available slots. |
required | |
cmap_name |
Matplotlib colormap name. |
'viridis'
|
Returns:
| Type | Description |
|---|---|
RGBA tuple sampled from the requested colormap. |
Source code in pynasonde/vipir/ngi/utils.py
get_gridded_parameters(q, xparam, yparam, zparam, r=1, rounding=True)
¶
Reshape scattered parameter samples onto an evenly-spaced grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q |
Dataframe containing the source columns. |
required | |
xparam |
Column name used for the X dimension. |
required | |
yparam |
Column name used for the Y dimension. |
required | |
zparam |
Column name containing the values to grid. |
required | |
r |
Rounding precision applied before grouping. |
1
|
|
rounding |
Whether to round values prior to pivoting. |
True
|
Returns:
| Type | Description |
|---|---|
Tuple of |