generated from openclimatefix/ocf-template
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from openclimatefix/spatial_slice_tests
Spatial slice tests
- Loading branch information
Showing
13 changed files
with
383 additions
and
262 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
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
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
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
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
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
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,29 @@ | ||
import xarray as xr | ||
import pandas as pd | ||
|
||
def check_time_unique_increasing(datetimes) -> None: | ||
"""Check that the time dimension is unique and increasing""" | ||
time = pd.DatetimeIndex(datetimes) | ||
assert time.is_unique | ||
assert time.is_monotonic_increasing | ||
|
||
def make_spatial_coords_increasing(ds: xr.Dataset, x_coord: str, y_coord: str) -> xr.Dataset: | ||
"""Make sure the spatial coordinates are in increasing order | ||
Args: | ||
ds: Xarray Dataset | ||
x_coord: Name of the x coordinate | ||
y_coord: Name of the y coordinate | ||
""" | ||
|
||
# Make sure the coords are in increasing order | ||
if ds[x_coord][0] > ds[x_coord][-1]: | ||
ds = ds.isel({x_coord:slice(None, None, -1)}) | ||
if ds[y_coord][0] > ds[y_coord][-1]: | ||
ds = ds.isel({y_coord:slice(None, None, -1)}) | ||
|
||
# Check the coords are all increasing now | ||
assert (ds[x_coord].diff(dim=x_coord) > 0).all() | ||
assert (ds[y_coord].diff(dim=y_coord) > 0).all() | ||
|
||
return ds |
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
Oops, something went wrong.