Skip to content
This repository was archived by the owner on Jun 2, 2025. It is now read-only.

Commit 3d8b0c2

Browse files
Merge pull request #362 from openclimatefix/satellite-scalling
Satellite scalling
2 parents 4bf534e + a1b10d7 commit 3d8b0c2

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

ocf_datapipes/config/model.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,11 @@ class Satellite(DataSourceMixin, TimeResolutionMixin, DropoutMixin):
502502
description="The temporal resolution (in minutes) of the data."
503503
"Note that this needs to be divisible by 5.",
504504
)
505+
satellite_scaling_methods: Optional[List[str]] = Field(
506+
["mean_std"],
507+
description="There are few ways to scale the satellite data. "
508+
"1. None, 2. mean_std, 3. min_max",
509+
)
505510

506511

507512
class HRVSatellite(DataSourceMixin, TimeResolutionMixin, DropoutMixin):

ocf_datapipes/training/pvnet_site.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
NWP_MEANS,
2525
NWP_STDS,
2626
RSS_MEAN,
27+
RSS_RAW_MAX,
28+
RSS_RAW_MIN,
2729
RSS_STD,
2830
)
2931
from ocf_datapipes.utils.utils import (
@@ -273,7 +275,11 @@ def construct_sliced_data_pipeline(
273275
roi_height_pixels=conf_sat.satellite_image_size_pixels_height,
274276
roi_width_pixels=conf_sat.satellite_image_size_pixels_width,
275277
)
276-
sat_datapipe = sat_datapipe.normalize(mean=RSS_MEAN, std=RSS_STD)
278+
scaling_methods = conf_sat.satellite_scaling_methods
279+
if "min_max" in scaling_methods:
280+
sat_datapipe = sat_datapipe.normalize(min_values=RSS_RAW_MIN, max_values=RSS_RAW_MAX)
281+
if "mean_std" in scaling_methods:
282+
sat_datapipe = sat_datapipe.normalize(mean=RSS_MEAN, std=RSS_STD)
277283

278284
if "pv" in datapipes_dict:
279285
# Recombine Sensor arrays - see function doc for further explanation

ocf_datapipes/transform/xarray/normalize.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ def __init__(
2222
max_value: Optional[Union[int, float]] = None,
2323
calculate_mean_std_from_example: bool = False,
2424
normalize_fn: Optional[Callable] = None,
25+
min_values: Optional[Union[xr.Dataset, xr.DataArray, np.ndarray]] = None,
26+
max_values: Optional[Union[xr.Dataset, xr.DataArray, np.ndarray]] = None,
2527
):
2628
"""
2729
Normalize the data with either given mean/std,
@@ -37,13 +39,17 @@ def __init__(
3739
calculate_mean_std_from_example: Whether to calculate the
3840
mean/std from the input data or not
3941
normalize_fn: Callable function to apply to the data to normalize it
42+
min_values: Min values for each channel
43+
max_values: Max values for each channel
4044
"""
4145
self.source_datapipe = source_datapipe
4246
self.mean = mean
4347
self.std = std
4448
self.max_value = max_value
4549
self.calculate_mean_std_from_example = calculate_mean_std_from_example
4650
self.normalize_fn = normalize_fn
51+
self.min_values = min_values
52+
self.max_values = max_values
4753

4854
def __iter__(self) -> Union[xr.Dataset, xr.DataArray]:
4955
"""Normalize the data depending on the init arguments"""
@@ -61,6 +67,8 @@ def __iter__(self) -> Union[xr.Dataset, xr.DataArray]:
6167
# For Topo data for example
6268
xr_data -= xr_data.mean().item()
6369
xr_data /= xr_data.std().item()
70+
elif (self.min_values is not None) and (self.max_values is not None):
71+
xr_data = (xr_data - self.min_values) / (self.max_values - self.min_values)
6472
else:
6573
try:
6674
logger.debug(f"Normalizing by {self.normalize_fn}")

ocf_datapipes/utils/consts.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,41 @@ def __getitem__(self, key):
413413
RSS_STD = _to_data_array(RSS_STD)
414414
RSS_MEAN = _to_data_array(RSS_MEAN)
415415

416+
# normalizing from raw values
417+
418+
RSS_RAW_MIN = {
419+
"IR_016": -2.5118103,
420+
"IR_039": -64.83977,
421+
"IR_087": 63.404694,
422+
"IR_097": 2.844452,
423+
"IR_108": 199.10002,
424+
"IR_120": -17.254883,
425+
"IR_134": -26.29155,
426+
"VIS006": -1.1009827,
427+
"VIS008": -2.4184198,
428+
"WV_062": 199.57048,
429+
"WV_073": 198.95093,
430+
"HRV": -1.2278595,
431+
}
432+
433+
RSS_RAW_MAX = {
434+
"IR_016": 69.60857,
435+
"IR_039": 339.15588,
436+
"IR_087": 340.26526,
437+
"IR_097": 317.86752,
438+
"IR_108": 313.2767,
439+
"IR_120": 315.99194,
440+
"IR_134": 274.82297,
441+
"VIS006": 93.786545,
442+
"VIS008": 101.34922,
443+
"WV_062": 249.91806,
444+
"WV_073": 286.96323,
445+
"HRV": 103.90016,
446+
}
447+
448+
RSS_RAW_MIN = _to_data_array(RSS_RAW_MIN)
449+
RSS_RAW_MAX = _to_data_array(RSS_RAW_MAX)
450+
416451

417452
# --------------------------- SENSORS --------------------------------
418453

0 commit comments

Comments
 (0)