forked from pydata/xarray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreindexing.py
48 lines (36 loc) · 1.32 KB
/
reindexing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import numpy as np
import xarray as xr
from . import requires_dask
class Reindex:
def setup(self):
data = np.random.RandomState(0).randn(1000, 100, 100)
self.ds = xr.Dataset(
{"temperature": (("time", "x", "y"), data)},
coords={"time": np.arange(1000), "x": np.arange(100), "y": np.arange(100)},
)
def time_1d_coarse(self):
self.ds.reindex(time=np.arange(0, 1000, 5)).load()
def time_1d_fine_all_found(self):
self.ds.reindex(time=np.arange(0, 1000, 0.5), method="nearest").load()
def time_1d_fine_some_missing(self):
self.ds.reindex(
time=np.arange(0, 1000, 0.5), method="nearest", tolerance=0.1
).load()
def time_2d_coarse(self):
self.ds.reindex(x=np.arange(0, 100, 2), y=np.arange(0, 100, 2)).load()
def time_2d_fine_all_found(self):
self.ds.reindex(
x=np.arange(0, 100, 0.5), y=np.arange(0, 100, 0.5), method="nearest"
).load()
def time_2d_fine_some_missing(self):
self.ds.reindex(
x=np.arange(0, 100, 0.5),
y=np.arange(0, 100, 0.5),
method="nearest",
tolerance=0.1,
).load()
class ReindexDask(Reindex):
def setup(self):
requires_dask()
super().setup()
self.ds = self.ds.chunk({"time": 100})