Skip to content

Commit

Permalink
Merge pull request #228 from NREL/pp/rex_regridder
Browse files Browse the repository at this point in the history
Use `rex Regridder` port
  • Loading branch information
ppinchuk committed Jul 29, 2024
2 parents 0dc8928 + e1b8f87 commit c72c817
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 316 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ xarray = ">=2023.0"

[tool.pixi.pypi-dependencies]
NREL-sup3r = { path = ".", editable = true }
NREL-rex = { version = ">=0.2.84" }
NREL-rex = { version = ">=0.2.87" }
NREL-phygnn = { version = ">=0.0.23" }
NREL-gaps = { version = ">=0.6.0" }
NREL-farms = { version = ">=1.0.4" }
Expand Down
2 changes: 1 addition & 1 deletion sup3r/preprocessing/extracters/dual.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import pandas as pd
import xarray as xr

from rex.utilities.regridder import Regridder
from sup3r.preprocessing.base import Container, Sup3rDataset
from sup3r.preprocessing.cachers import Cacher
from sup3r.preprocessing.names import Dimension
from sup3r.preprocessing.utilities import _compute_if_dask
from sup3r.utilities.regridder import Regridder
from sup3r.utilities.utilities import spatial_coarsening

logger = logging.getLogger(__name__)
Expand Down
267 changes: 0 additions & 267 deletions sup3r/utilities/regridder.py

This file was deleted.

48 changes: 1 addition & 47 deletions tests/utilities/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import matplotlib.pyplot as plt
import numpy as np
import pytest
from rex import Resource

from scipy.interpolate import interp1d

from sup3r.models.utilities import st_interp
Expand All @@ -18,7 +18,6 @@
weighted_time_sampler,
)
from sup3r.utilities.interpolation import Interpolator
from sup3r.utilities.regridder import Regridder
from sup3r.utilities.utilities import (
RANDOM_GENERATOR,
spatial_coarsening,
Expand Down Expand Up @@ -54,51 +53,6 @@ def between_check(first, mid, second):
assert u_check


def test_regridding():
"""Make sure regridding reproduces original data when coordinates in the
meta is the same"""

with Resource(pytest.FP_WTK) as res:
source_meta = res.meta.copy()
source_meta['gid'] = np.arange(len(source_meta))
shuffled_meta = source_meta.sample(frac=1, random_state=0)

regridder = Regridder(
source_meta=source_meta,
target_meta=shuffled_meta,
max_workers=1,
)

out = regridder(res['windspeed_100m', ...].T).T.compute()

assert np.array_equal(
res['windspeed_100m', ...][:, shuffled_meta['gid'].values], out
)

new_shuffled_meta = shuffled_meta.copy()
rand = RANDOM_GENERATOR.uniform(
0, 1e-12, size=(2 * len(shuffled_meta))
)
rand = rand.reshape((len(shuffled_meta), 2))
new_shuffled_meta['latitude'] += rand[:, 0]
new_shuffled_meta['longitude'] += rand[:, 1]

regridder = Regridder(
source_meta=source_meta,
target_meta=new_shuffled_meta,
max_workers=1,
min_distance=0,
)

out = regridder(res['windspeed_100m', ...].T).T.compute()

assert np.allclose(
res['windspeed_100m', ...][:, new_shuffled_meta['gid'].values],
out,
atol=0.1,
)


def test_get_chunk_slices():
"""Test get_chunk_slices function for correct start/end"""

Expand Down

0 comments on commit c72c817

Please sign in to comment.