This repository has been archived by the owner on Aug 30, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resample NWP to half hourly. Closes #143
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |