-
Notifications
You must be signed in to change notification settings - Fork 4
/
transform.py
26 lines (18 loc) · 878 Bytes
/
transform.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
"""Transformations."""
__all__ = ["rotateinplane", "rotatestackinplane"]
import numpy as np
import xarray as xr
def rotateinplane(data: xr.DataArray, rotate, **interp_kwargs):
interp_kwargs.setdefault("method", "linearfast")
theta = np.radians(rotate)
d0, d1 = data.dims
x = xr.DataArray(data[d0] * np.cos(theta) - data[d1] * np.sin(theta))
y = xr.DataArray(data[d0] * np.sin(theta) + data[d1] * np.cos(theta))
return data.interp({d0: x, d1: y}, **interp_kwargs)
def rotatestackinplane(data: xr.DataArray, rotate, **interp_kwargs):
interp_kwargs.setdefault("method", "linearfast")
theta = np.radians(rotate)
d0, d1, _ = data.dims
x = xr.DataArray(data[d0] * np.cos(theta) - data[d1] * np.sin(theta))
y = xr.DataArray(data[d0] * np.sin(theta) + data[d1] * np.cos(theta))
return data.interp({d0: x, d1: y}, **interp_kwargs)