Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
Resample NWP to half hourly. Closes #143
Browse files Browse the repository at this point in the history
  • Loading branch information
JackKelly committed Jun 17, 2022
1 parent 0c66bf3 commit 7a0c8e9
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions power_perceiver/transforms/nwp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from dataclasses import dataclass
from typing import Union

import xarray as xr

from power_perceiver.time import set_new_sample_period_and_t0_idx_attrs


@dataclass
class NWPInterpolate:
"""Interpolate NWPs.
The xr.Dataset is modified in-place, and is returned.
Initialisation arguments:
freq:
"""

freq: str = "30T"
kind: str = "cubic"

def __call__(self, xr_data: Union[xr.Dataset, xr.DataArray]) -> Union[xr.Dataset, xr.DataArray]:
xr_data = xr_data.resample(target_time_utc=self.freq).interpolate(kind=self.kind)
xr_data = set_new_sample_period_and_t0_idx_attrs(xr_data, new_sample_period=self.freq)
return xr_data

0 comments on commit 7a0c8e9

Please sign in to comment.