Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[skip-ci] Add alignment benchmarks #7738

Merged
merged 3 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion asv_bench/asv.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
"distributed": [""],
"flox": [""],
"numpy_groupies": [""],
"sparse": [""]
"sparse": [""],
"cftime": [""]
},


Expand Down
45 changes: 45 additions & 0 deletions asv_bench/benchmarks/alignment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import numpy as np

import xarray as xr

from . import parameterized, requires_dask

ntime = 365 * 30
nx = 50
ny = 50


class Align:
def setup(self, *args, **kwargs):
data = np.random.RandomState(0).randn(ntime, nx, ny)
self.ds = xr.Dataset(
{"temperature": (("time", "x", "y"), data)},
coords={
"time": xr.date_range("2000", periods=ntime),
"x": np.arange(nx),
"y": np.arange(ny),
},
)
self.year = self.ds.time.dt.year

@parameterized(["join"], [("outer", "inner", "left", "right", "exact", "override")])
def time_already_aligned(self, join):
xr.align(self.ds, self.year, join=join)

@parameterized(["join"], [("outer", "inner", "left", "right")])
def time_not_aligned(self, join):
xr.align(self.ds, self.year[-100:], join=join)


class AlignCFTime(Align):
def setup(self, *args, **kwargs):
super().setup()
self.ds["time"] = xr.date_range("2000", periods=ntime, calendar="noleap")
self.year = self.ds.time.dt.year


class AlignDask(Align):
def setup(self, *args, **kwargs):
requires_dask()
super().setup()
self.ds = self.ds.chunk({"time": 100})