Datasets:
Update RTC channel-specific normalization helper
Browse files- nasar_dataset.py +25 -8
nasar_dataset.py
CHANGED
|
@@ -22,19 +22,36 @@ import numpy as np
|
|
| 22 |
import pandas as pd
|
| 23 |
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
|
| 33 |
def _prepare_rtc(
|
| 34 |
arr: np.ndarray,
|
| 35 |
log_scale: bool,
|
| 36 |
alpha: float,
|
| 37 |
-
norm_stats:
|
| 38 |
) -> np.ndarray:
|
| 39 |
"""Apply the same RTC preprocessing used during NASAR pretraining."""
|
| 40 |
arr = arr.astype(np.float32, copy=True)
|
|
@@ -145,7 +162,7 @@ class NASARRTCDataset(_NASARBase):
|
|
| 145 |
years: list[int] | None = None,
|
| 146 |
random_temporal: bool = True,
|
| 147 |
min_quality_score: float | None = 0.53,
|
| 148 |
-
norm_stats:
|
| 149 |
shard_size: int = 10_000,
|
| 150 |
) -> None:
|
| 151 |
super().__init__(
|
|
|
|
| 22 |
import pandas as pd
|
| 23 |
|
| 24 |
|
| 25 |
+
RTC_COPOL_NORM_STATS = (0.150255, 2.387287)
|
| 26 |
+
RTC_XPOL_NORM_STATS = (0.02, 1.09)
|
| 27 |
+
DEFAULT_RTC_NORM_STATS = (RTC_COPOL_NORM_STATS, RTC_XPOL_NORM_STATS)
|
| 28 |
+
RTCNormStats = tuple[float, float] | tuple[tuple[float, float], tuple[float, float]]
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def _normalize_rtc(arr: np.ndarray, norm_stats: RTCNormStats) -> np.ndarray:
|
| 32 |
+
"""Clip to channel p1/p99 and rescale to [0, 1]. Zeros stay zero.
|
| 33 |
+
|
| 34 |
+
``norm_stats`` can be either a shared ``(p1, p99)`` tuple or
|
| 35 |
+
``((co_p1, co_p99), (x_p1, x_p99))`` for channel-specific RTC normalization.
|
| 36 |
+
"""
|
| 37 |
+
out = arr.astype(np.float32, copy=True)
|
| 38 |
+
first = norm_stats[0]
|
| 39 |
+
if isinstance(first, (tuple, list, np.ndarray)):
|
| 40 |
+
channel_stats = norm_stats
|
| 41 |
+
else:
|
| 42 |
+
channel_stats = (norm_stats,) * out.shape[0]
|
| 43 |
+
|
| 44 |
+
for ch, (p1, p99) in enumerate(channel_stats[: out.shape[0]]):
|
| 45 |
+
valid = out[ch] > 0
|
| 46 |
+
out[ch] = np.where(valid, np.clip((out[ch] - p1) / (p99 - p1), 0.0, 1.0), 0.0)
|
| 47 |
+
return out
|
| 48 |
|
| 49 |
|
| 50 |
def _prepare_rtc(
|
| 51 |
arr: np.ndarray,
|
| 52 |
log_scale: bool,
|
| 53 |
alpha: float,
|
| 54 |
+
norm_stats: RTCNormStats | None,
|
| 55 |
) -> np.ndarray:
|
| 56 |
"""Apply the same RTC preprocessing used during NASAR pretraining."""
|
| 57 |
arr = arr.astype(np.float32, copy=True)
|
|
|
|
| 162 |
years: list[int] | None = None,
|
| 163 |
random_temporal: bool = True,
|
| 164 |
min_quality_score: float | None = 0.53,
|
| 165 |
+
norm_stats: RTCNormStats | None = DEFAULT_RTC_NORM_STATS,
|
| 166 |
shard_size: int = 10_000,
|
| 167 |
) -> None:
|
| 168 |
super().__init__(
|