Skip to content

Commit

Permalink
convert UKV to float16
Browse files Browse the repository at this point in the history
  • Loading branch information
dfulu committed Mar 7, 2024
1 parent 9d40215 commit c962df0
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pvnet_app/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,23 @@ def fix_ecmwf_data():
# Re-save inplace
os.system(f"rm -rf {nwp_ecmwf_path}")
ds.to_zarr(nwp_ecmwf_path)


def fix_ukv_data():
"""Extra steps to align UKV production data with training
- In training the UKV data is float16. This causes it to overflow into inf values which are then
clipped.
"""

ds = xr.open_zarr(nwp_ukv_path).compute()
ds = ds.astype(np.float16)

ds["variable"] = ds["variable"].astype(str)

# Re-save inplace
os.system(f"rm -rf {nwp_ukv_path}")
ds.to_zarr(nwp_ukv_path)


def preprocess_nwp_data():
Expand All @@ -192,5 +209,8 @@ def preprocess_nwp_data():
method="conservative" # this is needed to avoid zeros around edges of ECMWF data
)

# UKV data must be float16 to allow overflow to inf like in training
fix_ukv_data()

# Names need to be aligned between training and prod, and we need to infill the shetlands
fix_ecmwf_data()

0 comments on commit c962df0

Please sign in to comment.