Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit cbbfd28

Browse files
Merge pull request #335 from openclimatefix/nwp-int16
nwp float16
2 parents e8a355d + 16d6652 commit cbbfd28

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+12
-5
lines changed

nowcasting_dataset/data_sources/nwp/nwp_data_source.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def _post_process_example(
118118
selected_data = selected_data.interpolate()
119119
selected_data = selected_data.sel(target_time=slice(start_dt, end_dt))
120120
selected_data = selected_data.rename({"target_time": "time", "variable": "channels"})
121-
selected_data.data = selected_data.data.astype(np.float32)
121+
selected_data.data = selected_data.data.astype(np.float16)
122122

123123
return selected_data
124124

nowcasting_dataset/data_sources/satellite/satellite_data_source.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def _get_time_slice(self, t0_dt: pd.Timestamp) -> xr.DataArray:
5555
start_dt = self._get_start_dt(t0_dt)
5656
end_dt = self._get_end_dt(t0_dt)
5757
data = self.data.sel(time=slice(start_dt, end_dt))
58+
5859
return data
5960

6061
def datetime_index(self, remove_night: bool = True) -> pd.DatetimeIndex:

scripts/generate_data_for_tests/generate_satellite_test_data.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
#!/usr/bin/env python3
1+
""" Make satellite test data """
2+
import os
23
from pathlib import Path
34

45
import numcodecs
56
import pandas as pd
67
import xarray as xr
78

9+
import nowcasting_dataset
810
from nowcasting_dataset import consts
911

1012
START = pd.Timestamp("2019-01-01T12:00")
1113
END = pd.Timestamp("2019-01-01T18:00")
12-
OUTPUT_PATH = Path(__file__).parent.absolute() / ".." / "nowcasting_dataset" / "tests" / "data"
14+
OUTPUT_PATH = Path(os.path.dirname(nowcasting_dataset.__file__)).parent / "tests" / "data"
15+
print(OUTPUT_PATH)
1316

1417

1518
def generate_satellite_test_data():
19+
""" Main function to make satelllite test data """
1620
output_filename = OUTPUT_PATH / "sat_data.zarr"
1721
print("Writing satellite tests data to", output_filename)
18-
sat_data = xr.open_zarr(consts.SAT_DATA_ZARR, consolidated=True)
22+
sat_data = xr.open_zarr(consts.SAT_FILENAME, consolidated=True)
1923
sat_data = sat_data.sel(variable=["HRV"], time=slice(START, END))
2024
encoding = {"stacked_eumetsat_data": {"compressor": numcodecs.Blosc(cname="zstd", clevel=5)}}
2125
sat_data = sat_data.chunk({"time": 1, "y": 704, "x": 548, "variable": 1})

scripts/generate_data_for_tests/get_test_data.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import gcsfs
99
import numcodecs
10+
import numpy as np
1011
import pandas as pd
1112
import xarray as xr
1213

@@ -70,13 +71,14 @@
7071
"UKV__2018-01_to_2019-12__chunks__variable10__init_time1__step1__x548__y704__.zarr"
7172
)
7273

73-
nwp_data_raw = open_nwp(filename=NWP_BASE_PATH, consolidated=True)
74+
nwp_data_raw = open_nwp(zarr_path=NWP_BASE_PATH, consolidated=True)
7475
nwp_data = nwp_data_raw.sel(variable=list(NWP_VARIABLE_NAMES))
7576
nwp_data = nwp_data.sel(init_time=slice(start_dt, end_dt))
7677
nwp_data = nwp_data.sel(variable=["t"])
7778
nwp_data = nwp_data.sel(step=slice(nwp_data.step[0], nwp_data.step[4])) # take 4 hours periods
7879
# nwp_data = nwp_data.sel(x=slice(nwp_data.x[50], nwp_data.x[100]))
7980
# nwp_data = nwp_data.sel(y=slice(nwp_data.y[50], nwp_data.y[100]))
81+
nwp_data.UKV.values = nwp_data.UKV.values.astype(np.float16)
8082

8183
nwp_data.to_zarr(f"{local_path}/tests/data/nwp_data/test.zarr")
8284

-158 KB
Binary file not shown.
-159 KB
Binary file not shown.
-159 KB
Binary file not shown.
-160 KB
Binary file not shown.
-162 KB
Binary file not shown.
-162 KB
Binary file not shown.

0 commit comments

Comments
 (0)