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

Commit 07a1448

Browse files
authored
Merge pull request #284 from openclimatefix/jacob/downsampling
Add Downsampling and new Mean/Stddev for India
2 parents 91403ec + 17c7f46 commit 07a1448

File tree

4 files changed

+77
-6
lines changed

4 files changed

+77
-6
lines changed

ocf_datapipes/training/common.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,3 +1215,11 @@ def create_t0_and_loc_datapipes(
12151215
location_pipe, t0_datapipe = t0_loc_datapipe.unzip(sequence_length=2)
12161216

12171217
return location_pipe, t0_datapipe
1218+
1219+
1220+
def potentially_coarsen(xr_data: xr.Dataset):
1221+
"""Coarsen the data, if it is separated by 0.05 degrees each"""
1222+
if "latitude" in xr_data.coords and "longitude" in xr_data.coords:
1223+
if xr_data.latitude.values[1] - xr_data.latitude.values[0] == 0.05:
1224+
xr_data = xr_data.coarsen(latitude=2, longitude=2)
1225+
return xr_data

ocf_datapipes/training/pvnet_site.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
fill_nans_in_arrays,
1717
fill_nans_in_pv,
1818
normalize_gsp,
19+
potentially_coarsen,
1920
slice_datapipes_by_time,
2021
)
2122
from ocf_datapipes.utils.consts import (
@@ -231,9 +232,16 @@ def construct_sliced_data_pipeline(
231232
roi_height_pixels=conf_nwp[nwp_key].nwp_image_size_pixels_height,
232233
roi_width_pixels=conf_nwp[nwp_key].nwp_image_size_pixels_width,
233234
)
235+
# Coarsen the data, if it is separated by 0.05 degrees each
236+
nwp_datapipe = nwp_datapipe.map(potentially_coarsen)
237+
# Somewhat hacky way for India specifically, need different mean/std for ECMWF data
238+
if conf_nwp[nwp_key].nwp_provider in ["ecmwf"]:
239+
normalize_provider = "ecmwf_india"
240+
else:
241+
normalize_provider = conf_nwp[nwp_key].nwp_provider
234242
nwp_datapipes_dict[nwp_key] = nwp_datapipe.normalize(
235-
mean=NWP_MEANS[conf_nwp[nwp_key].nwp_provider],
236-
std=NWP_STDS[conf_nwp[nwp_key].nwp_provider],
243+
mean=NWP_MEANS[normalize_provider],
244+
std=NWP_STDS[normalize_provider],
237245
)
238246

239247
if "sat" in datapipes_dict:

ocf_datapipes/training/windnet.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
fill_nans_in_pv,
1818
normalize_gsp,
1919
normalize_wind,
20+
potentially_coarsen,
2021
slice_datapipes_by_time,
2122
)
2223
from ocf_datapipes.utils.consts import (
@@ -236,9 +237,15 @@ def construct_sliced_data_pipeline(
236237
roi_height_pixels=conf_nwp[nwp_key].nwp_image_size_pixels_height,
237238
roi_width_pixels=conf_nwp[nwp_key].nwp_image_size_pixels_width,
238239
)
240+
nwp_datapipe = nwp_datapipe.map(potentially_coarsen)
241+
# Somewhat hacky way for India specifically, need different mean/std for ECMWF data
242+
if conf_nwp[nwp_key].nwp_provider in ["ecmwf"]:
243+
normalize_provider = "ecmwf_india"
244+
else:
245+
normalize_provider = conf_nwp[nwp_key].nwp_provider
239246
nwp_datapipes_dict[nwp_key] = nwp_datapipe.normalize(
240-
mean=NWP_MEANS[conf_nwp[nwp_key].nwp_provider],
241-
std=NWP_STDS[conf_nwp[nwp_key].nwp_provider],
247+
mean=NWP_MEANS[normalize_provider],
248+
std=NWP_STDS[normalize_provider],
242249
)
243250

244251
if upsample_nwp:

ocf_datapipes/utils/consts.py

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __getitem__(self, key):
3535

3636
# --------------------------- NWP ------------------------------------
3737

38-
NWP_PROVIDERS = ["ukv", "gfs", "icon-eu", "icon-global", "ecmwf"]
38+
NWP_PROVIDERS = ["ukv", "gfs", "icon-eu", "icon-global", "ecmwf", "ecmwf_india"]
3939

4040
# ------ UKV
4141
# Means and std computed WITH version_7 and higher, MetOffice values
@@ -189,19 +189,67 @@ def __getitem__(self, key):
189189
ECMWF_STD = _to_data_array(ECMWF_STD)
190190
ECMWF_MEAN = _to_data_array(ECMWF_MEAN)
191191

192+
# These were calculated from 200 random init times of ECMWF data from 2020-2024
193+
INDIA_ECMWF_MEAN = {
194+
"dlwrf": 56931292.0,
195+
"dswrf": 31114434.0,
196+
"duvrs": 3363442.75,
197+
"hcc": 0.2640938460826874,
198+
"lcc": 0.09548956900835037,
199+
"mcc": 0.11118797957897186,
200+
"prate": 3.028022729267832e-05,
201+
"sde": 0.0015021926956251264,
202+
"sr": 31403020.0,
203+
"t2m": 298.24462890625,
204+
"tcc": 0.33420485258102417,
205+
"u10": 0.7755107283592224,
206+
"u100": 1.0605329275131226,
207+
"u200": 1.2298915386199951,
208+
"v10": 0.02332865633070469,
209+
"v100": -0.07577426731586456,
210+
"v200": -0.1255049854516983,
211+
}
212+
213+
INDIA_ECMWF_STD = {
214+
"dlwrf": 34551808.0,
215+
"dswrf": 21211150.0,
216+
"duvrs": 2300205.5,
217+
"hcc": 0.3942722678184509,
218+
"lcc": 0.22802403569221497,
219+
"mcc": 0.2254289835691452,
220+
"prate": 0.00023954990319907665,
221+
"sde": 0.09043189883232117,
222+
"sr": 23481620.0,
223+
"t2m": 7.574307918548584,
224+
"tcc": 0.4046371579170227,
225+
"u10": 2.7440550327301025,
226+
"u100": 4.084362506866455,
227+
"u200": 4.770451068878174,
228+
"v10": 2.401158571243286,
229+
"v100": 3.5278923511505127,
230+
"v200": 3.974159002304077,
231+
}
232+
233+
234+
INDIA_ECMWF_VARIABLE_NAMES = tuple(INDIA_ECMWF_MEAN.keys())
235+
INDIA_ECMWF_STD = _to_data_array(INDIA_ECMWF_STD)
236+
INDIA_ECMWF_MEAN = _to_data_array(INDIA_ECMWF_MEAN)
237+
192238
# ------ ALL NWPS
193239
# These dictionaries are for convenience
194240
NWP_VARIABLE_NAMES = NWPStatDict(
195241
ukv=UKV_VARIABLE_NAMES,
196242
gfs=GFS_VARIABLE_NAMES,
197243
ecmwf=ECMWF_VARIABLE_NAMES,
244+
ecmwf_india=INDIA_ECMWF_VARIABLE_NAMES,
198245
)
199246
NWP_STDS = NWPStatDict(
200247
ukv=UKV_STD,
201248
gfs=GFS_STD,
202249
ecmwf=ECMWF_STD,
250+
ecmwf_india=INDIA_ECMWF_STD,
203251
)
204-
NWP_MEANS = NWPStatDict(ukv=UKV_MEAN, gfs=GFS_MEAN, ecmwf=ECMWF_MEAN)
252+
NWP_MEANS = NWPStatDict(ukv=UKV_MEAN, gfs=GFS_MEAN, ecmwf=ECMWF_MEAN, ecmwf_india=INDIA_ECMWF_MEAN)
205253

206254
# --------------------------- SATELLITE ------------------------------
207255

0 commit comments

Comments
 (0)