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

Commit 6451ed9

Browse files
committed
Fix potentially coarsen to take alternating points
Since ECMWF just interpolates to lower than 0.1, the 0.1 values should be right, so take those instead here
1 parent 45d8436 commit 6451ed9

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

ocf_datapipes/training/common.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,13 @@ def create_t0_and_loc_datapipes(
12201220
def potentially_coarsen(xr_data: xr.Dataset):
12211221
"""Coarsen the data, if it is separated by 0.05 degrees each"""
12221222
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)
1223+
if np.isclose(np.abs(xr_data.latitude.values[1] - xr_data.latitude.values[0]), 0.05):
1224+
# Take every second latitude and longitude point, no interpolation, from the first point, or second,
1225+
# Check if the first point is 0.05 degrees or not, only take ones that are 0.1
1226+
# Check if the first point rounds to the same 0.1 as itself, otherwise take the second point
1227+
if np.isclose(np.round(xr_data.latitude.values[0], 1), xr_data.latitude.values[0]):
1228+
xr_data = xr_data.isel(latitude=slice(0, None, 2), longitude=slice(0, None, 2))
1229+
else:
1230+
xr_data = xr_data.isel(latitude=slice(1, None, 2), longitude=slice(1, None, 2))
1231+
# xr_data = xr_data.coarsen(latitude=2, longitude=2, coord_func="").mean()
12251232
return xr_data

ocf_datapipes/training/windnet.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -391,19 +391,18 @@ def windnet_netcdf_datapipe(
391391

392392
if __name__ == "__main__":
393393
# Load the ECMWF and sensor data here
394-
datapipe = windnet_datapipe(
395-
config_filename="/home/jacob/Development/ocf_datapipes/tests/config/india_test.yaml",
396-
start_time=datetime(2023, 1, 1),
397-
end_time=datetime(2023, 11, 2),
398-
)
399-
batch = next(iter(datapipe))
400-
print(batch)
401-
batch.to_netcdf("test.nc", engine="h5netcdf")
394+
# datapipe = windnet_datapipe(
395+
# config_filename="/home/jacob/Development/ocf_datapipes/tests/config/india_test.yaml",
396+
# start_time=datetime(2023, 1, 1),
397+
# end_time=datetime(2023, 11, 2),
398+
# )
399+
# batch = next(iter(datapipe))
400+
# print(batch)
401+
# batch.to_netcdf("test.nc", engine="h5netcdf")
402402
# Load the saved NetCDF files here
403403
datapipe = windnet_netcdf_datapipe(
404-
config_filename="/home/jacob/Development/ocf_datapipes/tests/config/india_test.yaml",
405-
keys=["nwp", "sensor"],
406-
filenames=["test.nc"],
404+
keys=["nwp", "wind"],
405+
filenames=["/run/media/jacob/data/windnet_india_batches_medium/val/000000.nc"],
407406
)
408407
batch = next(iter(datapipe))
409-
print(batch)
408+
# print(batch)

0 commit comments

Comments
 (0)